JBoss-7.1.1-Finalの Bean で RestEasy クライアント フレームワークを使用し@Named @ViewScoped
て、カスタムで REST サービスからデータを取得していますHttpRequestInterceptor
。
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor("test","test"), 0);
ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient); //<---
//The error occurs above, the code below is only for completeness
MyRest rest = ProxyFactory.create(MyRest.class,
"http://localhost:8080/rest",clientExecutor);
これは、スタンドアロンのクライアント アプリケーションで問題なく動作します ( を削除しても問題ClientExecutor
ありませんが、REST サービスを認証するために必要です)。Bean は 内のWAR
モジュールにありEAR
、resteasy の依存関係階層は次のように解決されます。
httpclient
またはhttpcore
にWAR
またははありませんEAR
。Bean 内で次の例外が発生します。
java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor
簡単なようですが(resteasyパッケージングについて疑問に思っていますが)、コンパイルスコープを追加org.apache.httpcomponents:httpclient
しました:
いいえ、私は彼に次の例外を取得しています:
java.lang.LinkageError: loader constraint violation: when resolving method
"org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor.<init>
(Lorg/apache/http/client/HttpClient;)V"
the class loader (instance of org/jboss/modules/ModuleClassLoader)
of the current class, my/TestBean, and
the class loader (instance of org/jboss/modules/ModuleClassLoader)
for resolved class,
org/jboss/resteasy/client/core/executors/ApacheHttpClient4Executor,
have different Class objects for the type org/apache/http/client/HttpClient
used in the signature my.TestBean.init(TestBean.java:65)
更新これを再現するには、REST インターフェイスは必要ありません。インスタンス化中にエラーが発生しますApacheHttpClient4Executor
が、カスタムが必要になる場合がありますPreemptiveAuthInterceptor
。
public class PreemptiveAuthInterceptor implements HttpRequestInterceptor
{
private String username;
private String password;
public PreemptiveAuthInterceptor(String username, String password)
{
this.username=username;
this.password=password;
}
@Override
public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException
{
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
authState.setAuthScope(org.apache.http.auth.AuthScope.ANY);
authState.setCredentials(new UsernamePasswordCredentials(username,password));
authState.setAuthScheme(new BasicScheme());
}
}