Yashar
Yashar

Reputation: 1162

Subresource for target class has no jax-rs annotations

I am trying to call a webservice method via a proxy but I have got an error message that says: "Subresource for target class has no jax-rs annotations.: org.jboss.resteasy.core.ServerResponse"

Here is my server class

@Path("/authorizationCheck")
public class AuthorizationRestService implements AuthorizationService  {

  @Override
    @Path("/webserviceTest")
    public Response webserviceTest(){
    TestDTO  x = new TestDTO();
    x.setFieldOne("ffff");
    x.setFieldTwo("gggg");
    Response res = Response.ok(x).build();
    return res;


    }
}

with a an interface like this

@Path("/authorizationCheck")
public interface AuthorizationService {

    @POST
    @Path("/webserviceTest")
    public Response webserviceTest();
}

and my return object wrapped in response

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class TestDTO {

    private String fieldOne;

    private String fieldTwo;

    public String getFieldOne() {
        return fieldOne;
    }

    public void setFieldOne(String fieldOne) {
        this.fieldOne = fieldOne;
    }

    public String getFieldTwo() {
        return fieldTwo;
    }

    public void setFieldTwo(String fieldTwo) {
        this.fieldTwo = fieldTwo;
    }



}

and finally my client class

@Stateful
@Scope(ScopeType.CONVERSATION)
@Name("authorizationCheckService")
public class AuthorizationCheckService {

    public void testWebservice(){
        RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
        AuthorizationService  proxy = 
                ProxyFactory.create(AuthorizationService.class,
                        ApplicationConfig.WORKFLOWSERVER_URL + "services/authorizationCheck/webserviceTest");
        Response response =   proxy.webserviceTest();
        return;



    }
}

what I am doing wrong here , any help will be appreciated.

Upvotes: 5

Views: 13451

Answers (3)

Matt Luedke
Matt Luedke

Reputation: 21

You can remove the @Path annotations on the implementation class and concrete method, and only annotate your interfaces, like this:

public class AuthorizationRestService implements AuthorizationService  {

    @Override
    public Response webserviceTest(){
        TestDTO  x = new TestDTO();
        x.setFieldOne("ffff");
        x.setFieldTwo("gggg");
        Response res = Response.ok(x).build();
        return res;
    }
}

Note: don't forget @Produces on your interface method to define your MIME type, such as MediaType.APPLICATION_XML

@Path("/authorizationCheck")
public interface AuthorizationService {

    @POST
    @Path("/webserviceTest")
    @Produces(MediaType.APPLICATION_XML)
    public Response webserviceTest();
}

See an example here: http://pic.dhe.ibm.com/infocenter/initiate/v9r5/index.jsp?topic=%2Fcom.ibm.composer.doc%2Ftopics%2Fr_composer_extending_services_creating_rest_service_rest_interface.html

and here: http://pic.dhe.ibm.com/infocenter/initiate/v9r5/index.jsp?topic=%2Fcom.ibm.composer.doc%2Ftopics%2Fr_composer_extending_services_creating_rest_service_rest_interface.html

Upvotes: 2

Satish
Satish

Reputation: 711

I changed like this

@Path("/authorizationCheck")
public class AuthorizationRestService implements AuthorizationService  {

@Override
@Path("/webserviceTest")
@POST
@Produces(MediaType.APPLICATION_XML)
public Response webserviceTest(){
TestDTO  x = new TestDTO();
x.setFieldOne("ffff");
x.setFieldTwo("gggg");
Response res = Response.ok(x).build();
return res;


}
}

My Test Client is different

public class CustomerResourceTest
{
@Test
public void testCustomerResource() throws Exception
{
   URL postUrl = new URL("http://localhost:9095/authorizationCheck/webserviceTest");
   HttpURLConnection   connection = (HttpURLConnection) postUrl.openConnection();
      connection.setRequestMethod("POST");
      System.out.println("Content-Type: " + connection.getContentType());

      BufferedReader reader = new BufferedReader(new
              InputStreamReader(connection.getInputStream()));

      String line = reader.readLine();
      while (line != null)
      {
         System.out.println(line);
         line = reader.readLine();
      }
      Assert.assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
      connection.disconnect();

   return;
}
}

It produced output

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><testDTO><fieldOne>ffff</fieldOne><fieldTwo>gggg</fieldTwo></testDTO>

Had to add following dependency also

<dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.11</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>2.2.0.GA</version>
    </dependency>

Tried your code.

public void testCustomerResource() throws Exception
{
   RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
   AuthorizationService  proxy = 
           ProxyFactory.create(AuthorizationService.class,"http://localhost:9095/");
   ClientResponse response = (ClientResponse) proxy.webserviceTest();
   String str = (String)response.getEntity(String.class);
   System.out.println(str);
   return;
}

Produced same output

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><testDTO><fieldOne>ffff</fieldOne><fieldTwo>gggg</fieldTwo></testDTO>

Note how I created proxy. I had only base url **http://localhost:9095/**. I did not mention resources authorizationCheck/webserviceTest in that. This is different from how you coded.

Upvotes: 0

Rakesh Waghela
Rakesh Waghela

Reputation: 2297

You have two annotations with webserviceTest() which are @POST and @Path.

Repeat BOTH the annotations in over ridden method in implemented class. That means add the @POST annotation to webserviceTest() method.

It should work then !

And here is the reason why it din't work.. without proper annotations in implementing class. Why java classes do not inherit annotations from implemented interfaces?

Upvotes: 5

Related Questions