axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simon Fell" <sf...@salesforce.com>
Subject RE: Adding Handlers to Axis 1.2.1
Date Tue, 12 Jul 2005 18:06:47 GMT
I use this.getSoapWSDDServiceName() for the service name. 

-----Original Message-----
From: Jonathan Bruce [mailto:Jonathan.Bruce@datadirect.com] 
Sent: Tuesday, July 12, 2005 11:01 AM
To: axis-user@ws.apache.org
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:sfell@salesforce.com]
Sent: Tuesday, July 12, 2005 13:02
To: axis-user@ws.apache.org
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:Jonathan.Bruce@datadirect.com]
Sent: Tuesday, July 12, 2005 7:51 AM
To: axis-user@ws.apache.org
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 








Mime
View raw message