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();
}
}
分享到:
相关推荐
Exporting Context Data into Excel Using the WebDynpro Binary Cache.pdf
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
NULL 博文链接:https://fengyonghui.iteye.com/blog/643507
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需要用到的会一同上传
Exporting data using column format Using MaxL to extract the outline in XML format Using @XREF functions to move data between BSO cubes Partitioning data from BSO to ASO cubes Using MDX for extracting...
文档描述:Exporting a Storyboard Project as an Android Application Crank是一家致力于创新嵌入式图形用户界面解决方案的软件公司。Crank软件提供的产品和服务,使得UI设计者和开发设计团队能够在资源受限的...
NULL 博文链接:https://xujq.iteye.com/blog/1714222
Chapter 21: Web Applications and Web Services 459 REST: The Architecture of the Web 460 Characteristics of REST 460 A Distributed Network of Interlinked Documents 461 A Client-Server Architecture ...
Connectivity Services using PowerShell 105 Introduction 105 Importing a custom BCS model to SharePoint 106 Exporting SharePoint BCS model and schema 111 Creating instances of external lists with ...
Harness the power of TensorFlow by exporting saved models into web applications Create rich web dashboards to handle complex real-time user input with JavaScript and Ajax to yield interactive and ...
■For instructions about configuring naming information in a directory server, and exporting existing naming data to a directory server, read Chapter 8, "Configuring Naming Methods" in Part II ...
15 ■ Web applications and web services 477 vii contents foreword xiv preface xvii acknowledgments xix about this book xx about the authors xxv PART 1 INTRODUCING OSGI: MODULARITY, LIFECYCLE, AND ...
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格式版。
This book is well suited for data scientists and data analysts who want to perform interactive data visualization on their web browsers using Bokeh. Some exposure to Python programming will be helpful...
网上下载的 highcharts.js;draggable-legend.js;exporting.js,
Accordingly, you will repeatedly return to this book as both a valuable instructional tool and reference guide. What you’ll learn How to install and configure Apache, PHP 5.3, and MySQL ...