Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 573
Yashar Avatar asked Sep 25 '13 08:09

Yashar


2 Answers

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?

like image 186
Rakesh Waghela Avatar answered Oct 22 '22 12:10

Rakesh Waghela


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

like image 31
Matt Luedke Avatar answered Oct 22 '22 14:10

Matt Luedke