Temp
来源:互联网 发布:淘宝css滚动栏 编辑:程序博客网 时间:2024/05/18 03:52
CXF
/**
* 自定义扩展Struts2过滤器,用于解决struts会拦截cxf webservice请求的问题
*
*/
public class ExtendStrutsPrepareFilter extends StrutsPrepareFilter {
private static final Logger logger = LoggerFactory.getLogger(ExtendStrutsPrepareFilter.class);
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { try { HttpServletRequest request = (HttpServletRequest) req; // 判断是否是向WebService发出的请求 if (request.getRequestURI().contains("/interface")) { // 如果是来自向CXFService发出的请求 chain.doFilter(req, res); } else { // 默认action请求 super.doFilter(req, res, chain); } } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); } }
}
HttpClient
cxf
package com.admin.util;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClientUtil {
public static String doGet(String url, Map<String, String> param) { // 创建Httpclient对象 CloseableHttpClient httpclient = HttpClients.createDefault(); String resultString = ""; CloseableHttpResponse response = null; try { // 创建uri URIBuilder builder = new URIBuilder(url); if (param != null) { for (String key : param.keySet()) { builder.addParameter(key, param.get(key)); } } URI uri = builder.build(); // 创建http GET请求 HttpGet httpGet = new HttpGet(uri); // 执行请求 response = httpclient.execute(httpGet); // 判断返回状态是否为200 if (response.getStatusLine().getStatusCode() == 200) { resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (response != null) { response.close(); } httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } return resultString;}public static String doGet(String url) { return doGet(url, null);}public static String doPost(String url, Map<String, String> param) { // 创建Httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; String resultString = ""; try { // 创建Http Post请求 HttpPost httpPost = new HttpPost(url); // 创建参数列表 if (param != null) { List<NameValuePair> paramList = new ArrayList<>(); for (String key : param.keySet()) { paramList.add(new BasicNameValuePair(key, param.get(key))); } // 模拟表单 UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList); httpPost.setEntity(entity); } // 执行http请求 response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return resultString;}public static String doPost(String url) { return doPost(url, null);}public static String doPostJson(String url, String json) { // 创建Httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; String resultString = ""; try { // 创建Http Post请求 HttpPost httpPost = new HttpPost(url); // 创建请求内容 StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httpPost.setEntity(entity); // 执行http请求 response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return resultString;}/*添加鉴权请求 * public static String doPostJson(String url, String json) { // 创建Httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); CloseableHttpResponse response = null; String resultString = ""; try { // 创建Http Post请求 HttpPost httpPost = new HttpPost(url); // 创建请求内容 StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON); httpPost.setEntity(entity); // 执行http请求 response = httpClient.execute(httpPost); resultString = EntityUtils.toString(response.getEntity(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { try { response.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return resultString;}*/
}
package com.admin.servlet;import javax.ws.rs.Consumes;import javax.ws.rs.POST;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.Produces;import javax.ws.rs.core.MediaType;import org.springframework.web.bind.annotation.RequestParam;@Path(value = "/")@Produces({"application/json;charset=UTF-8", "application/xml;charset=UTF-8", "text/javascript;charset=UTF-8", "text/plain;charset=utf-8"})public interface AppInterefaceService { /** * 查询分页信息 * @param queryParams * @return */ @POST @Path("app/queryPage") @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public String appQuery(@RequestParam("queryParams") String queryParams);package com.admin.servlet.impl;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.concurrent.CopyOnWriteArrayList;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.apache.zookeeper.CreateMode;import org.apache.zookeeper.KeeperException;import org.apache.zookeeper.ZooDefs.Ids;import org.apache.zookeeper.ZooKeeper;import org.apache.zookeeper.data.Stat;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import org.springframework.transaction.annotation.Transactional;import com.admin.dao.IpccDao;import com.admin.model.PageContainer;import com.admin.servlet.AppInterefaceService;import com.admin.util.HttpClientUtil;import com.admin.util.JsonUtils;import com.admin.util.StringUtils;import com.admin.util.SysConfig;import com.admin.util.ZookeeperUtil;import com.admin.util.log.AddOperateLogUtil;import com.admin.util.web.AuthorityUtils;import com.admin.util.web.StrutsUtils;@Service("AppInterefaceServiceImpl")public class AppInterefaceServiceImpl implements AppInterefaceService{ private static final Logger logger = LogManager.getLogger(AppInterefaceServiceImpl.class); @Autowired private IpccDao ipccDao; @Override public String appQuery(String queryParams) { Map<String, Object> paramsMap = JsonUtils.toMap(queryParams); //超级管理员判断 if((!StringUtils.isEmpty(paramsMap.get("sid").toString()))){ String sid = paramsMap.get("sid").toString(); if(SysConfig.getInstance().getProperty("sid").equals(sid)){ paramsMap.remove("sid"); } } PageContainer searchPage = ipccDao.getSearchPage("appConfig.queryPage", "appConfig.queryCount", paramsMap); return JsonUtils.toJson(searchPage); }<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd "> <bean id="LoggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" /> <bean id="LoggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" /> <bean id="CxfResponseInterceptor" class="com.admin.util.interceptor.CxfResponseInterceptor" /> <bean id="SimpleConverter" class="org.codehaus.jettison.mapped.SimpleConverter" /> <bean id="JSONProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider"> <property name="typeConverter" ref="SimpleConverter" /> <property name="arrayKeys" value="memberName" /> </bean> <jaxrs:server id="asServiceContainer" address="/"> <jaxrs:serviceBeans> <ref bean="AppInterefaceServiceImpl"/> <ref bean="CallInterefaceServiceImpl"/> <ref bean="ClientInterefaceServiceImpl"/> <ref bean="CbInterefaceServiceImpl"/> <ref bean="IvrInterefaceServiceImpl"/> <ref bean="GroupInterefaceServiceImpl"/> <ref bean="SeatInterefaceServiceImpl"/> <ref bean="RecoverDateInterefaceServiceImpl"/> </jaxrs:serviceBeans> <!-- 输入日志拦截器 --> <jaxrs:inInterceptors> <ref bean="LoggingInInterceptor" /> </jaxrs:inInterceptors> <!-- 输出拦截器 --> <jaxrs:outInterceptors> <!-- 输出日志拦截器 --> <ref bean="LoggingOutInterceptor" /> <!-- 输出响应拦截器 --> <ref bean="CxfResponseInterceptor" /> </jaxrs:outInterceptors> <jaxrs:providers> <ref bean="JSONProvider" /> </jaxrs:providers> <jaxrs:extensionMappings> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </jaxrs:extensionMappings> <jaxrs:languageMappings> <entry key="en" value="en-gb" /> </jaxrs:languageMappings> </jaxrs:server></beans>这里写代码片
- temp
- temp
- temp
- temp
- temp
- temp
- temp
- temp
- TEMP
- temp
- temp
- Temp
- temp
- Temp
- TEMP
- Temp
- temp
- temp
- 前端颜色对照表
- TSF 响应按键
- 使用Spring的HttpInovoker进行远程方法调用
- [BZOJ]3257树的难题 树型DP
- java redis 删除指定前缀的key
- Temp
- Ubuntu下配置Samba
- Android:WebView与 JS 交互方式
- 【spark】之Job调度模式
- visibility
- HTTPS协议和SSL协议完整交互过程
- POJ2396 Budget
- JAVA异常-ERROR
- 安卓运行时监听配置更改:sim卡、本地语言、键盘显示或隐藏、字体大小、UI模式、屏幕方向、屏幕布局(另一个屏幕)、可用屏幕大小(横纵向)、无屏幕大小(外接屏幕)。