skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, October 15, 2012

Java Axis Test Client to Invoke Webservice

Posted by Raju Gupta at 6:00 PM – 0 comments
 
This client program is a consumer process to invoke Axis Webservice.

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.io.*;


// Argument 1 : End Point URL
// Argument 2 : Method Name
// Argument 3 : Input Request XML file

public class TestAxisWSClient {
 public static void main(String [] args)  throws Exception{
   
  if (args[0] ==null || args[1] ==null || args[2] ==null){
System.out.println("Enter all the Inputs for End Point URL (1st arg), Method Name (2nd arg), XML (Input file) (3rd arg)");
  }

   String endpoint = args[0];
   String methodName = args[1];
    String fileName = args[2];

  String thisLine;

// To process the Request XML file and store as string
  BufferedReader br = new BufferedReader(new FileReader(fileName));
  String xmlRequest = "";
  while ((thisLine = br.readLine()) != null) {
   xmlRequest = xmlRequest  + thisLine;
  }
  System.out.println("Request XML is :\n" + xmlRequest); 
  try {

// Service and Call methods to invoke the webservice
   Service service = new Service();
   Call call = (Call) service.createCall();

   call.setTargetEndpointAddress( new java.net.URL(endpoint));
call.setOperationName(new QName("http://soapinterop.org/", methodName));
   Object obj[] = {new String(xmlRequest)};
   String ret = (String) call.invoke( obj );
   System.out.println("Response : " + ret );
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

} 


Labels: Java Webservice Example

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger