Hi,
sorry for potentially confusing anybody; The last questions (point c)
should be:
 
Are there other predefined formatters (not handlers, as i wrote), that i
can use?

If yes, how can i manage to use them instead of the default formatter?

 

Martin


________________________________

Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Gesendet: Freitag, 31. Oktober 2008 11:57
An: [email protected]
Betreff: AW: AW: Axis2 wsdl2java client: How to add processing
instructions


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(O
MSourcedElementImpl.java:771)

at
org.apache.axis2.transport.http.ApplicationXMLFormatter.getBytes(Applica
tionXMLFormatter.java:99)

at
org.apache.axis2.transport.http.ApplicationXMLFormatter.getBytes(Applica
tionXMLFormatter.java:52)

at
org.apache.axis2.transport.http.AxisRequestEntity.getContentLength(AxisR
equestEntity.java:109)

at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.getRequestCo
ntentLength(EntityEnclosingMethod.java:336)

at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.addContentLe
ngthRequestHeader(EntityEnclosingMethod.java:406)

at
org.apache.commons.httpclient.methods.EntityEnclosingMethod.addRequestHe
aders(EntityEnclosingMethod.java:374)

at
org.apache.commons.httpclient.HttpMethodBase.writeRequestHeaders(HttpMet
hodBase.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(HttpMe
thodDirector.java:398)

at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMetho
dDirector.java:171)

at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
97)

at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:3
46)

at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(Abstrac
tHTTPSender.java:542)

at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:1
89)

at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)

at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageW
ithCommons(CommonsHTTPTransportSender.java:371)

at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(Common
sHTTPTransportSender.java:209)

at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)

at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOper
ation.java:401)

at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInA
xisOperation.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(rep
ositoryPath, 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.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(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

Reply via email to