View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.wsat.simple;
18  
19  import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
20  
21  import org.jboss.as.quickstarts.wsat.simple.jaxws.RestaurantServiceAT;
22  
23  import javax.xml.namespace.QName;
24  import javax.xml.ws.BindingProvider;
25  import javax.xml.ws.Service;
26  import javax.xml.ws.handler.Handler;
27  
28  import java.net.MalformedURLException;
29  import java.net.URL;
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  /**
34   * A Client stub to the restaurant service.
35   * 
36   * @author paul.robinson@redhat.com, 2012-01-04
37   */
38  @ClientStub
39  public class Client implements RestaurantServiceAT {
40      private RestaurantServiceAT restaurant;
41  
42      /**
43       * Default constructor with hard-coded values for the RestaurantServiceAT endpoint details (wsdl url, service name & port
44       * name)
45       * 
46       * @throws MalformedURLException if the WSDL url is malformed.
47       */
48      public Client() throws MalformedURLException {
49          URL wsdlLocation = new URL("http://localhost:8080/wsat-simple/RestaurantServiceAT?wsdl");
50          QName serviceName = new QName("http://www.jboss.org/jboss-jdf/jboss-as-quickstart/wsat/simple/Restaurant",
51                  "RestaurantServiceATService");
52          QName portName = new QName("http://www.jboss.org/jboss-jdf/jboss-as-quickstart/wsat/simple/Restaurant",
53                  "RestaurantServiceAT");
54  
55          Service service = Service.create(wsdlLocation, serviceName);
56          restaurant = service.getPort(portName, RestaurantServiceAT.class);
57  
58          /*
59           * Add client handler chain
60           */
61          BindingProvider bindingProvider = (BindingProvider) restaurant;
62          @SuppressWarnings("rawtypes")
63          List<Handler> handlers = new ArrayList<Handler>(1);
64          handlers.add(new JaxWSHeaderContextProcessor());
65          bindingProvider.getBinding().setHandlerChain(handlers);
66      }
67  
68      /**
69       * Create a new booking
70       */
71      @Override
72      public void makeBooking() throws RestaurantException {
73          restaurant.makeBooking();
74      }
75  
76      /**
77       * obtain the number of existing bookings
78       * 
79       * @return the number of current bookings
80       */
81      @Override
82      public int getBookingCount() {
83          return restaurant.getBookingCount();
84      }
85  
86      /**
87       * Reset the booking count to zero
88       */
89      @Override
90      public void reset() {
91          restaurant.reset();
92      }
93  }