Khaled adel Khaled adel - 4 months ago 18
Java Question

Get rid of empty xmlns element in JAX-WS

I am trying to generate a request like this using JAX-WS Client:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:alin="http://www.alinma.com" xmlns="http://www.alinma.com">
<soapenv:Header/>
<soapenv:Body>
<alin:CustDtlsInqRq>
<alin:MsgRqHdr>
<RqUID>BPM11957T201508101626333904816</RqUID>
<SCId>BPMP</SCId>
<FuncId>24000000</FuncId>
<RqMode>0</RqMode>
<CustLangPref>En</CustLangPref>
<CustId>
<CIF>6060</CIF>
</CustId>
<AgentId>OprtSupportReviewer</AgentId>
</alin:MsgRqHdr>
<Body>
<CIF>6060</CIF>
</Body>
</alin:CustDtlsInqRq>
</soapenv:Body>




But the request is generated like this:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.alinma.com">
<S:Header/>
<S:Body>
<ns2:CustDtlsInqRq xmlns:ns2="http://www.alinma.com">
<MsgRqHdr xmlns="">
<RqUID>OLPM201508261333149660000020</RqUID>
<SCId>BPMP</SCId>
<FuncId>24000000</FuncId>
<CustLangPref>En</CustLangPref>
<CustId>
<CIF>6060</CIF>
</CustId>
</MsgRqHdr>
<Body xmlns="">
<CIF>6060</CIF>
</Body>
</ns2:CustDtlsInqRq>
</S:Body>




the added tag
xmlns=""
makes problems in server side
This is the code of my Handler that surround the request with SOAP Envelop

if (outboundProperty.booleanValue()) {

try {
SOAPMessage soapMessage = context.getMessage();

SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
soapEnvelope.addNamespaceDeclaration("", "http://www.alinma.com");
// Grab the header of the SOAP envelop
SOAPHeader soapHeader = soapEnvelope.getHeader();

// Attach a new header if there is none...
if (soapHeader == null) {
soapHeader = soapEnvelope.addHeader();
}

soapMessage.saveChanges();
soapMessage.writeTo(System.out); //TODO: remove this line (just for debugging)

} catch (Exception e) {
logger.error("Error Creating SOAP message", e);
}

}


How can I adjust the empty
xmlns
tags?

Answer

I could solve the problem. By mistake I removed the generated file package-info.java which include a header namespace definition for all the package classes

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.alinma.com", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.ejada.sadadolp.bkf.mwservices.core;