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

本文介绍如何使用 Spring JAX-WS 构建并消费 Web 服务。通过 WSDL 定义使用 wsimport 工具生成代码,并展示了如何在 Spring 中配置 Web 服务客户端。同时,提供了控制器类示例来调用 Web 服务。

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"
         value = "http://localhost:8081/OrderServiceEndpoint?WSDL" />
     < 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.

分布式微服务企业级系统是一个基于Spring、SpringMVC、MyBatis和Dubbo等技术的分布式敏捷开发系统架构。该系统采用微服务架构和模块化设计,提供整套公共微服务模块,包括集中权限管理(支持单点登录)、内容管理、支付中心、用户管理(支持第三方登录)、微信平台、存储系统、配置中心、日志分析、任务和通知等功能。系统支持服务治理、监控和追踪,确保高可用性和可扩展性,适用于中小型企业的J2EE企业级开发解决方案。 该系统使用Java作为主要编程语言,结合Spring框架实现依赖注入和事务管理,SpringMVC处理Web请求,MyBatis进行数据持久化操作,Dubbo实现分布式服务调用。架构模式包括微服务架构、分布式系统架构和模块化架构,设计模式应用了单例模式、工厂模式和观察者模式,以提高代码复用性和系统稳定性。 应用场景广泛,可用于企业信息化管理、电子商务平台、社交应用开发等领域,帮助开发者快速构建高效、安全的分布式系统。本资源包含完整的源码和详细论文,适合计算机科学或软件工程专业的毕业设计参考,提供实践案例和技术文档,助力学生和开发者深入理解微服务架构和分布式系统实现。 【版权说明】源码来源于网络,遵循原项目开源协议。付费内容为本人原创论文,包含技术分析和实现思路。仅供学习交流使用。
### 关于《无尽冬日》游戏脚本与MOD开发 #### 1. 游戏脚本实现基础 对于《无尽冬日》这款游戏,其自动化脚本主要通过模拟器运行来实现。具体来说,这些脚本可以完成诸如建筑升级、资源采集、战斗检测等功能[^2]。以下是基于Python的一个简单示例代码框架,用于实现某些重复性任务: ```python import time from pynput.mouse import Button, Controller as MouseController from pynput.keyboard import Key, Controller as KeyboardController mouse = MouseController() keyboard = KeyboardController() def click_position(x, y): """移动鼠标到指定位置并点击""" mouse.position = (x, y) mouse.click(Button.left) def press_key(key_code): """按下键盘上的某个键""" keyboard.press(key_code) keyboard.release(key_code) def automate_task(task_name, interval=60): """ 自动化执行某项任务 :param task_name: 需要自动化的任务名称 :param interval: 执行两次任务之间的时间间隔(秒) """ while True: if task_name == 'building_upgrade': # 示例:假设建筑升级的位置为(800, 450) click_position(800, 450) elif task_name == 'resource_collection': # 示例:假设资源采集的位置为(900, 500) click_position(900, 500) time.sleep(interval) if __name__ == "__main__": automate_task('building_upgrade', interval=120) # 每隔两分钟尝试升级建筑 ``` 此代码片段展示了如何利用`pynput`库控制鼠标和键盘动作,从而实现简单的自动化任务。 --- #### 2. MOD开发入门 如果想进一步深入到MOD开发领域,则需要熟悉该游戏使用的引擎以及文件结构。大多数情况下,《无尽冬日》可能采用Unity或其他常见游戏引擎构建。因此,学习以下工具和技术将是必不可少的: - **Lua 或 C# 编程语言**:许多现代游戏都支持这两种语言作为脚本编写的主要方式。 - **Modding API 文档**:查找是否存在官方或社区维护的相关API文档[^3]。 - **反编译与逆向工程**:当缺乏正式资料时,可以通过合法手段研究现有二进制文件的工作原理。 下面是一个使用C#创建自定义UI组件的小例子: ```csharp using UnityEngine; using System.Collections; public class CustomUIExample : MonoBehaviour { void OnGUI() { GUI.Label(new Rect(10, 10, 100, 20), "Hello Player!"); if(GUI.Button(new Rect(10, 40, 100, 20), "Click Me")) { Debug.Log("Button was clicked."); } } } ``` 这段程序会在屏幕上显示一条消息标签,并附带一个可交互按钮。 --- #### 3. 技术注意事项 无论选择哪种方法进行扩展开发,请始终注意遵守版权法律和服务条款规定。未经授权擅自修改他人作品可能导致法律责任风险。此外,在实际部署前务必充分测试所有改动以防止意外行为损害用户体验或者破坏服务器平衡[^1]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值