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

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.

分享到:
评论

相关推荐

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

    它支持基于标准的服务实现,如JAX-WS(Java API for XML Web Services)和JAX-RS(Java API for RESTful Web Services)。CXF不仅提供了服务端的实现,还支持客户端调用,使得开发者可以方便地创建、发布和管理Web...

    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所需要的JAR包

    Java API for XML Web Services(JAX-WS)是Java平台上用于构建和消费Web服务的标准API。它简化了创建和使用Web服务的过程,使得开发者能够通过SOAP消息与远程服务进行交互。JAX-WS允许开发者将服务接口直接映射到...

    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所需Jar包

    JAX-WS(Java API for XML Web Services)是Java平台上的一个标准,用于构建和部署Web服务。这个标准允许开发人员使用简单的编程模型来创建和消费Web服务,从而简化了分布式系统间的交互。在Java环境中,JAX-WS提供...

    jax-ws api jar包

    JAX-WS(Java API for XML Web Services)是Java平台标准版(Java SE)和企业版(Java EE)的一部分,它为创建、部署和消费基于SOAP(Simple Object Access Protocol)的Web服务提供了全面的支持。JAX-WS允许开发者...

    jax-0.4.13.tar.gz

    `jax-0.4.13.tar.gz` 是一个开源库 JAX 的特定版本,即版本 0.4.13 的压缩包文件。JAX 是一个由 Google Brain 团队开发的高性能计算库,专为科学计算和深度学习任务设计,尤其在机器学习研究领域广泛应用。JAX 提供...

    jax-ws2.1.zip

    2. **webservices-extra.jar** - 此文件可能包含JAX-WS的一些扩展或额外功能,如WS-I(Web Services Interoperability)支持,或者对特定Web服务协议的实现,例如WS-Security(Web Services Security)或其他厂商...

    Jax-ws RI.zip

    Java API for XML Web Services (JAX-WS) 是Java平台上的一个标准,用于构建和部署Web服务。JAX-WS RI(Reference Implementation)是这个规范的官方参考实现,它提供了开发、测试和运行基于SOAP(Simple Object ...

    jax-rs jax-ws所需包,亲测可用

    2. **JAX-WS**(Java API for XML Web Services)是Java平台上的SOAP(Simple Object Access Protocol)Web服务标准,主要用于创建面向服务的架构(SOA)。JAX-WS提供了处理XML消息、WSDL(Web服务描述语言)和UDDI...

    JAX-WS所需要的JAR包

    JAX-WS(Java API for XML Web Services)是Java平台上的一个标准,用于构建和部署Web服务。它提供了一种基于标准的、类型安全的方式来创建和消费SOAP消息。JAX-WS通过Java SE和Java EE环境下的API,使得开发者能够...

    jax-ws webservice demo

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

    JAX-WS.zip

    Java Architecture for XML Binding (JAX-WS) 是Java平台上的一个标准组件,用于处理Web服务。它提供了在Java应用程序和Web服务之间交换XML数据的能力。JAX-WS允许开发者创建符合WS-I Basic Profile的Web服务,确保...

    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...

    解决weblogic部署JAX-WS需要的配置文件

    JAX-WS(Java API for XML Web Services)是Java平台上的一个标准,用于创建和部署Web服务。WebLogic作为一款强大的Java EE应用服务器,支持JAX-WS标准,但正确配置和部署这些服务需要一些额外的步骤。本指南将详细...

    jax-0.3.25-py3-none-any.whl

    文件格式:whl安装步骤:切换到whl路径执行pip install [whl文件名]注意whl对应python版本

    JAX-WS + Spring 实现webService示例.docx

    在本文中,我们将深入探讨如何使用JAX-WS(Java API for XML Web Services)与Spring框架集成来实现一个Web服务示例。这个示例将帮助我们理解如何在Spring环境中创建、配置和部署JAX-WS服务,同时利用Spring的依赖...

    metro-jax-ws-jaxws221x.zip

    【标题】"metro-jax-ws-jaxws221x.zip" 提供的是一个关于JAX-WS(Java API for XML Web Services)的开发示例,其中包含了JAX-WS 2.2.1版本的相关组件和库文件。这个压缩包是针对Java开发者设计的,用于帮助他们理解...

Global site tag (gtag.js) - Google Analytics