Hey Simon,
Something is not quite right unfortunately. I looks like my Handler is
not registering correctly and as a result I get the following stack
trace.
Unexpected error: ; nested exception is:
javax.xml.rpc.JAXRPCException: Unable to create handler of type
class com.jmb.axis.handlers.MyHandler
AxisFault
faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: javax.xml.rpc.JAXRPCException: Unable to create handler of
type class com.jmb.axis.handlers.MyHandler
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:javax.xml.rpc.JAXRPCException:
Unable to create handler of type class com.jmb.axis.handlers.MyHandler
at
org.apache.axis.handlers.HandlerChainImpl.newHandler(HandlerChainImpl.ja
va:247)
at
org.apache.axis.handlers.HandlerChainImpl.<init>(HandlerChainImpl.
java:77)
at
org.apache.axis.handlers.HandlerInfoChainFactory.createHandlerChain(Hand
lerInfoChainFactory.java:42)
at
org.apache.axis.client.AxisClient.getJAXRPChandlerChain(AxisClient.java:
274)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:140)
at org.apache.axis.client.Call.invokeEngine(Call.java:2765)
at org.apache.axis.client.Call.invoke(Call.java:2748)
at org.apache.axis.client.Call.invoke(Call.java:2424)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at
com.sforce.soap.enterprise.SoapBindingStub.login(SoapBindingStub.java:15
07)
at com.jmb.SFTest.setUp(SFTest.java:86)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)
{http://xml.apache.org/axis/}hostname:nc-jbruce2
So far I have extended the SforceServiceLocator class and with my own
class that includes a single method that adds the handler as follows:
HandlerRegistry hr = this.getHandlerRegistry();
QName soap = new QName(this.getSoapWSDDServiceName());
ArrayList handlerChain = new ArrayList();
QName[] headers = null;
HandlerInfo handler = new
HandlerInfo(com.jmb.axis.handlers.MyHandler.class, null, headers);
handlerChain.add(handler);
hr.setHandlerChain(soap, handlerChain);
And I'm initializing the Sforce handle as you'd expect...
ServiceLocatorXMLHandler slXML = new ServiceLocatorXMLHandler();
slXML.addHandler(); // adds handler as above
binding = (SoapBindingStub)slXML.getSoap();
In debugging it is clear that my registration of the my Handler class is
working correctly, however this may be a simple class loading issue. I
have this is a Junit framework, so perhaps thay may be causing an issue.
I have so far failed to dig up any reasonable explanation for this. Any
thoughts?
Cheers,
-Jonathan
-----Original Message-----
From: Simon Fell [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 12, 2005 14:07
To: [email protected]
Subject: RE: Adding Handlers to Axis 1.2.1
I use this.getSoapWSDDServiceName() for the service name.
-----Original Message-----
From: Jonathan Bruce [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 12, 2005 11:01 AM
To: [email protected]
Subject: RE: Adding Handlers to Axis 1.2.1
Hey Simon,
Sounds good, I definitly prefer leaving the stubs alone and modifying
the Handler chain at the service level. One question however.
What should the 'serviceName' variable be equal to in the Qname
instantiation?
-Jonathan
-----Original Message-----
From: Simon Fell [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 12, 2005 13:02
To: [email protected]
Subject: RE: Adding Handlers to Axis 1.2.1
Hi Jonathan,
I haven't tried this with 1.2.1 yet, but I have a client side handler
that does something similar in Axis 1.1, this works fine for me.
SOAPMessageContext sc = (SOAPMessageContext)ctx; SOAPEnvelope env =
sc.getMessage().getSOAPPart().getEnvelope();
checkResponse(env.toString());
Although I hook it into the chain at the service level rather than
changing the generated stub (by subclassing the generated ServiceLocator
class)
HandlerRegistry hr = this.getHandlerRegistry(); QName soap = new
QName(serviceName); ArrayList handlerChain = new ArrayList();
HandlerInfo handler = new HandlerInfo(LoggingHandler.class, null, null);
handlerChain.add(handler); hr.setHandlerChain(soap, handlerChain);
Not entirely answering your question, but hope it helps Cheers Simon
-----Original Message-----
From: Jonathan Bruce [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 12, 2005 7:51 AM
To: [email protected]
Subject: Adding Handlers to Axis 1.2.1
Hi,
I've recently built a set of client stubs from a Salesforce.com WSDL
tailored for my company.
I however need to gain access to the RAW XML returned by interactions
with the SFDC API, figured adding a Handler was the best way to go. I
added the 'setClientHandlers' call to a specific generated stub class
prior to the invoke() call.
org.apache.axis.client.Call _call = createCall();
:
:
_call.setClientHandlers(null, responseHandler);
My handler looks something like this:
package com.jmb.axis.handlers;
import org.apache.axis.handlers.BasicHandler;
import org.apache.axis.*;
import javax.xml.*;
import javax.xml.parsers.*;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import java.io.*;
public class MyHandler extends BasicHandler {
private String bodyXML;
/**
* Mandatory method. Required by BasicHandler super-class
*
*/
public void invoke(MessageContext ctx) {
try {
bodyXML =
ctx.getMessage().getSOAPPart().getEnvelope().getBody().toString();
// Hand off to another program anyway you like.
Don't have to work with string,
// getBody() will return a SOAPBody object which
extends a SOAPElement object
// which extends a SOAPNode
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @return
*/
public Document buildDOM() {
Document document = null;
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
//InputSoure is = new InputStream();
StringReader reader = new StringReader(this.bodyXML);
document = parser.parse(new InputSource(reader));
} catch (Exception e) {
e.printStackTrace();
}
return document;
}
/**
*
*/
public String toString() {
return bodyXML;
}
}
This causes a problem in the parsing of the SOAP response, however, as
the following exception is thrown (stack trace follows)
- Exception:
org.xml.sax.SAXException: Invalid element in
com.sforce.soap.enterprise.sobject.SObject - CloseDate
at
org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeseriali
zer.java:258)
at
org.apache.axis.encoding.DeserializationContext.startElement(Deserializa
tionContext.java:1035)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:
165)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.j
ava:1141)
at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at
org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2448)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at
com.sforce.soap.enterprise.SoapBindingStub.query(SoapBindingStub.java:20
91)
at com.jmb.SFTest.testQuery1(SFTest.java:409)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)
AxisFault
faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Invalid element in
com.sforce.soap.enterprise.sobject.SObject - CloseDate
faultActor:
faultNode:
faultDetail:
I am not sure what is happening here, but it is possible that by
outputting the message from the MessageContext, I may need to reset the
parser to read from the beginning of the SOAP response?
Any suggestions very welcome!
Cheers,
-Jonathan
BEGIN:VCARD
VERSION:2.1
N:Bruce;Jonathan
FN:Jonathan Bruce
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20050222T172123Z
END:VCARD