Package org.jboss.soa.bpel.examples.jaxws

Source Code of org.jboss.soa.bpel.examples.jaxws.JAXWSDispatcherClient

package org.jboss.soa.bpel.examples.jaxws;

/**
* Please modify this class to meet your needs
* This class is not complete
*/

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;

/**
* This class was generated by Apache CXF 2.2.6
* Thu May 06 14:29:08 BST 2010
* Generated source version: 2.2.6
*
*/

public final class JAXWSDispatcherClient {

    private static final QName SERVICE_NAME = new QName("http://www.jboss.org/bpel/examples/wsdl", "SecureHelloService");

    private JAXWSDispatcherClient() {
    }

    public static void main(String args[]) throws Exception {
        URL wsdlURL = null;
       
        if (args.length != 2) {
          System.err.println("Usage: JAXWSDispatcherClient wsdlURL messageFile");
          System.exit(1);
        }
       
        File wsdlFile = new File(args[0]);
        try {
            if (wsdlFile.exists()) {
                wsdlURL = wsdlFile.toURI().toURL();
            } else {
                wsdlURL = new URL(args[0]);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
            System.exit(2);
        }
     
        SpringBusFactory bf = new SpringBusFactory();
        URL busFile = ClassLoader.getSystemResource("wssec.xml");
        Bus bus = bf.createBus(busFile.toString());
        bf.setDefaultBus(bus);
       
        QName portName=new QName("http://www.jboss.org/bpel/examples/wsdl", "SecureHelloPort");
       
       
        Service service = Service.create(wsdlURL, SERVICE_NAME);
        Dispatch<SOAPMessage> dispatcher = service.createDispatch(
            portName,
            SOAPMessage.class,
            Service.Mode.MESSAGE
        );
      
        MessageFactory factory = MessageFactory.newInstance();
       
        String str="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsdl=\"http://www.jboss.org/bpel/examples/wsdl\">"+
            "<soapenv:Header/><soapenv:Body><wsdl:hello><TestPart>Hello</TestPart></wsdl:hello></soapenv:Body></soapenv:Envelope>";
        java.io.InputStream is=new java.io.ByteArrayInputStream(str.getBytes());
       
        SOAPMessage soapReq1 = factory.createMessage(null, is);
       
          System.out.println("Invoking server through Dispatch interface using SOAPMessage");
          SOAPMessage soapResp = dispatcher.invoke(soapReq1);
          System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent());
         
        System.exit(0);
    }

}
TOP

Related Classes of org.jboss.soa.bpel.examples.jaxws.JAXWSDispatcherClient

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.