2017-02-27 12 views
1

をテストするためのJUnitとジャージーのクライアントを使用して、私はWildFly 10にこのアプリケーションを実行しているJava EEアプリケーションは、ジャージーを使用し、私はRESTクライアントを使用してテストするとき細かい実行されています。JAX-RSアプリケーション

私は上記のアプリケーションへの要求を行うジャージークライアントAPIを使用してJUnitテストを書きました。私はそれを実行すると、私は次の取得:

javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error 
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:209) 
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:174) 
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:473) 
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.get(ClientInvocationBuilder.java:165) 

トレースの次の行は、以下のrequest()コールを参照しています

@Test 
public void test() { 
    Client client = ClientBuilder.newClient(); 
    WebTarget target = client.target("http://localhost:8080/myapp/webapi"); 
    target.path("/users"); 
    String response = target.request("application/json").get(String.class); 
    assertEquals("test", response); 
} 

任意のアイデア?

+0

それはERROを語りますrは、クライアントにサーバー側ではありませんが、おそらくあなたは、サーバーに必要なすべてのパラメータを渡すことはありません。 – hoaz

答えて

1

あなたの問題は、あなたがそれを自分でチェックする場合(エラー500を参照)、ブラウザを開き、URLに移動し、サーバ側から来ている:http://localhost:8080/myapp/webapi

またWebTarget.path(のJavadocからのお知らせ)を返し、私はあなたが実際に何をしたいのか、あなたのコードを信じて新しいWebTarget

https://jersey.java.net/apidocs/2.22/jersey/javax/ws/rs/client/WebTarget.html#path(java.lang.String)

は次のとおりです。

@Test 
public void test() { 
    Client client = ClientBuilder.newClient(); 
    WebTarget target = client.target("http://localhost:8080/myapp/webapi"); 
    WebTarget targetUpdated = target.path("/users"); 
    String response = targetUpdated.request("application/json").get(String.class); 
    assertEquals("test", response); 
} 
関連する問題