Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSON支持不起作用_Java_Json_Rest_Jersey - Fatal编程技术网

Java JSON支持不起作用

Java JSON支持不起作用,java,json,rest,jersey,Java,Json,Rest,Jersey,我跟随这位官员,尝试了许多已经被问到的问题,但没有任何效果。有人能帮我找到问题吗 在这里,我添加了我能找到的所有细节 web.xml: <servlet> <servlet-name>REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <!-- Reg

我跟随这位官员,尝试了许多已经被问到的问题,但没有任何效果。有人能帮我找到问题吗

在这里,我添加了我能找到的所有细节

web.xml

<servlet>
    <servlet-name>REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <!-- Register resources and providers under com.stxt.rest package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.stxt.supercentral.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
@Path("/agent")
@Component
public class AgentRestAPI {

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public Response getAgent(@QueryParam("id") String agentId, Profile profile) {
    return ApiResponseFactory.generateResponse(agentId);
}

@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/get")
public Response getAgent(@QueryParam("id") String agentId) {
    return ApiResponseFactory.generateResponse(agentId);
}
public class Profile {

    private String profileId;
    private String emailAddress;
    private String name;

    public String getProfileId() {
        return profileId;
    }

    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Profile{" +
                "profileId='" + profileId + '\'' +
                ", emailAddress='" + emailAddress + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
<?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: 2.2 2013-08-14 08:51:58"/>
    <grammars/>
    <resources base="http://localhost:8080/rest/">
        <resource path="/task">
            <resource path="/">
                <method id="getTask" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/customer">
            <resource path="/">
                <method id="getCustomer" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/agent">
            <resource path="/get">
                <method id="getAgent" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
            <resource path="/">
                <method id="getAgent" name="POST">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="application.wadl">
            <method id="getWadl" name="GET">
                <response>
                    <representation mediaType="application/vnd.sun.wadl+xml"/>
                    <representation mediaType="application/xml"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="text/plain"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="*/*"/>
                </response>
            </method>
            <resource path="{path}">
                <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="path" style="template" type="xs:string"/>
                <method id="geExternalGrammar" name="GET">
                    <response>
                        <representation mediaType="application/xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>
}

资源类

<servlet>
    <servlet-name>REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <!-- Register resources and providers under com.stxt.rest package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.stxt.supercentral.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
@Path("/agent")
@Component
public class AgentRestAPI {

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public Response getAgent(@QueryParam("id") String agentId, Profile profile) {
    return ApiResponseFactory.generateResponse(agentId);
}

@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/get")
public Response getAgent(@QueryParam("id") String agentId) {
    return ApiResponseFactory.generateResponse(agentId);
}
public class Profile {

    private String profileId;
    private String emailAddress;
    private String name;

