添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
迷茫的小笼包  ·  android ...·  2 年前    · 
俊秀的石榴  ·  pbi ...·  2 年前    · 
道上混的沙发  ·  c++ 注入dll-掘金·  2 年前    · 
犯傻的毛衣  ·  python支持泛型编程吗 ...·  2 年前    · 
[解决]RESTEASY003215: could not find writer for content-type text/html type: java.lang.String 2018-10-13 15:18:00

一、问题描述

1)项目一开始采用JAX-RS 2.1+Jersey 2.26调用REST服务能正常调用并获得正确响应;

2)当项目引入dubbo 2.6.2后也用到rest而dubbo要用到RESTEasy,项目就引入了RESTEasy;

3)项目引入RESTEasy后,JAX-RS 2.1+Jersey 2.26调用REST服务出现异常!异常信息如下:

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:61)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:219)
    at com.lutao.pigeon.iclient.ibeplus.common.IBEPlusCaller.invoke(IBEPlusCaller.java:63)
    at com.lutao.pigeon.gds.ibe.service.impl.IbeGdsShoppingService.flightShopping(IbeGdsShoppingService.java:89)
    at com.lutao.pigeon.gds.resource.impl.GdsShoppingResource.flightShopping(GdsShoppingResource.java:37)
    at com.lutao.pigeon.gds.resource.impl.GdsShoppingResource$$FastClassBySpringCGLIB$$77b131d0.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
    at com.lutao.openservice.common.aspect.BaseRestAspectProcessor.syncAroundHandle(BaseRestAspectProcessor.java:340)
    at com.lutao.openservice.common.aspect.BaseRestAspectProcessor.lambda$asyncAroundHandle$0(BaseRestAspectProcessor.java:267)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type text/html type: java.lang.String
    at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:146)
    at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:121)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:394)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:666)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:631)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:509)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:310)
    ... 16 more

二、问题分析

1)从异常错误信息看调用REST服务端的代码变成了RESTEasy,而不是原正常的Jersey咯

2)在网上找问题看到一位同学讲把clientConfig参数去掉可解决问题,讲的应该有道这个clientConfig是Jersey包的代码而从异常错信息来看客户端用的是RESTEasy的代码;不过我的有这个clientConfig配置,所以我并没有去验证这位同学讲的解决方法;

3)创建代码,如下:

Client client = ClientBuilder.newBuilder(clientConfig)
      .register(feature)
      .build();
    

4)阅读 ClientBuilder.newBuilder() 源码发现,ClientBuilder的构建是这样子的:会加载 META-INF/services/javax.ws.rs.client.ClientBuilder 文件的的实现类并使用,如果在META-INF/services/javax.ws.rs.client.ClientBuilder 文件中未加载则默认使用 org.glassfish.jersey.client.JerseyClientBuilder 类;从这个逻辑中看出来之前rest服务正常调用是没有引入RESTEasy jar包,肯定设置使用的是Jersey,猜测RESTEasy jar包中应该有 META-INF/services/javax.ws.rs.client.ClientBuilder 文件并配置了RESTEasy的ClientBuilder的继承类才会导致JAX-RS加载到RESTEasy并使用RESTEasy作为客户端调用REST服务;

5)接着查找一下是否有RESTEasy的META-INF/services/javax.ws.rs.client.ClientBuilder,结果是有的,如下:

6)问题确认了我们就好处理咯。

三、问题解决

1)修改客户代码,指定使用Jersey,如下:

Client client = ClientBuilder.newBuilder(clientConfig)
      .register(feature)
      .build();
    

改为(直接指定使用JerseyClientBuilder.createClient(...)创建,这样、JAX-RX就不会根据 META-INF/services/javax.ws.rs.client.ClientBuilder 文件中去加载了)

Client client = JerseyClientBuilder.createClient(clientConfig)
   .register(feature);

 2)修改后,再次调用测试,能正常调用并响应正常。

RESTful Java Web Services (2009).pdf This book is for developers who want to code RESTful web services using the Java technology stack together with any of the frameworks Jersey's JAX-RS, Restlet's Lightweight REST, JBoss's JAX-RS RESTEasy, and Struts 2 with the REST plugin. You don't need to know REST, as we cover the theory behind it all; however, you should be familiar with the Java language and have some understanding of Java web applications. For each framework, we develop the same web service outlined in Chapter 4, RESTful Web Services Design. This is a practical guide and a greater part of the book is about coding RESTful web services, and not just about the theory of REST. 一、问题描述1)项目一开始采用JAX-RS 2.1+Jersey 2.26调用REST服务能正常调用并获得正确响应;2)当项目引入dubbo 2.6.2后也用到rest而dubbo要用到RESTEasy,项目就引入了RESTEasy;3)项目引入RESTEasy后,JAX-RS 2.1+Jersey 2.26调用REST服务出现异常!异常信息如下:javax.ws.rs.ProcessingExc... 建议用时:30min Postman是邮递员的意思,那个图标也很Q,感觉像是悬浮的宇航员。在HTTP等协议中,这个软件测试接口,就类似邮递员,传递参数,发起请求,等待响应,很... 问题描述今天在使用dubbox的时候,在启动服务的时候报出一个错误,导致应用无法启动,错误的提示信息为: Initialization of bean failed; nested exception is java.lang.RuntimeException: RESTEASY003130: Class is not a root resource. 2016-07-05 10:00:15,933  WARN [Log4jLogger.java:135] : failed to execute javax.ws.rs.NotAllowedException: No resource method found for POST, return 405 with Allow header at org.jboss.resteasy.core.r 具体部分报错: Exception in thread "main" ConnectionException{message=RESTEASY004655: Unable to invoke request, status=0} at org.openstack4j.connectors.resteasy.HttpExecutorServiceImpl.invoke(HttpExecutorServiceImpl.java:57) 写完后,EA组解散了,全当纪念!  共同的目标 高度的责任感    我们团队从建立之初起,就有一个明确的目标:规划企业系统架构,提供企业架构解决方案.团队所有成员以此为己任,致力于解决各种架构问题,提供架构解决方案。    有了目标也就有工作的重心和前进的方向,团队的工作计划也是围绕这个目录而制定。团队信任与支持    公司的系统关联比较复杂,我们参与的许多大项目不是一个人就完成的,需 用的是webService JAX-WS-RS   我这里报的错误是因为访问webService的路径错误 才会导致以下错误 20:23:46,200 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: HTTP 400 Bad Request javax.ws.rs.Ba resteasy提供了一个ExceptionMapper接口异常处理. ExceptionMapper依赖@Provider注解 本次采用servlet3.0容器(为了方便使用initializer) pom.xml org.jboss.resteasy resteasy-jaxrs 3.1.3.Final org.jboss.resteasy restea