1

I am attempting to make a file upload RESTful service. But it is spitting out a dependency error.

Here is my code:

    @ApiOperation(
        value = "Upload File.", 
        notes = "Uploads and stores user files to the server." )
@ApiResponses(value = {
        @ApiResponse(code = 403, message = "User not authorized to upload files."),
        @ApiResponse(code = 500, message = "Server error")})
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
        @ApiParam( value = "File", required = false)
        @FormDataParam("file") InputStream uploadInputStream,
        @ApiParam( value = "File Data", required = false)
        @FormDataParam("file") FormDataContentDisposition fileDetail
        ){
    return Response.ok("Test new endpoint").build();
}

I do have matching versions or jersey and multipart in my pom in my pom.xml

        <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>${jersey.version}</version>
    </dependency>

    <!-- jersey -->    
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>${jersey.version}</version>
    </dependency>

and here is the error that is being produces

SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.lotame.ws.api.resources.FileResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 0
SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.lotame.ws.api.resources.FileResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response com.lotame.ws.api.resources.FileResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition), annotated with POST of resource, class com.lotame.ws.api.resources.FileResource, is not recognized as valid resource method.

Any advice would be appreciated!

JarODirt
  • 157
  • 11
  • See http://stackoverflow.com/questions/15909978/jersey-rest-ws-error-missing-dependency-for-method-at-parameter-at-index-x – kapex Sep 27 '13 at 21:19
  • For those interested, the above question was not the issue. With this project I am also using swagger for API documentation/testing and the @ApiParam()'s were causing the conflicts. I have no idea why, if anyone has an explanation for that, let me know! – JarODirt Sep 30 '13 at 13:48

1 Answers1

0

This exception was being caused by some of Swaggers annotation around the Response parameters (@ApiParam(...)). I'm unsure as to why they were causing the issue, I believe it is because Swagger has limited support for complex objects as parameters.

Removing the Swagger ApiParam notations has solved the issue, and only results the inability to edit documentation for those parameters.

JarODirt
  • 157
  • 11
  • I got the same issue today using jersey (1.19),jaxrs,guice. I tryed using exactly the same code as [swagger petstore sample](https://github.com/swagger-api/swagger-samples/blob/master/java/java-jersey-jaxrs/src/main/java/io/swagger/sample/resource/PetResource.java) without any success :( – boly38 Jul 09 '15 at 08:42
  • oops I was using swagger UI latest version but swagger core 1.3 instead of 1.5 ! It works (without @ApiParam for `InputStream` and `FormDataContentDisposition` parameter)... – boly38 Jul 09 '15 at 15:05