質問

<soapenv:Envelope> 
<soapenv:Header>    
      <cor:india>test</cor:india>
     </soapenv:Header>

<soapenv:Body>
.
.
</soapenv:Body>
</soapenv:Envelope>

     OMFactory omFactory =OMAbstractFactory.getOMFactory();
    OMNamespace omNamespace = omFactory.createOMNamespace("http://example.com/...", "cor");
    OMElement header = omFactory.createOMElement("india", omNamespace);
    header.setText("test");
    stub._getServiceClient().addHeader(header);

I wanted to add the custom header to the soap request which was using the axis 2 and rampart. but below is the exception i am getting

Caused by: org.apache.rampart.RampartException: Error in extracting message properties
    at org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:379)
    at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
    at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:65)
    ... 10 more
Caused by: org.apache.ws.security.WSSecurityException: Error in converting SOAP Envelope to Document; nested exception is: 
    java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to org.apache.axiom.soap.SOAPHeaderBlock
    at org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:191)
    at org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:270)
    ... 12 more
Caused by: java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to org.apache.axiom.soap.SOAPHeaderBlock
    at org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:141)
    ... 13 more
役に立ちましたか?

解決

If you are trying to add header using the tips provided here Example Custom Headers and where as you are using rampart to engage then you are like to face the above problem.

Solution for that is to add your own module.xml in the META-INF and add the out flow where you are adding your custom header

<module name="test" class="exampleClass">

    <OutFlow>

            <handler name="handle" class="exampleClass">
                <order phase="Security"  />
            </handler>
        </OutFlow>
</module>

==================================================================================

public class exampleClass AbstractHandler implements org.apache.axis2.modules.Module {

public InvocationResponse invoke(MessageContext ctx) throws AxisFault {

SOAPEnvelope env = ctx.getEnvelope();
SOAPHeader hdr = env.getHeader();

SOAPFactory factory = (SOAPFactory) env.getOMFactory();

OMNamespace ns = factory.createOMNamespace("http://google.com", "cor");

//SOAPHeader head = factory.createSOAPHeader(env);

hdr.addHeaderBlock("india", ns).setText("value here");

return InvocationResponse.CONTINUE;
}


public void applyPolicy(Policy arg0, AxisDescription arg1) throws AxisFault {
    // TODO Auto-generated method stub

}

public boolean canSupportAssertion(Assertion arg0) {
    // TODO Auto-generated method stub
    return false;
}

public void engageNotify(AxisDescription arg0) throws AxisFault {
    // TODO Auto-generated method stub

}

public void init(ConfigurationContext arg0, AxisModule arg1) throws AxisFault {
    // TODO Auto-generated method stub

}

public void shutdown(ConfigurationContext arg0) throws AxisFault {
    // TODO Auto-generated method stub

} }

================================================================================

In the client engage your module before rampart like

Options options = serviceClient.getOptions();
serviceClient.engageModule("test");

options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,loadPolicy("policy.xml"));
serviceClient.engageModule("rampart");
..

..

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top