Once XFire is in your build’s classpath, creating a web service is as simple as following these three steps:
1. Configure an XFireExporter bean to export a Spring bean as a web service.
2. Configure a Spring DispatcherServlet to handle incoming HTTP requests.
3. Configure a handler mapping so as to map DispatcherServlet-handled requests to XFireExporter-exported services.
(1)、定义Interface和Implement
public interface GreetService {
String sayHello(String name);
}
import org.springframework.stereotype.Repository;
@Repository("greetService")
public class GreetServiceImpl implements GreetService{
public String sayHello(String name) {
return "welcome to you, "+name;
}
}
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService
public interface HelloService {
@WebMethod(operationName="hello")
@WebResult(name="helloWords")
String sayHello(String name);
}
import javax.jws.WebService;
import org.springframework.stereotype.Repository;
@WebService(serviceName="helloService",
endpointInterface="com.logcd.jws.HelloService")
@Repository("helloService")
public class HelloServiceImpl implements HelloService{
public String sayHello(String name) {
return "hello, " + name;
}
}
(2)、web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:jwsContext.xml,
classpath:xfire-servlet.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 -->
org.codehaus.xfire.spring.XFireSpringServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>xfire</servlet-name>
<url-pattern>/jws/*</url-pattern>
</servlet-mapping>
(3)、jwsContext.xml
<context:component-scan base-package="com.logcd.jws"/>
<!-- import the XFire-defined Spring context
where xfire.serviceFactory and xfire are already declared in -->
<import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
<!-- Configuring XFireExporter -->
<bean id="greetService.xfire"
class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceFactory"
ref="xfire.serviceFactory" />
<property name="xfire" ref="xfire" />
<property name="serviceBean"
ref="greetService" />
<property name="serviceClass"
value="com.logcd.jws.GreetService" />
</bean>
<!-- declaring web services with JSR-181 annotations -->
<bean id="webAnnotations"
class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations"/>
<bean id="annotationHandlerMapping"
class="org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping">
<property name="typeMappingRegistry">
<ref bean="xfire.typeMappingRegistry"/>
</property>
<property name="xfire" ref="xfire" />
<property name="webAnnotations">
<ref bean="webAnnotations"/>
</property>
</bean>
(4)、xfire-servlet.xml(注意命名与web.xml中对应)
<!-- Mapping requests to XFireExporter -->
<bean id="handlerMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="greetService">greetService.xfire</prop>
<prop key="helloService">annotationHandlerMapping</prop>
</props>
</property>
<!--
<property name="urlMap">
<map>
<entry key="/">
<ref bean="annotationHandlerMapping"/>
</entry>
</map>
</property>
-->
</bean>
(5)、Consuming web services
import java.net.MalformedURLException;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
public class ConsumeService {
public static void accessJwsUseXFireAPI() throws MalformedURLException{
Service serviceModel = new ObjectServiceFactory()
.create(GreetService.class);
GreetService greetService =
(GreetService) new XFireProxyFactory().create(
serviceModel,
"http://127.0.0.1/spring_ws/jws/GreetService");
System.out.println(greetService.sayHello("bela"));
}
public static void accessJwsUseXFireAPI2() throws MalformedURLException{
Service serviceModel = new AnnotationServiceFactory()
.create(HelloService.class);
HelloService helloService =
(HelloService) new XFireProxyFactory().create(
serviceModel,
"http://127.0.0.1/spring_ws/jws/helloService");
System.out.println(helloService.sayHello("bela"));
}
public static void main(String[] args) throws Exception {
accessJwsUseXFireAPI();
accessJwsUseXFireAPI2();
}
}
分享到:
相关推荐
### 使用WebDynpro二进制缓存将上下文数据导出到Excel的知识点解析 #### 一、引言 在企业级应用开发中,数据处理与报表生成是常见且重要的需求之一。SAP WebDynpro作为一种高效的企业级应用开发框架,提供了丰富的...
Import data from local sources and external web services as well as exporting your data to third parties Implement a multilingual search with Haystack Test and deploy your project efficiently
标题中的“Importing and Exporting Repositories Using Repimexp”是指使用Repimexp工具进行仓库导入与导出的操作。在IT行业中,特别是软件开发和版本控制领域,仓库(Repository)通常指的是存储代码、文档等资源...
Exporting the operator repeat_interleave to ONNX opset version 11 is not supported TypeError: 'torch._C.Value' object is not iterable (Occurred when translating repeat_interleave). 问题解决: 1....
15.4.1. Exposing beans as HTTP services 15.4.2. Accessing services via HTTP 15.5. Publishing and consuming web services 15.5.1. Creating Spring-enabled JAX-WS endpoints 15.5.2. Proxying JAX-WS ...
highchars图表用到的基础js,还有其他js需要用到的会一同上传
标题“EXP-00091 Exporting questionable statistics”似乎是指在数据库管理或者数据导出过程中遇到的一个特定问题,可能是关于Oracle数据库中的一个错误代码或警告。这个问题涉及到数据的统计信息,这在数据库管理...
3. **获取WSDL链接**:WSDL(Web Services Description Language)文件描述了Web服务的接口规范,包括操作、消息格式、绑定和地址信息等。通常,这些信息由Web服务提供商提供。 #### 三、详细步骤 下面将详细介绍...
Highcharts是一款广泛应用于Web开发中的JavaScript图表库,它允许开发者创建出交互性强、美观的静态和动态图表。这里我们关注的三个JavaScript文件——`highcharts.js`、`draggable-legend.js`和`exporting.js`,都...
从给定文件内容中提取的知识点涵盖了如何使用Storyboard Designer将Storyboard项目导出为Android应用程序的过程,以及如何安装Subclipse客户端以连接到Crank软件的公共代码仓库。以下是详细的知识点: ...
The final section of the course is a practical 4-part lesson, teaching how to implement a fully animated HTML5 Canvas project using WebAssembly as the main processor. Upon completion of this course ...
参数 参数解释 svg SVG 字符串,当指定了 options 参数是该参数将会被忽略 options 图表配置 type 导出文件的类型,可以是 'image/png'、'image/jpeg'、'application/pdf' 或 'image/svg+xml' 中的一个 ...
Excel Importing & Exporting Text Data ---Quickly Turn Raw Data Into Excel Tables, By Scott Hartshorn, epub格式版。
### Webdynpro上载PDF文件 #### 知识点概览 本文将详细介绍如何通过Webdynpro组件在SAP系统中实现PDF文件的上传功能。主要内容包括:创建Webdynpro组件、定义属性、插入文件上传元素、绑定数据属性以及编写上传方法...