org.jboss.resteasy.spi.UnhandledException:javax.xml.ws.soap.SOAPFaultException:ARERR [149]控制记录中必须提供用户名

时间:2014-11-18 08:22:27

标签: java web-services rest java-ee soap

大家好,我需要一个帮助。

我正在编写wsdl的包装器顶部。

我的SOAPUI-请求是: -

我需要像这样发送我的请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UET_CMContacts_WS">
   <soapenv:Header>
      <urn:AuthenticationInfo>
         <urn:userName>test</urn:userName>
         <urn:password>test</urn:password>
      </urn:AuthenticationInfo>
   </soapenv:Header>
   <soapenv:Body>
      <urn:opGetContacts>
         <urn:Qualification>LoginName="TEST"</urn:Qualification>
         <urn:startRecord>0</urn:startRecord>
         <urn:maxLimit>20</urn:maxLimit>
      </urn:opGetContacts>
   </soapenv:Body>
</soapenv:Envelope>

这是我的Java代码

        UETCMContactsWSService service1 = new UETCMContactsWSService();
        service1.setHandlerResolver(new SOAPHandlerResolver());
        ContactDetailsPortType port1 = service1.getContactDetailsSoap();

        AuthenticationInfo authInfo = new AuthenticationInfo();
        authInfo.setUserName(uetRequestParameters.getUserName());
        authInfo.setPassword(uetRequestParameters.getPassword());

        Map<String, Object> requestContext = ((BindingProvider)port1).getRequestContext();
        requestContext.put(BindingProvider.USERNAME_PROPERTY, uetRequestParameters.getUserName());  
        requestContext.put(BindingProvider.PASSWORD_PROPERTY, uetRequestParameters.getPassword());  
        requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, requestContext);    

        InputMapping1 inputMap = new InputMapping1();
        inputMap.setQualification(uetRequestParameters.getQualification());
        inputMap.setStartRecord(uetRequestParameters.getStartRecord());
        inputMap.setMaxLimit(uetRequestParameters.getMaxLimit());

         List<GetListValues>  getListValue= port1.opGetContacts(
                 inputMap.getQualification(),
                 inputMap.getStartRecord(),
                 inputMap.getMaxLimit());

在我在SOAPHandler中查看我的响应时使用此代码

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
    <soap:Body>
        <opGetContacts xmlns="urn:UET_CMContacts_WS">
            <Qualification>VKUMARRA</Qualification>
            <startRecord>0</startRecord>
            <maxLimit>20</maxLimit>
        </opGetContacts>
    </soap:Body>
</soap:Envelope>

我也得到例外: -

12:50:15,924 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/UETProfile].[Resteasy]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet Resteasy threw exception: org.jboss.resteasy.spi.UnhandledException: javax.xml.ws.soap.SOAPFaultException: ARERR [149] A user name must be supplied in the control record
    at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:365) [resteasy-jaxrs-2.3.7.Final-redhat-2.jar:2.3.7.Final-redhat-2]
    [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_65]
Caused by: javax.xml.ws.soap.SOAPFaultException: ARERR [149] A user name must be supplied in the control record
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:157)
    at com.sun.proxy.$Proxy62.opGetContacts(Unknown Source)
    at com.cox.etadirect.rs.route.GetUetProfileWS.startRoute(GetUetProfileWS.java:90) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_65]

任何人对我出错的地方都有任何想法。

1 个答案:

答案 0 :(得分:0)

我认为您的代码中有些内容与您的请求不符。例如,如您所说,您想在soap:Header

中添加跟随xml片段
<soap:Header>
   <urn:AuthenticationInfo>
      <urn:userName>test</urn:userName>
      <urn:password>test</urn:password>
   </urn:AuthenticationInfo>
</soap:Header>

正如我在您的代码中看到的,您正在创建此结构:

AuthenticationInfo authInfo = new AuthenticationInfo();
authInfo.setUserName(uetRequestParameters.getUserName());
authInfo.setPassword(uetRequestParameters.getPassword());

但是,在您的代码中,您可以定义它,但不会在soap:Header请求中分配它。

此外,您正在尝试为http heades添加http basic authentication,我认为这对您的WS来说并不是必需的(至少您不会在您的问题中说出来):

Map<String, Object> requestContext = ((BindingProvider)port1).getRequestContext();
requestContext.put(BindingProvider.USERNAME_PROPERTY, uetRequestParameters.getUserName());  
requestContext.put(BindingProvider.PASSWORD_PROPERTY, uetRequestParameters.getPassword());  
requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, requestContext);  

我认为解决方案只是将authInfo放在{期望的soap:Header中。

希望这有帮助,