0

I am tried to consuming SOAP web service in Spring Boot. and generated the classes using Axis.

I am sending the soap request from client and it is changing the format of the request while going to server.

Please find the client sending request and server receiving request as below:

SOAP Client sending Request:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prim="http://..../..Services">
        <soapenv:Header />
        <soapenv:Body>
          <prim:UserList>
            <prim:XMLRequest>
              <prim:Header>
                <prim:MessageID>1</prim:MessageID>
                <prim:CorrelationID>1</CorrelationID>
              </prim:Header>
            </prim:XMLRequest>
          </prim:UserList>
        </soapenv:Body>
      </soapenv:Envelope>

SOAP Server receiving Request:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <soapenv:Body>
          <UserList xmlns="hhttp://..../..Services">
            <XMLRequest>
              <header>
                <MessageID>1</MessageID>
                <CorrelationID>1</CorrelationID>
              </header>
            </XMLRequest>
          </UserList>
        </soapenv:Body>
      </soapenv:Envelope>

Trying to call using below code:

public  UserListResponse UserListService(UserList request)
            throws RemoteException, ServiceException {


        UserListRequest xmlRequest = new UserListRequest();

        Header reqHeader = request.getXMLRequest().getHeader();

        Header header = new Header();

        header.setCorrelationID(reqHeader.getCorrelationID());
        header.setMessageID(reqHeader.getMessageID());

        xmlRequest.setHeader(header);

        return soapStub.UserList(xmlRequest);

    }

Axis Serializer & deSerializer code as below:

// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
    new org.apache.axis.description.TypeDesc(Header.class, true);

static {
    typeDesc.setXmlType(new javax.xml.namespace.QName("http://..../..Services", "Header","prim"));

    org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
    elemField.setFieldName("messageID");
    elemField.setXmlName(new javax.xml.namespace.QName("http://..../..Services", "MessageID","prim"));
    elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
    elemField.setMinOccurs(0);
    elemField.setNillable(false);
    typeDesc.addFieldDesc(elemField);
    elemField = new org.apache.axis.description.ElementDesc();
    elemField.setFieldName("correlationID");
    elemField.setXmlName(new javax.xml.namespace.QName("http://..../..Services", "CorrelationID","prim"));
    elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
    elemField.setMinOccurs(0);
    elemField.setNillable(false);
    typeDesc.addFieldDesc(elemField);


}

/**
 * Return type metadata object
 */
public static org.apache.axis.description.TypeDesc getTypeDesc() {
    return typeDesc;
}

/**
 * Get Custom Serializer
 */
public static org.apache.axis.encoding.Serializer getSerializer(
       java.lang.String mechType, 
       java.lang.Class _javaType,  
       javax.xml.namespace.QName _xmlType) {
    return 
      new  org.apache.axis.encoding.ser.BeanSerializer(
        _javaType, _xmlType, typeDesc);
}

/**
 * Get Custom Deserializer
 */
public static org.apache.axis.encoding.Deserializer getDeserializer(
       java.lang.String mechType, 
       java.lang.Class _javaType,  
       javax.xml.namespace.QName _xmlType) {
    return 
      new  org.apache.axis.encoding.ser.BeanDeserializer(
        _javaType, _xmlType, typeDesc);
}

Can anyone please help on this.

Rajeswari Reddy
  • 193
  • 1
  • 6
  • 24
  • You need to provide additional information about the underlying API you're using for Bean to XML serialization. – Red Boy Jun 12 '18 at 16:04

1 Answers1

0

I'm not sure, why you are caring much about the place of XML namespace prefix.

Logically XML A

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prim="http://..../..Services">... <prim:UserList>...</prim:UserList> </soapenv:Body> </soapenv:Envelope>

And XML B

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">... <UserList xmlns="hhttp://..../..Services"> </UserList> </soapenv:Body> </soapenv:Envelope>

of your use case are same. There is no difference except few String characters here and there.

In case of XML A, namespaces are defined at root level, Hence, child needs to have local name prefix to identify(though could be skipped if no conflicting\same name nodes, which seems your case), it belong to namespace soap or prim.

In case of XML B, namespace is defined at parent node(UserList )level, hence all child nodes could be avoided to have localname prefix. i.e. Defining a default namespace for an element saves us from using prefixes in all the child elements.

I hope that answers your question.

Refer XML Namespace for more details.

Red Boy
  • 5,429
  • 3
  • 28
  • 41
  • As per xml I agree with you. But the existing SOAP services are not accepting the Request without prefix. So is there any possibility to create the request same as above like with prefixes in java. Thanks @Red Boy – Rajeswari Reddy Jun 12 '18 at 15:02
  • Yes, there is way, but if depends on library you are using. See if it could help you, if you are using JAXB. https://stackoverflow.com/questions/6895486/jaxb-need-namespace-prefix-to-all-the-elements – Red Boy Jun 12 '18 at 16:05
  • No,I am not using JAXB and i am using axis to generate the classes from wsdl and axis using Serializer and Deserializer to conver xml and i have updated the code above. Please check and help on this. Thanks @Red Boy – Rajeswari Reddy Jun 13 '18 at 05:34
  • You have to modify the beans. like this, `public static final QName MY_QNAME = new QName("http://www.hello.com/Service/", "tagname", "prefix");` Refer https://stackoverflow.com/questions/74960/how-do-i-add-a-namespace-reference-to-a-soap-response-with-apache-axis2-and-wsdl2 – Red Boy Jun 13 '18 at 05:42
  • So prefix need to be set to all elements in the request like as elemField.setXmlName(new javax.xml.namespace.QName("http://..../..Services", "MessageID","prim"));. Please confirm. Thanks @Red Boy – Rajeswari Reddy Jun 13 '18 at 06:00
  • Now i have added prefix to QName even it is not working. I have added code to the post. Can you please check and suggest me. Thanks @Red Boy – Rajeswari Reddy Jun 13 '18 at 07:21