2013-02-13 74 views
1
<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); 

我想將自定義頭添加到使用軸2和壘的soap請求中。 但低於是我得到Axis 2和壘開發問題,同時將請求頭添加到請求中

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 
+0

我得到了同樣的錯誤。但我沒有發現錯誤請給我示例應用程序 – 2015-10-12 04:39:17

+0

@sureshmanda,您是否正在通過軸2在soap請求中添加額外的標題信息,例如:「 test」? – 2016-01-11 09:33:26

+0

是的,但我不是這樣的。 – 2016-01-14 03:47:47

回答

0

如果你想使用你正在使用壁壘搞那麼你喜歡面對上述問題在這裏Example Custom Headers和地方提供的提示來添加標題中的例外。

解決方案是增加在META-INF自己module.xml並添加了流動在其中添加自定義頁眉

<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 

} } 

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

在客戶端搞你的模塊前壘像

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

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

..