| Summary | This article explains a way to manipulate the prefix of SOAP elements in a response sent out from an Artix 5.6 JAX-WS server. |
|---|---|
| Article Number | 35881 |
| Environment | Artix 5.6 Java (JAX-WS) All supported Operating Systems |
| Question/Problem Description | How to manipulate the prefix of SOAP elements in a response sent out from an Artix JAX-WS server? How to change the prefix of standard SOAP elements (Envelope, Header, Body) in a response? |
| Clarifying Information | An Artix 5.6 JAX-WS response has the following format: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body> ... </soap:Body></soap:Envelope> In certain cases the client might expect a different prefix for the SOAP elements in the respose, e.g. in the following format <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body> ... </SOAP-ENV:Body></SOAP-ENV:Envelope> In such a case the response needs to be manipulated in order to achieve the expected format. |
| Error Message | |
| Defect/Enhancement Number | |
| Cause | |
| Resolution | The prefix can be changed by manipulating the response sent back to the client in a JAX-WS handler and replacing the soap prefix with SOAP-ENV prefix. Artix 5.6 Java contains samples of JAX-WS handlers in the samples\\cxf\\jaxws_handlers which demonstrates how to write a JAX-WS handler. Please see the LoggingHandler as an example. In order to replace the prefix of a response, the handleMessage() method needs to contain the following code: public boolean handleMessage(SOAPMessageContext smc) { Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (outboundProperty.booleanValue()) { try { SOAPMessage msg = smc.getMessage(); SOAPPart sp = msg.getSOAPPart(); sp.getEnvelope().removeNamespaceDeclaration("soap"); sp.getEnvelope().setPrefix("SOAP-ENV"); sp.getEnvelope().getBody().setPrefix("SOAP-ENV"); sp.getEnvelope().getHeader().setPrefix("SOAP-ENV"); smc.setMessage(msg); } catch (Exception e) { e.printStackTrace(); } return true; } |
| Workaround | |
| Notes | |
| Attachment |
| Created date: | 31 October 2012 |
|---|---|
| Last Modified: | 12 February 2013 |
| Last Published: | 31 October 2012 |
| First Published date: | 31 October 2012 |
#KnowledgeDocs
#Orbix



