415 error when sending json data back to java rest service using AJAX

I have an ajax request on my front end that sends a JSON doc to a rest service implementation. It is wired up through Spring and the @GET request in the REST service works well. The issue is that whenever i try to use the @POST method it always throws a 415 error. I have tried manipulating how i send it back and the type of variable that is accepted in the post method according to various gu

使用AJAX将json数据发送回java rest服务时发生错误415

我在我的前端有一个ajax请求,将JSON文档发送到其他服务实现。 它通过Spring进行连接,并且REST服务中的@GET请求运行良好。 问题是,每当我尝试使用@POST方法时,它总是会引发415错误。 我已经尝试操纵我如何发送回来,并根据各种指南在线发布方法中接受的变量类型,但我不确定接下来要看的内容。 我有双重检查,我确实有数据被发送到@POST方法,但我觉得它根本不解析JSON并抛出错误。 不幸的是,我不知道如何解决这个

Jersey multiple get responses on same path possible?

Currently I am using Jetty + Jersey to make it possible to have different responses according to the @GET parameters, if an id is passed it shall return the task, if not return all tasks. @GET @Path("task") @Produces(MediaType.APPLICATION_JSON) public ArrayList<Task> getTask(){ return tasks; } @GET @Path("task") @Produces(MediaType.APPLICATION_JSON) public ArrayList<Task> getTas

泽西岛多个获得同一路径上的回应可能?

目前,我正在使用Jetty + Jersey根据@GET参数使不同的响应成为可能,如果一个id被传递,它将返回任务,如果not返回所有任务。 @GET @Path("task") @Produces(MediaType.APPLICATION_JSON) public ArrayList<Task> getTask(){ return tasks; } @GET @Path("task") @Produces(MediaType.APPLICATION_JSON) public ArrayList<Task> getTasks(@QueryParam("id") String id){ return task(uuid); } 这可能吗?

page with Jersey's ExceptionMapper

@Provider public class JerseyExceptionMapper implements ExceptionMapper<JerseyException> { @Override public Response toResponse(JerseyException jerseyException) { return Response.status(jerseyException.getErrorCode()). entity(jerseyException.getJsonResponseObj()). type(MediaType.APPLICATION_JSON). build(); } } The code a

与泽西的ExceptionMapper页面

@Provider public class JerseyExceptionMapper implements ExceptionMapper<JerseyException> { @Override public Response toResponse(JerseyException jerseyException) { return Response.status(jerseyException.getErrorCode()). entity(jerseyException.getJsonResponseObj()). type(MediaType.APPLICATION_JSON). build(); } } 当您在web

How to return http status code for exceptions in rest services

In my application I have different layers like the rest layer, service layer and DB layer, according to business scenarios I am trowing different business exceptions from the service layer. But now, I have to set different HTTP codes like 400, 403, 409, 412.. to REST responses. How can I set different HTTP status codes based on different scenarios? Which is the most feasible way like: aspec

如何为休息服务中的异常返回http状态码

在我的应用程序中,根据业务场景,我有不同的层,如休息层,服务层和数据库层,我正在从服务层中抛出不同的业务异常。 但是现在,我必须将不同的HTTP代码设置为400,403,409,412 ..到REST响应。 如何根据不同的场景设置不同的HTTP状态码? 这是最可行的方式,如:方面,异常映射,或....? 由于我只能在休息层设置一次HTTP状态(参考本文),所以我无法映射到不同的HTTP代码,因为我的异常来自服务层。 我的异常类看

RS so that user sees download popup for Excel?

I wrote code that generate Excel file using REST JAX-RS and I confirmed that the generated Excel file is in GlassFish server directory. But my goal is when user click on the button (which generate Excel .xls), I want download popup to show up asking user whether to save or open the .xls file just like any other web services doing for downloading any type of files. According to my search, the

RS,以便用户看到Excel的下载弹出窗口?

我编写了使用REST JAX-RS生成Excel文件的代码,并确认生成的Excel文件位于GlassFish服务器目录中。 但是我的目标是当用户点击按钮(生成Excel .xls)时,我想要下载弹出窗口来显示询问用户是否要保存或打开.xls文件,就像任何其他用于下载任何类型文件的Web服务一样。 根据我的搜索,步骤是: 生成Excel .xls(完成) 写excel流 在JAX-RS文件中,将响应头设置为类似的东西, String fileName =“Blah_Report.xls”; r

How to produce JSON output with Jersey 1.6 using JAXB

