Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java call SOAP???  RSS feed

 
ping shx
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone!
The Web service of SOAP was programmed with Delphi,There is a Function Called GetMessage;now ,I want that the Function is called by java language.
the following is my program:
import java.io.*;
import java.util.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
import java.net.*;
public class SOAP_Test
{
public static void main(String[] args)
{
URL url=null;
Call call =null;
try
{
url = new URL("http://192.168.7.17:8081/Test9.CoTest9/wsdl/ITest9");
call = new Call();
call.setTargetObjectURI("urn:CoTest9"); //Maybe there are errors.
call.setMethodName("GetMessage");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
}catch(Exception e)
{
e.printStackTrace();
}
Response resp;
try
{
Vector params=new Vector();
params.addElement(new Parameter("Number",Integer.class,new Integer(1),null));
//params.addElement(new Parameter("name",String.class,"Solidworks",null));
call.setParams(params);
resp = call.invoke(url,"");
}
catch (SOAPException e)
{
System.err.println("Caught SOAPException (" +e.getFaultCode() + "): "+e.getMessage());
return;
}
if (!resp.generatedFault())
{
Parameter ret = resp.getReturnValue();
System.out.println(ret.getValue());}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: " + fault);
}
}
when run:
E:\>javac SOAP_Test.java
E:\>java SOAP_Test
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at SOAP_Test.main(SOAP_Test.java:19)
C:\>echo %classpath%
.;D:\web\j2e\lib\dt.jar;D:\web\j2e\lib\tools.jar;D:\web\j2e\bin;D:\web\j2e\lib\classes12.zip;D:\web\j2e\lib\servlet.zip;D:\web\jakarta-tomcat\classes\servlet.zip;D:\web\jakarta-tomcat\classes\classes12.zip;D:\web\jakarta-tomcat\common\lib\s
ervlet.jar;D:\web\jakarta-tomcat\common\lib\;F:\Program Files\RUPBuilder;F:\Program Files\common\java\swingall.jar;F:\Program Files\common\java\javahelp\jh.jar;D:\web\j2e\lib\soap\soap.jar;
what's make these?? must I download Mail package?? Thank everybody!
[ January 08, 2004: Message edited by: ping shx ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you need the mail.jar in your classpath.
If you don't have it already, you can download the JavaMail API from http://java.sun.com/products/javamail/downloads/index.html
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds more like a classpath issue than a web services issue. I'll move this to the Java In General Beginner forum for you.
 
ping shx
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I beleive it is not a classpath problem,Some knowledge tell me How can I get a java file through the wsdl! if i get the java file ,then I can use it in my program.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Returning to the Web Services forum...
Pong!
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Time to clean out that classpath too, lots of double entries which might at some point come to bite you as/if/when they become out of sync!
C:\>echo %classpath%
.;D:\web\j2e\lib\dt.jar;D:\web\j2e\lib\tools.jar;D:\web\j2e\bin;D:\web\j2e\lib\classes12.zip;D:\web\j2e\lib\servlet.zip;D:\web\jakarta-tomcat\common\lib\;F:\Program Files\RUPBuilder;F:\Program Files\common\java\swingall.jar;F:\Program Files\common\java\javahelp\jh.jar;D:\web\j2e\lib\soap\soap.jar;
is the most you need. I suspect you can get rid of more...
swingall.jar, dt.jar and tools.jar shouldn't be needed for example if you're using a modern environment (1.2 or later). This might be true for jh.jar as well.
I'd replace servlet.zip with the full j2ee.jar from the j2ee distribution which gives you Javamail support as well.
classes12.zip is an old Oracle driver. Check for a later version, there have been many improvements.
And yes it IS a problem with your classpath. There is an underlying problem with the SOAP message but until your program can throw that MessagingException that it can't find you'll never find out what it is!
 
ping shx
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks every body! I had clean my classpath,now I can call Soap's function using the following code:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="org.apache.axis.client.Call"%>
<%@ page import="org.apache.axis.client.Service"%>
<%@ page import="org.apache.axis.encoding.XMLType"%>
<%@ page import="javax.xml.rpc.ParameterMode"%>
<%@ page import="javax.xml.rpc.ParameterMode"%>
<%@ page import="java.util.Vector"%>
<%
Service service = new Service();
Call call = ( Call ) service.createCall();
call.setTargetEndpointAddress( "http://192.168.7.17:8081/Test9.CoTest9/soap/ITest9" );
call.setOperationName( "GetMessage" );
call.addParameter( "Number", XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType( XMLType.XSD_STRING );//ShowData
int dl = 2;
String dd= call.invoke(new java.lang.Object[]{"9"}) ;
%>
<br>
<%=dd%>
It shows the result I want,but now the Question is :
If the function GetMessage returns an array of strings(numbers,others),or arrays of strings(numbers,others),using java ,I can't get the result.Using Delphi at the client,I can get the right results.This is My Delphi Code at then web service:
TArrayString =array of array of String;
function TTest9.GetMessage(str:string):TArrayString;stdcall;
begin
setlength(result,2);
Setlength(result[0],2);
Setlength(result[1],2);
result[0][0]:='000'; result[0][1]:='011';
result[1][0]:='100'; result[1][1]:='111';
end;
How can I get the right result using java?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you perhaps post the actual incoming SOAP response (using a TCP "sniffer" such as the tcpmon tool that comes with Axis)?
 
ping shx
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tcpmon tool ? Where can I get the tool?Could you please tell where can I Download it ?
now ,using java ,I can get one-dimession array!
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tcpmon is part of Apache Axis and is documented in the User's Guide.
 
ping shx
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lasse Koskela:thanks!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!