`
jaesonchen
  • 浏览: 299375 次
  • 来自: ...
社区版块
存档分类
最新评论

Spring Jax-Ws. Build and consume Web Services – part 2

 
阅读更多

Spring Jax-Ws. Build and consume Web Services – part 2

In the previous article we’ve seen how build a Jax Web Services with spring. Now it’s time to see how consume it always with spring.

Obviously we can consume every types of web services with this technology, not only the spring web services.

 

Starting from WSDL definition you can use wsimport tool for generating the code:

wsimport -s c:\src http://localhost:8081/OrderServiceEndpoint?WSDL "-target 2.0
parsing WSDL...
Generating code...
Compiling code...

For my purpose, I need only two files: OrderServiceEndpoint.java (rename in OrderService.java) and Order.java.

The first file contains the service interface mapped with Jax annotations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package it.springjaxws;
 
import javax.jws.WebParam;
import javax.jws.WebService;
 
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
 
/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 *
 */
@WebService(name = "OrderServiceEndpoint", targetNamespace = "http://springjaxws.it/")
public interface OrderService {
 
    /**
     *
     * @param order
     * @throws Exception_Exception
     */
    @WebMethod(operationName = "Check")
    @RequestWrapper(localName = "Check", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.Check")
    @ResponseWrapper(localName = "CheckResponse", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.CheckResponse")
    public void check(
        @WebParam(name = "order", targetNamespace = "")
        Order order)
        throws Exception
    ;
 
    /**
     *
     * @param order
     * @return
     *     returns it.springjaxws.Order
     */
    @WebMethod(operationName = "Process")
    @WebResult(targetNamespace = "")
    @RequestWrapper(localName = "Process", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.Process")
    @ResponseWrapper(localName = "ProcessResponse", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.ProcessResponse")
    public Order process(
        @WebParam(name = "order", targetNamespace = "")
        Order order);
 
    /**
     *
     * @param order
     * @return
     *     returns it.springjaxws.Order
     */
    @WebMethod(operationName = "Shipping")
    @WebResult(targetNamespace = "")
    @RequestWrapper(localName = "Shipping", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.Shipping")
    @ResponseWrapper(localName = "ShippingResponse", targetNamespace = "http://springjaxws.it/", className = "it.springjaxws.ShippingResponse")
    public Order shipping(
        @WebParam(name = "order", targetNamespace = "")
        Order order);
 
}

The order file class is the same used in server part.

The spring configuration file contains the binding with the Web Service.

1
2
3
4
5
6
7
8
9
<bean id="orderWebService"
    class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="serviceInterface" value="it.springjaxws.OrderService" />
    <property name="wsdlDocumentUrl"
    <property name="namespaceUri" value="http://springjaxws.it/" />
    <property name="serviceName" value="OrderService" />
    <property name="portName" value="OrderServiceEndpointPort" />
</bean>

I used Spring Mvc to call the Web Services. This is the controller class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package it.consumespringjaxws.controller;
 
import it.springjaxws.Order;
 
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
 
@Controller
public class OrderController {
  
 @Autowired
 private it.springjaxws.OrderService orderClient;
  
 Logger log = Logger.getLogger(this.getClass());
  
 @RequestMapping(value="/order")
 public String getOrder(ModelMap model) {
 
  Order order = new Order();
  order.setOrderId("CK-1244");
  order.setItemNumber(5);
   
  try {
   orderClient.check(order);
  } catch (Exception e) {
   log.error(e);
  }
  log.info("******************************************");
  order = orderClient.process(order);
  log.info("******************************************");
  order = orderClient.shipping(order);
   
  model.addAttribute("detail", order);
  return "order";
 
 }
}

The result is in the below screenshot.

Summary

I think that spring is a good implementation of Jax-Ws reference. Personally, this is my prefer approach for building and consuming web services. That’s because you need a very few configuration options and you can expose all Java class file as service.

分享到:
评论

相关推荐

    JAX-WS 2.2 完整jar包

    FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar ...stax2-api-source.jar streambuffer.jar woodstox-core-asl.jar woodstox-core-asl-source.jar

    JAX-WS 2.2 RI所有相关jar包

    JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...

    jax-ws webservice demo

    基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...

    jax-ws-2.2.rar

    tools.jar/jaxws-tools.javadoc.jar/jsr181-api.jar/management-api.jar/mimepull.jar/policy.jar/saaj-api.jar/saaj-impl.jar/stax2-api.jar/stax2-api-source.jar/stax-ex.jar/streambuffer.jar/woodstox-core-asl...

    jaxb-api.jar.jaxws-api.zip_ jaxb-api.jar_cxf_jax-ws.jar_jaxb-api

    cxf框架与jdk6出现冲突的支持包,请大家支持下!

    jax-0.4.13.tar.gz

    该资源为jax-0.4.13.tar.gz,欢迎下载使用哦!

    用MyEclipse创建jax-ws.doc

    用MyEclipse创建jax-ws.doc

    javax.ws.rs-api-2.0.1.jar

    javax.ws.rs-api-2.0.1.jar JAX-RS 2.0.1 类库

    jax-ws2.1.zip

    webservices-api.jar webservices-extra.jar webservices-extra-api.jar webservices-rt.jar

    JAX-WS 2.2 RI 所包含的JAR包集合

    JAX-WS 2.2 RI 所包含的JAR包集合,包含21个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api.jar jaxws-rt.jar ...

    Jax-ws Weblogic12c metro-default.xml not fund

    使用weblogic12c发布jax-ws的webservice服务端,启动时报错“metro-default.xml not fund ”百度了很长时间,方案都不能解决问题,后来goole了一下,参考了一个网页,非常管用,考虑到google有些同学没法访问,特地...

    JAX-WS自学笔记

    JAX-WS自学笔记 本人自学JAX-WS笔记和简单例子,文档标题结构如下: JAX-WS使用教程 1、JAX-WS概述 2、创建Web Service 2.1 从java开始 2.1.1 运行wsgen 2.1.2 生成的WSDL和XSD 2.1.3 目录结构 2.2 从WSDL...

    cxf(jax-ws)+spring+hibernate整合包

    spring-expression-3.0.7.RELEASE.jar,spring-hibernate3.jar,spring-jms-3.0.7.RELEASE.jar,spring-tx-3.0.7.RELEASE.jar,spring-web-3.0.7.RELEASE.jar,sqljdbc4.jar,stax2-api-3.1.1.jar,velocity-1.7.jar,WHICH_...

    使用JAX-WS(JWS)发布WebService

    使用JAX-WS(JWS)发布WebService 使用myeclipse开发java的webservice的两种方式 方式一: (此方式只能作为调试,有以下bug:jdk1.6u17?以下编译器不支持以Endpoint.publish方式发布document方式的soap,必须在...

    jackson-databind-2.9.10.8.jar升级相关jar包

    jackson-databind-2.9.10.8.jar升级相关...jackson-jaxrs-json-provider-2.9.10.jar jackson-jaxrs-base-2.9.10.jar 下载地址 https://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.9.10.8/

    基于JAX-WS2.2开发WebService所需jar资源包

    使用 Eclipse JavaEE 开发 WebService 时,若选择手动创建原生的JAX-WS服务,需要导入此jar资源(教程详见我的博文https://blog.csdn.net/weixin_50604409/article/details/116399530)。 如果您同时装有 IntelliJ ...

    metro-jax-ws-master

    The Java API for XML Web Services (JAX-WS) is a Java programming language API for creating web services, particularly SOAP services. JAX-WS is one of the Java XML programming APIs. It's a part of the ...

    JAX-WS所需Jar包

    JAX-WS基于WEB应用服务器发布WebService所需全部Jar包,需要的可以在这里下载

Global site tag (gtag.js) - Google Analytics