I've now attached the code. I've also read that this might be a classloader
or xml parser issue. Any help would be great. thanks
> I am using the following environment
> java 1.4
> Tomcat 4.0.3
> Soap 2.3
>
> I have written a simple class that implements not only the class
functions,
> but the serialization and deserialization as well. I am having problems
> calling a simple function on the class that returns itself. Right now the
> class has only one member (a string) and thus the marshall and unmarshall
> functions are responsible for handling just that member. When a client
> calls the function, apache tomcat loads the constructor, calls the
function,
> but never calls the marshall function (as reported through the apache
> console). The only thing returned to the client is
>
> Fault Code = SOAP-ENV:Server
> Fault String = java.lang.NullPointerException
>
> Does anyone have any ideas? I've gotten the simple soap examples to run
> just fine. (And subsequently my code and descriptor are pretty identical)
> The server is failing on line 138 of RPCRouterServlet. Could it be having
problems loading the class that implements the serializer/deserializer?
>
> Thanks,
>
> Todd D. Johnson
>
Implementing server class:
public Guide getSampleGuide(int guideSeq){
System.out.println("Guide.getSampleGuide called");
setGuideName("Sample Tickler Guide");
//g.setGuideType("DefaultGuidePublishingAgentImpl");
System.out.println("Guide.getSampleGuide exiting");
return this;
}
DeploymentDescriptor:
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:tickler">
<isd:provider type="java" scope="Request" methods="getSampleGuide">
<isd:java class="com.salarinc.tickler.foundation.Guide"
static="false"/>
</isd:provider>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListene
r>
<isd:mappings>
<isd:map encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:x="urn:tickler-guide" qname="x:guide"
javaType="com.salarinc.tickler.foundation.Guide"
java2XMLClassName="org.apache.soap.encoding.soapenc.BeanSerializer"
xml2JavaClassName="org.apache.soap.encoding.soapenc.BeanSerializer"/>
</isd:mappings>
</isd:service>
Client code:
Integer x=new Integer(7);
Integer y=new Integer(8);
final String urn= "urn:tickler";
Vector params = new Vector();
URL url = null;
try{
url = new URL("http://" + serverhost + ":" + serverport+
soapservlet);
}catch(java.net.MalformedURLException e){
System.out.println("Error creating a url: "+e.getMessage());
}
ServiceManagerClient client = new ServiceManagerClient(url);
try{
String[] apps = client.list();
System.out.println("Deployed Services at "+url.toString()+"
are:");
for(int i = 0; i < apps.length; i++){
System.out.println("\t"+apps[i]);
DeploymentDescriptor desc = client.query(apps[i]);
System.out.println("\t\tMethods for
"+desc.getScriptFilenameOrString()+" are:");
String[] methods = desc.getMethods();
for(int j = 0; j < methods.length; j++){
System.out.println("\t\t\t"+methods[j]);
}
}
}catch(SOAPException e){
System.out.println("Could not connect to ServiceManager at
"+url.toString()+": "+e.getMessage());
}
// Build the call.
Call call = new Call();
SOAPHTTPConnection shc = new SOAPHTTPConnection ();
shc.setMaintainSession (true);
call.setSOAPTransport(shc);
call.setTargetObjectURI(urn);
call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
call.setMethodName("getSampleGuide");
params.addElement(new Parameter("guideSeq" , Integer.class, new
Integer(7), null));
call.setParams(params);
GuideSerializer ser_0 = new GuideSerializer();
SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
smr.mapTypes("http://schemas.xmlsoap.org/soap/encoding/", new QName(
"urn:tickler-guide", "guide"), Guide.class, ser_0, ser_0);
call.setSOAPMappingRegistry(smr);
Response resp = null;
try{
resp = call.invoke(url,"");
}catch(org.apache.soap.SOAPException e){
System.out.println("Got a soap exception while invoking
"+e.getMessage());
System.exit(1);
}
if (resp.generatedFault()) {
Fault fault = resp.getFault();
System.out.println("Ouch, the call failed: ");
System.out.println(" Fault Code = " + fault.getFaultCode());
System.out.println(" Fault String = " +
fault.getFaultString());
} else {
Parameter result = resp.getReturnValue();
if(result.getType() == Guide.class){
Guide g = (Guide)result.getValue();
System.out.println("The guide name is " + g.getGuideName());
}else{
System.out.println("ERROR server returned a
:"+result.getType().toString());
System.exit(1);
}
}
Serializer/Deserializer
public Bean unmarshall(String inScopeEncStyle, QName elementType,
Node src, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
throws IllegalArgumentException
{
Element root = (Element)src;
Element tempEl = DOMUtils.getFirstChildElement(root);
Guide target;
try
{
target =
(Guide)Guide.class.newInstance
();
}
catch (Exception e)
{
throw new IllegalArgumentException("Problem instantiating bean: "
+ e.getMessage());
}
while (tempEl != null)
{
Bean paramBean = xjmr.unmarshall(inScopeEncStyle,
RPCConstants.Q_ELEM_PARAMETER,
tempEl, ctx);
Parameter param = (Parameter)paramBean.value;
String tagName = tempEl.getTagName();
if (tagName.equals("name"))
{
target.setGuideName((java.lang.String)param.getValue());
}
tempEl = DOMUtils.getNextSiblingElement(tempEl);
}
return new Bean(Guide.class, target);
}
public void marshall(String inScopeEncStyle, Class javaType,
Object src, Object context, Writer sink,
NSStack nsStack, XMLJavaMappingRegistry xjmr, SOAPContext ctx)
throws IllegalArgumentException, IOException
{
nsStack.pushScope();
SoapEncUtils.generateStructureHeader(inScopeEncStyle, javaType,
context,
sink, nsStack, xjmr);
sink.write(StringUtils.lineSeparator);
Guide src2 = (Guide)src;
Parameter param;
param = new Parameter("namme", String.class, new String
("Test"), null);
xjmr.marshall(inScopeEncStyle, Parameter.class, param, null,
sink, nsStack, ctx);
sink.write(StringUtils.lineSeparator);
sink.write("</" + context + '>');
nsStack.popScope();
}