Manual Instruction Document

Web Service

JAX-WS & JAX-RS

Author: Liu Xiang

Date: 2018/01/12

1. Summary....................................................................................................................... 1

2. JAX-WS.......................................................................................................................... 1

2.1 The common interface..................................................................................... 1

2.2 The functions.................................................................................................. 1

2.3 To call common JAX-WS.................................................................................... 4

2.4 To call private JAX-WS which released by ourself................................................. 7

2.5 Other common JAX-WS.................................................................................. 10

3. JAX-RS......................................................................................................................... 12

3.1 The common interface................................................................................... 12

3.2 The functions................................................................................................ 12

3.3 To call common JAX-RS................................................................................... 15

3.4 To call private JAX-RS which released by ourself................................................. 18

3.5 Other common JAX-RS................................................................................... 18

1. Summary

There are twotypes of Web Service.

JAX-WS, java apifor xml-based webservice.

JAX-RS, java apifor RESTful webservice.

2. JAX-WS

2.1 Thecommon
interface

Jar name

WsClient.jar

Interface

package com.cn;

 

publicinterface WsClient {

public String getResult(StringapplyKey, Stringtype,
String...message);

}

Parameters

Type

Name

Description

String

applyKey

User's Key, user's verification

String

type

The provided Web Service type name

String...

message

The input parameters

 

Return

Type

Description

String

The Web Service calling result

2.2The functions

2.2.1 Validations

2.2.1.2 CheckapplyKey

ToDo

2.2.1.2 Checktype

Check resource/resource.properties which key = support.type to verify if theincoming
type is support or not.

2.2.2 Prepare Web ServiceRequest

Use the SOAP 1.2 templates in "/com/cn/resource/request/template/"to prepare the request message.

For example:

2.2.3 Get Web Service Response

To call the related WSDL(Web Services DescriptionLanguage) URL, get the response.

For example:

2.2.4 Parse the response

Use the related key word to get result node.

For example:

2.3 Tocall common
JAX-WS

2.3.1 Validations

Pass.

2.3.2 To call the interface

Use below code to call 2.1 common method, to get"苏州"weather.

WsClientwsClient =new WsClientImpl();

System.out.println(wsClient.getResult("","weather","苏州",""));

2.3.3 Send the request SOAP 1.2request

<?xmlversion="1.0"encoding="utf-8"?>

<soap12:Envelopexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">

<soap12:Body>

<getWeatherxmlns="http://WebXml.com.cn/">

<theCityCode>苏州</theCityCode>

<theUserID></theUserID>

</getWeather>

</soap12:Body>

</soap12:Envelope>

2.3.4 Get the response

<?xmlversion="1.0"encoding="utf-8"?>

<soap:Envelopexmlns:soap="http://www.w3.org/2003/05/soap-envelope"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<soap:Body>

<getWeatherResponsexmlns="http://WebXml.com.cn/">

<getWeatherResult>

<string>江苏苏州</string>

<string>苏州</string>

</string>

<string>2018/01/1210:26:03</string>

级;湿度:31%</string>

<string>紫外线强度:中等。空气质量:中。</string>

、PA+防晒护肤品。健臻·血糖指数:易波动,血糖易波动,注意监测。感冒指数:较易发,天凉温差大,适当增减衣服。穿衣指数:冷,建议着棉衣加羊毛衫等冬季服装。洗车指数:较适宜,无雨且风力较小,易保持清洁度。空气污染指数:中,易感人群应适当减少室外活动。</string>

日晴</string>

<string>-3℃/5℃</string>

级</string>

<string>0.gif</string>

<string>0.gif</string>

日晴转多云</string>

<string>-1℃/7℃</string>

<string>东南风3-4级</string>

<string>0.gif</string>

<string>1.gif</string>

日多云</string>

℃/11℃</string>

<string>东南风3-4级</string>

<string>1.gif</string>

<string>1.gif</string>

日阴</string>

℃/15℃</string>

