如何在JAVA类中使用Unmarshaller SOAP UI值uisng JAXBElement

时间:2018-04-18 06:31:00

标签: java web-services soap soapui

我正在尝试Unmarshaller java类中的SOAP UI值。请找到以下示例:

Apr 17 20:14:10 appserver filebeat: 2018/04/18 00:14:10.378702 log.go:36: 
INFO producer/broker/[[0]] maximum request accumulated, waiting for space

SOAP请求XML在SOAP UI中传递,如下所示:

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserList")
    @ResponsePayload
    public JAXBElement<UserListResponse> UserListRequest(@RequestPayload JAXBElement<UserListRequest> request) throws Exception {
        System.out.println("Enters into UserList()");

          // create an unmarshaller
              JAXBContext context = 
                           JAXBContext.newInstance(UserListRequest.class);//Here i am providing the class name of request parameter
              Unmarshaller unmarshaller = context.createUnmarshaller();

              JAXBElement<UserListRequest> root = unmarshaller.unmarshal(new StreamSource(
                        header), UserListRequest.class); //here I am struggling to unmarshal and I am not getting what is value needs to be passed in place "header"

                 UserListRequest list = root .getValue();

                }
            }

任何人都可以帮助Java Class中的Unmarshaller <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prim="http://COM.SERVICES.WebServices/UserServices"> <soapenv:Header/> <soapenv:Body> <prim:UserList> <!--Optional:--> <prim:XMLRequest> <!--Optional:--> <prim:Header> <!--Optional:--> <prim:MessageID>2</prim:MessageID> <!--Optional:--> <prim:CorrelationID>2</prim:CorrelationID> <!--Optional:--> <prim:SystemID>2</prim:SystemID> <!--Optional:--> <prim:RequestorID>2</prim:RequestorID> </prim:Header> <prim:Reference>C</prim:Reference> <!--Optional:--> <prim:Number>1120521877477751</prim:Number> <!--Optional:--> <prim:Usercount>51</prim:Usercount> </prim:XMLRequest> </prim:UserList> </soapenv:Body> </soapenv:Envelope> 请求。

1 个答案:

答案 0 :(得分:0)

抛出错误的行......

JAXBElement<UserListRequest> root =
    unmarshaller.unmarshal(new StreamSource(header), UserListRequest.class)

在方法中的任何位置都没有声明var标头。你不应该最初&#39; unmarshall&#39;或解析传入的请求&#39;在尝试查看传入的标头之前的var?

还值得注意的是,您的SoapUI请求没有标题。

<soapenv:Header/>

表示我没有传递任何标题信息。