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 ...
随机推荐
- chrome pyv8下载
url: https://code.google.com/archive/p/pyv8/downloads linux命令: $sudo pip install -v pyv8
- Hibernate5-课程笔记2
单表的增删改查操作: (1)定义获取Session和SessionFactory的工具类: package com.tongji.utils; import org.hibernate.Session ...
- JqGrid相关操作
JqGrid相关操作 根据jqGrid的文档,要想生成一个jqGrid,最直接的方法就是:$("#grid_id").jqGrid(options);也就是通过选择符得到一个tab ...
- c#委托与事件(详解)
引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去 ...
- Android之ListView异步加载图片且仅显示可见子项中的图片
折腾了好多天,遇到 N 多让人崩溃无语的问题,不过今天终于有些收获了,这是实验的第一版,有些混乱,下一步进行改造细分,先把代码记录在这儿吧. 网上查了很多资料,发现都千篇一律,抄来抄去,很多细节和完整 ...
- WITH common_table_expression
Feature: 公用表表达式只能包含一个SELECT,多SELECT需UNION,UNION ALL 公用表表达式只能引用一次 公用表表达式可以包括对自身的引用,这种表达式称为递归公用表表达式 -- ...
- Dubbo集成步骤
dubbo协议实现与webservice一样的效果,用于服务调用之间的接口.dubbo可在中间实现真正意义上的中间调用管理,是一个中间管理系统. demo:http://www.devnote.cn/ ...
- Eclipse Kepler maven工程配置JDK1.8
首先需要下载插件:"Help" --> "Market Place" --> Search for java 8 kepler. install J ...
- java中三大修饰符
一.static 1.属性:类变量 定义在类以内,方法以外,全类有效,全类公共一个属性 类变量与创建对象无关,有默认值0 使用方式 类名.类变量 System.out.println(); ...
- 【Python@Thread】锁示例
当出现竞态条件时候,即在同一个时刻只有一个线程可以进入临界区,需要使用同步. 常见的同步原语有两种:锁/互斥,信号量. 锁是最简单,最低级的机制. 首先看一个不使用锁时候的多线程示例: from at ...