@XmlRootElement public class Todo { private String s = "test"; public String getS() { return s; } public void setS(String s) { this.s = s; } } and service: @Path("/test") public class Service { @GET @Produces({MediaType.APPLICATION_JSON }) public List<Todo> getAllGadgets() { return Arrays.asList(new Todo[] { new Todo() }); }

如何使用JAXB为Jersey 1.6生成JSON输出

@XmlRootElement public class Todo { private String s = "test"; public String getS() { return s; } public void setS(String s) { this.s = s; } } 和服务: @Path("/test") public class Service { @GET @Produces({MediaType.APPLICATION_JSON }) public List<Todo> getAllGadgets() { return Arrays.asList(new Todo[] { new Todo() }); } }

Is it ever OK to throw a java.lang.Error?

I have a plugin module that goes into a web application. If the module does not load correctly, it does not make sense for the web application to go on, and the web application should probably not load at all, we would prefer this module to initialize correctly always. If I were to throw a runtime exception, it would get into the logs, and just get ignored since the application will continue an

抛出java.lang.Error是否可行?

我有一个进入Web应用程序的插件模块。 如果模块加载不正确,Web应用程序无法继续,Web应用程序可能根本无法加载,我们希望此模块始终正确初始化。 如果我要抛出一个运行时异常,它会进入日志,只是被忽略,因为应用程序仍然会继续,并且最终用户永远不会知道......我知道错误只能在特殊情况下抛出,他们通常必须处理系统无法恢复的情况,但在这种情况下你会做什么? 我经常在业务代码中使用的唯一Error是ExceptionInInitiali

How to index BigDecimal values in Lucene 3.0.1

I have some BigDecimal values which should be indexed for searching. Lucene has NumericField but it has setters only for long, double, float and int. I could store it as a String but then I would not benefit from NumericRangeQuery. How you have stored your BigDecimals? Any best practices to share? Steven Rowe provides interesting ideas in this post: http://www.lucidimagination.com/search

如何在Lucene 3.0.1中索引BigDecimal值

我有一些BigDecimal值应该被索引搜索。 Lucene有NumericField,但它只有long,double,float和int的setter。 我可以将它存储为一个字符串,但是我不会从NumericRangeQuery中受益。 您如何存储BigDecimals? 任何最佳实践分享? Steven Rowe在这篇文章中提供了有趣的想法: http://www.lucidimagination.com/search/document/ad648772f8825a28/bigdecimal_values#2502f96055839c3d 他说他的方案可能可以用来代表所有Bi

MIME Type is null for log files

I am developing a Spring REST service using Spring Boot, that is, in a nutshell, sending emails. It supports attachments. I got a validator class that ensures that only expected attachment types are accepted, through MIME type (content type). Supports MIME type are: application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vn

日志文件的MIME类型为空

我正在使用Spring Boot开发Spring REST服务,简而言之就是发送电子邮件。 它支持附件。 我有一个验证器类,通过MIME类型(内容类型)确保只接受预期的附件类型。 支持MIME类型是: 应用程序/ pdf应用程序/ msword 应用/ vnd.openxmlformats-officedocument.wordprocessingml.document 应用/ vnd.ms-Excel中 应用/ vnd.openxmlformats-officedocument.spreadsheetml.sheet 纯文本/ 它为doc,docx,xl​​s,xlsx,

limit name size and file extention

I need regular expression for icefaces input file component, file name length should be less than 15 characters and have proper extention. I wrote this, but it fails: ^.{0,100}.+.(asf|avi|csv|pdf|doc|docx|dot|eml|gif|htm|html|idx|tif|jpg|jpeg|bmp|png|mp3|mpg|msg|ppt|pptx|pst|rtf|txt|wav|wma|xls|xlsx|zip"+ "|ASF|ASI|CSV|PDF|DOC|DOCX|DOT|EML|GIF|HTM|HTML|IDX|TIF|JPG|JPEG|BMP|PNG|MP3|MP

限制名称大小和文件扩展

我需要对icefaces输入文件组件进行正则表达式,文件名长度应小于15个字符并且有适当的扩展。 我写了这个,但是失败了: ^ {0,100} +(ASF |。AVI | CSV | PDF | DOC | DOCX |点| EML | GIF | HTM |全文| IDX | TIF | JPG | JPEG | BMP | PNG | MP3 |英里|留言| PPT | pptx | pst | rtf | txt | wav | wma | xls | xlsx | zip“+”| ASF | ASI | CSV | PDF | DOC | DOCX | DOT | EML | GIF | HTM | HTML | IDX | TIF | JPEG | BM