001: package demo.jms_greeter.client;
002:
003: import java.io.File;
004: import java.lang.reflect.InvocationHandler;
005: import java.lang.reflect.Proxy;
006: import java.util.Map;
007:
008: import javax.xml.namespace.QName;
009: import javax.xml.ws.BindingProvider;
010: import org.objectweb.celtix.jms_greeter.JMSGreeterPortType;
011: import org.objectweb.celtix.jms_greeter.JMSGreeterService;
012: import org.objectweb.celtix.transports.jms.context.JMSMessageHeadersType;
013: import org.objectweb.celtix.transports.jms.context.JMSPropertyType;
014:
015: public final class Client {
016:
017: private static final QName SERVICE_NAME = new QName(
018: "http://celtix.objectweb.org/jms_greeter",
019: "JMSGreeterService");
020: private static final QName PORT_NAME = new QName(
021: "http://celtix.objectweb.org/jms_greeter",
022: "JMSGreeterPortType");
023:
024: private Client() {
025: }
026:
027: public static void main(String[] args) throws Exception {
028:
029: if (args.length == 0) {
030: System.out.println("please specify wsdl");
031: System.exit(1);
032: }
033:
034: File wsdl = new File(args[0]);
035:
036: JMSGreeterService service = new JMSGreeterService(wsdl.toURL(),
037: SERVICE_NAME);
038: JMSGreeterPortType greeter = (JMSGreeterPortType) service
039: .getPort(PORT_NAME, JMSGreeterPortType.class);
040:
041: System.out.println("Invoking sayHi...");
042: System.out.println("server responded with: " + greeter.sayHi());
043: System.out.println();
044:
045: System.out.println("Invoking greetMe...");
046: System.out.println("server responded with: "
047: + greeter.greetMe(System.getProperty("user.name")));
048: System.out.println();
049:
050: System.out.println("Invoking greetMeOneWay...");
051: greeter.greetMeOneWay(System.getProperty("user.name"));
052: System.out
053: .println("No response from server as method is OneWay");
054: System.out.println();
055:
056: // Demonstration of JMS Context usage
057:
058: InvocationHandler handler = Proxy.getInvocationHandler(greeter);
059:
060: BindingProvider bp = null;
061:
062: if (handler instanceof BindingProvider) {
063: bp = (BindingProvider) handler;
064: Map<String, Object> requestContext = bp.getRequestContext();
065: JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
066: requestHeader
067: .setJMSCorrelationID("JMS_QUEUE_SAMPLE_CORRELATION_ID");
068: requestHeader.setJMSExpiration(3600000L);
069: JMSPropertyType propType = new JMSPropertyType();
070: propType.setName("Test.Prop");
071: propType.setValue("mustReturn");
072: requestHeader.getProperty().add(propType);
073: requestContext.put(
074: "org.objectweb.celtix.jms.client.request.headers",
075: requestHeader);
076: //To override the default receive timeout.
077: requestContext.put(
078: "org.objectweb.celtix.jms.client.timeout",
079: new Long(1000));
080: }
081:
082: System.out
083: .println("Invoking sayHi with JMS Context information ...");
084: System.out.println("server responded with: " + greeter.sayHi());
085:
086: if (bp != null) {
087: Map<String, Object> responseContext = bp
088: .getResponseContext();
089: JMSMessageHeadersType responseHdr = (JMSMessageHeadersType) responseContext
090: .get("org.objectweb.celtix.jms.client.response.headers");
091: if (responseHdr == null) {
092: System.out
093: .println("response Header should not be null");
094: System.out.println();
095: System.exit(1);
096: }
097:
098: if ("JMS_QUEUE_SAMPLE_CORRELATION_ID".equals(responseHdr
099: .getJMSCorrelationID())
100: && responseHdr.getProperty() != null) {
101: System.out
102: .println("Received expected contents in response context");
103: } else {
104: System.out
105: .println("Received wrong contents in response context");
106: System.out.println();
107: System.exit(2);
108: }
109: } else {
110: System.out
111: .println("Failed to get the binding provider cannot access context info.");
112: System.exit(3);
113: }
114:
115: System.out.println();
116:
117: System.exit(0);
118: }
119: }
|