2012-07-08 55 views
0

無法找到別處的建議。Restlet - 連接問題 - 406不可接受 - 純文本

我正在爲Jersey(!)Restful Service編寫Restlet JSE客戶端。我已經爲此寫了一個澤西客戶,它正在工作,所以球衣服務沒問題。現在,我得到的問題,在編寫的Restlet客戶端:

我的服務根本ADRESS是:

http://localhost:8080/com-project-core/rest, so I call: 

ClientResource = service = new ClientResource("http://localhost:8080/com-project-core/rest"); 

我的基本認證Credentiels admin和XXX的,所以我呼籲:

service.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "admin", "xxx"); 

現在的問題:

ClientResource service = new ClientResource("http://localhost:8080/com-project-core/rest/ping"); 

調用我的服務。從那以後,我儘量

String myString = service.get(String.class); 
System.out.println(myString); 

我得到一個:在我的輸出

08.07.2012 17:41:48 org.restlet.engine.http.connector.HttpClientHelper start 
INFO: Starting the default HTTP client 

。不多! Junit測試說:

Not Acceptable (406) - Not Acceptable 

因此,他可以找到資源,但不能產生@Produces(「text/plain」)?

所以,當我在服務器端刪除@Produces(「text/plain」)它的工作原理!

對於resourcey我的服務器端是這樣的:

@Path("/ping") 
    @RolesAllowed({"admin", "user"}) 
    public class ConnectedResourceBean implements ConnectedResourceIF { 

     @GET 
     @Produces("text/plain") 
     public String getPingMessage() throws NamingException {    

     return "Hello World"; 
     } 
} 

爲我設定的這個POM的依賴關係:

<dependency> 
    <groupId>org.restlet.jse</groupId> 
    <artifactId>org.restlet</artifactId> 
    <version>${restlet.version}</version> 
</dependency> 

<dependency> 
    <groupId>org.restlet.jse</groupId> 
    <artifactId>org.restlet.ext.xstream</artifactId> 
    <version>${restlet.version}</version> 
</dependency> 

正如我所說的,它與我的球衣客戶合作。

+0

那你試試用myString的做工作?如果你不打印它,你不會看到它... – Jari 2012-07-08 15:59:15

+0

我做到了:System.out.println(myString); – 2012-07-08 15:59:59

+0

您是否看到請求進入服務器端? – Jari 2012-07-08 16:01:08

回答

1

沒辦法:的Restlet有問題與球衣服務器端

@Produces("text/plain") 

。有人能解釋我這個事實嗎?

編輯:

製造它

<properties> 
    <restlet.version>2.1-M3</restlet.version> 
</properties> 
+0

唯一我能想到的是有人忘記發送一個'Accept:'標題。 – 2012-07-09 08:06:31

+0

如何設置?沒有任何關於它的restlet文檔... – 2012-07-09 08:12:53

+0

不知道。我從未聽說過Jersey或Restlet。我所知道的是,406錯誤意味着傳入的「Accept:」標頭不包含傳出的「Content-Type」的值。 – 2012-07-09 08:15:33