package com.geostar.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) {
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状�?是否�?00
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<NameValuePair>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
webservice(cxf),客户端和服务器端
共212个文件
jar:112个
xml:24个
class:18个
需积分: 10 15 下载量 61 浏览量
2017-04-08
18:26:39
上传
评论 2
收藏 46.9MB RAR 举报
温馨提示
springmvc+mybatis+cxf+客户端+服务器端+soap+rest方式+内部有数据库
资源推荐
资源详情
资源评论
收起资源包目录
webservice(cxf),客户端和服务器端 (212个子文件)
HttpClientUtil.class 4KB
User1Controller.class 1KB
User2Controller.class 1KB
WSUserService2Impl.class 1KB
WSUserService1Impl.class 1KB
User.class 1KB
WSUserService3Impl.class 1KB
User.class 1KB
UserServiceImpl.class 936B
UserServiceImpl.class 815B
WSUserService1.class 557B
WSUserService2.class 557B
WSUserService2.class 355B
WSUserService1.class 355B
UserService.class 207B
UserService.class 205B
UserDao.class 195B
UserDao.class 195B
.classpath 885B
.classpath 885B
org.eclipse.wst.common.component 544B
org.eclipse.wst.common.component 544B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
cxf-2.7.18.jar 6.98MB
xmlbeans-2.6.0.jar 2.6MB
hibernate3.jar 2.31MB
guava-17.0.jar 2.14MB
druid-1.0.20.jar 2.03MB
jaxb-xjc-2.2.6.jar 1.98MB
aspectjweaver.jar 1.8MB
SQLiteJDBC-3.7.6.3.jar 1.79MB
mybatis-3.3.0.jar 1.35MB
opensaml-2.6.1.jar 1.35MB
ehcache-core-2.5.1.jar 1.17MB
activemq-client-5.8.0.jar 1.09MB
jaxb-impl-2.2.6.jar 1.06MB
mysql-connector-java-5.1.31-bin.jar 942KB
activemq-broker-5.8.0.jar 937KB
javaee.jar 935KB
spring-core-3.2.8.RELEASE.jar 853KB
js-1.7R2.jar 851KB
spring-context-3.2.8.RELEASE.jar 846KB
msv-core-2011.1.jar 666KB
xmltooling-1.4.1.jar 655KB
xmlsec-1.5.8.jar 643KB
mina-core-2.0.7.jar 630KB
spring-webmvc-3.2.8.RELEASE.jar 623KB
spring-web-3.2.8.RELEASE.jar 614KB
spring-beans-3.2.8.RELEASE.jar 598KB
javassist-3.9.0.GA.jar 583KB
activemq-openwire-legacy-5.8.0.jar 574KB
httpclient-4.3.1.jar 572KB
commons-collections-3.2.1.jar 562KB
openws-1.5.1.jar 561KB
joda-time-2.2.jar 560KB
woodstox-core-asl-4.4.1.jar 475KB
wss4j-1.6.19.jar 454KB
velocity-1.7.jar 439KB
antlr-2.7.7.jar 435KB
httpclient-4.2.5.jar 423KB
commons-lang3-3.3.2.jar 403KB
spring-jdbc-3.2.8.RELEASE.jar 396KB
spring-orm-3.2.8.RELEASE.jar 376KB
jetty-server-8.1.15.v20140411.jar 352KB
spring-aop-3.2.8.RELEASE.jar 330KB
cglib-nodep-2.1_3.jar 317KB
dom4j-1.6.1.jar 307KB
FastInfoset-1.2.13.jar 290KB
httpcore-nio-4.2.4.jar 283KB
jetty-util-8.1.15.v20140411.jar 281KB
commons-lang-2.6.jar 278KB
commons-codec-1.10.jar 278KB
httpcore-4.3.jar 276KB
hibernate-annotations.jar 274KB
serializer-2.7.1.jar 272KB
cxf-services-sts-core-2.7.18.jar 253KB
jsqlparser-0.9.1.jar 246KB
spring-tx-3.2.8.RELEASE.jar 237KB
cxf-services-wsn-api-2.7.18.jar 229KB
xsdlib-2010.1.jar 224KB
httpcore-4.2.4.jar 222KB
geronimo-javamail_1.4_spec-1.7.1.jar 218KB
spring-expression-3.2.8.RELEASE.jar 192KB
isorelax-20030108.jar 188KB
commons-beanutils.jar 184KB
spring-webmvc-portlet-3.2.8.RELEASE.jar 184KB
wsdl4j-1.6.3.jar 182KB
commons-io-2.4.jar 181KB
xmlschema-core-2.1.0.jar 162KB
stax2-api-3.1.4.jar 158KB
json-lib-2.4-jdk15.jar 155KB
httpclient-cache-4.3.1.jar 145KB
aspectjrt-1.5.4.jar 112KB
javax.ws.rs-api-2.0-m10.jar 108KB
jetty-io-8.1.15.v20140411.jar 103KB
jaxb-api-2.2.6.jar 97KB
geronimo-servlet_3.0_spec-1.0.jar 94KB
jetty-http-8.1.15.v20140411.jar 94KB
jetty-security-8.1.15.v20140411.jar 88KB
共 212 条
- 1
- 2
- 3
资源评论
GISyepan
- 粉丝: 2
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功