spring+XFire構築webservicクライアントは、サービスアドレスからクライアントを作成して呼び出します。
example-client.xmlプロファイル
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="baseService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean" lazy-init="false" abstract="true"/>
<bean id="echoService" parent="baseService">
<property name="serviceClass">
<value>com.hyw.example.Echo</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/MyWebService/EchoService?wsdl</value>
</property>
</bean>
<bean id="userService" parent="baseService">
<property name="serviceClass">
<value>com.hyw.example.UserService</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/MyWebService/UserService?wsdl</value>
</property>
</bean>
</beans>
WebServiceCient Test.javaファイル
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hyw.example.Echo;
public class WebServiceClientTest {
/**
* @param args
*/
public static void main(String[] args) {
WebServiceClientTest test = new WebServiceClientTest();
test.client();
}
public void client() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("example-client.xml");
Echo echoService = (Echo) ctx.getBean("echoService");
System.out.println(echoService.echo(" "));
}
}
UserWebServiceCient.javaファイル
package test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hyw.example.User;
import com.hyw.example.UserService;
public class UserWebServiceClient {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
UserWebServiceClient test = new UserWebServiceClient();
test.client();
}
public void client() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("example-client.xml");
UserService userService = (UserService)ctx.getBean("userService");
System.out.println("================== getUser() ==================");
User user = userService.getUser(" 1");
System.out.println(user);
}
}