jax-rs的客户端完整实例
本地接口:
@Override
public Response formsubGet(String accountContent, char inputContent,
String opEntrustWay, String opStation, String sysName,String sdkType,String comsFunc,String password,
char passwordType) {
return this.formsubPost(accountContent, inputContent, opEntrustWay, opStation,sysName,sdkType,comsFunc, password, passwordType);
}
@Override
public Response formsubPost(String accountContent, char inputContent,
String opEntrustWay, String opStation, String sysName, String sdkType,String comsFunc,String password,
char passwordType) {
Response loginAuth = null;
本地实现类:
public class AuthLoginServerImpl implements AuthLoginServer
{
private static final Logger logger = Logger.getLogger(AuthLoginServerImpl.class);
private AuthLoginClient authLoginClient;
@Override
public Response formsubGet(String accountContent, char inputContent,
String opEntrustWay, String opStation, String sysName,String sdkType,String comsFunc,String password,
char passwordType) {
return this.formsubPost(accountContent, inputContent, opEntrustWay, opStation,sysName,sdkType,comsFunc, password, passwordType);
}
@Override
public Response formsubPost(String accountContent, char inputContent,
String opEntrustWay, String opStation, String sysName, String sdkType,String comsFunc,String password,
char passwordType) {
Response loginAuth = null;
try {
loginAuth = authLoginClient.login(accountContent, inputContent, opEntrustWay, opStation, sysName,sdkType,comsFunc,password, passwordType);
} catch (Exception e) {
logger.info("调用login认证异常:"+ e.getMessage());
loginAuth.setRetCode("-1");
loginAuth.setRetMessage("login方法认证失败!");
}
return loginAuth;
}
public void setAuthLoginClient(AuthLoginClient authLoginClient) {
this.authLoginClient = authLoginClient;
}
}
客户端类:
@Path("/mds")
@Produces("application/json;charset=UTF-8")
public interface AuthLoginClient
{
@POST
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED + ";charset=UTF-8",
MediaType.MULTIPART_FORM_DATA + ";charset=UTF-8" })
@Path("/formsub.json")
/*
* F_OP_SRC首字母大写,无法将所有参数进行封装处理,因为对象属性是通过geter获取,结果得到的属性名为f_OP_SRC
*/
public Response login(@FormParam("AccountContent") String accountContent, @FormParam("InputContent") char inputContent,
@FormParam("OpEntrustWay") String opEntrustWay, @FormParam("OpStation") String opStation,
@FormParam("sys_name") String sysName, @FormParam("sdk_type") String sdkType,
@FormParam("coms_func") String comsFunc,@FormParam("Password") String password,
@FormParam("PasswordType") char passwordType);
}
xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<!-- 资源文件配置 -->
<bean id="propertiesBean"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 不需要加载log4j.properties -->
<value>classpath:global.properties</value>
</list>
</property>
<property name="fileEncoding">
<value>UTF-8</value>
</property>
</bean>
<jaxrs:client id="authComClient"
serviceClass="com.citics.esb.rest.client.AuthComClient"
address="${url}">
<jaxrs:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxrs:features>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="dropRootElement" value="true" /><!--默认false-->
<property name="supportUnwrapped" value="true" /><!--默认false-->
</bean>
</jaxrs:providers>
</jaxrs:client>
<jaxrs:server id="cutIdtiByPassServer" address="/identifications/jsonapi">
<jaxrs:serviceBeans>
<bean class="com.citics.esb.rest.server.impl.AuthComServerImpl">
<property name="authComClient" ref="authComClient"></property>
</bean>
</jaxrs:serviceBeans>
<jaxrs:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxrs:features>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="ignoreNamespaces" value="true" />
<property name="dropRootElement" value="false" />
</bean>
</jaxrs:providers>
</jaxrs:server>
<jaxrs:client id="authLoginClient"
serviceClass="com.citics.esb.rest.client.AuthLoginClient"
address="${loginUrl}">
<jaxrs:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxrs:features>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="dropRootElement" value="true" /><!--默认false-->
<property name="supportUnwrapped" value="true" /><!--默认false-->
</bean>
</jaxrs:providers>
</jaxrs:client>
<jaxrs:server id="formsubServer" address="/mds">
<jaxrs:serviceBeans>
<bean class="com.citics.esb.rest.server.impl.AuthLoginServerImpl">
<property name="authLoginClient" ref="authLoginClient"></property>
</bean>
</jaxrs:serviceBeans>
<jaxrs:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxrs:features>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="ignoreNamespaces" value="true" />
<property name="dropRootElement" value="false" />
</bean>
</jaxrs:providers>
</jaxrs:server>
</beans>
返回的Response类:
@XmlRootElement(name = "Response")
@XmlAccessorType(XmlAccessType.NONE)
public class Response
{
@XmlElement(name = "RET_CODE")
private String retCode;
@XmlElement(name = "RET_MESSAGE")
private String retMessage;
@XmlElement(name = "RESULTSET")
private ResultSet resultSet;
public String getRetCode()
{
return retCode;
}
public void setRetCode(String retCode)
{
this.retCode = retCode;
}
public String getRetMessage()
{
return retMessage;
}
public void setRetMessage(String retMessage)
{
this.retMessage = retMessage;
}
public ResultSet getResultSet()
{
return resultSet;
}
public void setResultSet(ResultSet resultSet)
{
this.resultSet = resultSet;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
public class ResultSet
{
@XmlElement(name = "Account")
private String account;
@XmlElement(name = "BranchNo ")
private String branchNo ;
@XmlElement(name = "ClientID ")
private String clientID ;
@XmlElement(name = "SysnodeId")
private int sysnodeId;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getBranchNo() {
return branchNo;
}
public void setBranchNo(String branchNo) {
this.branchNo = branchNo;
}
public String getClientID() {
return clientID;
}
public void setClientID(String clientID) {
this.clientID = clientID;
}
public int getSysnodeId() {
return sysnodeId;
}
public void setSysnodeId(int sysnodeId) {
this.sysnodeId = sysnodeId;
}
}
jax-rs的客户端完整实例的更多相关文章
- JAX-RS 2.0 REST客户端编程实例
JAX-RS 2.0 REST客户端编程实例 2014/01/28 | 分类: 基础技术, 教程 | 0 条评论 | 标签: JAX-RS, RESTFUL 分享到:3 本文由 ImportNew - ...
- python测试mysql写入性能完整实例
这篇文章主要介绍了python测试mysql写入性能完整实例,具有一定借鉴价值,需要的朋友可以参考下 本文主要研究的是python测试mysql写入性能,分享了一则完整代码,具体介绍如下. 测试环境: ...
- Netty实现SSL双向验证完整实例
Netty实现SSL双向验证完整实例 博客分类: netty nettyssl自签证书 一.证书准备 要使用ssl双向验证,就必须先要生成服务端和客户端的证书,并相互添加信任,具体流程如下(本人调试 ...
- 【转】Android Https服务器端和客户端简单实例
转载地址:http://blog.csdn.net/gf771115/article/details/7827233 AndroidHttps服务器端和客户端简单实例 工具介绍 Eclipse3.7 ...
- C# 调用第三方DLL完整实例
C# 调用第三方DLL完整实例 分类: C/C++ 以下代码为本人在实际项目中编写的调用第三方DLL接口程序的完整代码. public class ExecuteDLL : Form { ...//忽 ...
- (转)多个mapreduce工作相互依赖处理方法完整实例(JobControl)
多个mapreduce工作相互依赖处理方法完整实例(JobControl) 原文地址:http://mntms.iteye.com/blog/2096456?utm_source=tuicool&am ...
- 利用Div+CSS(嵌套+盒模型)布局页面完整实例流程
Div+CSS(嵌套+盒模型)布局页面完整实例流程: <!DOCTYPE html><html> <head> <meta charset="UT ...
- 微信小程序发送短信验证码完整实例
微信小程序注册完整实例,发送短信验证码,带60秒倒计时功能,无需服务器端.效果图: 代码: index.wxml <!--index.wxml--> <view class=&quo ...
- Hadoop HDFS的shell(命令行客户端)操作实例
HDFS的shell(命令行客户端)操作实例 3.2 常用命令参数介绍 -help 功能:输出这个命令参数手册 -ls 功能:显示目录信息 示例: hadoop fs ...
随机推荐
- cxf 报错:java.lang.NoSuchMethodError: org.apache.ws.commons.schema.XmlSchemaCollection.read(Lorg/w3c/dom/Document;Ljava/lang/String;)
由于没有仔细查看官方提供的文档,由jdk版本不一致导致的出错: http://cxf.apache.org/cxf-316-release-notes.html 自己使用的是jdk1.8. 报Exce ...
- android app 集成 支付宝支付 微信支付
项目中部分功能点需要用到支付功能,移动端主要集成支付宝支付和微信支付 支付宝sdk以及demo下载地址:https://doc.open.alipay.com/doc2/detail.htm?spm= ...
- UEditor的jQuery插件化
UEditor本身并不依赖jQuery,但如果在项目中同时使用两者的话,可能会希望使用jQuery语法创建和获取编辑器实例.为此,需要为jQuery编写插件,代码如下: (function ($) { ...
- Dubbo集成步骤
dubbo协议实现与webservice一样的效果,用于服务调用之间的接口.dubbo可在中间实现真正意义上的中间调用管理,是一个中间管理系统. demo:http://www.devnote.cn/ ...
- [jquery备忘]
has :包含,找元素里面的子元素(单个) <div><span>123</span></div> $('div').has('span').css() ...
- iOS开发关于xcode中souceControl的苹果文档翻译(节选)
Subversion 1.7 provides many benefits: svn1.7版本有以下好处: Improved performance. Increased speed for many ...
- JS复习:第二十章
一.JSON 1.JSON的语法可以表示以下三种类型的值: (1)简单值:字符串.数值.布尔值和null.如:5,“Hello,World!” (2)对象:javascript中对象字面量: var ...
- mysql去重的最方便的两种方法
参考资料:http://blog.csdn.net/guocuifang655/article/details/3993612 方法一: 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然m ...
- MongoDB文档基本操作
一.插入文档 使用insert()或save()方法向集合插入文档 >db.COLLECTION_NAME.insert(document) 详细用法可以参考MongoDB菜鸟教程 二.查找文档 ...
- nefu 903 字符串去星
字符串去星 Problem : 903 Time Limit : 1000ms Memory Limit : 65536K description 有一个字符串(长度小于100),要统计其中有多少个* ...