Question

I am developing some RESTful webservices using the following technologies

* Java 1.7
* Jersey 2.4.1
* spring 3.2.1
* Jboss-5.1.0.GA

So far, I have used eclipse to build the war file, both an exploded version and a compressed version. I have copied the files one at a time to {jboss-home}/server/web/deploy and have started the server using the command line by running run.bat -c web. In both cases the server starts up without error and the log files are identical. (timestamps excluded)

When I deploy the exploded war file and then navigate to the url http://mydomain.com:8080/{app}/rest/application.wadl, jersey is correctly identifying the annotated resources and I can use them as expected.

jersey annotated

@Path("/v1/ping")
@Service("pingV1")
public class PingV1 extends BaseResource {

    @Autowired
    private PingBusiness pingBusiness; 

    @GET
    @Produces(MediaType.APPLICATION_XML)
    public PingVO getPing(
            @Context UriInfo uriInfo, 
            @Context HttpServletRequest httpServletRequest){
        ...
        PingVO pingVO = pingBusiness.doGet();
        ...
        return pingVO;
    }

}

application.wadl (dynamically generated)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.4.1 2013-11-08 12:08:47"/>
    <grammars>
        <include href="application.wadl/xsd0.xsd">
            <doc xml:lang="en" title="Generated"/>
        </include>
    </grammars>
    <resources base="http://mydomain.com:8080/{app}/rest/">
        <resource path="/v1/ping">...</resource>
        <resource path="/">...</resource>
        <resource path="application.wadl">...</resource>
    </resources>
</application>

However, when I deploy the compressed .war file and navigation to the same url http://mydomain.com:8080/{app}/rest/application.wadl, jersey it not finding the annotated resource and when I hit the expected urls jboss returns a 404 - NOT FOUND.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 2.4.1 2013-11-08 12:08:47"/>
    <grammars/>
    <resources base="http://mydomain.com:8080/{app}/rest/">
        <resource path="application.wadl">...</resource>
    </resources>
</application>

Lastly, I used winRAR to extract the contents of the compressed war file into a folder, then used Beyond Compare to do a folder comparison of the original exploded war to the contexts that were just extracted and they were IDENTICAL.

This leads me to believe that there is something unique about how jboss deploys exploded wars vs compressed war files, but I don't understand what that may be or why it behaves this way. Can anyone help or point me in a new direction?

While a simple response could be ok, well just deploy the exploded war file, I would like to understand why this happens and continue to use my existing build.xml which produces the compressed .war file.

Était-ce utile?

La solution

You can try this:

public class MyApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        s.add(HelloWorldResource.class);
        return s;
    }
}

or other examples from the Jersey documentation if you want to use reflection to get the resources.

You may have a condition where the unpacking of the war is interfering with the jersey autoscan process and this should fix it.

Autres conseils

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.xyz.app.rest.MyApplication</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.xyz.app.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

package com.xyz.app.rest;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

public class MyApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();
        s.add(MyDataResource.class);
        return s;
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top