2

I am migrating a webservice from Weblogic to JBoss. One of the existing clients uses a parser that is sensitive to the namespace prefixes used and I'm not able to influence this. The migration has changed some of the prefixes and I need to be able to revert them.

I looked at various options, many of them coming from this answer, but none seem suitable.

I am using the cxf-codegen-plugin and generating my sources from a WSDL. This seems to deny me the option of adding annotations to my sources.

I also don't use Spring with CXF (since this is not a Spring app, and I'm deploying to JBoss which uses CXF natively), so I don't have the option described in the CXF documentation of using a jaxws:dataBinding (or if I do have that option, I don't understand how to configure it).

I've seen at least one code-based JAXB example that sets a marshaller property, but can't see how to do that declaratively.

My JAXB invocation already involves a custom bindings.xml for mapping dateTime types (for legacy reasons associated with the existing code) and I was expecting that something along the same lines would be possible, but I haven't been able to unearth it.

Does anyone have an idea of how this can be done, given these limitations?

lexicore
  • 42,748
  • 17
  • 132
  • 221
Andy McKibbin
  • 784
  • 1
  • 6
  • 21

1 Answers1

1

Use SOAPHandler and specify as handlerchain in the webservice.

@HandlerChain(file="/handler-chain.xml")
public class WebserviceImpl {

handler-chain.xml (inside WEB-INF/classes)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
    <handler-chain>
        <handler>
            <handler-name>NamespacePrefixHandler</handler-name>
            <handler-class>com.my.package.CustomHandler</handler-class>
        </handler>
    </handler-chain>
</handler-chains>

Implement handleMessage() to get soapenvelope and set the prefix as you want.

final SOAPMessage soapMessage = context.getMessage();
final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
final SOAPBody soapBody = soapMessage.getSOAPBody();

soapEnvelope.setPrefix("my");
soapEnvelope.removeNamespaceDeclaration("soap");

removeNSprefix(soapBody.getChildElements());
soapBody.setPrefix("my");
ulab
  • 1,079
  • 3
  • 15
  • 45