调用webservice

时间:2016-11-18 12:19:18

标签: java eclipse web-services jboss jaxb

我们有一个web服务,其实现在.net中完成。我们从java调用这个web服务。 web服务在大多数情况下都完全正常,但有时它会抛出IllegalArgumentException。

webservice有两个名为pointEnquiry和pointEarnedEnquiry的方法。这两种方法都有一个参数,如pointEnquiryResult和pointEarnedEnquiryResult。响应包装器分别是PointEnquiryResponse和PointsEarnedEnquiryResponse。

面临的问题是抛出IllegalArgumentException,状态无法将PointEnquiryRespone.pointEnquiryResult设置为PointEarnedEnquiryResponse。

此外,这两种方法的返回类型都是JAXBElement。

我无法理解与包装类相关的返回类型是什么以及为什么pointEnquiryResult在它不属于该类时尝试将自身映射到PointEarnedEnquiry响应。

请找到堆栈跟踪

javax.xml.ws.WebServiceExcep`tion:java.lang.IllegalArgumentException异常:无法设置javax.xml.bind.JAXBElement字段com.abc.xyz.PointEnquiryResponse.pointEnquiryResult到com.abc.xyz.PointEarnedEnquiryResponse在有机位于org.jboss.ws的org.jboss.ws.core.jaxws.client.ClientImpl.invoke(ClientImpl.java:314)的jboss.ws.core.jaxws.client.ClientImpl.handleRemoteException(ClientImpl.java:404)。来自com的$ Proxy464.pointEarnedEnquiry(未知来源)的org.jboss.ws.core.jaxws.client.ClientProxy.invoke(ClientProxy.java:152)中的core.jaxws.client.ClientProxy.invoke(ClientProxy.java:172) .hh.test.client.KioskService.pointEarnedEnquiry(CMPKioskService.java:118)在com.hh.test.service.kioskInterface.KioskEndPointImpl.pointsEarnedEnquiry(KioskEndPointImpl.java:704)在sun.reflect.GeneratedMethodAccessor2561.invoke(未知来源)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at或g.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)在org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)在org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke( EJB3InterceptorsInterceptor.java:63)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)在org.jboss.aop .joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)在org.jboss.aspects.tx.TxInterceptor $ Required.invoke(TxInterceptor.java:191)在org.jboss.aop.joinpoint.MethodInvocation。 org.jboss中的invokeNext(MethodInvocation.java:101)。方案.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java: 62)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.aspects.security.RoleBasedAuthorizationInterceptor.invoke(RoleBasedAuthorizationInterceptor.java:166)在org.jboss.ejb3.security.RoleBasedAuthorizationInterceptor .invoke(RoleBasedAuthorizationInterceptor.java:115)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)在有机jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.ejb3.ENCPropagationIntercept or.invoke(ENCPropagationInterceptor.java:46)在org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)在组织.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)在org.jboss.wsf.container.jboss42.InvocationHandlerEJB3.invoke(InvocationHandlerEJB3.java:103)在org.jboss.ws.core.server.ServiceEndpointInvoker .invoke(ServiceEndpointInvoker.java:221)org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:466)org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:284) )在org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:201)在org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:134)在org.jboss.wsf。 stack.jbws.EndpointServlet.service(EndpointServlet.java:84),位于javax.servlet.http.HttpServlet.service(HttpSer) vlet.java:803)处org.jboss.web在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290))位于org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)的.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java) :206)在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)在org.jboss.web.tomcat。 security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)在org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java: 84)at org.apache.catalina.core.StandardH ostValve.invoke(StandardHostValve.java:127)在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)在org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java: 157)在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)在org.apache.coyote.http11.Http11Processor .process(Http11Processor.java:844)在org.apache.coyote.http11.Http11Protocol $在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run Http11ConnectionHandler.process(Http11Protocol.java:583)(JIoEndpoint.java :446)at java.lang.Thread.run(Thread.java:662)引起:java.lang.IllegalArgumentException:无法将com.ballytech.kioskpoint中的javax.xml.bind.JAXBElement字段com.ballytech.kioskpointsenquiry.PointEnquiryResponse.pointEnquiryResult设置为com。 sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentExcepti的ballytech.kioskpointsenquiry.PointEarnedEnquiryResponse on(UnsafeFieldAccessorImpl.java:146)sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java) :18)在java.lang.reflect.Field.get(Field.java:358)的com.sun.xml.bind.v2.runtime.reflect.Accessor $ FieldReflection.get(Accessor.java:231)at com。 sun.com.bind.v2.runtime.property.SingleReferenceNodeProperty $ 1.get(SingleReferenceNodeProperty.java:141)at com.sun.xml.bind.v2.runtime.reflect.Accessor.getUnadapted(Accessor.java:147)at com位于org.jboss.ws的org.jboss.ws.metadata.accessor.JAXBAccessor.get(JAXBAccessor.java:50)的.sun.xml.bind.v2.runtime.JAXBContextImpl $ 6.get(JAXBContextImpl.java:917)。 org.jb上的org.jboss.ws.core.CommonClient.syncOutputParams(CommonClient.java:510)中的core.jaxrpc.ParameterWrapping.unwrapResponseParameters(ParameterWrapping.java:226) oss.ws.core.CommonClient.invoke(CommonClient.java:396)atg.jboss.ws.core.jaxws.client.ClientImpl.invoke(ClientImpl.java:302)

请找到更多详情:

以下是用于调用Web服务的代码。它使用RPC样式通信。

public PlayerPointsEnquiryParameter pointEnquiry(String playerId) throws Exception {
    PlayerPointsEnquiryParameter playerPointsEnquiryParameter  =null;
    try {
        if(iPointsEnquiry == null){
            URL wsdlURL = new URL(SWSUtility.getCMPPointEquiryURL());
            if(logger.isDebugEnabled()){
                logger.debug("URL invoked : " + wsdlURL.toString());
            }
            Service service = Service.create(wsdlURL,_cmpPointEnqiry_QNAME);
            iPointsEnquiry = service.getPort(IPointsEnquiry.class);
        }

        playerPointsEnquiryParameter  = iPointsEnquiry.pointEnquiry(playerId);
        if(logger.isDebugEnabled()){
            logger.debug("playerPointsEnquiryParameter"+ playerPointsEnquiryParameter);
        }
    } catch (MalformedURLException e) {
        iPointsEnquiry = null;
        logger.error("Malformed URL", e);
        throw e;
    } catch (Exception e) {
        iPointsEnquiry = null;
        logger.error("Exception @", e);
        throw e;
    }
    return playerPointsEnquiryParameter;
}

public PlayerPointsEnquiryParameter pointEarnedEnquiry(String partonID, GregorianCalendar dtStartDate, GregorianCalendar dtEndDate ) throws Exception {
    PlayerPointsEnquiryParameter playerPointsEnquiryParameter  =null;
    try {
        XMLGregorianCalendar calenderdtStartDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(dtStartDate);  
        XMLGregorianCalendar calendedtEndDater = DatatypeFactory.newInstance().newXMLGregorianCalendar(dtEndDate);
        if(iPointsEnquiry == null){
            URL wsdlURL = new URL(SWSUtility.getCMPPointEquiryURL());
            if(logger.isDebugEnabled()){
                logger.debug("URL invoked : " + wsdlURL.toString());
            }
            Service service = Service.create(wsdlURL,_cmpPointEnqiry_QNAME);
            iPointsEnquiry = service.getPort(IPointsEnquiry.class);
        }

        playerPointsEnquiryParameter  = iPointsEnquiry.pointEarnedEnquiry(partonID, calenderdtStartDate, calendedtEndDater);
        if(logger.isDebugEnabled()){
            logger.debug("playerPointsEnquiryParameter"+ playerPointsEnquiryParameter);
        }
    } catch (MalformedURLException e) {
        logger.error("Malformed URL", e);
        iPointsEnquiry = null;
        throw e;
    } catch (Exception e) {
        logger.error("Exception @", e);
        iPointsEnquiry = null;
        throw e;
    }
    return playerPointsEnquiryParameter;
}

以下是实施

public abstract interface IPointsEnquiry
{
  @WebMethod(operationName="PointEnquiry", action="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEnquiry")
  @WebResult(name="PointEnquiryResult", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry")
  @RequestWrapper(localName="PointEnquiry", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry", className="com.hhtechno.kioskpointsenquiry.PointEnquiry")
  @ResponseWrapper(localName="PointEnquiryResponse", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry", className="com.hhtechno.kioskpointsenquiry.PointEnquiryResponse")
  @Action(input="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEnquiry", output="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEnquiryResponse")
  public abstract PlayerPointsEnquiryParameter pointEnquiry(@WebParam(name="strPlayerId", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry") String paramString);


  @WebMethod(operationName="PointEarnedEnquiry", action="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEarnedEnquiry")
  @WebResult(name="PointEarnedEnquiryResult", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry")
  @RequestWrapper(localName="PointEarnedEnquiry", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry", className="com.hhtechno.kioskpointsenquiry.PointEarnedEnquiry")
  @ResponseWrapper(localName="PointEarnedEnquiryResponse", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry", className="com.hhtechno.kioskpointsenquiry.PointEarnedEnquiryResponse")
  @Action(input="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEarnedEnquiry", output="http://www.hhtechno.com/KioskPointsEnquiry/IPointsEnquiry/PointEarnedEnquiryResponse")
  public abstract PlayerPointsEnquiryParameter pointEarnedEnquiry(@WebParam(name="strPlayerId", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry") String paramString, @WebParam(name="strStartDate", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry") XMLGregorianCalendar paramXMLGregorianCalendar1, @WebParam(name="strEndDate", targetNamespace="http://www.hhtechno.com/KioskPointsEnquiry") XMLGregorianCalendar paramXMLGregorianCalendar2);
}

我遇到的问题是其中一个线程让我们说t1正在调用方法pointEnquiry并等待响应。同时,另一个线程t2进入图片并调用pointsEarnedEnquiry。几秒钟后,线程t1抛出IllegalArgumentException,如上所述。

我检查了服务器端,对于线程t1发出的请求,生成并发送了适当的响应。

我的问题:

  1. 由于Web服务中两个web方法的返回类型相同,即PlayerPointsEnquiryMethod,我在客户端没有进行任何类型的解包,为什么我会得到一个例外

      

    无法将javax.xml.bind.JAXBElement字段com.hhtechno.kioskpointsenquiry.PointEarnedEnquiryResponse.pointEarnedEnquiryResult设置为com.hhtechno.kioskpointsenquiry.PointEnquiryResponse。

  2. 两种方法的不同之处在于Request和Response Wrappers。虽然pointsEnquiry将ResponseWrapper作为PointsEnquiryResponse,但pointsEarnedEnquiry将ResponseWrapper作为PointsEarnedEnquiryResponse。必须有一些东西指示unmarshaller打开对PointsEarnedEnquiryResponse或PointsEnquiryResponse的响应。如果我在这里错了,请指导我。

  3. 代码大部分时间都能正常工作,它只抛出IllegalArgumentException几次。这是否与某些缓存问题有关?

  4. 请求社区的帮助,因为我已经尝试了很多,并且处于如何进行的死胡同。

0 个答案:

没有答案