Results 1 to 3 of 3
Thread: SOAP Client
- 10-30-2007, 01:31 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 17
- Rep Power
- 0
SOAP Client
Hi,
I have SOAP server running. I need to write a SOAP client for the server. Can you please suggest plugin in eclipse or give me the URL related to this?
can you please provide me it you have any sample SOAP Client code?
My SOAP client should use complex objects as parmeter/arguments for the SOAP function which is exposed in the SOAP server.
Thanks in advance.
- 08-18-2009, 09:13 AM #2
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
SOAP Client
I have used a SOAP Client using apache axis client.
/* only code --- take care of the package and filename*/
package mypackage1;
import java.util.Iterator;
import java.util.Vector;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPElement;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.soap.*;
public class HdsRulebaseStub
{
public static int save_employee(String grade, String location)
{
int save_employee =5;
try
{
HdsRulebaseStub stub = new HdsRulebaseStub();
// Add your own code here.
SOAPFactoryImpl fact=new SOAPFactoryImpl();
SOAPElement assessRequest =fact.createElement("assess-request","ns0","<GIve here Qname--- but optional --if not giving remove ns0>");
SOAPElement config =assessRequest.addChildElement("config");
config.addChildElement("show-events").addTextNode("show-events").setValue("true");
SOAPElement sessionData = assessRequest.addChildElement("session-data");
SOAPElement listEntity = sessionData.addChildElement("list-entity");
listEntity.setAttribute("entity-type","global");
SOAPElement globalEntity = listEntity.addChildElement("entity");
globalEntity.setAttribute("id","global");
SOAPElement attroutcome = globalEntity.addChildElement("attribute-outcome");
attroutcome.setAttribute("id","not_save");
attroutcome.setAttribute("outcome-style","attribute-only");
attroutcome.setAttribute("screen-if-unknown","false");
SOAPElement entityAttrib1 = globalEntity.addChildElement("attribute");
entityAttrib1.setAttribute("id","grade");
SOAPElement gradevalue = entityAttrib1.addChildElement("text-val");
gradevalue.setValue(grade);
SOAPElement entityAttrib2 = globalEntity.addChildElement("attribute");
entityAttrib2.setAttribute("id","location");
SOAPElement locationValue = entityAttrib2.addChildElement("text-val");
locationValue.setValue(location);
//System.out.println(assessRequest);
SOAPBodyElement params[]=new SOAPBodyElement[1];
params[0] = new SOAPBodyElement(assessRequest);
//System.out.println(params[0]);
Service serv = new Service();
QName qname = new QName("<Give here Qname>","ns0");
Call call = (Call)serv.createCall(qname);
call.setTargetEndpointAddress("<give here endpoint address");
call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "<Give here SOAP action URI>");
call.setProperty(Call.OPERATION_STYLE_PROPERTY, "literal");
call.setOperationName("Assess");
Vector res = (Vector)call.invoke(params);
//System.out.println(res);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
- 01-27-2010, 07:08 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
Soap Client in Java
Hello All,
================================================== ======
import java.io.*;
import java.net.*;
import java.util.*;
public class SOAPClient4XG {
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage: java SOAPClient4XG " +
"http://soapURL soapEnvelopefile.xml" +
" [SOAPAction]");
System.err.println("SOAPAction is optional.");
System.exit(1);
}
String SOAPUrl = args[0];
String xmlFile2Send = args[1];
String SOAPAction = "";
long startTime = 0;
long endTime = 0;
int maxReqCount = 1;
if (args.length > 2)
maxReqCount = Integer.parseInt(args[2]);
if (args.length > 3)
SOAPAction = args[3];
// Open the input file. After we copy it to a byte array, we can see
// how big it is so that we can set the HTTP Cotent-Length
// property. (See complete e-mail below for more on this.)
FileInputStream fin = new FileInputStream(xmlFile2Send);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
// Copy the SOAP file to the open connection.
copy(fin,bout);
fin.close();
byte[] b = bout.toByteArray();
// Everything's set up; send the XML that was read in to b.
// Read the response and write it to standard out.
System.out.println("hello");
String inputLine;
try
{
Date date = new Date();
System.out.println("Initial Time: " + date.getTime());
}
catch (Exception e)
{
e.printStackTrace();
}
int reqCount = 0;
do
{
// Create the connection where we're going to send the file.
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length",
String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction",SOAPActio n);
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream out = httpConn.getOutputStream();
try
{
Date date = new Date();
startTime = date.getTime();
// System.out.println(date.getTime());
}
catch (Exception e)
{
e.printStackTrace();
}
out.write( b );
out.close();
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);
inputLine = null;
while ((inputLine = in.readLine()) != null);
// System.out.println(inputLine);
try
{
Date date = new Date();
endTime = date.getTime();
// System.out.println(date.getTime());
}
catch (Exception e)
{
e.printStackTrace();
}
in.close();
reqCount++;
System.out.println("Request: " + reqCount + ", ResponseTime: " + (endTime - startTime));
}while(reqCount < maxReqCount);
// out.close();
// in.close();
try
{
Date date = new Date();
System.out.println("Final Time: " + date.getTime());
}
catch (Exception e)
{
e.printStackTrace();
}
}
// copy method from From E.R. Harold's book "Java I/O"
public static void copy(InputStream in, OutputStream out)
throws IOException {
// do not allow other threads to read from the
// input or write to the output while copying is
// taking place
synchronized (in) {
synchronized (out) {
byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
}
================================================== ======
I am using above soap client code for java. Same code is working on Windows and same code is not working on Linux. Client gets hang while receiving response.
Please help me out.
Thanks & Regards in advance,
Prashant Narkhede
Similar Threads
-
create a Java Client to consume WEBSERVICES XML SOAP
By Felissa in forum Web FrameworksReplies: 2Last Post: 05-16-2008, 06:42 AM -
Identify Client in Socket Client Server Application
By masadjie in forum NetworkingReplies: 1Last Post: 12-20-2007, 09:18 AM -
Java GForge SOAP Interface 0.0.8
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-13-2007, 05:33 PM -
SOAP over HTTP/POST
By sabatier in forum NetBeansReplies: 0Last Post: 07-10-2007, 08:04 AM -
Java GForge SOAP Interface 0.0.3
By levent in forum Java SoftwareReplies: 0Last Post: 06-19-2007, 05:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks