일부 Rest 응용 프로그램에 대한 클라이언트를 만들려고합니다. Chrome에서 고급 REST 클라이언트로 Rest 애플리케이션을 테스트했습니다. 클라이언트 응답 Application.Json
내가받은 :{
"authorization": false,
"provider": "Provider"
}
좋아요 즉. 하지만 난 내 고객이를 얻을 싶습니다
λ java -jar Client_consumer-1.0-SNAPSHOT.jar
or[email protected]6591f517
클래스는 다음과 같습니다 :
@XmlRootElement
public class Auth_response implements Serializable {
private String Provider;
private boolean authorization;
public Auth_response() {
super();
}
public Auth_response(String Provider, boolean authorization) {
super();
this.Provider = Provider;
this.authorization = authorization;
}
public String getProvider() {
return Provider;
}
public boolean isAuthorization() {
return authorization;
}
public void setProvider(String Provider) {
this.Provider = Provider;
}
public void setAuthorization(boolean authorization) {
this.authorization = authorization;
}
@Override
public String toString() {
return "Auth_response{" + "Provider=" + Provider + ", authorization=" + authorization + '}';
}
}
I
public class MainApp extends Application {
public static final String BASE_URI = "http://localhost:8000/test";
public static final String PATH_NAME= "/sytem/Consumer/r/Provider";
@Override
public void start(Stage stage) throws Exception {
}
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(BASE_URI).path(PATH_NAME);
Response response = target.request(MediaType.APPLICATION_JSON).get();
System.out.println(response);
client.close();
}
}
내가 터미널 만이 나타납니다 응답을 올바르게 출력하는 방법과 Java 객체로 다시 변환하는 방법을 알고 싶습니다. 몇 가지 예를 들어 보았지만 아무 것도 작동하지 않아 일부 가이드가 필요하다고 생각합니다.
편집 : 객체 얻기를 위해이 시도 :
Auth_response r=
client.target("http://localhost:8000/test/system/Consumer/r/Provider")
.request(MediaType.APPLICATION_JSON_TYPE).
get(Auth_response.class);
System.out.println("funciona:");
System.out.println(r.getProvider());
System.out.println(r.isAuthorization());
을하지만 다음 오류 얻을 :
Caused by: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class ah.client_consumer.Auth_response
at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:42)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:75)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:52)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:55)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:213)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:105)
... 14 more
예외 실행중인 응용 프로그램을 ah.client_consumer.MainApp는
오류 '에 의한 HTTP 404 찾을 수 없음 '는 액세스하려는 웹 서비스에 액세스 할 수 없음을 의미합니다. 그 부분도 게시 할 수 있습니까? –
도구를 사용할 때 고급 클라이언트 웹 서비스 작동을 중지하십시오. –
경로에서 실수를 했으므로 현재 오류에 대한 오류를 편집했습니다. –