org.jboss.resteasy.client.ClientResponseFailure:无法找到内容类型为text / plain的MessageBodyReader并输入类java.lang.String
请帮助解决问题
提供者应用程序:
@Path("/payment")
public class PaymetResource {
Object object=null;
@Path("{type}/{gateWay}")
public Object getResource(@PathParam("type") String type){
if(type.equals("creditCard"))
object = new CreditCardPaymentResource();
if(type.equals("debitCard"))
object = new DebitCardPaymentResource();
return object;
}
}
public class CreditCardPaymentResource {
/*
@GET
@Produces(MediaType.TEXT_PLAIN)
public String processPayments(){
return "hi boss";
}*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response processPayment(@QueryParam("cardNo") String cardNo,@PathParam("gateWay") String gateWay){
String result="processed payment with Gateway:"+gateWay+" and cardNo :"+cardNo;
return Response.status(201).entity(result).build();
//return "processed payment with Gateway:"+gateWay+" and cardNo :"+cardNo;
}
}
public class DebitCardPaymentResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String processPayment(@QueryParam("cardNo") String cardNo,@PathParam("gateWay") String gateWay,@QueryParam("pin") String pin){
return "processed payment with Gateway:"+gateWay+" and cardNo :"+cardNo+"pin No"+pin;
}
}
客户端应用:
public class RestFirstClient{
public static void main(String[] args) {
try{
ClientRequest request = new ClientRequest("http://localhost:8081/DynamicDispatch/rest/payment/creditCard/HDFC");
request.accept("text/plain");
request.queryParameter("cardNo", "669888554");
ClientResponse<String> response = request.get(String.class);
System.out.println(response.getEntity().toString());
}catch (Exception e) {
e.printStackTrace();
}
}
}
当我们通过网址访问服务时,我的程序运行正常。请帮帮我
网址:http://localhost:8081/DynamicDispatch/rest/payment/creditCard/HDFC?cardNo=99809990876
输出:使用Gateway处理付款:HDFC和cardNo:99809990876
答案 0 :(得分:0)
内容类型文本/纯文本和类型类java.lang.String 的组合由 org.jboss.resteasy.plugins.providers处理在 resteasy-core 中找到了.StringTextStar 。
客户端的创建方式如下:
final ResteasyClient client =
new ResteasyClientBuilderImpl() //
.connectTimeout(10, SECONDS) //
.readTimeout(10, SECONDS) //
.connectionCheckoutTimeout(10, SECONDS) //
.register(new StringTextStar()) //
.build();
final ResteasyWebTarget target = client.target(UriBuilder.fromPath("whatever path"));
final CreditCardPaymentResource client = target.proxy(CreditCardPaymentResource.class);