- 浏览: 772504 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (208)
- Java (77)
- JavaScript (16)
- UML (1)
- Spring (24)
- Hibernate (11)
- J2EE部署 (18)
- 操作系统 (13)
- struts (11)
- jsp (3)
- J2EE (34)
- 数据库 (22)
- tomcat (4)
- apache (2)
- MyEclipse (13)
- Linux (14)
- Ext (6)
- Weblogic (2)
- 数据库 Oracle 空表导出 (1)
- Oracle (3)
- 编码 乱码 (1)
- 多线程 (5)
- jQuery (2)
- Apache Mina (1)
- ibatis (6)
- abator (1)
- svn (1)
- jvm (1)
- ERwin (2)
- mysql (2)
- ant (1)
- memcache (1)
- dubbo (1)
- PowerDesigner (1)
最新评论
-
di1984HIT:
Shallow heap & Retained heap -
tinguo002:
非常感谢 , 太棒了。
Spring注解方式,异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法 -
白天看黑夜:
Apache Mina Server 2.0 中文参考手册(带 ...
Apache Mina – 简单的客户端/服务端应用示例 -
wumingxingzhe:
好文
Shallow heap & Retained heap -
di1984HIT:
学习了!!
工作流(Workflow)和BPM的不同
转自: http://www.celinio.net/techblog/?p=637
This is a short follow-up to a previous post about Web Services with CXF.
Developing RESTful web services with CXF is quite easy. Here I quickly explore 2 ways to do it.
1) HTTP Binding :
One way to do it is to use HTTP Binding as described here : https://cwiki.apache.org/CXF20DOC/http-binding.html
The spring bean xml configuration file is modified to add the bindingUri parameter and also the JaxWsServiceFactoryBean factory :
cxf.xml :
Then add to the interface the annotations from the Java Rest Annotations codehaus project :
IBMICalculator.java:
In the JBoss console, we can observe that the mapping is done :
However, as stated in CXF web site, the “binding has been deprecated and is likely to be removed from CXF in one of its future releases.” So it’s best to use a different way before it’s too late !
2) JAX-RS
An alternative way is to use the implementation of the JAX-RS api provided by CXF. So all you need to do is annotate the class with the JAX-RS annotations and modify the spring configuration file (called cxf.xml in the example of my previous post).
cxf.xml :
And annotate the class that implements the interface :
IBMICalculatorImpl.java :
IBMICalculatorImpl computeBMI(weight, height) is mapped to an HTTP GET request on /computeBMI/{weight}/{height}. This request contains 2 parameters : weight and height.
The data format, definied with the annotation @Produces, is plain text but it could be XML, JSON…
So we see that very little is needed to transform the IBMICalculator service to make it available in the form of an HTTP GET method at the following URL : http://localhost:8085/BMI/services/computeBMI/75/170 . The result is displayed in plain text :
This is a short follow-up to a previous post about Web Services with CXF.
Developing RESTful web services with CXF is quite easy. Here I quickly explore 2 ways to do it.
1) HTTP Binding :
One way to do it is to use HTTP Binding as described here : https://cwiki.apache.org/CXF20DOC/http-binding.html
The spring bean xml configuration file is modified to add the bindingUri parameter and also the JaxWsServiceFactoryBean factory :
cxf.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 "> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-http-binding.xml"/> <jaxws:endpoint id="calcBMI" implementor="com.company.bmi.services.IBMICalculatorImpl" address="/cxfBmi" bindingUri="http://apache.org/cxf/binding/http"> <jaxws:serviceFactory> <bean> <property name="wrapped" value="true" /> </bean> </jaxws:serviceFactory> </jaxws:endpoint> </beans>
Then add to the interface the annotations from the Java Rest Annotations codehaus project :
IBMICalculator.java:
package com.company.bmi.services; import javax.jws.WebParam; import javax.jws.WebService; import org.codehaus.jra.Get; import org.codehaus.jra.HttpResource; @WebService public interface IBMICalculator { @Get @HttpResource(location = "/computeBMI/{weight}/{height}") public double computeBMI(@WebParam(name="weight") double weight, @WebParam(name="height") double height) ; }
In the JBoss console, we can observe that the mapping is done :
20:21:59,250 INFO [ReflectionServiceFactoryBean] Creating Service {http://services.bmi.company.com/}IBMICalculatorImplService from class com.company.bmi.services.IBMICalculator 20:21:59,469 INFO [JRAStrategy] Mapping method computeBMI to resource /computeBMI/{weight}/{height} and verb GET 20:21:59,512 INFO [ServerImpl] Setting the server's publish address to be /cxfBmi 20:21:59,528 INFO [ContextLoader] Root WebApplicationContext: initialization completed in 710 ms
However, as stated in CXF web site, the “binding has been deprecated and is likely to be removed from CXF in one of its future releases.” So it’s best to use a different way before it’s too late !
2) JAX-RS
An alternative way is to use the implementation of the JAX-RS api provided by CXF. So all you need to do is annotate the class with the JAX-RS annotations and modify the spring configuration file (called cxf.xml in the example of my previous post).
cxf.xml :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 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/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> <jaxws:endpoint id="calcBMI" implementor="com.company.bmi.services.IBMICalculatorImpl" address="/cxfBmi" /> <jaxrs:server id="bmiservice" address="/"> <jaxrs:serviceBeans> <ref bean="IBMICalculatorImpl"/> </jaxrs:serviceBeans> </jaxrs:server> <bean id="IBMICalculatorImpl"/> </beans>
And annotate the class that implements the interface :
IBMICalculatorImpl.java :
package com.company.bmi.services; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @Produces("text/plain") public class IBMICalculatorImpl implements IBMICalculator{ //@Override @GET @Path("/computeBMI/{weight}/{height}") public double computeBMI(@PathParam("weight") double weight, @PathParam("height") double height) { return weight / (height * height); } }
IBMICalculatorImpl computeBMI(weight, height) is mapped to an HTTP GET request on /computeBMI/{weight}/{height}. This request contains 2 parameters : weight and height.
The data format, definied with the annotation @Produces, is plain text but it could be XML, JSON…
So we see that very little is needed to transform the IBMICalculator service to make it available in the form of an HTTP GET method at the following URL : http://localhost:8085/BMI/services/computeBMI/75/170 . The result is displayed in plain text :
发表评论
-
什么是两阶段提交协议
2012-05-08 16:58 1065两阶段提交协议 实现分布式事务的关键就是两阶段提交协议。在此 ... -
使用Eclipse远程调试Tomcat
2012-03-23 22:56 1510有些时候,调试不得不用外网,比如说做支付宝的支付接口,服务器后 ... -
Java compiler level does not match the version of the installed Java project fac
2012-03-02 11:32 1318问题现象:项目图标报错“Java compiler level ... -
WebService的事务处理
2012-03-01 15:03 1560如果你只是要解决两个系统之间的事务同步问题,可以采用判断服务是 ... -
线程池(java.util.concurrent.ThreadPoolExecutor)的使用
2012-02-29 15:50 2508一、简介 线程池类为 j ... -
Quartz表达式解析
2012-02-08 14:40 807字段 允许值 允许的特 ... -
newCachedThreadPool线程池
2011-11-20 11:35 43035public static ExecutorService n ... -
Apache Mina – 简单的客户端/服务端应用示例
2011-11-19 23:49 5528转自http://javasight.net/2011/05/ ... -
Class.forName()、Class.forName().newInstance() 、New 三者区别!
2011-11-15 09:18 1263终于明白为什么加载数据库驱动只用Class.forName() ... -
Apache MINA 快速入门指南
2011-11-13 12:04 1660最近用到Socket套接字编程,在服务器监听方面还没有具体思路 ... -
apache mina (异步连接框架)实例
2011-11-13 11:53 2068一、介绍 mina(Multipurpose Infrastr ... -
多线程的队列----BlockingQueue
2011-11-11 17:06 985import java.util.concurrent.Arr ... -
Java多线程之Callable接口的实现
2011-11-11 11:39 937import java.util.concurrent.Cal ... -
FutureTask的使用方法和使用实例
2011-11-11 11:23 1242FutureTask是一种可以取消的异步的计算任务。它的计算是 ... -
使用Eclipse(MyEclipse)+ abator自动生成iBatis代码
2011-11-03 00:39 1158一.安装插件Abator Abator for Eclipse ... -
Spring框架下获取Bean的几种方式
2011-11-03 00:06 4088通过xml配置文件 bean配置在xml里面,spri ... -
使用JAX-WS standard Endpoint APIs开发WebService完整的例子
2011-09-29 15:16 2133编程发布WebService方式的完整例子 WS服务端: (1 ... -
Activiti 5.6:子流程(subProcess)
2011-09-22 15:26 12716Activiti 5.6提供了子流程的实现,包括两种基于子流程 ... -
工作流(Workflow)和BPM的不同
2011-09-21 15:31 13591、工作流(Workflow) 在模 ... -
Activiti 5.6:配置与Spring整合
2011-09-21 13:00 11432Activiti 5.6与Spring整合也比较简单,其基本 ...
相关推荐
WSDL(Web Services Description Language)是一种 XML 格式的文档,用于描述 Web 服务的接口和绑定。WSDL 包含三个主要部分: - **接口(Interface)**:定义了服务的抽象操作和消息。 - **绑定(Binding)**:指定...
### Java™ Web Services 教程知识点详解 #### 一、教程概述 《Java™ Web Services 教程》是一本指导开发者使用 Java Web Services Developer Pack(Java WSDP)开发 Web 应用程序的专业指南。该教程由 Sun ...
### Java Web Services 教程知识点解析 #### 一、Java Web Services 概述 Java Web Services 是一种构建可互操作的分布式应用系统的方法。通过利用Java技术,开发人员可以创建和部署符合工业标准且能够在互联网上...
Effectively deploy and integrate Go web services with applications in the real worldFamiliarize yourself with RESTful practices and apply them in GoA comprehensive tutorial with lots of tips and ...
在Java中,通常使用JAX-RS(Java API for RESTful Web Services)来实现REST服务。 6. **JAX-RS**:JAX-RS提供了简单的注解,如`@Path`、`@GET`、`@POST`等,使得开发者可以在Java类和方法上声明RESTful资源的URI...
AWS Amazon Web Services Tutorial The Ultimate Beginners Guide 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Interoperable Python ZSI WSDL SOAP Web Services tutorial
AWS Amazon Web Services Tutorial The Ultimate Beginners Guide 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Chapter 13: Building RESTful Web Services with JAX-RS 219 What Are RESTful Web Services? 219 Creating a RESTful Root Resource Class 220 Example Applications for JAX-RS 235 Further Information ...
本文档主要探讨了如何在ASP.NET AJAX框架中利用Web服务(Web Services)实现跨平台的数据交换功能。通过介绍基本概念、配置方法以及具体实现细节,帮助读者更好地理解如何利用ASP.NET AJAX进行动态数据注入或从前端...
《SQL Server 2012 Analysis Services教程》是针对数据分析师和数据库管理员的一份详尽指南,旨在深入理解和掌握微软的商务智能工具——Analysis Services。SQL Server 2012版本引入了许多增强功能,使得数据处理、...
本书教您如何使用Ruby on Rails开发和部署真正的,具有工业实力的Web应用程序,Ruby on Rails是为诸如Twitter,Hulu,GitHub和Yellow Pages等顶级网站提供支持的开源Web框架。
通过学习《Java Web Services Tutorial》,我们可以了解到Java Web Services的基础概念、核心技术以及开发流程。这对于构建可靠的、可扩展的企业级应用具有重要意义。掌握这些知识将有助于开发者更好地利用Java技术...
3. **Restful 设计**:Rails 鼓励采用 RESTful 架构风格进行设计,这有助于创建符合 Web 标准且易于理解的应用程序接口(API)。 4. **测试驱动开发**:Rails 支持并鼓励使用测试驱动开发(Test-Driven Development,...
Java Web Services and XML