Question

When deploying a war using Jersey Multipart 1.13 on a Glassfish 2.1.1 server, the following error message appear afterwards.:

Method, public javax.ws.rs.core.Response no.xx.nn.resources.ConverterResources.post(java.lang.String,java.lang.String,java.io.InputStream), annotated with POST of resource, class oo.xx.nn.resources.ConverterResources, is not recognized as valid Java method annotated with @HttpMethod. at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.(ResourceHttpMethod.java:92) at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.(ResourceHttpMethod.java:69) at com.sun.jersey.server.impl.model.method.ResourceHttpMethod.(ResourceHttpMethod.java:61) at com.sun.jersey.server.impl.model.ResourceClass.processMethods(ResourceClass.java:283) at com.sun.jersey.server.impl.model.ResourceClass.(ResourceClass.java:131)

By trial and failure, I've found out that this belongs to the following code:

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response post(@FormDataParam("providerId") int providerId,
                     @FormDataParam("datasetId") int datasetid,
                     @FormDataParam("file") InputStream file)

And more specificly the @FormDataParam parameter annotation. When removing these, the war deploys just fine. I have tried to add @DefaultValue to all of the @FormDataParams without any luck. Also, I have tried to add a @Produces, also, without any luck. It does not seem that the error has anything to do with the current @Consumes(..) either.

My web.xml looks pretty standard:

<servlet>
    <servlet-name>xxxx</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>oo.xx.nn.resources</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>xxxx</servlet-name>
    <url-pattern>/zzzz/*</url-pattern>
</servlet-mapping>

I have included all required Jersey dependencies, as shown below:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-multipart</artifactId>
    <version>1.13</version>
</dependency>

I have also tried deploying from IDEA to Tomcat6 and Glassfish 3.1.1, and this works perfectly. Runs on Java 7 both locally and remote (where it won't work). Any ideas?

Was it helpful?

Solution

Ok, so I found out. Glassfish was bundled with old Jersey dependencies, so I had to give a JVM argument to force it to give my app some room and provide own dependency versions. In addition I provided a sun-web.xml.

http://jersey.java.net/nonav/documentation/latest/glassfish.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top