<string>东南风3-4级</string>

<string>2.gif</string>

<string>2.gif</string>

日小雨</string>

℃/16℃</string>

<string>西北风3-4级</string>

<string>7.gif</string>

<string>7.gif</string>

</getWeatherResult>

</getWeatherResponse>

</soap:Body>

</soap:Envelope>

2.3.5 Parse the response

江苏苏州

苏州

2004

2018/01/12 10:26:03

级;湿度:31%

紫外线强度:中等。空气质量:中。

、PA+防晒护肤品。健臻·血糖指数:易波动,血糖易波动,注意监测。感冒指数:较易发,天凉温差大,适当增减衣服。穿衣指数:冷,建议着棉衣加羊毛衫等冬季服装。洗车指数:较适宜,无雨且风力较小,易保持清洁度。空气污染指数:中,易感人群应适当减少室外活动。

日晴

-3℃/5℃

0.gif

0.gif

日晴转多云

-1℃/7℃

东南风3-4级

0.gif

1.gif

日多云

3℃/11℃

东南风3-4级

1.gif

1.gif

日阴

9℃/15℃

东南风3-4级

2.gif

2.gif

日小雨

7℃/16℃

西北风3-4级

7.gif

7.gif

2.4 Tocall private
JAX-WS which released by ourself

2.4.1 Validations

Pass.

2.4.2 Release private JAX-WS

2.4.2.1 New project HelloFriend

1. New java projectHelloFriend, New class MyService.java

package service;

publicclass MyService {

public String getGreeting(Stringname)

{

return"您好 "+name;

}

}

2. New META-INF folder and services.xml

services.xml

Service name is "myService", useRPC method

<servicename="myService">

<description>

WebService例子

</description>

<parametername="ServiceClass">

service.MyService

</parameter>

<operationname="getGreeting">

<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>

</operation>

</service>

3. Export the project to jar

jar cvf ws.aar .

2.4.2.2 Use axis2 to releaseit to tomcat

1. Move 2.4.1.1 step 3 jar \apache-tomcat-9.0.2\webapps\axis2\WEB-INF\services

2. Startup tomcat

3. Visit the private wsdl

2.4.3 To call the interface

WsClientwsClient =new
WsClientImpl();

System.out.println(wsClient.getResult("","myservice","刘大人"));

2.4.4 Send the request SOAP 1.2request

<?xmlversion="1.0"encoding="utf-8"?>

<soap12:Envelopexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">

<soap12:Body>

<getGreetingxmlns="http://service">

<name>刘大人</name>

</getGreeting>

</soap12:Body>

</soap12:Envelope>

2.4.5 Get the response

<?xmlversion="1.0"encoding="utf-8"?>

<soapenv:Envelopexmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">

<soapenv:Header/>

<soapenv:Body>

<ns:getGreetingResponsexmlns:ns="http://service">

<ns:return>您好刘大人</ns:return>

</ns:getGreetingResponse>

</soapenv:Body>

</soapenv:Envelope>

2.4.6 Parse the response

您好刘大人

2.5 Othercommon
JAX-WS

2.5.1 Attribution of mobilephones

WsClientwsClient =new
WsClientImpl();

wsClient.getResult("","mobile","18662638888","");

==>

18662638888:江苏苏州江苏联通GSM卡

2.5.2 Flight inquiries

WsClientwsClient =new
WsClientImpl();

wsClient.getResult("","airline","上海","北京","2018-01-12","");

==>

2.5.3 Chinese/Englishtranslations

WsClientwsClient =new
WsClientImpl();

wsClient.getResult("","englishswpchinese","airline","");

==>

airline

'e?lain

adj. (飞机)航线的;n. (飞机的)航线,航空公司

65562.mp3

However short the journey is, you always get something to eat on thisairline.

不管航程多麽短,这一班机上都有些吃的.

That was the worst airline disaster in history.

那是历史上最严重的空难。

The timetable is obtainable post-free from the airline office.

