001: package demo.soap_header.client;
002:
003: import java.io.File;
004: import java.net.URL;
005:
006: import javax.xml.namespace.QName;
007: import javax.xml.ws.Holder;
008: import org.objectweb.headers.HeaderService;
009: import org.objectweb.headers.HeaderTester;
010: import org.objectweb.headers.InHeader;
011: import org.objectweb.headers.InHeaderResponse;
012: import org.objectweb.headers.InoutHeader;
013: import org.objectweb.headers.InoutHeaderResponse;
014: import org.objectweb.headers.OutHeader;
015: import org.objectweb.headers.OutHeaderResponse;
016: import org.objectweb.headers.SOAPHeaderData;
017:
018: public final class Client {
019:
020: private static final QName SERVICE_NAME = new QName(
021: "http://objectweb.org/headers", "HeaderService");
022:
023: private Client() {
024: }
025:
026: public static void main(String args[]) throws Exception {
027:
028: if (args.length == 0) {
029: System.out.println("please specify wsdl");
030: System.exit(1);
031: }
032:
033: URL wsdlURL;
034: File wsdlFile = new File(args[0]);
035: if (wsdlFile.exists()) {
036: wsdlURL = wsdlFile.toURL();
037: } else {
038: wsdlURL = new URL(args[0]);
039: }
040:
041: HeaderService hs = new HeaderService(wsdlURL, SERVICE_NAME);
042: HeaderTester proxy = hs.getSoapPort();
043:
044: invokeInHeader(proxy);
045: invokeOutHeader(proxy);
046: invokeInOutHeader(proxy);
047: }
048:
049: private static void invokeInHeader(HeaderTester proxy) {
050: // invoke inHeader operation
051: System.out.println("Invoking inHeader operation");
052: InHeader me = new InHeader();
053: me.setRequestType("Celtix user");
054: SOAPHeaderData headerInfo = new SOAPHeaderData();
055: headerInfo.setOriginator("Celtix client");
056: headerInfo.setMessage("Invoking inHeader operation");
057: InHeaderResponse response = proxy.inHeader(me, headerInfo);
058: System.out.println("\tinHeader invocation returned: ");
059: System.out.println("\t\tResult: " + response.getResponseType());
060: }
061:
062: private static void invokeOutHeader(HeaderTester proxy) {
063: // invoke outHeaderoperation
064: System.out.println("Invoking outHeader operation");
065: OutHeader me = new OutHeader();
066: me.setRequestType("Celtix user");
067: Holder<OutHeaderResponse> theResponse = new Holder<OutHeaderResponse>();
068: Holder<SOAPHeaderData> headerInfo = new Holder<SOAPHeaderData>();
069: proxy.outHeader(me, theResponse, headerInfo);
070: System.out.println("\toutHeader invocation returned: ");
071: System.out.println("\t\tOut parameter: "
072: + theResponse.value.getResponseType());
073: System.out.println("\t\tHeader content:");
074: System.out.println("\t\t\tOriginator: "
075: + headerInfo.value.getOriginator());
076: System.out.println("\t\t\tMessage: "
077: + headerInfo.value.getMessage());
078: }
079:
080: private static void invokeInOutHeader(HeaderTester proxy) {
081: System.out.println("Inovking inoutHeader operation");
082: InoutHeader me = new InoutHeader();
083: me.setRequestType("Celtix user");
084: Holder<SOAPHeaderData> headerInfo = new Holder<SOAPHeaderData>();
085: SOAPHeaderData shd = new SOAPHeaderData();
086: shd.setOriginator("Celtix client");
087: shd.setMessage("Inovking inoutHeader operation");
088: headerInfo.value = shd;
089: InoutHeaderResponse response = proxy
090: .inoutHeader(me, headerInfo);
091: System.out.println("\tinoutHeader invocation returned: ");
092: System.out.println("\t\tResult: " + response.getResponseType());
093: System.out.println("\t\tHeader content:");
094: System.out.println("\t\t\tOriginator: "
095: + headerInfo.value.getOriginator());
096: System.out.println("\t\t\tMessage: "
097: + headerInfo.value.getMessage());
098:
099: System.exit(0);
100: }
101: }
|