私は良いリクエストをする上でいくつか問題があります。エラー400不良リクエスト
@Path("/activitiesGenerator")
public class ActivityResource {
ActivityStub acstub = new ActivityStub();
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Collection<Activity> getAllActivities(){
return acstub.Find_All_Activities();
}
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("{activityId}") // Will act as parameter that will take value from the browser!
public Response getActivity(@PathParam("activityId") String activityId){
if(activityId.equals(null) || activityId.length() < 4){
return Response.status(Status.BAD_REQUEST).build();
}
Activity activity = acstub.FindActivity(activityId);
if(activity.equals(null)){
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok().entity(activity).build();
}
ここから私は値を渡します!ここで
@Test
public void main() {
ActivityClient client = new ActivityClient();
Activity activity = client.get("3204987");
System.out.println(activity);
assertNotNull(activity);
}
私はgetメソッドから例外が発生しました
public Activity get(String id){
WebTarget target = client.target("http://localhost:8080/Activities/rest/");
Response response = target.path("activitiesGenerator/"+id).request(MediaType.APPLICATION_JSON).get(Response.class);
System.out.println(response.getStatus());
if(response.getStatus() != 200){
throw new RuntimeException(response.getStatus()+ ": there was an error on the server");
}
return response.readEntity(Activity.class);
}
..応答のチェックを行います。応答は400 Bad Requestです。 どうしたのですか?
ここは私のweb.xmlファイルです!
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Activities</display-name>
<servlet>
<servlet-name>ActiviteExample</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>activity.model</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>ActiviteExample</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Could not get any response
This seems to be like an error connecting to http://HTTP://localhost:8080/Activities/rest/activities-generator/3204987.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
SSL connections are being blocked:
Fix this by importing SSL certificates in Chrome
Cookies not being sent:
ここは私が郵便配達員から得たものです。誰でも私にこの可能な解決策についてより具体的に説明できれば感謝します...
についての続きを読むには、サーバー・ログにすべてのエラーを参照していますか?エラーから応答エンティティをチェックして、デバッグに役立つ情報があるかどうか確認しましたか? –
私は応答から400の番号を得ました。私は応答番号を印刷しました。 私は400を得て、私はいくつかの構文エラーを知っている..しかし、私は構文エラーが表示されません..私はweb.xmlを追加します –
あなたはpom.xmlを持っていますか? – Whitefret