2016-12-12 15 views
0

CXF JAX-RSクライアントを使用してパーティーにPUTリクエストを実行します。リクエストの本文は空です。 単純な要求の呼び出しは、私たちの党のRESTサーバーを設定するのContent-Length HTTPヘッダーを必要とするコード411CXF JAX-RSクライアントは常にAllowChunking設定のチャンクモードで空のPUTリクエストを送信します

Response-Code: 411 
"Content-Length is missing" 

とサーバの応答につながります。

note about chunkingに従ってチャンクをオフにしましたが、これで問題は解決しませんでした。 RESTサーバーは411エラーでも応答します。ログ内のcxf.xmlファイルから

ここに私たちのコンジットの設定がある

<http-conf:conduit name="{http://myhost.com/ChangePassword}WebClient.http-conduit"> 
     <http-conf:client AllowChunking="false"/> 
    </http-conf:conduit> 

ラインは、私たちのコンジットの設定にバインドされた私たちの要求の実行を確認:

明示的にContent-Lengthヘッダを追加
DEBUG o.a.cxf.transport.http.HTTPConduit - Conduit '{http://myhost.com/ChangePassword}WebClient.http-conduit' has been configured for plain http. 

また助けになりませんでした。

Invocation.Builder builder = ... 
    builder = builder.header(HttpHeaders.CONTENT_LENGTH, 0); 

A CXFクライアントのログエントリは、ヘッダーの設定を確認し、我々はパケットを傍受するとき、しかし、我々は驚くべきことに、ヘッダの設定が完全​​にCXFクライアントによって無視されてきた発見しました。 Content-Lengthヘッダーは送信されませんでした。

ここにログがあります。 Content-Lengthヘッダーがあります。

INFO o.a.c.i.LoggingOutInterceptor - Outbound Message 
--------------------------- 
ID: 1 
Address: http://myhost.com/ChangePassword?username=abc%40gmail.com&oldPassword=qwerty123&newPassword=321ytrewq 
Http-Method: PUT 
Content-Type: application/x-www-form-urlencoded 
Headers: {Accept=[application/json], client_id=[abcdefg1234567890abcdefg12345678], Content-Length=[0], Content-Type=[application/x-www-form-urlencoded], Cache-Control=[no-cache], Connection=[Keep-Alive]} 
-------------------------------------- 
DEBUG o.apache.cxf.transport.http.Headers - Accept: application/json 
DEBUG o.apache.cxf.transport.http.Headers - client_id: abcdefg1234567890abcdefg12345678 
DEBUG o.apache.cxf.transport.http.Headers - Content-Length: 0 
DEBUG o.apache.cxf.transport.http.Headers - Content-Type: application/x-www-form-urlencoded 
DEBUG o.apache.cxf.transport.http.Headers - Cache-Control: no-cache 
DEBUG o.apache.cxf.transport.http.Headers - Connection: Keep-Alive 

ここにパケットスニッファの出力があります。コンテンツ長ヘッダーが存在しません:

PUT http://myhost.com/ChangePassword?username=abc%40gmail.com&oldPassword=qwerty123&newPassword=321ytrewq HTTP/1.1 
Content-Type: application/x-www-form-urlencoded 
Accept: application/json 
client_id: abcdefg1234567890abcdefg12345678 
Cache-Control: no-cache 
User-Agent: Apache-CXF/3.1.8 
Pragma: no-cache 
Host: myhost.com 
Proxy-Connection: keep-alive 

実際にチャンクを無効にする方法は誰にも分かりますか?ここで

は、私たちのコードです:

public static void main(String[] args) 
    { 
     String clientId = "abcdefg1234567890abcdefg12345678"; 
     String uri  = "http://myhost.com"; 
     String user  = "[email protected]"; 

     Client client = ClientBuilder.newBuilder().newClient(); 
     WebTarget target = client.target(uri); 
     target = target.path("ChangePassword").queryParam("username", user).queryParam("oldPassword", "qwerty123").queryParam("newPassword", "321ytrewq"); 
     Invocation.Builder builder = target.request("application/json").header("client_id", clientId).header(HttpHeaders.CONTENT_LENGTH, 0); 
     Response response = builder.put(Entity.form(new Form())); 
     String body = response.readEntity(String.class); 
     System.out.println(body); 
    } 

バージョン:

  • OS:Windows 7のエンタープライズSP1
  • アーチ:x86_64版
  • のJava:1.7.0_80
  • CXF:3.1 .8

答えて

0

チャンクを無効にしようとしたときと同じように、私が解決できなかった問題は非常に似ていました。

私がやったことは、Content-Lengthを1に設定し、体として空白を追加することでした。私にとっては、サーバーアプリケーションの前のプロキシサーバーが要求を拒否され、それによってプロキシサーバーを越えてしまい、サーバーはURLに基​​づいて動作していただけで要求を処理できたように見えました。

関連する問題