Swagger UI file upload form exceptions and display

3,102 views
Skip to first unread message

Karsten Becker

unread,
Aug 23, 2013, 4:14:43 PM8/23/13
to swagger-sw...@googlegroups.com
Hi again :)
So here is probably the last thing that I am wondering about. I have the following code:
@POST
@Path("/{WID}")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@Produces({ MediaType.TEXT_HTML })
@ApiOperation("Upload a file as MultiPart [HTML]")
public Response postWorkspaceWithID_HTML(//
@FormDataParam("file") InputStream uploadedInputStream,//
@FormDataParam("file") FormDataContentDisposition fileDetail,//
@ApiParam(WID_DESC) @PathParam("WID") String wid, //
@ApiParam(DOWN_DESC) @QueryParam("download") @DefaultValue("false") boolean download//
) {
//Do something useful
}


But it results in:
            {
               "method":"POST",
               "summary":"Upload a file as MultiPart [HTML]",
               "notes":"",
               "type":"void",
               "nickname":"postWorkspaceWithID_HTML",
               "produces":[
                  "text/html"
               ],
               "consumes":[
                  "multipart/form-data"
               ],
               "parameters":[
                  {
                     "name":"body",
                     "required":false,
                     "allowMultiple":false,
                     "type":"java.io.InputStream",
                     "paramType":"body"
                  },
                  {
                     "name":"body",
                     "required":false,
                     "allowMultiple":false,
                     "type":"FormDataContentDisposition",
                     "paramType":"body"
                  },
                  {
                     "name":"WID",
                     "description":"The workspace ID",
                     "required":true,
                     "allowMultiple":false,
                     "type":"string",
                     "paramType":"path"
                  },
                  {
                     "name":"download",
                     "description":"If <b>true</b> then the file will forced as download (default: <b>false</b>)",
                     "defaultValue":"false",
                     "required":false,
                     "allowMultiple":false,
                     "type":"boolean",
                     "paramType":"query"
                  }
               ]
            },

      {
         "path":"/pet/uploadImage",
         "operations":[
            {
               "method":"POST",
               "summary":"uploads an image",
               "notes":"",
               "type":"void",
               "nickname":"uploadFile",
               "consumes":[
                  "multipart/form-data"
               ],
               "parameters":[
                  {
                     "name":"additionalMetadata",
                     "description":"Additional data to pass to server",
                     "required":false,
                     "allowMultiple":false,
                     "type":"string",
                     "paramType":"form"
                  },
                  {
                     "name":"file",
                     "description":"file to upload",
                     "required":false,
                     "allowMultiple":false,
                     "type":"File",
                     "paramType":"body"
                  }
               ]
            }
         ]
      },

Also I have the problem that when I add a @ApiParam to the file parameter, I get the following exceptions:
Aug 23, 2013 10:11:23 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public javax.ws.rs.core.Response org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean) throws java.lang.Exception at parameter at index 0
  SEVERE: Missing dependency for method public javax.ws.rs.core.Response org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean) throws java.lang.Exception at parameter at index 1
  SEVERE: Method, public javax.ws.rs.core.Response org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean) throws java.lang.Exception, annotated with POST of resource, class org.pshdl.rest.jersey.Workspace, is not recognized as valid resource method.
Aug 23, 2013 10:11:23 PM org.atmosphere.cpr.AtmosphereFramework init
SEVERE: Failed to initialize Atmosphere Framework
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.atmosphere.util.AtmosphereFilterChain.init(AtmosphereFilterChain.java:125)
at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.init(ReflectorServletProcessor.java:329)
at org.atmosphere.handler.ReflectorServletProcessor.init(ReflectorServletProcessor.java:210)
at org.atmosphere.cpr.AtmosphereFramework.initAtmosphereHandler(AtmosphereFramework.java:1099)
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:584)
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:510)
at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:74)
at org.glassfish.grizzly.servlet.WebappContext.initServlets(WebappContext.java:1496)
at org.glassfish.grizzly.servlet.WebappContext.deploy(WebappContext.java:265)
at org.pshdl.rest.Main.startGrizzly(Main.java:127)
at org.pshdl.rest.Main.main(Main.java:160)
Aug 23, 2013 10:11:23 PM org.glassfish.grizzly.servlet.WebappContext deploy
SEVERE: [WebappContext] Exception deploying application.  See stack trace for details.
java.lang.RuntimeException: javax.servlet.ServletException: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at org.glassfish.grizzly.servlet.WebappContext.initServlets(WebappContext.java:1498)
at org.glassfish.grizzly.servlet.WebappContext.deploy(WebappContext.java:265)
at org.pshdl.rest.Main.startGrizzly(Main.java:127)
at org.pshdl.rest.Main.main(Main.java:160)
Caused by: javax.servlet.ServletException: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:628)
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:510)
at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:74)
at org.glassfish.grizzly.servlet.WebappContext.initServlets(WebappContext.java:1496)
... 3 more
Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at org.atmosphere.util.AtmosphereFilterChain.init(AtmosphereFilterChain.java:125)
at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.init(ReflectorServletProcessor.java:329)
at org.atmosphere.handler.ReflectorServletProcessor.init(ReflectorServletProcessor.java:210)
at org.atmosphere.cpr.AtmosphereFramework.initAtmosphereHandler(AtmosphereFramework.java:1099)
at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:584)
... 6 more

