繁体   English   中英

org.jboss.resteasy.client.ClientResponseFailure:无法找到内容类型为文本/纯文本且类型为类java.lang.String的MessageBodyReader

[英]org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/plain and type class java.lang.String

org.jboss.resteasy.client.ClientResponseFailure:无法找到内容类型为文本/纯文本且类型为类java.lang.String的MessageBodyReader

请协助解决问题

提供商应用:

@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();
        }
    }
}

当我们通过url访问服务时,我的程序运行正常。 请帮我

网址: http:// localhost:8081 / DynamicDispatch / rest / payment / creditCard / HDFC?cardNo = 99809990876

输出:使用网关:HDFC和卡处理付款:99809990876

内容类型文本/纯文本类型类java.lang.String的组合由在resteasy-core中找到的org.jboss.resteasy.plugins.providers.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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM