gpt4 book ai didi

java - 泽西声明式链接不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:22:27 27 4
gpt4 key购买 nike

我尝试使用 Jersey 创建一个完整的网络服务。我想在该请求的响应中提供一个链接:

GET /mac/ws/gtm HTTP/1.1
Host: localhost:8080
Accept: application/json
Cache-Control: no-cache

我希望响应是:

HTTP/1.1 200 OK
link: </dossiers>;rel=dossiers

{
"message": "Hello"
}

但是响应是:

HTTP/1.1 200 OK

{
"message": "Hello"
}

链接未生成!

看看我的 Gtm 资源:

@Component
@Path("/gtm")
public class GTmRessource
{
@GET
@Produces(MediaType.APPLICATION_JSON)
public GTm getJson()
{
GTm gtm = new GTm();
return gtm;
}
}

还有我的 Gtm 实体

@XmlRootElement()
@Link(value = @Ref(value = "/dossiers", method = "get"), rel = "dossiers")
public class GTm
{
String message = "Hello";

public String getMessage()
{
return message;
}

public void setMessage(String message)
{
this.message = message;
}
}

怎么了?

感谢您的帮助。通过

最佳答案

参见 Declarative Hyperlinking: Configuration

您需要以编程方式添加 LinkFilter:

resourceConfig.getContainerResponseFilters().add(LinkFilter.class);

或通过 web.xml

<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.server.linking.LinkFilter</param-value>
</init-param>

C:\>curl -i http://localhost:8080/gtm

HTTP/1.1 200 OK
Content-Type: application/json
Link: </dossiers>;rel=dossiers
Date: Thu, 04 Dec 2014 12:38:06 GMT
Transfer-Encoding: chunked

{"message":"Hello"}

关于java - 泽西声明式链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27292246/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com