航班时刻表可以向航空公司免费索取。

WsClientwsClient =new
WsClientImpl();

wsClient.getResult("","englishswpchinese","苏州","");

==>

苏州

Suzhou (city)

soochow pladj.

Suchou

Soochow

对不起,打扰了,请问坐火车去苏州该乘什么车?

Excuse me, how can I go to suzhou by train?

一个孕妇把他从苏州河救了起来。

A pregnant lady rescued him from the Suzhou River.

这是从这里去苏州的直达列车吗?

Be this a through carriage for Suzhou from here?

3. JAX-RS

3.1The common
interface

Jar name

RsClient.jar

Interface

package com.cn;

 

import java.util.Map;

 

public interface RsClient {

      public <K, V> String getResult(String applyKey, String httpType, String type, Map<K,V>  parameters, String... message);

}

Parameters

Type

Name

Description

String

applyKey

User's Key, user's verification

String

httpType

Http calling type, GET/POST/PUT/DELETE

String

type

The provided Web Service type name

Map<K,V>

parameters

httpType is POST, the related parameters

String…

message

The input parameters

 

Return

Type

Description

String

The RESTful Web Service calling result

3.2The functions

3.2.1 Validations

3.2.1.2 CheckapplyKey

ToDo

3.2.1.2 Checktype

Check resource/resource.properties which key = support.type to verify if theincoming
type is support or not.

3.2.1.3 Check HTTPtype

Only support GET/POST/PUT/DELETE now.

3.2.2 Prepare RESTful WebService URL

Use the configured method and path to getthe correct URL.

For example

3.2.3 Get RESTful Web ServiceResponse

To call the related URL, get the response.

For example

3.2.4 Parse the response

Use the configured result key word to parseand format the result.

For example

3.3 Tocall common
JAX-RS

3.3.1 Validations

Pass.

3.3.2 Prepare RESTful WebService URL

Use the configured method and path to getthe correct URL.

For example

1. Get the base context path
http://www.weather.com.cn/data/sk/

2. Use the method to get the pathInfogetWeatherPathInfo

Get city code for苏州

3. If no "weather.path.info.method",use "weather.path.info.url" directly;

4.Get pathInfo suffix.

5. Get the final URL: http://www.weather.com.cn/data/sk/101190401.html

3.3.3 Get RESTful Web ServiceResponse

To call the related URL, get the response.

For example

{

"weatherinfo":{

"city":"苏州",

"cityid":"101190401",

"temp":"17",

"WD":"东南风",

"WS":"2级",

"SD":"44%",

"WSE":"2",

"time":"17:05",

"isRadar":"0",

"Radar":"",

"njd":"暂无实况",

"qy":"1017",

"rain":"0"

}

}

3.3.4 Parse the response

城市:苏州

温度:17

风向:东南风

风速:2级

湿度:44%

发布时间:17:05

3.4 Tocall private
JAX-RS which released by ourself

TODO.

3.5 Othercommon JAX-RS

3.5.1 PM 2.5

RsClientImplrsClient =new
RsClientImpl();

rsClient.getResult("","GET","pm2.5",null,"苏州");

==>

3.5.2 O3

RsClientImplrsClient =new
RsClientImpl();

rsClient.getResult("","GET","o3",null,"苏州");

==>

代码链接

