You must use at least one but not more than one HTTP method annotation for the proaseasy proxy client

I try to implement a simple client at rest, but I get the error message "You must use at least one but not more than one http method annotation." In my server implementation, I added the http annotation to my method.

@Path("/") public class TestResource { @GET @Path("/domain/{value}") public String get(@PathParam("value") final String value) { return "Hello" + value; } } 

I debugged this, the first time it didn't hit an exception at runtime. However, it makes a second call and does not work, not sure why and how.

My client as a junit test:

 @Test public void testPerformRestEasy() { ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target("http://localhost:8080/"); TestResource proxy = target.proxy(TestResource.class); String response = proxy.get("user"); Assert.assertEquals("Hellouser", response); } 

The code in which it crashes

  private static <T> ClientInvoker createClientInvoker(Class<T> clazz, Method method, ResteasyWebTarget base, ProxyConfig config) { Set<String> httpMethods = IsHttpMethod.getHttpMethods(method); if (httpMethods == null || httpMethods.size() != 1) { throw new RuntimeException("You must use at least one, but no more than one http method annotation on: " + method.toString()); } ClientInvoker invoker = new ClientInvoker(base, clazz, method, config); invoker.setHttpMethod(httpMethods.iterator().next()); return invoker; } 

Mistake:

 java.lang.RuntimeException: You must use at least one, but no more than one http method annotation on: public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException at org.jboss.resteasy.client.jaxrs.ProxyBuilder.createClientInvoker(ProxyBuilder.java:76) at org.jboss.resteasy.client.jaxrs.ProxyBuilder.proxy(ProxyBuilder.java:52) at org.jboss.resteasy.client.jaxrs.ProxyBuilder.build(ProxyBuilder.java:120) at org.jboss.resteasy.client.jaxrs.internal.ClientWebTarget.proxy(ClientWebTarget.java:72) 

Does anyone know what the problem is?

+7
java rest web-services resteasy
source share
3 answers

The Restaase JAXRS 2 client does not seem to directly accept implementation classes. For it to work, you must create a properly annotated interface. It is used by Resteasy to create a client proxy, and your server must implement exactly the same interface.

So, in your case, you need to split your code into an interface and a separate implementation class:

 @Path("/") public interface TestResource { @GET @Path("/domain/{value}") String get(@PathParam("value") final String value); } public class TestResourceImpl implements TestResource { @Override String get(final String value) { return "Hello" + value; } } 

I am not sure if this is a Resteasy specification or a specification is required, but the same problem was solved for me. You can find the section that gave me the hint here in the documentation .

+3
source

You must define a resource resource representation of the resource MIME type ( @Produces/@Consumes ) from the client. How -

 @Path("/") public class TestResource { @GET @Produces("text/plain") @Path("/domain/{value}") public String get(@PathParam("value") final String value) { return "Hello" + value; } } 

Jocoss Client Doc will help you more.

+1
source

In my case, the developer of the client interface for leisure mistakenly extended RestEasyClientProxy . These were not methods in the Loss interface that lacked http annotations, but inherited methods.

Removing extends RestEasyClientProxy from the extends RestEasyClientProxy client interface code resolves the issue.

0
source

All Articles