![](/img/trans.png)
[英]RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
[英]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.