WebService与RESTful WebService的更多相关文章

  1. SOAP Webservice和RESTful Webservice

    http://blog.sina.com.cn/s/blog_493a845501012566.html REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的 ...

  2. Restful是什么,SOAP Webservice和RESTful Webservice

    首先,应该怀着这样一种心态来学习Restful——Restful你可以将其理解一种软件架构风格,并且诠释了Http协议的设计初衷,所以不要把他理解的那么神秘,Restful风格有好处,当然也是有坏处的 ...

  3. Web Service进阶(七)浅谈SOAP Webservice和RESTful Webservice

    浅谈SOAP Webservice和RESTful Webservice REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性.RE ...

  4. "SOAP WebService " 和 "RESTful WebService" 的定义分别是什么???

    一个个来,要知道区别,首先得知道各自的意义及用途web service采用Xml传输结构化的数据,轻量级跨平台而soap则是一种基于http的应用层通讯协议,同样采用xml编码,只不过soap又更进了 ...

  5. 转载-- http接口、api接口、RPC接口、RMI、webservice、Restful等概念

     http接口.api接口.RPC接口.RMI.webservice.Restful等概念 收藏 Linux一叶 https://my.oschina.net/heavenly/blog/499661 ...

  6. webservice和restful的区别

    REST是一种架构风格,其核心是面向资源,REST专门针对网络应用设计和开发方式,以降低开发的复杂性,提高系统的可伸缩性.REST提出设计概念和准则为: 1.网络上的所有事物都可以被抽象为资源(res ...

  7. 使用CXF与Spring集成实现RESTFul WebService

    以下引用与网络中!!!     一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...

  8. RESTful WebService入门

    RESTful WebService入门   RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状 ...

  9. RESTful Webservice

    1,REST和RESTFUL是什么? REST ( REpresentational State Transfer ),State Transfer 为 "状态传输" 或 &quo ...

随机推荐

  1. Qt 常用类 (4)—— QPoint

    转载:落叶知秋时 QPoint 类代表一个坐标点,实现在 QtCore 共享库中.它可以认为是一个整型的横坐标和一个整型的纵坐标的组合. 构造 QPoint 类支持以下两种构造方式: QPoint() ...

  2. shell文件描述符和重定向

    1.文件描述符是与一个打开的文件或数据流相关联的整数.文件描述符0,1,2是系统预留的. 0 --------stdin(标准输入) 1 --------stdout(标准输出) 2--------- ...

  3. Tomcat Docker容器自动重启问题排查

    1. 问题 前两天发现 APP 刷新数据偶尔出现等半天没有响应的情况,感觉不像 APP 的问题,就查了下服务端的日志. 服务端用的是 Java,部署采用的 Docker 官方的 tomcat 镜像,并 ...

  4. Django的模板层简介

    Django的模板层 如果我们想要利用视图函数返回一个页面,一种比较简单的方式是利用HttpResponse()方法返回一个含有html内容的字符串: def current_datetime(req ...

  5. Jmeter(三十八)Jmeter Question 之 ‘批量执行SQL语句’

    知识使我们变得玩世不恭,智慧使我们变得冷酷无情,我们思考的太多,感知太少,除了机器,我们更需要人性,除了智慧,我们需要仁慈和善良. ------出自查理卓别林的演讲 前面有提到Jmeter使用JDBC ...

  6. tpadmin导入数据库问题

    tpadmin导入数据库后,修改表名tp_web_log_all时报1168错误 原因:该为联合表,原始sql语句中的联合表tp_web_log_001未改变表名,必须修改后用sql语句添加该表

  7. 关于Jedis连接Linux上的redis出现 DENIED Redis is running in protected mode问题的解决方案

    redis 添加了requirepass 123456后还是报错,原来是重新启动的时候./redis-cli  没有指定配置文件. https://blog.csdn.net/a532672728/a ...

  8. system调用导致子进程socket句柄泄漏问题分析

    问题引出:A进程与B进程各自独立,都是服务器进程,常驻系统,互不相干.在某次重启A进程后,发现由于固定监听的端口被占用而无法启动.检查,发现是B进程占用了该端口,检查B进程代码,没有相关的打开该固定端 ...

  9. SAS 数值转日期

    DATA _NULL_;FORMAT A YYMMDDN8.;B=PUT(20180101,$8.);A=INPUT(B,YYMMDD8.);PUT B= A=;RUN; 输出:47   DATA _ ...

  10. POJ3635 Full Tank?

    [题解] 用dijkstra算法求最短路.同时考虑在每个节点加油(一单位)与否. [代码] #include <iostream> #include <map> #includ ...