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.
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With