    public String getProfileId() {
        return profileId;
    }

    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Profile{" +
                "profileId='" + profileId + '\'' +
                ", emailAddress='" + emailAddress + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
<?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: 2.2 2013-08-14 08:51:58"/>
    <grammars/>
    <resources base="http://localhost:8080/rest/">
        <resource path="/task">
            <resource path="/">
                <method id="getTask" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/customer">
            <resource path="/">
                <method id="getCustomer" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/agent">
            <resource path="/get">
                <method id="getAgent" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
            <resource path="/">
                <method id="getAgent" name="POST">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="application.wadl">
            <method id="getWadl" name="GET">
                <response>
                    <representation mediaType="application/vnd.sun.wadl+xml"/>
                    <representation mediaType="application/xml"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="text/plain"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="*/*"/>
                </response>
            </method>
            <resource path="{path}">
                <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="path" style="template" type="xs:string"/>
                <method id="geExternalGrammar" name="GET">
                    <response>
                        <representation mediaType="application/xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>
应用程序。wadl

<servlet>
    <servlet-name>REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <!-- Register resources and providers under com.stxt.rest package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.stxt.supercentral.rest</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
@Path("/agent")
@Component
public class AgentRestAPI {

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/")
public Response getAgent(@QueryParam("id") String agentId, Profile profile) {
    return ApiResponseFactory.generateResponse(agentId);
}

@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/get")
public Response getAgent(@QueryParam("id") String agentId) {
    return ApiResponseFactory.generateResponse(agentId);
}
public class Profile {

    private String profileId;
    private String emailAddress;
    private String name;

    public String getProfileId() {
        return profileId;
    }

    public void setProfileId(String profileId) {
        this.profileId = profileId;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Profile{" +
                "profileId='" + profileId + '\'' +
                ", emailAddress='" + emailAddress + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
<?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: 2.2 2013-08-14 08:51:58"/>
    <grammars/>
    <resources base="http://localhost:8080/rest/">
        <resource path="/task">
            <resource path="/">
                <method id="getTask" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/customer">
            <resource path="/">
                <method id="getCustomer" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response/>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="/agent">
            <resource path="/get">
                <method id="getAgent" name="GET">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
            <resource path="/">
                <method id="getAgent" name="POST">
                    <request>
                        <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="id" style="query" type="xs:string"/>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="application/vnd.sun.wadl+xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
        <resource path="application.wadl">
            <method id="getWadl" name="GET">
                <response>
                    <representation mediaType="application/vnd.sun.wadl+xml"/>
                    <representation mediaType="application/xml"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="text/plain"/>
                </response>
            </method>
            <method id="apply" name="OPTIONS">
                <request>
                    <representation mediaType="*/*"/>
                </request>
                <response>
                    <representation mediaType="*/*"/>
                </response>
            </method>
            <resource path="{path}">
                <param xmlns:xs="http://www.w3.org/2001/XMLSchema" name="path" style="template" type="xs:string"/>
                <method id="geExternalGrammar" name="GET">
                    <response>
                        <representation mediaType="application/xml"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="text/plain"/>
                    </response>
                </method>
                <method id="apply" name="OPTIONS">
                    <request>
                        <representation mediaType="*/*"/>
                    </request>
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>
响应标题:

Cache-Control:must-revalidate,no-cache,no-store
Content-Length:352
Content-Type:text/html;charset=iso-8859-1
Server:Jetty(9.3.0.v20150612)
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:JSESSIONID=132gft2iqjdzgcrn6eliv77ox
Host:localhost:8080
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36
请求标头:

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:17
Content-Type:application/json
Cookie:JSESSIONID=1e6smzkea0dds17t964t3u7fc2
CSP:active
Host:localhost:8080
Origin:chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36
id:23
查询字符串参数:

id:23
"23"
请求有效负载:

{"profileId": "1"}
答复:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
        <title>Error 415 Unsupported Media Type</title>
    </head>
    <body><h2>HTTP ERROR 415</h2>
        <p>Problem accessing /rest/agent. Reason:
            <pre>    Unsupported Media Type</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.0.v20150612</a><hr/>

    </body>
</html>
asm-all-repackaged-2.2.0-b14.jar
cglib-2.2.0-b14.jar
hk2-api-2.2.0-b14.jar
hk2-locator-2.2.0-b14.jar
hk2-utils-2.2.0-b14.jar
jaxb-api-2.2.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-server.jar
activation-1.1.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-xc-1.9.2.jar
jaxb-api-2.2.2.jar
jaxb-impl-2.2.3-1.jar
jersey-core-1.19.jar
jersey-json-1.19.jar
jettison-1.1.jar
stax-api-1.0-2.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
响应标题:

Cache-Control:must-revalidate,no-cache,no-store
Content-Length:352
Content-Type:text/html;charset=iso-8859-1
Server:Jetty(9.3.0.v20150612)
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:JSESSIONID=132gft2iqjdzgcrn6eliv77ox
Host:localhost:8080
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36
请求标头:

Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:17
Content-Type:application/json
Cookie:JSESSIONID=1e6smzkea0dds17t964t3u7fc2
CSP:active
Host:localhost:8080
Origin:chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36
id:23
查询字符串参数:

id:23
"23"
答复:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
        <title>Error 415 Unsupported Media Type</title>
    </head>
    <body><h2>HTTP ERROR 415</h2>
        <p>Problem accessing /rest/agent. Reason:
            <pre>    Unsupported Media Type</pre></p><hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.0.v20150612</a><hr/>

    </body>
</html>
asm-all-repackaged-2.2.0-b14.jar
cglib-2.2.0-b14.jar
hk2-api-2.2.0-b14.jar
hk2-locator-2.2.0-b14.jar
hk2-utils-2.2.0-b14.jar
jaxb-api-2.2.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-server.jar
activation-1.1.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-xc-1.9.2.jar
jaxb-api-2.2.2.jar
jaxb-impl-2.2.3-1.jar
jersey-core-1.19.jar
jersey-json-1.19.jar
jettison-1.1.jar
stax-api-1.0-2.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
附加库: 可能会有额外的未使用库(我可能在网上尝试一些解决方案时添加了这些库)


问题解决了。在Jersey
2.*
中,我们需要手动注册
MessageBodyReader
MessageBodyWriter
。问题很好地解释了这一点。

如何以及在哪里调用后端?我正在使用Postman Rest客户端扩展进行
POST
调用。不知道您试图在
where
部分中询问什么,但服务器在同一台机器上运行,并且
GET
请求工作正常。当您向邮递员发出请求时,是否将mime类型设置为“application/javascript”?你也可以发布工作GET端点吗?我更新了问题以包含GET细节,请参见上文。我没有设置mime类型的详细信息。我不知道怎么做。但是我确实将内容类型设置为
application/json
您可以从post-getProfile方法中删除@Path(“/”)注释吗?我觉得这是不对的。