Question

I have a JAX-RS webservice using Jersey-1. There is only a single method at the moment, which sends mails with attachment. The attachment has to be provided as a multipart form data.

@POST
@Path("/mail")
@Consumes(MediaType.MULTIPART_FORM_DATA)   
public Response sendInfomailWithAttachment(

        @Context ServletContext context,
        @Context SecurityContext security,

        @QueryParam ("FROM") String senderAddress,
        @QueryParam ("SUBJECT") String subject,

        @QueryParam ("TO") String toRecipients,
        @QueryParam ("CC") String ccRecipients,
        @QueryParam ("BCC") String bccRecipients,

        @QueryParam ("noCopy") boolean sendNoCopy,

        @FormDataParam("attachment") InputStream fileInputStream,
        @FormDataParam("attachment") FormDataContentDisposition contentDispositionHeader,
        @FormDataParam("attachment") FormDataBodyPart fileBody,

        @FormDataParam("content") FormDataBodyPart content
        ){}

The method works fine. But when I try to integrate swagger, I always get this error(s):

SEVERE: Missing dependency for method public javax.ws.rs.core.Response ... throws java.lang.Exception at parameter at index 8 (this error is thrown for param 9, 10 and 11 as well)

in combination with

SEVERE: Method, public javax.ws.rs.core.Response ... throws java.lang.Exception, annotated with POST of resource, class com.mywebservice.MyClass, is not recognized as valid resource method.

If I throw out the FormDataParam stuff, the service starts normally, also with the swagger integration.

I use

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.3</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.17</version>
    </dependency>

    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.17</version>
    </dependency>

and

<dependency>
        <groupId>com.wordnik</groupId>
        <artifactId>swagger-jersey-jaxrs_2.10</artifactId>
        <version>1.3.4</version>
    </dependency>

Is there any known interference? Anything else I could do to come around this?

Was it helpful?

Solution

As I found out, it was a maven resolution problem.

The swagger lib 1.3.4 uses jersey-core-1.3 and jersey-server-1.3, which has been chosen by maven. Instead, I needed it in 1.17 like the jersey-servlet and jersey-multipart version. So I had to add those two dependencies to the pom to make the maven dependency resolution use 1.17 over 1.13.

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