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 ...
随机推荐
- cuda8.0 /usr/bin/ld: cannot find -lGL
/usr/bin/ld: cannot find -lGL collect2: ld returned 1 exit status tennycent@tennycent-desktop:~/$ ...
- 移动app的一些心得
周末的时候闲着没事,看到了个开源的红旅动漫的APP,于是自己就拿下来写了下,整个网站作者也解析成了接口,所以就可以写成app了,作者写的是用mui开发的,可以通过hbuilder软件打开,进行查看源代 ...
- ping 计算机全名,返回的不是IP地址
今天想看一下机子的IP地址,结果关闭局域防火墙后,在命令行中使用ping 计算机全名,返回的不是IP地址 其实,这也是一种IP地址,IP6地址 原因:默认情况下,win7以上的操作系统,ping 计算 ...
- bigdecimal使用
float和double类型 一般用于科学计算,用于金融的都用bigdecimal类型.在项目中浮点型数据没有指定 默认是double类型.bigdecimal的构造参数有浮点型和String类型.但 ...
- javaWEB总结(14):请求的转发和重定向
通俗理解请求转发与重定向的流程 通俗的来讲:我们可以把请求转发和重定向当成是一种借钱的情景模式. (1)请求的转发:A向B借钱,B自己没有钱,但是向C借到了钱,并且把钱借给了A.A只向B请求了一次. ...
- awk学习笔记一:基础(转)
awk内置变量 ARGC 命令行参数个数ARGV 命令行参数排列ENVIRON 支持队列中系统环境变量的使用FILENAME awk浏览的文件名FNR 浏览文件的记录数FS 设置输入域分隔符,等价于命 ...
- nodejs querystring
Query String querystring.parse(str[, sep][, eq][, options]) querystring.stringify(obj[, sep][, eq][, ...
- OpenCV2.x自学笔记——固定阈值
threshold( const CvArr* src, CvArr* dst, double threshold, double max_value, int threshold_type) ...
- web.py 学习(二)Worker
Rocket Server 启动一个线程监听客户端的连接,收到连接将连接放置到队列中.线程池中的Worker会以这个连接进行初始化.Rocket中Worker的基类是: class Worker(Th ...
- Objetive-C 中的相等比较
1.== 用于比较两个对象的地址是否相同 1)需要注意的是相同的短字符串,一定大小整数(nsnumber),Objetive-C 底层会做cache,两个对象,指向同一个地址. 例如: NSStrin ...