本文整理汇总了Java中org.apache.http.cookie.SM类的典型用法代码示例。如果您正苦于以下问题:Java SM类的具体用法?Java SM怎么用?Java SM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SM类属于org.apache.http.cookie包,在下文中一共展示了SM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Override
public List<Cookie> parse(
final Header header,
CookieOrigin origin) throws MalformedCookieException {
if (header == null) {
throw new IllegalArgumentException("Header may not be null");
}
if (origin == null) {
throw new IllegalArgumentException("Cookie origin may not be null");
}
if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
throw new MalformedCookieException("Unrecognized cookie header '"
+ header.toString() + "'");
}
origin = adjustEffectiveHost(origin);
HeaderElement[] elems = header.getElements();
return createCookies(elems, origin);
}
示例2: formatCookies
import org.apache.http.cookie.SM; //导入依赖的package包/类
public List<Header> formatCookies(final List<Cookie> cookies) {
if (cookies == null) {
throw new IllegalArgumentException("List of cookies may not be null");
}
if (cookies.isEmpty()) {
throw new IllegalArgumentException("List of cookies may not be empty");
}
CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
buffer.append(cookie.getName());
String s = cookie.getValue();
if (s != null) {
buffer.append("=");
buffer.append(s);
}
}
List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
示例3: formatCookies
import org.apache.http.cookie.SM; //导入依赖的package包/类
public List<Header> formatCookies(final List<Cookie> cookies) {
if (cookies == null) {
throw new IllegalArgumentException("List of cookies may not be null");
}
if (cookies.isEmpty()) {
throw new IllegalArgumentException("List of cookies may not be empty");
}
CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
for (int i = 0; i < cookies.size(); i++) {
Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
buffer.append(cookie.getName());
buffer.append("=");
String s = cookie.getValue();
if (s != null) {
buffer.append(s);
}
}
List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
示例4: formatCookies
import org.apache.http.cookie.SM; //导入依赖的package包/类
public List<Header> formatCookies(final List<Cookie> cookies) {
Args.notEmpty(cookies, "List of cookies");
final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
for (int i = 0; i < cookies.size(); i++) {
final Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
buffer.append(cookie.getName());
final String s = cookie.getValue();
if (s != null) {
buffer.append("=");
buffer.append(s);
}
}
final List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
示例5: formatCookies
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Override
public List<Header> formatCookies(final List<Cookie> cookies) {
Args.notEmpty(cookies, "List of cookies");
final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size());
buffer.append(SM.COOKIE);
buffer.append(": ");
for (int i = 0; i < cookies.size(); i++) {
final Cookie cookie = cookies.get(i);
if (i > 0) {
buffer.append("; ");
}
buffer.append(cookie.getName());
final String s = cookie.getValue();
if (s != null) {
buffer.append("=");
buffer.append(s);
}
}
final List<Header> headers = new ArrayList<Header>(1);
headers.add(new BufferedHeader(buffer));
return headers;
}
示例6: testParseCookies
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testParseCookies() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(1, cookies.size());
final Cookie cookie = cookies.get(0);
Assert.assertEquals(0, cookie.getVersion());
Assert.assertEquals("name1", cookie.getName());
Assert.assertEquals("value1", cookie.getValue());
Assert.assertEquals("localhost", cookie.getDomain());
Assert.assertEquals("/", cookie.getPath());
}
示例7: testNoCookieOrigin
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testNoCookieOrigin() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, null);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(0, cookies.size());
}
示例8: testNoCookieSpec
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testNoCookieSpec() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, null);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(0, cookies.size());
}
示例9: testNoCookieStore
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testNoCookieStore() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, null);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(0, cookies.size());
}
示例10: testSetCookie2OverrideSetCookie
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testSetCookie2OverrideSetCookie() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE, "name1=value1");
response.addHeader(SM.SET_COOKIE2, "name1=value2; Version=1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertEquals(1, cookies.size());
final Cookie cookie = cookies.get(0);
Assert.assertEquals(1, cookie.getVersion());
Assert.assertEquals("name1", cookie.getName());
Assert.assertEquals("value2", cookie.getValue());
Assert.assertEquals("localhost.local", cookie.getDomain());
Assert.assertEquals("/", cookie.getPath());
}
示例11: testInvalidHeader
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testInvalidHeader() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE2, "name=value; Version=crap");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertTrue(cookies.isEmpty());
}
示例12: testCookieRejected
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testCookieRejected() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
response.addHeader(SM.SET_COOKIE2, "name=value; Domain=www.somedomain.com; Version=1");
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpClientContext.COOKIE_ORIGIN, this.cookieOrigin);
context.setAttribute(HttpClientContext.COOKIE_SPEC, this.cookieSpec);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
final HttpResponseInterceptor interceptor = new ResponseProcessCookies();
interceptor.process(response, context);
final List<Cookie> cookies = this.cookieStore.getCookies();
Assert.assertNotNull(cookies);
Assert.assertTrue(cookies.isEmpty());
}
示例13: testCookiesForConnectRequest
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testCookiesForConnectRequest() throws Exception {
final HttpRequest request = new BasicHttpRequest("CONNECT", "www.somedomain.com");
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
Assert.assertNotNull(headers1);
Assert.assertEquals(0, headers1.length);
final Header[] headers2 = request.getHeaders(SM.COOKIE2);
Assert.assertNotNull(headers2);
Assert.assertEquals(0, headers2.length);
}
示例14: testNoCookieStore
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testNoCookieStore() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
context.setAttribute(HttpClientContext.COOKIE_STORE, null);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
Assert.assertNotNull(headers1);
Assert.assertEquals(0, headers1.length);
final Header[] headers2 = request.getHeaders(SM.COOKIE2);
Assert.assertNotNull(headers2);
Assert.assertEquals(0, headers2.length);
}
示例15: testNoCookieSpecRegistry
import org.apache.http.cookie.SM; //导入依赖的package包/类
@Test
public void testNoCookieSpecRegistry() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", "/");
final HttpRoute route = new HttpRoute(this.target, null, false);
final HttpClientContext context = HttpClientContext.create();
context.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, this.target);
context.setAttribute(HttpClientContext.HTTP_ROUTE, route);
context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, null);
final HttpRequestInterceptor interceptor = new RequestAddCookies();
interceptor.process(request, context);
final Header[] headers1 = request.getHeaders(SM.COOKIE);
Assert.assertNotNull(headers1);
Assert.assertEquals(0, headers1.length);
final Header[] headers2 = request.getHeaders(SM.COOKIE2);
Assert.assertNotNull(headers2);
Assert.assertEquals(0, headers2.length);
}