如何实现接收一个或多个String并返回String的rest jersey方法

时间:2014-12-02 14:21:27

标签: java rest jersey-2.0

例如。 如何实现接收一个或多个String并返回String的rest jersey方法 使用这种方式或其他方式

@GET
@Path("/autenticate/{mail}/{passwd}")
@Produces("text/plain")
public String autenticate(@PathParam("mail") String mail, 
@PathParam("passwd") String   passwd) {
 return "testok";
}        

public String autenticateUser(String mail, String passw) 
throws ClientErrorException {
    WebTarget resource = webTarget;
    resource = resource.path(
    java.text.MessageFormat.format("autenticate/{0}/{1}", 
    new Object[]{mail, passw}));
    System.out.println(resource.getUri());
    System.out.println(resource);
    return resource.request(javax.ws.rs.core.MediaType.TEXT_PLAIN).get(String.class);

}

以上代码返回

javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:929)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:770)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:90)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:671)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:422)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:667)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:396)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:296)

1 个答案:

答案 0 :(得分:0)

你有什么应该工作。我在码头尝试过它(而不是玻璃鱼),它运行良好。你是怎么试着打电话的?它应该是http(s):: // autenticate / something / something_else。

请注意,您的第二种方法并没有做任何事情,因为您只需返回" testok。"