简体   繁体   English

Ember POST请求在JAX-RS中以XML jersey响应进行响应

[英]Ember POST request responding with XML jersey response in JAX-RS

I have an ember application trying to make a post request to my Restful Java Web Service (JAX-RS). 我有一个余烬应用程序试图向我的Restful Java Web服务(JAX-RS)发出发布请求。 However, the request doesn't seem to be hitting the endpoint. 但是,请求似乎没有到达终点。 Instead, the Java web service is sending the following response to ember: 相反,Java Web服务将以下响应发送给ember:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 1.10 11/02/2011 04:41 PM"/>
    <grammars/>
    <resources base="http://localhost:3002/">
        <resource path="users">
            <method id="postUser" name="POST">
                <response>
                    <representation mediaType="application/json"/>
                </response>
            </method>
        </resource>
    </resources>
</application>

The web service itself prints the following message to the console Web服务本身将以下消息打印到控制台

Feb 19, 2017 2:48:06 PM com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response
Feb 19, 2017 2:48:06 PM com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response
Feb 19, 2017 2:48:06 PM com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response
Feb 19, 2017 2:48:06 PM com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class java.lang.String
Feb 19, 2017 2:48:06 PM com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class javax.ws.rs.core.Response

The endpoint on JAX-RS looks like this: JAX-RS上的端点如下所示:

@Path("/users")
public class Users {
    @POST
    @Produces("application/json")
    public Response postUser() {
        System.out.println("here");
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("{}").header("Access-Control-Allow-Origin", "*").build();
    }
}

Jersey Version: jax-rs-jersey-1.10 球衣版本: jax-rs-jersey-1.10

The adapter in ember looks like this: ember中的适配器如下所示:

   export default DS.RESTAdapter.extend({
        host: 'http://localhost:3002',
    });

Thank you in advance! 先感谢您!

Edit: When testing the request in postman, it all works with no issues. 编辑:在邮递员中测试该请求时,一切正常。 Could be something to do with headers in ember? 可能与ember中的标头有关吗?

The issue was that the client was making the OPTIONS request to check if the server responded with CORS, and the JAX-RS wasn't set up for CORS. 问题是客户端正在发出OPTIONS请求,以检查服务器是否响应了CORS,并且未为CORS设置JAX-RS。

The solution was to write the CORS filter and then to update Jersy to 2.22. 解决方案是编写CORS筛选器 ,然后将Jersy更新为2.22。 Therefore changing the HTTPServer setup to JdkHttpServerFactory 因此,将HTTPServer设置更改为JdkHttpServerFactory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM