4

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またはhttpcoreWARまたははありません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());

  }
}
4

4 に答える 4

10

アプリケーションをJBossにデプロイする際のリンケージエラーを回避するorg.apache.httpcomponentsには、JBossインストールのmodulesフォルダー内にモジュールを設定しますが、HttpComponentsからのJARをアプリケーションに含めないようにします。

  1. HttpComponentsから必要なJARをに配置しmodules/org/apache/httpcomponents/mainます。
  2. これらのJARをmodule.xmlこのディレクトリ内にリストします。
  3. コンポーネントのに追加Dependencies: org.apache.httpcomponentsMANIFEST.MFます。

手順1と2で参照したモジュールはすでに存在していることに注意してください。httpclient-cache-x.y.z.jarただし、追加のJARS(例)または異なるバージョンを含めることもできます。

もちろん、開発環境内でクラスを解決することも別の問題です。

于 2012-05-29T14:10:44.903 に答える
7

私は同様の状況で同じ問題を抱えていました。必要な HttpComponents モジュールは、すでに JBoss (AS 7.1.1) モジュール ディレクトリにありました。したがって、問題を解決するために私がしなければならなかったのは、Eustachius で説明されているようにマニフェスト エントリを追加することだけでした。これは、Maven では次のように行うことができます。

<build>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Dependencies>org.apache.httpcomponents</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

設定は maven-war-plugin と同じです。

于 2012-08-02T01:24:33.620 に答える
2

Arquillian テストでモジュールが必要な場合...

次のように src/test/resources に arquillian-manifest.mf を作成します。

Manifest-Version: 1.0
Dependencies: org.jboss.resteasy.resteasy-jaxrs,org.apache.httpcomponents

次に、ShrinkWrap の場合:

WebArchive war = ShrinkWrap.create...
    .addAsManifestResource("arquillian-manifest.mf", "MANIFEST.MF")
于 2012-10-01T14:42:54.853 に答える
0

But Add Dependencies: org.apache.httpcomponents to the MANIFEST.MF of your component.

causing an exception - Caused by: java.lang.IllegalStateException: JBAS014744: No META-INF/services/org.jboss.as.controller.Extension found for org.apache.httpcomponents:main at org.jboss.as.controller.parsing.ExtensionXml.loadModule(ExtensionXml.java:191) [jboss-as-controller-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]

于 2014-10-31T02:09:49.077 に答える