Run the web client via command line


XML & Web services: Run the web client via command line

  1. Run the web client via command line (3 messages)

    I am presently developing a reference implementation of a JAX-RPC one-way web service. The service will be run on an Oracle 10g server. I currently developing it on Oracle (OC4J 10.1.2) standalone developmental server.

    I used Lavadora Web Services Eclipse Plugin to create the service client. I can compile and run the client fine when I use eclipse (Success is defined when I see the xml payload getting transported to the server). When I compile and run the client using command line, the client doesn't seem to work.

    The only major difference I saw was that eclipse was using the elipse plugin jars and eclipse ant jars in it's classpath.

    Any suggestions?


    Enoch Moses

    P.S. The plugin generates classes using wsdl2java.

    Threaded Messages (3)

  2. Run the web client via command line[ Go to top ]

    Are you getting NoClassDefFoundError or something else ? Can you post the stacktrace if any ?

  3. Run the web client via command line[ Go to top ]

    I am using an ant script to add libraries to the classpath.

    Here is the script:
    <project name="ws-client" default="compile" basedir=".">
    <property name="build.dir" value="${basedir}/build"/>
    <property name="build.classes" value="${build.dir}/classes"/>
    <property name="lib.dir" value="${basedir}/lib"/>
    <property name="axis.lib.classpath" value="C:/axis-1_1/lib"/>
    <property name="ant.dir" value="c:/apache-ant-1.6.1/lib"/>
    <property name="src.dir" value="${basedir}/src"/>
    <property name="debug" value="true" />
    <path id="axis.classpath">
    <fileset dir="C:/axis-1_1/lib">
    <include name="**/*.jar" />
    <path id="ant.classpath">
    <fileset dir="${ant.dir}">
    <include name="**/*.jar" />
    <path id="classpath">
    <pathelement path="${build.classes}" />
    <pathelement path="${lib.dir}" />
    <fileset dir="${lib.dir}">
    <include name="**/*.jar" />


    <target name="compile" description="Compiles the client code">
    <delete dir="${build.classes}"/>
    <mkdir dir="${build.classes}"/>
    <mkdir dir="${build.classes}/config"/>
    <javac srcdir="${src.dir}" destdir="${build.classes}" includes="**/*.java" optimize="${optimize}" deprecation="${deprecation}">
    <classpath refid="ant.classpath" />
    <classpath refid="classpath" />
    <classpath refid="axis.classpath" />

    <target name="run" depends="compile" description="Run the client">
    <java classname="">
    <classpath refid="ant.classpath" />
    <classpath refid="classpath" />
    <classpath refid="axis.classpath" />


    My Class:


    import javax.xml.soap.MessageFactory;
    import javax.xml.soap.Name;
    import javax.xml.soap.SOAPBody;
    import javax.xml.soap.SOAPBodyElement;
    import javax.xml.soap.SOAPElement;
    import javax.xml.soap.SOAPElementFactory;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPException;
    import javax.xml.soap.SOAPFactory;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.soap.SOAPPart;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMResult;

    import org.w3c.dom.NamedNodeMap;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;

     * @author ENOCH MOSES
     * TODO To change the template for this generated type comment go to Window -
     * Preferences - Java - Code Style - Code Templates
    public class WS_Client {
    * A simple client to MOSTrimWebservice client.
    * @param args
    * args[0] The name and path of the file which will be the
    * SOAPBody
    * @throws Exception
    public static void main(String[] args) throws Exception {
    // Creating the SOAPMessage
    MessageFactory messageFact;
    messageFact = MessageFactory.newInstance();
    SOAPMessage message = messageFact.createMessage();
    SOAPPart soap = message.getSOAPPart();
    SOAPEnvelope envelope = soap.getEnvelope();
    SOAPBody body = envelope.getBody();
    Name name = envelope.createName("param");
    SOAPBodyElement paramElement = body.addBodyElement(name);

    // Adding the xmlPayload from a file and
    // converting from stream to DOM node.
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();

    String file = "C:/MOS-home/xmlschema/tempFile.xml";
    StreamSource source = new StreamSource(new FileInputStream(file));
    Node node = null;
    DOMResult result = new DOMResult(node);
    transformer.transform(source, result);
    // Converting from DOM node to SOAPElement and
    // add it to the soap
    SOAPFactory soapFactory = SOAPFactory.newInstance();
    SOAPElement xmlPayload = dom2SOAPElement(envelope, result.getNode()

    private static SOAPElement dom2SOAPElement(SOAPEnvelope env, Node domNode) {
    ... }
    // Implementing the generated code for the
    // Web service. Used Lavadora Web Services Plugin
    // to generated the generated code.
    MOSTrimWebserviceBindingStub _stub;
    _stub = (MOSTrimWebserviceBindingStub) new MOSTrimWebserviceLocator()
  4. Run the web client via command line[ Go to top ]

    I figured out the problem.

    I needed to add lines, "Thread.sleep(4000); System.exit(0);"