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.wsba.participantcompletion.simple;
18  
19  import com.arjuna.mw.wst11.client.JaxWSHeaderContextProcessor;
20  
21  import org.jboss.as.quickstarts.wsba.participantcompletion.simple.jaxws.SetServiceBA;
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 SetService.
35   * 
36   * @author paul.robinson@redhat.com, 2012-01-04
37   */
38  @ClientStub
39  public class Client implements SetServiceBA {
40      private SetServiceBA set;
41  
42      /**
43       * Default constructor with hard-coded values for the SetService endpoint details (wsdl url, service name & port name)
44       * 
45       * @throws MalformedURLException if the WSDL url is malformed.
46       */
47      public Client() throws MalformedURLException {
48          URL wsdlLocation = new URL("http://localhost:8080/test/SetServiceBA?wsdl");
49          QName serviceName = new QName("http://www.jboss.org/jboss-jdf/jboss-as-quickstart/helloworld/wsba/participantcompletion/set",
50                  "SetServiceBAService");
51          QName portName = new QName("http://www.jboss.org/jboss-jdf/jboss-as-quickstart/helloworld/wsba/participantcompletion/set",
52                  "SetServiceBA");
53  
54          Service service = Service.create(wsdlLocation, serviceName);
55          set = service.getPort(portName, SetServiceBA.class);
56  
57          /*
58           * Add client handler chain so that XTS can add the transaction context to the SOAP messages.
59           */
60          BindingProvider bindingProvider = (BindingProvider) set;
61          @SuppressWarnings("rawtypes")
62          List<Handler> handlers = new ArrayList<Handler>(1);
63          handlers.add(new JaxWSHeaderContextProcessor());
64          bindingProvider.getBinding().setHandlerChain(handlers);
65      }
66  
67      /**
68       * Add a value to the set
69       * 
70       * @param value Value to add to the set.
71       * @throws AlreadyInSetException if the item is already in the set.
72       * @throws SetServiceException if an error occurred during the adding of the item to the set.
73       */
74      public void addValueToSet(String value) throws AlreadyInSetException, SetServiceException {
75          set.addValueToSet(value);
76      }
77  
78      /**
79       * Query the set to see if it contains a particular value.
80       * 
81       * @param value the value to check for.
82       * @return true if the value was present, false otherwise.
83       */
84      public boolean isInSet(String value) {
85          return set.isInSet(value);
86      }
87  
88      /**
89       * Empty the set
90       */
91      public void clear() {
92          set.clear();
93      }
94  }