I have a response 406 Not Acceptable problem.

991 views
Skip to first unread message

Mike Stults

unread,
Aug 8, 2014, 6:39:18 PM8/8/14
to swagger-sw...@googlegroups.com
I am trying out swagger and have reached an impasse with a simple text service.

I have a Jersey 1.x service coded like this, which returns a simple string,
@Path("version")
@GET @Produces("text/plain")
public String getVersion() {
            System.out.println("***** request to version");
        ri = new RequestInfo(sw, uriInfo, request, requestHeaders);
         return ri.appConfig.getVersion();
 }

and a Swagger API object that look like this

 {
 "path": "/fdsnwsbeta/dataselect/1/version",
 "operations": [
   {
     "method": "GET",
     "summary": "Get handler version",
     "notes": "<p>The <strong>version</strong> service provides the version number of the handler as described in the dataselect service cfg file ",
     "produces": [
     "text/plain"
     ],
     "nickname": "getHandlerVersion",
     "authorizations": {},
     "parameters": [],
     "responseMessages": [
     {
       "code": 500,
       "message": "Internal Server Error"
     }
     ]
   }
   ]
 }

when I run this, I get a 406,

when I viewed the headers in chrome, I see Accept:application/json on the request header

so then I changed a similar service to @GET @Produces({"text/plain","application/json"})
and output a simple JSON string from the service
... then may swagger sample code works okay.

I am assuming the "produces" object should control the Accept contents? 
else maybe there is some other issue?

Ron

unread,
Aug 9, 2014, 10:15:15 AM8/9/14
to swagger-sw...@googlegroups.com
Hi Mike,

There are a few details missing in your question.
The code that you shared contains no Swagger annotations, so I'm left to assume that the Swagger json was manually written and not generated from the code.

The swagger json you shared is also invalid, to the least because it misses the return type of the operation.

When you say 'when I run this', what do you mean exactly? What is it that you're running and how do you run it?

Once you provide this information, I'm sure we can resolve the issue at hand.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mike Stults

unread,
Aug 9, 2014, 9:05:53 PM8/9/14
to swagger-sw...@googlegroups.com
Hi Ron,

Thanks for your reply.
Based on a search of this forum and finding a similar mention for the 406 response, I did an update from swagger-ui and that fixed my issue, so I consider this issue resolved.

I have a followup question from your response, and to answer your questions..
- Not wanting to touch my service at this time, I manually created json files based on my service, a colleagues files and the Swagger documentation and pet store examples

- I need more explanation as the why the json I included is invalid, it seems to work, I take -> "produces": [ "text/plain" ] -> as the "return type of the operation" is that not true?

- I started out with code from swagger-core/samples/no-server, added a pom file and packaged the files so as to make a war file, and deployed it to my normal tomcat environment. 

After searching the forum, I cloned from swagger-ui and updated any *.js, etc. files that were different, so I should to be consistent with the current swagger-ui code set.

thanks,
Mike
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Aug 10, 2014, 4:55:37 AM8/10/14
to swagger-sw...@googlegroups.com
Each operation must declare its return type (even if it returns nothing).
This is expressed using the "type" field of the operation (which your original sample does not contain).

If you look at the pet store example, you'll see that all operations include a "type" field, and if it returns nothing the value is "void".


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages