1

在为我的 Jersey REST 服务实现基本身份验证后,我正在使用HTTPBasicAuthFilter. 我正在使用 Glassfish 3.1.2 和 NetBeans。

我遵循了http://javaevangelist.blogspot.pt/2012/07/jax-rs-tip-of-day-basic-client_27.html中编写的代码,只是更改了以下参数:

erc.setUsernamePassword("blive2", "microio")- 这是正确的登录

private static final String BASE_URI = "http://localhost:8080/LULServices/webresources"

webResource = client.resource(BASE_URI).path("entities.user")

因此,当我运行此文件时,会出现以下消息:

    Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > GET http://localhost:8080/LULServices/webresources/entities.user
1 > Accept: text/plain
1 > Authorization: Basic YmxpdmUyOm1pY3JvaW8=

Mar 11, 2013 5:30:38 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client in-bound response
1 < 406
1 < Date: Mon, 11 Mar 2013 17:30:38 GMT
1 < Content-Length: 1231
1 < Expires: Thu, 01 Jan 1970 01:00:00 GMT
1 < Content-Type: text/html
1 < Server: GlassFish Server Open Source Edition 3.1.2.2
1 < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
1 < Cache-Control: no-cache
1 < Pragma: No-cache
1 < 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title><style type="text/css"><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - Not Acceptable</h1><hr/><p><b>type</b> Status report</p><p><b>message</b>Not Acceptable</p><p><b>description</b>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers (Not Acceptable).</p><hr/><h3>GlassFish Server Open Source Edition 3.1.2.2</h3></body></html>

Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/LULServices/webresources/entities.user returned a response status of 406 Not Acceptable
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:507)
    at lulClient.BasicAuthenticationClient$ExampleResourceClient.getMessage(BasicAuthenticationClient.java:38)
    at lulClient.BasicAuthenticationClient.main(BasicAuthenticationClient.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

所以出现的是406 Not Acceptable。你能帮我解决吗?

谢谢!

4

1 回答 1

2

问题已经解决了。我向服务询问的信息只是以两种类型返回:APPLICATION_JSON 或 APPLICATION_XML。所以我不得不改变我插入类型的代码部分:

javax.ws.rs.core.MediaType.APPLICATION_JSONjavax.ws.rs.core.MediaType.APPLICATION_XML

于 2013-03-12T09:33:51.283 回答