What is causing the exception? And what do I need to do to get a file chooser?

Karsten

tony tam

unread,
Aug 23, 2013, 5:31:24 PM8/23/13
to swagger-sw...@googlegroups.com
Hi, you are probably using the vanilla swagger-jaxrs module but if you want file upload support (which requires jersey for our implementation) you should depend no the swagger-jersey-jaxrs module.  Note that changing to use this requires you to specify a different configuration in your web.xml!  See here for an example:

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>com.wordnik.swagger.sample.resource;com.wordnik.swagger.jaxrs.listing</param-value>
    </init-param>

and here:

  <servlet>
    <servlet-name>JerseyJaxrsConfig</servlet-name>
    <servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
    <init-param>
      <param-name>api.version</param-name>


However, the file-upload support in swagger-ui is temporarily broken :(  We put in a new javascript client to support authentication customization and haven't migrated file upload over to it.

Karsten Becker

unread,
Aug 23, 2013, 5:45:20 PM8/23/13
to swagger-sw...@googlegroups.com
I bet you meant: com.wordnik.swagger.jersey.listing for
com.sun.jersey.config.property.packages, correct?

When I change all that, everything gets worse. I get an instant crash,
vs. a delayed crashed when using jaxrs.

Aug 23, 2013 11:37:32 PM org.atmosphere.cpr.AtmosphereFramework
detectSupportedFramework
WARNING: Missing META-INF/atmosphere.xml but found the Jersey runtime.
Starting Jersey
Aug 23, 2013 11:37:33 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with
resource and/or provider classes:
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 0
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_HTML(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception, annotated with POST of resource, class
org.pshdl.rest.jersey.Workspace, is not recognized as valid resource
method.
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.putWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 0
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.putWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.putWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception, annotated with PUT of resource, class
org.pshdl.rest.jersey.Workspace, is not recognized as valid resource
method.
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 0
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response
org.pshdl.rest.jersey.Workspace.postWorkspaceWithID_PLAIN(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition,java.lang.String,boolean)
throws java.lang.Exception, annotated with POST of resource, class
org.pshdl.rest.jersey.Workspace, is not recognized as valid resource
method.
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerSingleVHDL_PLAIN(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception at parameter at index 1
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerSingleVHDL_PLAIN(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception at parameter at index 2
SEVERE: Method, public javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerSingleVHDL_PLAIN(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception, annotated with POST of resource, class
org.pshdl.rest.jersey.WorkspaceCompiler, is not recognized as valid
resource method.
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerVHDLSingle_JSON(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception at parameter at index 1
SEVERE: Missing dependency for method public
javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerVHDLSingle_JSON(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception at parameter at index 2
SEVERE: Method, public javax.ws.rs.core.Response
org.pshdl.rest.jersey.WorkspaceCompiler.postCompilerVHDLSingle_JSON(java.lang.String,java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition)
throws java.lang.Exception, annotated with POST of resource, class
org.pshdl.rest.jersey.WorkspaceCompiler, is not recognized as valid
resource method.
Aug 23, 2013 11:37:33 PM org.atmosphere.cpr.AtmosphereFramework init
SEVERE: Failed to initialize Atmosphere Framework

Now all methods with File uploads are broken....

Karsten
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Swagger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> swagger-swaggers...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

tony tam

unread,
Aug 23, 2013, 5:51:36 PM8/23/13
to swagger-sw...@googlegroups.com
try using jersey version 1.13 as the sample does.  My guess is you're on a later one?  I'd like to sort out why later versions of jersey are causing this still

Karsten Becker

unread,
Aug 23, 2013, 6:26:18 PM8/23/13
to swagger-sw...@googlegroups.com
Hmm, ok, that worked..
Now I have another problem, the produce annotation is ignored. Swagger
UI sends the Accept Header of Application/JSON no matter what produces
said..

Karsten
>> > swagger-swaggers...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Swagger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> swagger-swaggers...@googlegroups.com.

tony tam

unread,
Sep 1, 2013, 2:19:08 AM9/1/13
to swagger-sw...@googlegroups.com
Hi Karsten, do you have a consumes/produces array in your swagger json?  Like this:


If so, you will see the drop-down which lets you choose the content type being sent back.  Try the petstore sample to see what I mean and post back if you're stuck.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Swagger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Karsten Becker

unread,
Sep 7, 2013, 5:21:05 PM9/7/13
to swagger-sw...@googlegroups.com
Hey Tony,
Yes, the produces/consumes is there, but no form is displayed (which
makes sense when you really just have one consumes/produces.
{ "operations" : [ { "method" : "GET",
"nickname" : "getWorkspace_HTML",
"notes" : "",
"parameters" : [ ],
"produces" : [ "text/html" ],
"summary" : "Display form for workspace creation [HTML]",
"type" : "void"
},
But the Accept header is set to application/json. You can see it live
at http://api.pshdl.org/#!/workspace

Karsten
>> >> > swagger-swaggers...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> > --
>> > You received this message because you are subscribed to a topic in the
>> > Google Groups "Swagger" group.
>> > To unsubscribe from this topic, visit
>> >
>> > https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
>> > To unsubscribe from this group and all its topics, send an email to
>> > swagger-swaggers...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Swagger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> swagger-swaggers...@googlegroups.com.

David Lim

unread,
Nov 7, 2013, 1:57:24 PM11/7/13
to swagger-sw...@googlegroups.com
Hi Tony,

Have the issues with file upload support in swagger-ui been resolved yet? I'm seeing similar issues to what Karsten was seeing. I also noticed that swagger-ui was sending a content-type of text/plain instead of the multipart/form-data that I'm expecting.

Thanks,
David
>> >> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> > --
>> > You received this message because you are subscribed to a topic in the
>> > Google Groups "Swagger" group.
>> > To unsubscribe from this topic, visit
>> >
>> > https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
>> > To unsubscribe from this group and all its topics, send an email to
>> > For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Swagger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/swagger-swaggersocket/wIp5CdNyWqs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Kevin Ford

unread,
Nov 14, 2013, 5:03:37 PM11/14/13
to swagger-sw...@googlegroups.com
I am also seeing the same thing.. Using node.js server  -- following is my resource definition, and the request headers (shown below the resource) being sent from swagger-ui are text/plain.  I can post any kind of file to this resource via curl with content type of multipart/form-data successfully... Thanks in advance.  I am using swagger-node-express version 1.3.2

exports.saveFile = {
  'spec' : {
    "description" : "Saves a file to filesystem",
    "path" : "/uploads/file",
    "notes" : "",
    "summary" : "POST a file to storage",
    "method" : "POST",
/*    "supportedContentTypes" : [ 'multipart/form-data' ],   */
    "produces":[ "application/json" ],
    "consumes":[ "multipart/form-data" ],
    "params" : [ {
      "paramType" : "body",
      "name" : "file",
      "description" : "POST a file to storage",
      "type" : "File",
      "required" : true
    } ],
    "responseClass" : "ArbitraryJson",
    "errorResponses" : [ swe.invalid('file') ],
    "nickname" : "saveFile"
  },
  'action' : function(req, res) {
    console.log(req.files);
     res.send('{"msg":"success", "file path": "' + req.files.file.path + '"}');
  }
};


POST http://127.0.0.1:3000/uploads/file HTTP/1.1
Host: 127.0.0.1:3000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:25.0) Gecko/20100101 Firefox/25.0
Accept: application/json
Accept-Language: en-US,en;q=0.5
Referer: http://127.0.0.1:3000/docs/
Content-Length: 0
Content-Type: text/plain; charset=UTF-8

Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Jason Goetz

unread,
Nov 27, 2013, 12:28:17 PM11/27/13
to swagger-sw...@googlegroups.com
I am seeing the same thing as well. Everything else seems to be configured correctly but when sending a file from Swagger UI, my Content-Type is text/plain and my Content-Length is 0. There is no payload. Does anyone have this working?
Reply all
Reply to author
Forward
0 new messages