Thursday, October 25, 2007

Java|WebServices - Axis

Use most of the jar lib from Axis 1.4 for this testing.


import java.io.FileInputStream;

import com.ncs.test.MessageSender;

import junit.framework.TestCase;

import java.io.FileNotFoundException ;
import java.io.IOException;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.message.SOAPEnvelope;

 

    public void testMain() {

       FileInputStream fileinputstream = null;

       String callbackContentFile= "c:\\temp\\SoapTest_In.xml";

       String callbackEndPoint= "http://wgwdevappl001:7001/ec/wssyncservlet/WsgServiceOrderService" ;

       String callbackWSOperation= "ActivateServiceRequest";

      

      

       try {

           fileinputstream = new FileInputStream(callbackContentFile);

           SOAPEnvelope soapenvelope = new SOAPEnvelope(fileinputstream);

           fileinputstream.close();

 

           info( "sucessfully load call back message from: "

                  + callbackContentFile);

 

           org.apache.axis.client.Service service = new org.apache.axis.client.Service();

          

           service.setCacheWSDL( false);

 

           Call call = (Call) service.createCall ();

 

           call.setTargetEndpointAddress( new java.net.URL (

                  callbackEndPoint));

 

           call.setOperationName(callbackWSOperation);

 

           call.setOperationStyle( "document");

 

           call.invoke(soapenvelope);

          

 

           String result = call.getResponseMessage().getSOAPPartAsString();

 

           info( "sucesfully call back to remote server!" + call.getResponseMessage().getSOAPPartAsString());

 

       } catch (FileNotFoundException e) {

           info( "Failed to load the call back message from: "

                  + callbackContentFile + " \n Exception recieved: "

                  + e.getMessage());

       } catch (Exception e) {

           info( "Failed to call back : " + e.getMessage());

       } finally {

           if (fileinputstream != null) {

              try {

                  fileinputstream.close();

              } catch (IOException e) {

                  // TODO Auto-generated catch block

                  e.printStackTrace();

              }

           }

       }

 

    }


No comments: