スタンドアロン Java アプリケーションから cxf webservices メソッドを呼び出す問題に直面しており、pojo クラス オブジェクト パラメータをそのメソッドに渡したいと考えています。
2 に答える
Apache CXF は、いくつかのクライアント実装を提供します。そのうちの 1 つを使用できます。または、RESTful な JSON ベースのサービスの場合は、多くの既存のクライアントのいずれかを使用するか、GSON や Apache HttpComponents などを使用して独自のクライアントを作成することもできます。SOAP の場合は、さらに複雑になります。
わかりました。最後に、問題を解決します。次の手順を使用して、cxf Web サービス用のスタンドアロン Java クライアントを作成しました。
ステップ1:
Webサービスに存在する同じ名前のJavaプロジェクトとpojoクラスを作成します(呼び出し元のWebサービスメソッドに渡すオブジェクト).Ex
public class Client{
private String name;
// getter and setter
}
ステップ 2: 同じ名前のサービス エンドポイント インターフェイスを作成する()
import javax.jws.WebService;
@WebService
public interface CheckWebservice {
public boolean isWebservice(Client client);
}
ステップ 3: ここで、Spring ApplicationContext を使用して webservice メソッドを呼び出すので、application-beans.xml ファイルを作成し、プロジェクト ディレクトリ (プロジェクトの任意のフォルダー) に配置します。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="decisionBean" serviceClass="com.cxf.client.CheckWebservice"
address="http://localhost:8080/CXF-WEBSERVICES/services/CheckDecisionImplPort" />
ステップ 4: 以下のコードを使用して、サーバーで実行されている Web サービスを呼び出します。
try{
ApplicationContext context = new ClassPathXmlApplicationContext("demo/xml/application-beans.xml");
CheckWebservice checkDecision = (CheckWebservice ) context.getBean("decisionBean");
// Populate the Order bean
Client decision = new Client();
decision.setDecision("Decision test");
boolean checkDcn = checkDecision.isWebservice(decision);
System.out.println("Decision recived : "+checkDcn);
}catch(Exception e){
e.printStackTrace();
}
注: apache-cxf-2.7.7 ライブラリにあるライブラリを使用してください。