001: package demo.ws_addressing.client;
002:
003: import java.io.File;
004: import java.lang.reflect.UndeclaredThrowableException;
005: import java.util.Map;
006: import javax.xml.namespace.QName;
007: import javax.xml.ws.BindingProvider;
008:
009: import org.objectweb.celtix.ws.addressing.AddressingBuilder;
010: import org.objectweb.celtix.ws.addressing.AddressingProperties;
011: import org.objectweb.celtix.ws.addressing.AttributedURIType;
012: import org.objectweb.celtix.ws.addressing.ObjectFactory;
013: import org.objectweb.celtix.ws.addressing.RelatesToType;
014:
015: import org.objectweb.hello_world_soap_http.Greeter;
016: import org.objectweb.hello_world_soap_http.PingMeFault;
017: import org.objectweb.hello_world_soap_http.SOAPService;
018:
019: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES;
020:
021: public final class Client {
022:
023: private static final QName SERVICE_NAME = new QName(
024: "http://objectweb.org/hello_world_soap_http", "SOAPService");
025: private static final ObjectFactory WSA_OBJECT_FACTORY = new ObjectFactory();
026: private static final String USER_NAME = System
027: .getProperty("user.name");
028:
029: private Client() {
030: }
031:
032: public static void main(String args[]) throws Exception {
033: if (args.length == 0) {
034: System.out.println("please specify wsdl");
035: System.exit(1);
036: }
037:
038: try {
039: File wsdl = new File(args[0]);
040: SOAPService service = new SOAPService(wsdl.toURL(),
041: SERVICE_NAME);
042: Greeter port = service.getSoapPort();
043:
044: implicitPropagation(port);
045:
046: explicitPropagation(port);
047:
048: implicitPropagation(port);
049:
050: } catch (UndeclaredThrowableException ex) {
051: ex.getUndeclaredThrowable().printStackTrace();
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: } finally {
055: System.exit(0);
056: }
057: }
058:
059: /**
060: * A series of invocations with implicitly propogated
061: * Message Addressing Properties.
062: */
063: private static void implicitPropagation(Greeter port) {
064: System.out.println();
065: System.out
066: .println("Implicit MessageAddressingProperties propagation");
067: System.out
068: .println("------------------------------------------------");
069:
070: System.out.println("Invoking sayHi...");
071: String resp = port.sayHi();
072: System.out.println("Server responded with: " + resp + "\n");
073:
074: System.out.println("Invoking greetMe...");
075: resp = port.greetMe(USER_NAME);
076: System.out.println("Server responded with: " + resp + "\n");
077:
078: System.out.println("Invoking greetMeOneWay...");
079: port.greetMeOneWay(USER_NAME);
080: System.out
081: .println("No response from server as method is OneWay\n");
082:
083: try {
084: System.out
085: .println("Invoking pingMe, expecting exception...");
086: port.pingMe();
087: } catch (PingMeFault ex) {
088: System.out.println("Expected exception occurred: " + ex);
089: }
090: }
091:
092: /**
093: * A series of invocations with explicitly propogated
094: * Message Addressing Properties.
095: */
096: private static void explicitPropagation(Greeter port) {
097: System.out.println();
098: System.out
099: .println("Explicit MessageAddressingProperties propagation");
100: System.out
101: .println("------------------------------------------------");
102:
103: // get Message Addressing Properties instance
104: AddressingBuilder builder = AddressingBuilder
105: .getAddressingBuilder();
106: AddressingProperties maps = builder.newAddressingProperties();
107:
108: // set MessageID property
109: AttributedURIType messageID = WSA_OBJECT_FACTORY
110: .createAttributedURIType();
111: messageID.setValue("urn:uuid:12345");
112: maps.setMessageID(messageID);
113:
114: // associate MAPs with request context
115: Map<String, Object> requestContext = ((BindingProvider) port)
116: .getRequestContext();
117: requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
118:
119: System.out.println("Invoking sayHi...");
120: String resp = port.sayHi();
121: System.out.println("Server responded with: " + resp + "\n");
122:
123: // clear the message ID to ensure a duplicate is not sent on the
124: // next invocation
125: maps.setMessageID(null);
126:
127: // set the RelatesTo property to the initial message ID, so that
128: // the series of invocations are explicitly related
129: RelatesToType relatesTo = WSA_OBJECT_FACTORY
130: .createRelatesToType();
131: relatesTo.setValue(messageID.getValue());
132: maps.setRelatesTo(relatesTo);
133:
134: System.out.println("Invoking greetMe...");
135: resp = port.greetMe(USER_NAME);
136: System.out.println("Server responded with: " + resp + "\n");
137:
138: System.out.println("Invoking greetMeOneWay...");
139: port.greetMeOneWay(USER_NAME);
140: System.out
141: .println("No response from server as method is OneWay\n");
142:
143: // disassociate MAPs from request context
144: requestContext.put(CLIENT_ADDRESSING_PROPERTIES, null);
145: }
146: }
|