[xfire 1.2.6] try out xfire 1.2.6

1. server side:

(1) To demonstrate there's no issue with transferring objects, create a TestObj first:


package ws;

public class TestObj {

private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}


(2) Create service interface and implementation class

package ws;

public interface TestService {

TestObj sayHello(TestObj obj);
}



package ws;

public class TestServiceImpl implements TestService {

public TestObj sayHello(TestObj obj) {

obj.setName("hello" + obj.getName());
return obj;
}
}


(3) define a spring.xml under the WEB-INF folder

<?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="testBean" class="ws.TestServiceImpl"/>
</beans>


(4) define xfire-servlet.xml under the WEB-INF folder

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/TestService">
<ref bean="test" />
</entry>
</map>
</property>
</bean>

<bean id="test"
class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory" />
</property>
<property name="xfire">
<ref bean="xfire" />
</property>
<property name="serviceBean">
<ref bean="testBean" />
</property>
<property name="serviceClass">
<value>ws.TestService</value>
</property>
</bean>
</beans>


(5) define web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring.xml
classpath:/org/codehaus/xfire/spring/xfire.xml
</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>xfire</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>


(6) here's a list of libraries used

activation-1.1.jar
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jdom-1.0.jar
spring-1.2.6.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.0.jar
xbean-spring-2.8.jar
xfire-all-1.2.6.jar


2. client side

(1) Normal client:

package client;

import java.net.MalformedURLException;

import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import ws.TestObj;
import ws.TestService;

public class NormalClient {

public static void main(String[] args){

String serviceURL="http://localhost:8080/XFire_Server/TestService";
Service serviceModel = new ObjectServiceFactory().create(TestService.class,null,serviceURL,null);
XFireProxyFactory serviceFactory = new XFireProxyFactory();
TestService service = null;
try {

service = (TestService) serviceFactory.create(serviceModel, serviceURL);

TestObj obj = new TestObj();
obj.setName("example");
System.out.println(service.sayHello(obj).getName());

} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}


(2) Spring Client:
i. define spring.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="testWebService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
<property name="serviceClass">
<value>ws.TestService</value>
</property>
<property name="wsdlDocumentUrl">
<value>http://localhost:8080/XFire_Server/TestService?WSDL</value>
</property>
</bean>
</beans>


ii. how to revoke:

package client;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import ws.TestObj;
import ws.TestService;

public class SpringClient {

public static void main(String[] args){

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"client/spring.xml"});

TestService client = (TestService)context.getBean("testWebService");

TestObj obj = new TestObj();
obj.setName("example");
System.out.println(client.sayHello(obj).getName());
}
}


(3) list of libraries used:


activation-1.1.jar
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jdom-1.0.jar
spring-1.2.6.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.0.jar
xfire-all-1.2.6.jar
XmlSchema-1.1.jar
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章