I have a webservice developed in java working perfectly, but I need to send the namespace xmlns:xsi
and xmlns:xsd
as shown in the example below:
I have a webservice developed in java working perfectly, but I need to send the namespace xmlns:xsi
and xmlns:xsd
as shown in the example below:
Well, I was able to find a solution to my problem (I do not know if it would be better).
I accessed the message at the time of sending through a "message handlers" and added the namespace.
I implemented it as follows:
handler-chain.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE xml>
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>br.com.ws.handler.AddNamespaceDeclarationHandler</handler-class>
</handler>
<handler>
</handler-chain>
</handler-chains>
Webservice Implementation:
@WebService(serviceName = "NOTFIS",
endpointInterface = "br.com.ws.NOTFISSoap",
targetNamespace = "http://tempuri.org/")
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
@HandlerChain(file="/handler-chain.xml")
public class NOTFISSoapImpl implements NOTFISSoap {
// Código...
}
My "message handlers"
public class AddNamespaceDeclarationHandler implements SOAPHandler<SOAPMessageContext> {
private void addNamespaceDeclaration(SOAPMessageContext smc) {
try {
if((boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
SOAPMessage message = smc.getMessage();
SOAPPart part = message.getSOAPPart();
SOAPHeader header = message.getSOAPHeader();
SOAPEnvelope envelope = part.getEnvelope();
header.detachNode();
envelope.addNamespaceDeclaration("xsi", "http://www.w3.org/2001/XMLSchema-instance");
envelope.addNamespaceDeclaration("xsd", "http://www.w3.org/2001/XMLSchema");
}
}
catch (Exception e) {
System.out.printf("Exception in handler: %s%n", e);
}
}
}