• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help on SOAP

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone please show me how to write a SOAP request and response that takes a persons name and say date of birth and provide some kind of YES/NO response..thanx.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've recently done that. In the following code the client sends an object (made up of a name and a pet) to a service, then the service returns a "GOOD PET" or "BAD PET" string based upon the name of the pet.
Does this help?
-----------------------------------------------
package test2;
/**
* This is the Client information - it does the sending to service
*/
import java.net.*;
import java.util.*;
import org.apache.soap.*; // Body, Envelope, Fault, Header
import org.apache.soap.encoding.SOAPMappingRegistry;
import org.apache.soap.encoding.soapenc.BeanSerializer;
import org.apache.soap.rpc.*; // Call, Parameter, Response
import org.apache.soap.util.xml.QName;
public class Client2
{
public static void main( String[] args ) throws Exception
{
String idname = "";
String pet = "";

if (args.length > 0) {
for (int i = 0; i<args.length-1; i++)
{
if (i>0)
idname += " ";
idname += args[i];
}
pet = args[args.length-1];
} else {
System.err.println("Usage: java test2.Client2 name pet");
return;
}

URL url = new URL( "http://127.0.0.1:8070/soap/servlet/rpcrouter" );
String urn = "urn rocessmsg2";
// prepare the mapping registry
SOAPMappingRegistry registry = new SOAPMappingRegistry();
// set the urn and the name
QName qname = new QName( "urn:my_encoding2", "newleads" );
BeanSerializer serializer = new BeanSerializer();
// Set up the registry mapping for the encoder, urn, classes, and serializer
registry.mapTypes( Constants.NS_URI_SOAP_ENC, qname, NewLeads.class, serializer, serializer );
// prepare the service invocation
Call call = new Call();
// set the mapping registry for the call
call.setSOAPMappingRegistry( registry );
// Set the URN for the call
call.setTargetObjectURI( urn );
// Set the method used by call
call.setMethodName( "receive" );
// Set the encoding style used by that URI in the call
call.setEncodingStyleURI( Constants.NS_URI_SOAP_ENC );
// Create a vector to hold the parameters
Vector params = new Vector();
// create a vector using a new lead
// This creates a NewLeads object and puts it in as a parameter
params.addElement( new Parameter( "newlead", NewLeads.class, new NewLeads( idname, pet ), null ) );
// Set the parameters in the call
call.setParams( params );
try
{
System.out.println( "invoke service\n" + " URL= " + url + "\n URN= " + urn );
Response response = call.invoke( url, "" ); // invoke the service
if( !response.generatedFault() )
{
// Put the result into a parameter - then print it out
Parameter result = response.getReturnValue(); // response was OK
System.out.println( "Result= " + result.getValue() );
}
else
{
Fault f = response.getFault(); // an error occurred
System.err.println("PROBLEM WITH TRANSMISSION:");
System.err.println( "Fault= " + f.getFaultCode() + ", " + f.getFaultString() );
}
}
catch( SOAPException e ) // call could not be sent properly
{
System.err.println( "NO CONNECTION: " );
System.err.println( "SOAPException= " + e.getFaultCode() + ", " + e.getMessage() );
}
}
}
-----------------------------------------------
package test2;
/** Sets the interface for the function **/
public interface ILeads
{
String receive( NewLeads newleads);
}
------------------------------------------------
package test2;
/** This creates the object that the client sends */
public class NewLeads
{
String idname="";
String pet="";
public NewLeads()
{
}
public NewLeads( String idname, String pet )
{
this.idname = idname;
this.pet = pet;
}
public String toString()
{
return "NewLeads( " + idname + ", " + pet + " )";
}
public void setName( String idname )
{
this.idname = idname;
}
public String getName()
{
return idname;
}
public void setPet( String pet )
{
this.pet = pet;
}
public String getPet()
{
return pet;
}
}
--------------------------------------------------
package test2;
/** This is the class that responds to the clients request **/
public class Leads implements ILeads
{
public String receive( NewLeads newlead )
{
String myanswer = "";
System.out.println( "got new lead " + newlead );
// This is a check to see if the lead is good -- could be changed later to
// another comparison
if (newlead.getName().equals("BOGUS"))
return "BAD PET";
else
return "GOOD PET";
//return newlead;
}
}
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay...I didn't set the smilies off -- so in one line you'll see a smiley -- it should be:
String urn = "urn:Processmsg2";
Sorry about that!
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I FORGOT!!
Also, you'll need to set up your service on the server. For example, we are using the Weblogic server. To set it up you need the following values entered in your admin tool:
Property: VALUE
ID: urn rocessmsg2
Scope: Application
Provider type: java
Java Provider class: test2.Leads (the package to Leads)
Use Static Class: false
Methods: receive (see in Leads)
Type Mappings:
-------------
Number of mappings: 1
encoding style: SOAP
Namespace URI: urn:my_encoding2 (see Client2)
Local part: newleads
Java Type: test2.NewLeads (the new object)
java to XML Serializer:
org.apache.soap.encoding.soapenc.BeanSerializer
XML to java Serializer:
org.apache.soap.encoding.soapenc.BeanSerializer
This is how I was set up using the Apache SOAP and a Weblogic server.
 
midan myaa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank Leilani, but i'm not looking for an implementation i just want a SOAP request/response that will work..i hope you can still help me..thanx
 
Angela Margot
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a good 4 part tutorial on SOAP messaging with code examples - parts 2-4 were the best:
Part1:
http://www-106.ibm.com/developerworks/webservices/library/ws-peer1/?dwzone=ws
Part2:
http://www-106.ibm.com/developerworks/webservices/library/ws-peer2/?dwzone=ws
Part3:
http://www-106.ibm.com/developerworks/webservices/library/ws-peer3/?dwzone=ws
Part4:
http://www-106.ibm.com/developerworks/webservices/library/ws-peer4/?dwzone=ws
Maybe these might help?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What an amazing statement!


Thank Leilani, but i'm not looking for an implementation i just want a SOAP request/response that will work..i hope you can still help me..thanx


Are you just looking for the text of a SOAP message or what???
Bill
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic