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.wshelloworld;
18  
19  import org.jboss.as.quickstarts.wshelloworld.HelloWorldService;
20  
21  import javax.xml.namespace.QName;
22  import javax.xml.ws.Service;
23  import java.net.MalformedURLException;
24  import java.net.URL;
25  import java.util.List;
26  
27  /**
28   * A Client stub to the HelloWorld JAX-WS Web Service.
29   * 
30   * @author lnewson@redhat.com
31   */
32  public class Client implements HelloWorldService {
33      private HelloWorldService helloWorldService;
34  
35      /**
36       * Default constructor
37       * 
38       * @param url The URL to the Hello World WSDL endpoint.
39       */
40      public Client(final URL wsdlUrl) {
41          QName serviceName = new QName("http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld", "HelloWorldService");
42  
43          Service service = Service.create(wsdlUrl, serviceName);
44          helloWorldService = service.getPort(HelloWorldService.class);
45          assert (helloWorldService != null);
46      }
47      
48      /**
49       * Default constructor
50       * 
51       * @param url The URL to the Hello World WSDL endpoint.
52       * @throws MalformedURLException if the WSDL url is malformed.
53       */
54      public Client(final String url) throws MalformedURLException {
55          this(new URL(url));
56      }
57  
58      /**
59       * Gets the Web Service to say hello
60       */
61      @Override
62      public String sayHello() {
63          return helloWorldService.sayHello();
64      }
65  
66      /**
67       * Gets the Web Service to say hello to someone
68       */
69      @Override
70      public String sayHelloToName(final String name) {
71          return helloWorldService.sayHelloToName(name);
72      }
73  
74      /**
75       * Gets the Web Service to say hello to a group of people
76       */
77      @Override
78      public String sayHelloToNames(final List<String> names) {
79          return helloWorldService.sayHelloToNames(names);
80      }
81  }