Here is some of the codes.
This the function that send the request message:
public static BufferedReader invoke ( InputSource inMessage )
throws
org.apache.soap.SOAPException ,
org.xml.sax.SAXException ,
java.io.IOException ,
java.net.MalformedURLException
{
// Construct the envelope to send.
DOMParser aParser = new DOMParser();
aParser.parse ( inMessage );
Document doc = aParser.getDocument();
if ( doc == null )
{
throw new SOAPException (
Constants.FAULT_CODE_CLIENT, "parsing error" );
}
Envelope msgEnv =
Envelope.unmarshall ( doc.getDocumentElement() );
// Send the message
sLog.debug ( "sending the message ..." );
final String kURLStr =
Environment.getKeyValue ( "msgrouter-url" );
Message msg = new Message();
msg.send (
new URL ( kURLStr ) ,
"urn:this-is-the-action-uri" , // not used for messaging
msgEnv );
// Wait for and read the response.
sLog.debug ( "getting SOAP transport ..." );
SOAPTransport st = msg.getSOAPTransport();
sLog.debug ( "waiting for response ..." );
BufferedReader br = st.receive();
sLog.debug ( "received response" );
return br;
}
This the service request fuction that is deployed on SOAP:
public void requestCustListing (
Envelope inEnv ,
SOAPContext inRequest ,
SOAPContext outResponse )
throws MessagingException, IOException
{
String theParentCust = null;
try
{
Element theRequestElement =
(Element) inEnv.getBody().getBodyEntries().iterator().next();
NodeList theRequestSubElements =
theRequestElement.getElementsByTagName ( "parentCust" );
if ( theRequestSubElements.getLength() == 0 )
{
buildErrorResponse (
"MISSING_ELEMENT" , // inError
"parentCust element missing" , // inDescription
outResponse , // outResponse
inEnv ); // inoutEnv
logResponse ( inEnv );
return;
}
else
{
Element theParentCustlement =
(Element) theRequestSubElements.item ( 0 );
theParentCust =
( (CharacterData) theParentCustElement.getFirstChild() ).
getData();
}
}
catch ( Throwable e )
{
final String kErrorMsg =
"unexpected error encountered while parsing request";
sLog.error ( kErrorMsg, e );
buildErrorResponse (
"REQUEST_PROCESSING_ERROR" , // inError
kErrorMsg , // inDescription
outResponse , // outResponse
inEnv ); // inoutEnv
logResponse ( inEnv );
return;
}
sLog.debug ( "requested parentCust= " + theParentCust );
try
{
// Get a reference to the CustList bean.
CustListHome theCustListHome =
(CustListHome) ServiceLocator.lookup (
CustList.class, CustListHome.class );
CustList aCustList = theCustListHome.create();
// Get a list of all Custs known that are associated
// with the specified parentCust.
//
CustListing returnListing = aCustList.getChildCusts ( theParentCust );
// Build a normal SOAP response.
//
buildResponse (
"responseCustListing" ,
returnListing ,
outResponse ,
inEnv );
}
catch ( Throwable e )
{
RequestStatus.setError ( e );
// Build an error response.
//
buildErrorResponse ( e, outResponse, inEnv );
}
finally
{
logResponse ( inEnv );
}
}
This is one of the build reponse:
public void buildResponse (
String inMsgName ,
Object inContent ,
SOAPContext outResponse ,
Envelope inoutEnv )
throws MessagingException, IOException
{
// Create the response.
Document theDoc = new DocumentImpl();
Element theResponse = theDoc.createElement ( inMsgName );
try
{
Marshaller.marshal ( inContent, theResponse );
}
catch ( Throwable e )
{
sLog.error ( "error building response", e );
buildErrorResponse (
"ERROR_BUILDING_RESPONSE" , // inError
e.getMessage() , // inDescription
outResponse , // outResponse
inoutEnv ); // inoutEnv
return;
}
// Set this response as the content of the envelope.
Vector theBodyEntries = inoutEnv.getBody().getBodyEntries();
theBodyEntries.clear();
theBodyEntries.add ( theResponse );
StringWriter aWriter = new StringWriter();
inoutEnv.marshall ( aWriter, null );
// Send the envelope back to the client.
//
outResponse.setRootPart ( aWriter.toString(), "text/xml" );
}
Ide.
>>> [EMAIL PROTECTED] 03/28/02 12:31PM >>>
I can not tell the problem without having a look at the source code
----- Original Message -----
From: "Ide Roth" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 28, 2002 10:27 AM
Subject: SOAP 2.2 (500 Internal Server Error)
Hi,
I'm trying to do a service request and keep getting an interal server
error.
The error messages are:
"500 Internal Server Error"
"500 Servlet messagrouter: unable to service request: Error building
response envelope: java.lang.NullPointerException."
Has anyone encounter this problem before?
Please help.
Thank you in advance.
Ide