引起:java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSin

Posted

技术标签:

【中文标题】引起:java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSingleValue【英文标题】:Caused by: java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSingleValue 【发布时间】:2020-05-30 04:01:21 【问题描述】:

我有一个使用 jersey 2.x 并部署在 weblogic 12c 上的休息客户端。现在,当我通过邮递员发送 GET 请求时。它向我展示了以下异常:

原因:java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSingleValue(Ljavax/ws/rs/core/MultivaluedMap;Ljavax/ws/rs/core/Configuration;) Ljava/util/Map;

我尝试添加一些 jar,例如“Jersey Apache Connector”、“Jaxrs-ri jar”,但它仍然存在;但是,我已经对其进行了研究,并发现它是 Jersey-apache-connector jar 的一部分。

我被困在这里。

客户端 java 代码

@GET
    @Path("/fundTransfer")
    @Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
    public String soapCaller() throws IOException, JSONException  

        logger.info("FMS WEBSERVICE LOG >>> Inside the client method");

        @SuppressWarnings( "rawtypes", "unused" )
        HashMap map = new HashMap<>();

        String host = "172.18.101.2";
    //  String host = "172.18.106.13";
        String port = "80";
        logger.info("FMS WEBSERVICE LOG >>> Using proxy: " + host + ":" + port);

        System.setProperty("https.proxyHost", host);
        System.setProperty("http.proxyHost", host);
        System.setProperty("http.proxyPort", port);
        System.setProperty("https.proxyPort", port);

        SSLUtilities.trustAllHostnames();
        SSLUtilities.trustAllHttpsCertificates();

            try 

                final ClientConfig config = new ClientConfig();

                logger.info("FMS WEBSERVICE LOG >>> config " + config);


                config.connectorProvider(new ApacheConnectorProvider());
                config.property(ClientProperties.PROXY_URI, "http://172.18.101.2:80");
                config.property(ClientProperties.PROXY_USERNAME,"imjme1");
                config.property(ClientProperties.PROXY_PASSWORD,"Jvdonut5988!");


                /*config.property(ClientProperties.PROXY_URI, "172.18.101.2:8000");
                logger.info("FMS WEBSERVICE LOG >>> ClientProperties.PROXY_URI " + ClientProperties.PROXY_URI);

                CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                logger.info("FMS WEBSERVICE LOG >>> credentialsProvider " + credentialsProvider);

                final AuthScope ntlmAuthScope =
                        new AuthScope("172.18.101.2", 8080, AuthScope.ANY_REALM, "NTLM");

                logger.info("FMS WEBSERVICE LOG >>> ntlmAuthScope " + ntlmAuthScope);

                credentialsProvider.setCredentials(
                        ntlmAuthScope,
                        new NTCredentials("imjme1", "Jvdonut5988!", "", "") );

                logger.info("FMS WEBSERVICE LOG >>> credentialsProvider " + credentialsProvider.getCredentials(ntlmAuthScope));

                config.property(
                        ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);

                config.connectorProvider(new ApacheConnectorProvider());*/

                Client client = ClientBuilder.newClient( config.register( LoggingFilter.class ) );
                MultivaluedMap params = new MultivaluedHashMap();
                params.add("grant_type", "client_credentials");
                params.add("client_id", "0146b9a4-7e99-4c83-8e9e-6049cfec55da");
                params.add("client_secret", "nY3oL5xQ3bJ8yT3nC1nV5bY4mY6eW7yP1nY6dS6rQ2nE5iR0rM");
                params.add("scope", "ABLApis");


                WebTarget webTarget = client.target("https://221.120.211.69:443/abl-api/uat/oauth2/token");

                logger.info("FMS WEBSERVICE LOG >>> webTarget " + webTarget);


                Invocation.Builder invocationBuilder =  webTarget.request().accept(MediaType.APPLICATION_JSON);
                logger.info("FMS WEBSERVICE LOG >>> invocationBuilder: " + invocationBuilder);
                Response response = invocationBuilder.post(Entity.form(params));
                logger.info("FMS WEBSERVICE LOG >>> response " + response);
                String responses = response.readEntity(String.class);
                logger.info("FMS WEBSERVICE LOG >>> responses >> " + responses);     
                System.out.println(response.getStatus());
                System.out.println(responses);


               catch (Exception e) 

                e.printStackTrace();

               
            return "a";

    

    

堆栈跟踪

FMS WEBSERVICE LOG >>> Inside the client method
FMS WEBSERVICE LOG >>> Using proxy: 172.18.101.2:80
FMS WEBSERVICE LOG >>> config org.glassfish.jersey.client.ClientConfig@e4b9028d
FMS WEBSERVICE LOG >>> webTarget JerseyWebTarget  https://221.120.211.69:443/abl-api/uat/oauth2/token 
FMS WEBSERVICE LOG >>> invocationBuilder: org.glassfish.jersey.client.JerseyInvocation$Builder@70c19fa1
Feb 14, 2020 3:41:00 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 1 * Sending client request on thread [ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'
1 > POST https://221.120.211.69:443/abl-api/uat/oauth2/token
1 > Accept: application/json
1 > Content-Type: application/x-www-form-urlencoded

javax.ws.rs.ProcessingException: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSingleValue(Ljavax/ws/rs/core/MultivaluedMap;Ljavax/ws/rs/core/Configuration;)Ljava/util/Map;
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:264)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:684)
    at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:681)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:681)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:437)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:343)
    at com.fms.webservice.client.WebServiceClient.soapCaller(WebServiceClient.java:169)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:247)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3697)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3667)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
    at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
    at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2443)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2291)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2269)
    at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1703)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1663)
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
    at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
    at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
    at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
    at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
    at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:355)
Caused by: java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSingleValue(Ljavax/ws/rs/core/MultivaluedMap;Ljavax/ws/rs/core/Configuration;)Ljava/util/Map;
    at org.glassfish.jersey.apache.connector.ApacheConnector.writeOutBoundHeaders(ApacheConnector.java:653)
    at org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:461)
    at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
    ... 60 more

【问题讨论】:

确保所有 Jersey jar 版本都相同。 【参考方案1】:

据我所知,asStringHeadersSingleValue(MultivaluedMap) 功能已被弃用。

它现在接受 2 个参数,即 MultivaluedMapConfiguration。 尝试升级到 2.35 或更高版本。

【讨论】:

以上是关于引起:java.lang.NoSuchMethodError: org.glassfish.jersey.message.internal.HeaderUtils.asStringHeadersSin的主要内容,如果未能解决你的问题,请参考以下文章

如何区分两个“onpause”事件 - 由单击“暂停”按钮引起,以及由到达媒体片段末尾引起?

查询如何引起gc

杂牌设备网络接入引起交换机引起端口翻转的故障

csharp 可能会引起问题的类的继承问题,父类后来增加的方法可能会引起子类的函数重载错误

两则dhcp设置引起的故障

大开测试:性能-如何解决由于设置引起的运行失败问题(连载22)