|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.webframe.test.web.BaseWebServerTests
org.webframe.test.BaseHttpClientTests
public class BaseHttpClientTests
| Field Summary | |
|---|---|
protected static org.apache.http.impl.client.DefaultHttpClient |
client
|
private org.apache.http.protocol.HttpContext |
context
|
protected static String |
defaultEncode
|
private static Map<String,Boolean> |
userOnceMap
|
| Fields inherited from class org.webframe.test.web.BaseWebServerTests |
|---|
HTTP, HTTPS |
| Constructor Summary | |
|---|---|
BaseHttpClientTests()
|
|
| Method Summary | |
|---|---|
protected void |
enableAuth(String usernamePassword)
开启安全认证后,可以访问受限制资源 |
protected org.apache.http.HttpResponse |
executeGet(String url)
发送Get请求对象到服务器,返回HttpResponse |
protected org.apache.http.HttpResponse |
executePost(String url,
List<org.apache.http.NameValuePair> params)
发送Post请求对象到服务器,返回HttpResponse |
protected org.apache.http.HttpResponse |
executePost(String url,
Map<String,Object> params)
发送Post请求对象到服务器,返回HttpResponse |
protected String |
getBaseUrl()
|
protected org.apache.http.protocol.HttpContext |
getContext()
|
protected org.apache.http.client.methods.HttpGet |
getHttpGet(String url)
通过url获取Get请求对象 |
protected org.apache.http.client.methods.HttpPost |
getHttpPost(String url)
通过url获取Post请求对象 |
protected List<org.apache.http.NameValuePair> |
getPairs(Map<String,Object> params)
Map参数集合转换为NameValuePair List参数集合 |
protected String |
getResponseContent(org.apache.http.HttpResponse res)
|
protected String |
getUrl(String url)
获取url全路径包括主机和端口,默认使用http; |
protected String |
getUrlParamsString(List<org.apache.http.NameValuePair> params)
获取参数的字符串格式 |
protected String |
getUrlParamsString(Map<String,Object> params)
获取参数的字符串格式 |
protected void |
login()
使用默认的登陆链接进行登陆:url("/j_spring_security_check"), user("admin:1") |
protected void |
login(String loginUrl,
Map<String,Object> user)
执行登陆方法后,就有权限方法其他资源 |
protected void |
login(String loginUrl,
String usernamePassword)
执行登陆方法后,就有权限方法其他资源 |
protected String |
sendGet(String url)
发送Get请求对象到服务器,返回字符串 |
protected String |
sendPost(String url,
List<org.apache.http.NameValuePair> params)
发送Post请求对象到服务器,返回字符串 |
protected String |
sendPost(String url,
Map<String,Object> params)
发送Post请求对象到服务器,返回字符串 |
protected void |
setContext(org.apache.http.protocol.HttpContext context)
|
| Methods inherited from class org.webframe.test.web.BaseWebServerTests |
|---|
disposeConnector, getServerHost, getServerPort, getServerURL, getServerURL |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final String defaultEncode
protected static final org.apache.http.impl.client.DefaultHttpClient client
private org.apache.http.protocol.HttpContext context
private static Map<String,Boolean> userOnceMap
| Constructor Detail |
|---|
public BaseHttpClientTests()
| Method Detail |
|---|
protected String getBaseUrl()
protected String getUrl(String url)
url -
protected final org.apache.http.client.methods.HttpGet getHttpGet(String url)
url -
protected final org.apache.http.client.methods.HttpPost getHttpPost(String url)
url -
protected String sendGet(String url)
throws Exception
url - 字符串上可以包含参数,例如:/login?username=admin&password=1
Exception
protected String sendPost(String url,
Map<String,Object> params)
throws Exception
url - 不包含参数的url路径params - Map参数集合
Exception
protected String sendPost(String url,
List<org.apache.http.NameValuePair> params)
throws Exception
url - 不包含参数的url路径params - NameValuePair List参数集合
Exception
protected org.apache.http.HttpResponse executeGet(String url)
throws Exception
url - 字符串上可以包含参数,例如:/login?username=admin&password=1
Exception
protected org.apache.http.HttpResponse executePost(String url,
Map<String,Object> params)
throws Exception
url - 不包含参数的url路径params - Map参数集合
Exception
protected org.apache.http.HttpResponse executePost(String url,
List<org.apache.http.NameValuePair> params)
throws Exception
url - 不包含参数的url路径params - NameValuePair List参数集合
Exception
protected String getResponseContent(org.apache.http.HttpResponse res)
throws Exception
Exceptionprotected String getUrlParamsString(Map<String,Object> params)
params - Map参数集合
protected String getUrlParamsString(List<org.apache.http.NameValuePair> params)
params - NameValuePair List参数集合
protected final List<org.apache.http.NameValuePair> getPairs(Map<String,Object> params)
params - Map参数集合
protected void setContext(org.apache.http.protocol.HttpContext context)
protected final org.apache.http.protocol.HttpContext getContext()
protected final void enableAuth(String usernamePassword)
usernamePassword - 例如:'admin:123456'
protected void login()
throws Exception
Exception
protected void login(String loginUrl,
String usernamePassword)
throws Exception
loginUrl - 登陆url,例如:'/j_spring_security_check'usernamePassword - 用户信息,例如:"admin:1"
Exception
protected void login(String loginUrl,
Map<String,Object> user)
throws Exception
loginUrl - 登陆url,例如:'/j_spring_security_check'user - 包含用户信息的Map,例如:user.put("j_username", "admin");user.put("j_password", "1");
Exception
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||