简体   繁体   English

Java-在Spring Boot中使用AXIS更改SOAP请求格式

[英]Java - Change SOAP Request Format using AXIS in Spring Boot

I am tried to consuming SOAP web service in Spring Boot. 我试图在Spring Boot中使用SOAP Web服务。 and generated the classes using Axis. 并使用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: Axis Serializer和deSerializer代码如下:

// 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. 任何人都可以帮忙。

I'm not sure, why you are caring much about the place of XML namespace prefix. 我不确定,为什么您会关心XML名称空间前缀的位置。

Logically XML A 逻辑上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 和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. 除了在这里和那里很少的String字符外,没有什么区别。

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 . 在XML A的情况下,名称空间是在根级别定义的,因此,子级需要具有本地名称前缀以进行标识(尽管如果没有冲突的\\相同名称节点,则可以跳过此名称,这似乎是您的情况),它属于名称空间soapprim

In case of XML B, namespace is defined at parent node (UserList )level, hence all child nodes could be avoided to have localname prefix. 对于XML B,名称空间是在parent node (UserList)级别定义的,因此可以避免所有子节点都具有localname前缀。 ie Defining a default namespace for an element saves us from using prefixes in all the child elements. 即为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. 有关更多详细信息,请参考XML命名空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM