Spring Rest异常处理程序返回XML格式(Spring Rest exception handler return XML format)
我在我的项目中处理异常
这是我的GET端点:
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<V6SubnetRec> get(@RequestBody V6SubnetRequest requestBody) throws QIPException { Site site = getSite(requestBody.getOrganization()); V6SubnetRec wsSubnet = (V6SubnetRec) requestBody.getV6Subnet(); V6SubnetRec v6SubnetRec = null; try { v6SubnetRec = getQipService1().getV6Subnets(wsSubnet, site); } catch (Exception e) { log.error(Keys.QIP_CALLOUT_ERROR, e); throw new RestException(e); } return new ResponseEntity<V6SubnetRec>(v6SubnetRec, HttpStatus.OK); } @ExceptionHandler(RestException.class) public ResponseEntity rulesForRestException(RestException restEx){ return new ResponseEntity(restEx.getResponse().getContent(), restEx.getResponse().getStatus()); }
RestException.java
@XmlRootElement(name = "RestException") @XmlAccessorType(XmlAccessType.FIELD) public class RestException extends RuntimeException{ @XmlElement RestResponse response; public RestException(Exception e){ //... } }
当我使用URL http://localhost/api/v1/v6subnet.json (以JSON格式返回)请求时,它将返回HTTP状态代码404并包含内容。 没关系。
但是,当我使用相同的请求请求URL http://localhost/api/v1/v6subnet.xml (以XML格式返回)时,它返回HTTP状态代码500,就像正常异常一样,不作为JSON格式处理
我希望得到像我请求JSON格式时的结果。
谢谢。
I'm handling an exception in my project
This is my GET endpoint:
@RequestMapping(method = RequestMethod.GET) public ResponseEntity<V6SubnetRec> get(@RequestBody V6SubnetRequest requestBody) throws QIPException { Site site = getSite(requestBody.getOrganization()); V6SubnetRec wsSubnet = (V6SubnetRec) requestBody.getV6Subnet(); V6SubnetRec v6SubnetRec = null; try { v6SubnetRec = getQipService1().getV6Subnets(wsSubnet, site); } catch (Exception e) { log.error(Keys.QIP_CALLOUT_ERROR, e); throw new RestException(e); } return new ResponseEntity<V6SubnetRec>(v6SubnetRec, HttpStatus.OK); } @ExceptionHandler(RestException.class) public ResponseEntity rulesForRestException(RestException restEx){ return new ResponseEntity(restEx.getResponse().getContent(), restEx.getResponse().getStatus()); }
RestException.java
@XmlRootElement(name = "RestException") @XmlAccessorType(XmlAccessType.FIELD) public class RestException extends RuntimeException{ @XmlElement RestResponse response; public RestException(Exception e){ //... } }
When I request with URL http://localhost/api/v1/v6subnet.json (return with JSON format), it will return HTTP status code 404 and include the content. It's OK.
But when I request with URL http://localhost/api/v1/v6subnet.xml (return with XML format) with the same request, it return HTTP status code 500 like a normal exception which is not handled as JSON format
I want to have results like when I request to JSON format.
Thanks.
原文:https://stackoverflow.com/questions/34676393
最满意答案
由于leafletOutput中的
height
参数,它不起作用。 奇怪的是,如果你在%
指定它,地图就不会显示,但是如果你使用“px”(或者一个将被强制转换为字符串且附加了“px”的数字),它确实可以正常工作。
leafletOutput("map", width = "75%", height = "500px")
产生:我不知道为什么会发生这种情况,但是如果你想用
%
指定leafletOutput
的高度,你可以将它包装成div
并给它适当的高度。
默认情况下,宽度设置为
100%
,高度设置为400px。 因此,您不必指定这些参数 - 只有在我想要更改输出的大小时才会这样做。leafletOutput(outputId, width = "100%", height = 400)
It doesn't work because of the
height
parameter in leafletOutput. Strangely, if you specify it in%
the map doesn't show up, but if you use "px" (or a number which will be coerced to a string and have "px" appended) it does work fine.
leafletOutput("map", width = "75%", height = "500px")
yields:I don't know why this happens but if you wanted to specify the height of the
leafletOutput
in%
you could wrap it into adiv
and give it the appropriate height.
By default the width is set to
100%
and the height to 400px. So, you don't have to specify these parameters - I would do it only if I wanted to change the size of the output.leafletOutput(outputId, width = "100%", height = 400)
相关问答
更多-
r - 空的textInput()导致传单闪亮的应用程序错误(r - Empty textInput() causing error in leaflet shiny app)[2022-03-02]
你可以验证你是否得到了一个tibble或如果你得到一个空的tibble 。 如果tibble为空,则可以返回NULL 。 通过这种方式,您添加的验证APIdata()是否为NULL将会起作用。 您可以在您a <- ebirdnotable(region = as.character(input$region_in), back = as.numeric(input$slider_in))后添加if(length(a) == 0){return(NULL)}反应它工作。 编辑: 正如你在你的评论中提到的,你实 ... -
我有同样的问题,我想我发现了一些有效的方法: 使用LeafletProxy更改生成地图的方式,如Leaflet for R页面中所述,并在SuperZip示例中显示 。 首先,尝试设置renderLeaflet函数,如下所示: output$map = renderLeaflet(leaflet() %>% addTiles(urlTemplate = "http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png") %>% setView(.. ...
-
您的申请工作正常。 我尝试了两个不同的mapbox令牌,它们都在工作。 尝试这个: accessToken = 'your_token_from_your_mapbox_account')) %>% Your application is working fine. I tried two different mapbox tokens and they are both working. Try this: accessToken = 'your_token_from_your_mapbox_accou ...
-
我认为这个问题与map对象中的多边形顺序有关(如果你设置label = Country$names ,标签现在是正确的)。 无论如何,您可以通过将Country转换为SpatialPolygons对象来解决问题(请参阅此处 )。 library(maptools) IDs <- sapply(strsplit(Country$names, ":"), function(x) x[1]) Country <- map2SpatialPolygons(Country, ...
-
正如Yihui对上述评论所述,没有办法。 我在传单上填写了一个问题来询问这个功能: https : //github.com/rstudio/leaflet/issues/84 TKS As stated by Yihui on the comment above, there is no way to do it. I filled an issue at leaflet to ask this feature: https://github.com/rstudio/leaflet/issues/84 T ...
-
我错过了html头上的{{headContent}}标签。 I was missing the {{headContent}} tag on the html head.
-
你快到了。 你的app中只有一个错误: 你需要改变 center <- reactive({ ifelse(is.null(input$map01_bounds), c(179.462, -20.64275), c((input$map01_bounds$bounds$north + input$map01_bounds$bounds$south)/2.0, (input$map01_bounds$bounds$east + i ...
-
闪亮/传单地图无法渲染(Shiny/Leaflet map not rendering)[2022-10-19]
由于leafletOutput中的height参数,它不起作用。 奇怪的是,如果你在%指定它,地图就不会显示,但是如果你使用“px”(或者一个将被强制转换为字符串且附加了“px”的数字),它确实可以正常工作。 leafletOutput("map", width = "75%", height = "500px")产生: 我不知道为什么会发生这种情况,但是如果你想用%指定leafletOutput的高度,你可以将它包装成div并给它适当的高度。 默认情况下,宽度设置为100% ,高度设置为400px。 因此 ... -
没有找到闪亮的传单数据(shiny leaflet data not found)[2023-09-24]
要修复错误的过滤情况,您必须将代码切换到以下内容: fData <- reactive({ data <- hustonCrime if (input$offenseFilter != "All") { data <- subset(data, offense %in% input$offenseFilter) } if (input$monthFilter != "All") { data <- subset(data, month %in% input$monthFilt ... -
使用有光泽的传单(using leaflet with shiny)[2021-10-24]
几点 renderLeaflet()调用中的最后一个语句是返回的内容。 因此,如果您有一个print语句,那就是返回的内容,而不是leaflet对象 我认为你还需要围绕你的用户界面和服务器功能的shinyUI()和shinyServer() - 从发光的v0.10开始不推荐使用 height是一个棘手的争论 - 请参阅此主题 library(shiny) library(leaflet) ui <- fluidPage( leafletOutput(outputId = "map", wi ...