Search code examples
javajbossjava-ee-6jax-rs

Deploy simple Jax-RS example in JBoss community AS 7


I'm trying to deploy a simple REST example in JBOSS AS 7 but seems that I'm doing something wrong and I'm now clueless. I'm using Eclipse plugin to deploy.

The class I wrote is the following

@Path("/resources")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class ReceivedImagePersister {

    @POST
    @Path("/image")
    public Response save(String entry) {
        return Response.ok().build();
    }

}

Then I create a web.xml

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>API</display-name>

    <servlet-mapping>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>

</web-app>

And a jboss-web.xml

<jboss-web>
  <context-root>api</context-root>
</jboss-web>

When I deploy the application and try to send some data to the RESTful servlet the response is always:

(Could not find resource for relative : /image of full path: http://localhost:8080/api/resources/image)

Do I have to make some changes in configuration?

Thanks a lot in advance.


Solution

  • I think your web.xml your url pattern should /* i.e.

    <url-pattern>/resources/*</url-pattern>
    

    should be

    <url-pattern>/*</url-pattern>
    

    What i am getting at is you need let javax.ws.rs.core.Application parse your url starting from http://localhost/api/ only then will it able to detect that there is a resource named "resources" which has method "image"

    Right now it is trying to lookup a resource named "image" which is under the context path /api/resources/

    The following url may work for the way its been setup now http://localhost:8080/api/resources/resources/image