You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Echoes <ec...@free.fr> on 2001/03/09 12:43:59 UTC
Echo service
Hello,
Has anybody already written a simple echo soap service
with apache-soap.
I just need to know if my client (wich gathered data
from lots of external sources ) is ok. The server is
still to be developped...
Eugène
Re: Echo service
Posted by Ruth Bergman <Ru...@jpl.nasa.gov>.
> Has anybody already written a simple echo soap service
>with apache-soap.
Yes.
> I just need to know if my client (wich gathered data
>from lots of external sources ) is ok. The server is
>still to be developped...
I get the feeling you want me to point you to my server so you can use the
service. This I cannot do without clearing the site through a bunch of
beaurocratic hoops. But here is the simple sample.
Here the java Echo class (also has a hello method).
public class Echo {
public Echo() {}
public String hello() {
return "Hello!";
}
public String echo(String in) {
return in;
}
public Object echo(Object in) {
return in;
}
}
The deployment descriptor:
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:Copy">
<isd:provider type="java"
scope="Application"
methods="hello echo">
<isd:java class="Echo" static="false"/>
</isd:provider>
<isd:mappings>
</isd:mappings>
</isd:service>
A client:
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
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.*;
public class EchoClient
{
public static void main(String[] args) throws Exception
{
if (args.length != 2
&& (args.length != 3 || !args[0].startsWith("-")))
{
System.err.println("Usage:");
System.err.println(" java " + EchoClient.class.getName() +
" SOAP-router-URL string-input");
System.exit (1);
}
// Process the arguments.
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
URL url = new URL(args[0]);
String input = args[1];
SOAPMappingRegistry smr = new SOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
// Build the call.
Call call = new Call();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:Copy");
call.setMethodName("echo");
/* this invokes the hello method
call.setMethodName("hello");
call.setEncodingStyleURI(encodingStyleURI);
/*
Vector params = new Vector();
params.addElement(new Parameter("input", String.class,
input, null));
call.setParams(params);
*/
// Invoke the call.
Response resp;
try
{
resp = call.invoke(url, "");
}
catch (SOAPException e)
{
System.err.println("Caught SOAPException (" +
e.getFaultCode() + "): " +
e.getMessage());
return;
}
// Check the response.
if (!resp.generatedFault())
{
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println(value != null ? "\n" + value : "I don't know.");
}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
}
}
}
invoke the client just like the address book sample
%java EchoClient http://localhost:8080/soap/servlet/rpcrouter "Copy this"
Re: Echo service
Posted by Ruth Bergman <Ru...@jpl.nasa.gov>.
> Has anybody already written a simple echo soap service
>with apache-soap.
Yes.
> I just need to know if my client (wich gathered data
>from lots of external sources ) is ok. The server is
>still to be developped...
I get the feeling you want me to point you to my server so you can use the
service. This I cannot do without clearing the site through a bunch of
beaurocratic hoops. But here is the simple sample.
Here the java Echo class (also has a hello method).
public class Echo {
public Echo() {}
public String hello() {
return "Hello!";
}
public String echo(String in) {
return in;
}
public Object echo(Object in) {
return in;
}
}
The deployment descriptor:
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:Copy">
<isd:provider type="java"
scope="Application"
methods="hello echo">
<isd:java class="Echo" static="false"/>
</isd:provider>
<isd:mappings>
</isd:mappings>
</isd:service>
A client:
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
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.*;
public class EchoClient
{
public static void main(String[] args) throws Exception
{
if (args.length != 2
&& (args.length != 3 || !args[0].startsWith("-")))
{
System.err.println("Usage:");
System.err.println(" java " + EchoClient.class.getName() +
" SOAP-router-URL string-input");
System.exit (1);
}
// Process the arguments.
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
URL url = new URL(args[0]);
String input = args[1];
SOAPMappingRegistry smr = new SOAPMappingRegistry();
BeanSerializer beanSer = new BeanSerializer();
// Build the call.
Call call = new Call();
call.setSOAPMappingRegistry(smr);
call.setTargetObjectURI("urn:Copy");
call.setMethodName("echo");
/* this invokes the hello method
call.setMethodName("hello");
call.setEncodingStyleURI(encodingStyleURI);
/*
Vector params = new Vector();
params.addElement(new Parameter("input", String.class,
input, null));
call.setParams(params);
*/
// Invoke the call.
Response resp;
try
{
resp = call.invoke(url, "");
}
catch (SOAPException e)
{
System.err.println("Caught SOAPException (" +
e.getFaultCode() + "): " +
e.getMessage());
return;
}
// Check the response.
if (!resp.generatedFault())
{
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println(value != null ? "\n" + value : "I don't know.");
}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
}
}
}
invoke the client just like the address book sample
%java EchoClient http://localhost:8080/soap/servlet/rpcrouter "Copy this"