下载扬鞭宠物商店(简单)从swagger.io编辑页面,做了命令mvn码头:运行扬鞭代码生成 - 生成Spring的MVC GET没有得到设置内容类型
当Chrome浏览器开放DevTools和锻炼一个GET,我没有看到设置标题Content-Type字段。
这是关于GET /宠物{ID}
下载扬鞭宠物商店(简单)从swagger.io编辑页面,做了命令mvn码头:运行扬鞭代码生成 - 生成Spring的MVC GET没有得到设置内容类型
当Chrome浏览器开放DevTools和锻炼一个GET,我没有看到设置标题Content-Type字段。
这是关于GET /宠物{ID}
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
14.17内容类型
内容类型实体头字段指示的媒体类型 entity-body发送给收件人,或者在HEAD方法的情况下, 媒体类型已发送请求已获得GET。 的Content-Type = “内容类型”, “:” 媒体类型
内容类型是在请求的上下文中无意义的报头。 因为请求没有正文,所以对于“GET”是双倍的。
如果您可以为Chrome和curl发布请求和响应标头和正文,我可能会为您解决此问题。
话虽如此,回头看看周围的StackOverflow很快告诉我,Spring可以提出这个错误的原因与内容编码无关的多种原因。例如(比如)你试图序列化的对象缺少一个参数少的构造函数。
是否有任何记录设置可以跟踪InnerException和堆栈以查看基本错误是什么?
以下是Spring在我的应用程序(而不是宠物店)正在做的事情。你想从我的应用程序的swagger UI页面的屏幕截图吗?
谢谢你看着这个罗杰。
2015-11-04 18:32:13.977 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/hacker/api/mef/sca/v1/SCA_ETH_FDFr_EC/5]
2015-11-04 18:32:13.977 DEBUG 32416 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /api/mef/sca/v1/SCA_ETH_FDFr_EC/5
2015-11-04 18:32:13.980 DEBUG 32416 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'null' not supported
2015-11-04 18:32:13.980 DEBUG 32416 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Invoking @ExceptionHandler method: public void com.ciena.sca.exception.ApiExceptionHandler.handleOtherErrors(java.lang.Exception,javax.servlet.http.HttpServletResponse)
2015-11-04 18:32:13.980 ERROR 32416 --- [nio-8080-exec-1] c.c.sca.exception.ApiExceptionHandler : Content type 'null' not supported
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'null' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:231)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:349)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:296)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:56)
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:299)
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1120)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:932)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:299)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:76)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
2015-11-04 18:32:13.982 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2015-11-04 18:32:13.982 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
2015-11-04 18:32:13.983 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/hacker/error]
2015-11-04 18:32:13.983 DEBUG 32416 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /error
2015-11-04 18:32:13.983 DEBUG 32416 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Returning handler method [public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)]
2015-11-04 18:32:13.983 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Last-Modified value for [/hacker/error] is: -1
2015-11-04 18:32:13.985 DEBUG 32416 --- [nio-8080-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Written [{timestamp=Wed Nov 04 18:32:13 EST 2015, status=400, error=Bad Request, exception=org.springframework.web.HttpMediaTypeNotSupportedException, message=Content type 'null' not supported, path=/hacker/api/mef/sca/v1/SCA_ETH_FDFr_EC/5}] as "application/json;charset=UTF-8" using [org.springfr[email protected]2ed7a433]
2015-11-04 18:32:13.985 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
2015-11-04 18:32:13.985 DEBUG 32416 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Successfully completed request
好吧,前3行读给我看1.启动进程唱。 2.查找该URL的处理程序。 3.失败,因为我没有得到处理程序的映射。所以我会说url解析/路由是问题。不能太多帮助,因为这将是特定于应用程序的,您需要开始披露潜在的安全敏感细节。 –
OK,发现了这个问题,感谢的根本原因wing328在github上招摇代码生成项目。
事实证明,我们的YAML定义文件的顶部,我们有:
consumes: - application/json
导致所有生成的控制方法,以期望在内容类型的应用程序/ JSON。这打破了GET,DELETE和PATCH API调用,在我们的例子中没有任何有效载荷。
太棒了。虽然定义内容类型会破坏没有身体的东西,但我觉得奇怪。或者是,预期的返回类型打破东西? –
它将此添加到控制器类的顶部:@Controller @RequestMapping(value =“/ SCA_ETH_FDFr_EC”,consumes = {APPLICATION_JSON_VALUE},产生= {APPLICATION_JSON_VALUE})这显然告诉你所有的控制器方法,他们需要application/json 。故事的道德是要小心你的yaml ...定义消费/产生int的API部分 –
看到图像中的所有标题有点难。但是,您在HTML响应中将内容类型设置为“META”标记,而不是HTTP标头,这可能是您收到错误页面的一个副作用。如果没有REQUEST头文件,很难确定,但我认为它是说“你问了JSON,我不知道那是什么” –
我的意思是用于curl的REQUEST头文件。 DevTools会说“accept application/xml” –
yes,但devtools Request Headers根本没有内容类型集。我发布这个例子的原因是因为在我的弹簧控制器的真实代码中,我得到:{“timestamp”:1446597153755,“status”:400,“error”:“Bad Request”,“exception”:“org.springframework。web.HttpMediaTypeNotSupportedException“,”message“:”Content type'null'not supported“,”path“:”/ hacker/api/mef/sca/v1/SCA_ETH_FDFr_EC/5“} –