Hi,
i now managed to put in a Processing Instruction before the normal XML-payload,
by writing a module/handler that does the following:
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
public InvocationResponse invoke(MessageContext msgCtx) throws AxisFault {
SOAPEnvelope env = msgCtx.getEnvelope();
SOAPBody body = env.getBody();
QName docName = new QName(myUri, myRequest);
OMElement request = (OMElement) body.getFirstChildWithName(docName);
OMFactory factory = request.getOMFactory();
OMProcessingInstructionImpl pi = new
OMProcessingInstructionImpl(body,factory);
pi.setTarget(myTarget);
pi.setValue(myValue);
request.detach();
body.addChild(pi);
body.addChild(request);
return InvocationResponse.CONTINUE;
}
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
>From my point of view this works fine, but doing this i ran into a bunch of
>new problems:
a) First of all i get a NullpointerException:
java.lang.NullPointerException
at
org.apache.axiom.om.impl.llom.OMSourcedElementImpl.serializeAndConsume(OMSourcedElementImpl.java:771)
at
org.apache.axis2.transport.http.ApplicationXMLFormatter.getBytes(ApplicationXMLFormatter.java:99)
at
org.apache.axis2.transport.http.ApplicationXMLFormatter.getBytes(ApplicationXMLFormatter.java:52)
at
org.apache.axis2.transport.http.AxisRequestEntity.getContentLength(AxisRequestEntity.java:109)
at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.getRequestContentLength(EntityEnclosingMethod.java:336)
at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.addContentLengthRequestHeader(EntityEnclosingMethod.java:406)
at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.addRequestHeaders(EntityEnclosingMethod.java:374)
at
org.apache.commons.httpclient.HttpMethodBase.writeRequestHeaders(HttpMethodBase.java:2177)
at
org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2060)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:189)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)
at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:209)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
...
I did not yet realized, what exactly happened therein, but maybe the following
points put some light on this.
b) the above stack shows that the ApplicationXMLFormatter is used instead of
the XFormURLEncodedFormatter, which i would have expected as i configured the
service this way (line marked with /* !!! <----- !!! */) :
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
public static void main(String[] args) {
System.setProperty("javax.net.debug", "all");
System.setProperty("java.security.debug", "all");
System.setProperty("javax.net.ssl.keyStore", keyStore);
System.setProperty("javax.net.ssl.keyStorePassword", "materna");
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", keyStore);
System.setProperty("javax.net.ssl.trustStorePassword", "materna");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
AxisConfiguration axisConfig = new AxisConfiguration();
ConfigurationContext myConfigContext;
try {
myConfigContext =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repositoryPath,
axis2_XML_File );
} catch (AxisFault e1) {
e1.printStackTrace();
return;
}
myConfigContext.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION,
Constants.VALUE_TRUE);
myConfigContext.setProperty(Constants.Configuration.CONTENT_TYPE ,
HTTPConstants.MEDIA_TYPE_X_WWW_FORM); /* !!! <----- !!! */
myConfigContext.setProperty(Constants.Configuration.ENABLE_REST,
Constants.VALUE_TRUE);
myConfigContext.setProperty(Constants.Configuration.HTTP_METHOD ,
org.apache.axis2.Constants.Configuration.HTTP_METHOD_POST);
myConfigContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,
Boolean.FALSE);
org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties proxy =
new org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties();
proxy.setProxyName(proxyName);
proxy.setProxyPort(proxyPort);
myConfigContext.setProperty(HTTPConstants.PROXY , proxy);
myConfigContext.setProperty(HTTPConstants.PROTOCOL_VERSION ,
HTTPConstants.HEADER_PROTOCOL_10);
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
What am missing/doing wrong? The repository and axis2.xml are copies from the
axis2 distribution, with just one added module (see above) and one added phase
before soapmonitor.
c) Whilst debugging through the code i realized the following:
Axis2 1.4.1 in ApplicationXMLFormatter.getBytes , ApplicationXMLFormatter.java,
lines 78ff
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
SOAPFaultDetail soapFaultDetail = fault.getDetail();
omElement = soapFaultDetail.getFirstElement();
if (omElement == null) {
omElement = fault.getReason();
}
} else {
// Normal case: The xml payload is the first element in the body.
omElement = messageContext.getEnvelope().getBody().getFirstElement();
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
if (omElement != null) {
try {
if (preserve) {
omElement.serialize(bytesOut, format);
} else {
omElement.serializeAndConsume(bytesOut, format);
}
} catch (XMLStreamException e) {
throw AxisFault.makeFault(e);
}
return bytesOut.toByteArray();
}
---------------------------------------------------------------------------------8<---------------------------------------------------------------------------------
Calculating the content_length (and perhaps generating the message text?) by
looking at body.getFirstElement() only,
does the job in the normal case as mentioned in the comment,
but iterating through all siblings of body from body.getFirstElement to
body.getLastElement would have done a much more flexible job
with the same result in the normal case and perhaps my manipulated request, too.
I don't know whether this should be realized as a bug and my questions at this
point is:
Are there other predefined handlers that i can use?
If yes, how can i manag to use them instead?
Thanks a lot for any help
Martin
________________________________
Von: Berns, Martin
Gesendet: Montag, 27. Oktober 2008 12:10
An: '[email protected]'
Betreff: AW: AW: Axis2 wsdl2java client: How to add processing instructions
Hi Martin,
thanks a lot for your answer.
As i mentioned in my first email, i am indeed implementing a RESTful client,
where the XML-Request is just the body of a HTTP POST.
The server i am trying to interact with, is no axis2 server, nor is it a
Webservice at all, but a normal Servlet run by Apache Coyote. This servlet is
acting like a RESTful Server, with only one restriction: It requires a
processing instruction in front of the XML-Requst.
Currently my axis2-client is able to do the request in the Form
HTTP HEADERs
XML Request
but what i need is
HTTP HEADERs
<? provider version="1.0" ?>
XML Request
With other words i need is a possibility to enhance the body of the HTTP POST
with one line containg the processing instruction <? provider version="1.0" ?>.
Thanks in advance
Martin
________________________________
Von: Martin Gainty [mailto:[EMAIL PROTECTED]
Gesendet: Samstag, 25. Oktober 2008 03:48
An: [email protected]
Betreff: RE: AW: Axis2 wsdl2java client: How to add processing instructions
Martin-
there is no dynamic operation confugration available (perhaps with REST) but
none with typical doc-literal
so you'll need to ensure your webservice supports the operation before
attempting ant client to contact that service
so when you reference the service at
http://HOST:PORT/axis2/services
what operations and what parameters for those operations are available to the
client?
Viel Gluck
Martin-
> Subject: AW: Axis2 wsdl2java client: How to add processing instructions
> Date: Fri, 24 Oct 2008 17:32:46 +0200
> From: [EMAIL PROTECTED]
> To: [email protected]
>
> Hi,
>
> the response is now read correctly by axis2, so please forget about point b).
> (For your interest: It was a trailing "/" in the namespace uri that made the
> difference between server and client and forced this problem).
>
> So there is only one problem left - point a):
> I need a way to put a processing instruction before my requests like:
>
> <?provider version="1.0"?>
>
> Any hint is highly appreciated!
> Thanks in advance and best regards
>
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Gesendet: Donnerstag, 23. Oktober 2008 13:17
> An: [email protected]
> Betreff: Axis2 wsdl2java client: How to add processing instructions
>
> Hi,
>
>
> I am trying to implement a client with axis2 1.4.1 (REST) for a "legacy
> webservice". This webservice is defined as just sending XML per HTTP POST
> (x-www-form-urlencoded) and getting the answer message as a supplement of the
> http response.
> I generated a WSDL file according to the specification provided by the
> webservice provider and created a client with wsdl2java (ADB). This is
> working pretty fine, but i have two problems, i couldn't solve so far:
>
> a) My requests are answered with an error message hinting towards two missing
> processing instructions, at the beginnning of the request like
>
> <?xml version="1.0" encoding="ISO-8859-1"?> <?provider version="1.0"?>
>
> I found a mailthread(Need for Child API in OMDocument:
> http://markmail.org/search/?q=axis2+%22Need+for+Child+API+in+OMDocument+
> %22 ) that suggests a possibility, to add such instructions before the
> transport, but i did not find a way to use this. Can anybody give me a hint,
> how to do this or where to look further? Or is it possible to declare such
> processing instructions already inside the WSDL?
>
> b) the received http response of the webservice (containing the error message
> in the XML supplement) is not recognized by axis2, though it looks quite
> correct. The error message is
> org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException:
> Unexpected subelement EngineAnswer
> I have not finally analyzed the exact reason by debugging through the code,
> but I am affraid i will have to manipulate the http response in a similar
> manner like the request, before it is handed over to the axis2 parsing. So,
> if anybody has a way to achieve this at his fingertips, his help is
> appreciated very much!
>
> I'm pretty new to axis ( and java as well ) so please forgive me, if this is
> a BRTFM.
>
>
> Thanks in advance for any hint and best regards Martin Berns
>
>
> P.S.: My actual configuration is:
>
> AxisConfiguration axisConfig = new AxisConfiguration();
> ConfigurationContext myConfigContext;
> try {
> myConfigContext =
> ConfigurationContextFactory.createConfigurationContextFromFileSystem(nul
> l , null);
> } catch (AxisFault e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> return;
> }
> myConfigContext.setProperty(Constants.Configuration.ENABLE_REST,
> Constants.VALUE_TRUE);
> myConfigContext.setProperty(Constants.Configuration.HTTP_METHOD ,
> org.apache.axis2.Constants.Configuration.HTTP_METHOD_POST);
>
> myConfigContext.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION,
> Constants.VALUE_TRUE);
> myConfigContext.setProperty(Constants.Configuration.CONTENT_TYPE ,
> HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
>
> myConfigContext.setProperty(org.apache.axis2.transport.http.HTTPConstant
> s.CHUNKED, Boolean.FALSE);
>
> org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties
> proxy = new
> org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties(
> );
> proxy.setProxyName(proxyName);
> proxy.setProxyPort(8080);
> myConfigContext.setProperty(HTTPConstants.PROXY , proxy);
> myConfigContext.setProperty(HTTPConstants.PROTOCOL_VERSION ,
> HTTPConstants.HEADER_PROTOCOL_10);
> try {
> myServiceStub myStub = new myServiceStub(myConfigContext, myUrl);
> ...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
________________________________
You live life beyond your PC. So now Windows goes beyond your PC. See how
<http://clk.atdmt.com/MRT/go/115298556/direct/01/>