• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ClientCookieDecoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.codec.http.cookie.ClientCookieDecoder的典型用法代码示例。如果您正苦于以下问题:Java ClientCookieDecoder类的具体用法?Java ClientCookieDecoder怎么用?Java ClientCookieDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ClientCookieDecoder类属于io.netty.handler.codec.http.cookie包,在下文中一共展示了ClientCookieDecoder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getUrlConnection

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
    HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
    URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
    HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
    con.setHostnameVerifier((host, session) -> true);
    con.setRequestMethod("GET");
    con.setDoOutput(true);
    con.setRequestProperty("Content-Type", "application/json");
    con.connect();
    int responseCode = con.getResponseCode();
    if (401 == responseCode) {
        throw new UnauthorizedUserException();
    }
    Assert.assertEquals(200, responseCode);
    List<String> cookies = con.getHeaderFields().get(Names.SET_COOKIE);
    Assert.assertEquals(1, cookies.size());
    Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
    Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
    con = (HttpsURLConnection) url.openConnection();
    con.setRequestProperty(Names.COOKIE, sessionCookie.name() + "=" + sessionCookie.value());
    con.setHostnameVerifier((host, session) -> true);
    return con;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:24,代码来源:TwoWaySSLIT.java


示例2: channelRead

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
   FullHttpResponse response = (FullHttpResponse) msg;
   if (httpRequiresSessionId && !active) {
      final List<String> setCookieHeaderValues = response.headers().getAll(HttpHeaderNames.SET_COOKIE);
      for (String setCookieHeaderValue : setCookieHeaderValues) {
         final Cookie cookie = ClientCookieDecoder.LAX.decode(setCookieHeaderValue);
         if ("JSESSIONID".equals(cookie.name())) {
            this.cookie = setCookieHeaderValue;
            break;
         }
      }
      active = true;
      handShakeFuture.run();
   }
   waitingGet = false;
   ctx.fireChannelRead(response.content());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:19,代码来源:NettyConnector.java


示例3: testBasicAuthentication

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
@Test
public void testBasicAuthentication() throws Exception {
    Configuration config = TestConfiguration.createMinimalConfigurationForTest();

    BasicAuthLogin auth = new BasicAuthLogin();
    auth.setUsername("test");
    auth.setPassword("test1");
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
    request.content().writeBytes(JsonSerializer.getObjectMapper().writeValueAsBytes(auth));

    TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
    decoder.decode(null, request, results);
    Assert.assertEquals(1, results.size());
    Object result = results.iterator().next();
    Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());

    BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
    CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
    handler.channelRead(ctx, result);
    Assert.assertNotNull(ctx.msg);
    Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
    DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
    Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
    Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
    Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
    Assert.assertTrue(response.headers().contains(Names.SET_COOKIE));
    Cookie c = ClientCookieDecoder.STRICT.decode(response.headers().get(Names.SET_COOKIE));
    Assert.assertEquals(TestConfiguration.HTTP_ADDRESS_DEFAULT, c.domain());
    Assert.assertEquals(86400, c.maxAge());
    Assert.assertTrue(c.isHttpOnly());
    Assert.assertTrue(c.isSecure());
    Assert.assertEquals(Constants.COOKIE_NAME, c.name());
    UUID.fromString(c.value());
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:35,代码来源:BasicAuthLoginRequestHandlerTest.java


示例4: fromVertxCookie

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
static Cookie fromVertxCookie(io.vertx.ext.web.Cookie cookie) {
    io.netty.handler.codec.http.cookie.Cookie decoded = ClientCookieDecoder.STRICT.decode(cookie.encode());
    Cookie out = new Cookie(decoded.name(), decoded.value());
    Optional.ofNullable(decoded.domain()).ifPresent(out::setDomain);
    out.setPath(decoded.path());
    out.setHttpOnly(decoded.isHttpOnly());
    out.setSecure(decoded.isSecure());
    if (decoded.maxAge() != Long.MIN_VALUE) {
        out.setMaxAge((int) decoded.maxAge());
    }

    // TODO extract other values
    return out;
}
 
开发者ID:mcollovati,项目名称:vaadin-vertx-samples,代码行数:15,代码来源:CookieUtils.java


示例5: testBasicAuthentication

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
@Test
  public void testBasicAuthentication() throws Exception {
      Configuration config = TestConfiguration.createMinimalConfigurationForTest();

      // @formatter:off
String form = 
      "{\n" +
"    \"username\": \"test\",\n" +
      "    \"password\": \"test1\"\n" +
"}";
// @formatter:on
      DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/login");
      request.content().writeBytes(form.getBytes());

      TestHttpQueryDecoder decoder = new TestHttpQueryDecoder(config);
      decoder.decode(null, request, results);
      Assert.assertEquals(1, results.size());
      Object result = results.iterator().next();
      Assert.assertEquals(BasicAuthLoginRequest.class, result.getClass());

      BasicAuthLoginRequestHandler handler = new BasicAuthLoginRequestHandler(config);
      CaptureChannelHandlerContext ctx = new CaptureChannelHandlerContext();
      handler.channelRead(ctx, result);
      Assert.assertNotNull(ctx.msg);
      Assert.assertTrue(ctx.msg instanceof DefaultFullHttpResponse);
      DefaultFullHttpResponse response = (DefaultFullHttpResponse) ctx.msg;
      Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
      Assert.assertTrue(response.headers().contains(Names.CONTENT_TYPE));
      Assert.assertEquals(Constants.JSON_TYPE, response.headers().get(Names.CONTENT_TYPE));
      Assert.assertTrue(response.headers().contains(Names.SET_COOKIE));
      Cookie c = ClientCookieDecoder.STRICT.decode(response.headers().get(Names.SET_COOKIE));
      Assert.assertEquals(TestConfiguration.TIMELY_HTTP_ADDRESS_DEFAULT, c.domain());
      Assert.assertEquals(86400, c.maxAge());
      Assert.assertTrue(c.isHttpOnly());
      Assert.assertTrue(c.isSecure());
      Assert.assertEquals(Constants.COOKIE_NAME, c.name());
      UUID.fromString(c.value());
  }
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:39,代码来源:BasicAuthLoginRequestHandlerTest.java


示例6: getUrlConnection

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
    HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
    URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
    HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
    con.setHostnameVerifier((host, session) -> true);
    con.setRequestMethod("POST");
    con.setDoOutput(true);
    con.setRequestProperty("Content-Type", "application/json");
    BasicAuthLoginRequest request = new BasicAuthLoginRequest();
    request.setUsername(username);
    request.setPassword(password);
    String requestJSON = JsonUtil.getObjectMapper().writeValueAsString(request);
    con.setRequestProperty("Content-Length", String.valueOf(requestJSON.length()));
    OutputStream wr = con.getOutputStream();
    wr.write(requestJSON.getBytes(UTF_8));
    int responseCode = con.getResponseCode();
    if (401 == responseCode) {
        throw new UnauthorizedUserException();
    }
    Assert.assertEquals(200, responseCode);
    List<String> cookies = con.getHeaderFields().get(Names.SET_COOKIE);
    Assert.assertEquals(1, cookies.size());
    Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
    Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
    con = (HttpsURLConnection) url.openConnection();
    con.setRequestProperty(Names.COOKIE, sessionCookie.name() + "=" + sessionCookie.value());
    con.setHostnameVerifier((host, session) -> true);
    return con;
}
 
开发者ID:NationalSecurityAgency,项目名称:timely,代码行数:30,代码来源:OneWaySSLBasicAuthAccessIT.java


示例7: captureResponseCookies

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
protected void captureResponseCookies(HttpResponse httpResponse) {
    Log.e("InnerHandle", "captureResponseCookies " + harEntry.getId());
    List<String> setCookieHeaders = httpResponse.headers().getAll(HttpHeaders.Names.SET_COOKIE);
    if (setCookieHeaders == null) {
        return;
    }

    for (String setCookieHeader : setCookieHeaders) {
        Cookie cookie = ClientCookieDecoder.LAX.decode(setCookieHeader);
        if (cookie == null) {
            return;
        }

        HarCookie harCookie = new HarCookie();

        harCookie.setName(cookie.name());
        harCookie.setValue(cookie.value());
        // comment is no longer supported in the netty ClientCookieDecoder
        harCookie.setDomain(cookie.domain());
        harCookie.setHttpOnly(cookie.isHttpOnly());
        harCookie.setPath(cookie.path());
        harCookie.setSecure(cookie.isSecure());
        if (cookie.maxAge() > 0) {
            // use a Calendar with the current timestamp + maxAge seconds. the locale of the calendar is irrelevant,
            // since we are dealing with timestamps.
            Calendar expires = Calendar.getInstance();
            // zero out the milliseconds, since maxAge is in seconds
            expires.set(Calendar.MILLISECOND, 0);
            // we can't use Calendar.add, since that only takes ints. TimeUnit.convert handles second->millisecond
            // overflow reasonably well by returning the result as Long.MAX_VALUE.
            expires.setTimeInMillis(expires.getTimeInMillis() + TimeUnit.MILLISECONDS.convert(cookie.maxAge(), TimeUnit.SECONDS));

            harCookie.setExpires(expires.getTime());
        }

        harResponse.getResponse().getCookies().add(harCookie);
        harResponse.addHeader(harCookie.getName(), harCookie.getValue());
    }
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:40,代码来源:HarCaptureFilter.java


示例8: getResponseCookies

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
/**
 * 获得响应 cookie
 * 
 * @return cookies
 */
public static Cookie[] getResponseCookies(NHttpResponse response) {
    ArrayList<Cookie> cookies = new ArrayList<Cookie>();
    ClientCookieDecoder clientCookieDecoder = ClientCookieDecoder.STRICT;
    String[][] matchResult = NHttpTools.parseHeaders(response.response());
    for (String[] strings : matchResult) {
        if (strings[0].equalsIgnoreCase(HttpHeaders.Names.SET_COOKIE)) {
            Cookie cookie = clientCookieDecoder.decode(strings[1]);
            cookies.add(cookie);
        }
    }
    return cookies.toArray(new Cookie[0]);
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:18,代码来源:NHttpTools.java


示例9: cookieHeaderAlreadyExists

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
private boolean cookieHeaderAlreadyExists(HttpResponse response, org.mockserver.model.Cookie cookieValue) {
    List<String> setCookieHeaders = response.getHeader(SET_COOKIE.toString());
    for (String setCookieHeader : setCookieHeaders) {
        String existingCookieName = ClientCookieDecoder.LAX.decode(setCookieHeader).name();
        String existingCookieValue = ClientCookieDecoder.LAX.decode(setCookieHeader).value();
        if (existingCookieName.equalsIgnoreCase(cookieValue.getName().getValue()) && existingCookieValue.equalsIgnoreCase(cookieValue.getValue().getValue())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:12,代码来源:MockServerResponseEncoder.java


示例10: cookieHeaderAlreadyExists

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
private boolean cookieHeaderAlreadyExists(HttpResponse response, Cookie cookieValue) {
    List<String> setCookieHeaders = response.getHeader(SET_COOKIE.toString());
    for (String setCookieHeader : setCookieHeaders) {
        String existingCookieName = ClientCookieDecoder.LAX.decode(setCookieHeader).name();
        String existingCookieValue = ClientCookieDecoder.LAX.decode(setCookieHeader).value();
        if (existingCookieName.equalsIgnoreCase(cookieValue.getName().getValue()) && existingCookieValue.equalsIgnoreCase(cookieValue.getValue().getValue())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:12,代码来源:MockServerResponseToHttpServletResponseEncoder.java


示例11: handleHttpRequest

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
public void handleHttpRequest(ChannelHandlerContext ctx, HttpObject obj) throws Exception {
  	Logger.debug("got http message " + obj);
  	
  	if (obj instanceof HttpContent) {
  		if (this.decoder == null) {
  			Logger.error("Got chunk before getting headers!");	
  			return;
  		}
  		
  		this.decoder.offer((HttpContent)obj);
  		return;
  	}    	

  	if (!(obj instanceof HttpResponse)) {
	Logger.error("Got unknown instead of headers!");	
          return;
      }

  	HttpResponse resp = (HttpResponse) obj;

  	// keep the cookies - especially Session!
      List<String> cookies = resp.headers().getAll(Names.SET_COOKIE);
      
      for (String cookie : cookies) {
      	Cookie c = ClientCookieDecoder.STRICT.decode(cookie);
     		this.cookies.put(c.name(), c);
      }
      
      this.decoder = new HttpBodyRequestDecoder(4096 * 1024, new IBodyCallback() {			
	@Override
	public void ready(Memory mem) {
		// if response is empty ignore
		if (mem.getLength() == 0)
			return;
		
		FuncResult<CompositeStruct> pres = CompositeParser.parseJson(mem);
		
		if (pres.hasErrors()) {
			Logger.error("Error parsing response JSON!");  
			return;
		}
		
		CompositeStruct croot = pres.getResult();
		
		if ((croot == null) || !(croot instanceof RecordStruct)) {
			Logger.error("Error parsing response JSON!");  
			return;
		}
		
        ClientHandler.this.session.receiveMessage(MessageUtil.fromRecord((RecordStruct) croot));
	}
	
	@Override
	public void fail() {
		Logger.error("Failure processing http response");
	}
});
  }
 
开发者ID:Gadreel,项目名称:divconq,代码行数:59,代码来源:ClientHandler.java


示例12: channelRead0

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	//System.out.println("download client got object: " + msg.getClass().getName());

   	if (msg instanceof HttpContent) {
   		HttpContent chunk = (HttpContent) msg;
       	
		try {
			//System.out.println("client offered content");
			int camt = chunk.content().readableBytes();
			
			for (ByteBuffer bb : chunk.content().nioBuffers())
				this.dest.write(bb);
			
			this.sent += camt;

			this.callback.getContext().setAmountCompleted((int)(this.sent * 100 / this.size));
			
			// final only if not canceled
			if (chunk instanceof LastHttpContent) 
				this.finish();
		}
		catch (IOException x) {
			this.callback.error(1, "Failed download because of local io error: " + x);
			this.finish();
		}
		
   		return;
   	}    	

   	if (!(msg instanceof HttpResponse)) {
		System.out.println("Got unknown instead of headers!");	// TODO
           return;
       }

   	HttpResponse resp = (HttpResponse) msg;

   	// keep the cookies - especially Session!
       List<String> cookies = resp.headers().getAll(Names.SET_COOKIE);
       
       for (String cookie : cookies) {
       	Cookie c = ClientCookieDecoder.STRICT.decode(cookie);
      		this.cookies.put(c.name(), c);
       }

	// TODO if error response then cancel otherwise 
	// ignore we don't care 	
	
	//System.out.println("Got response: " + resp);
}
 
开发者ID:Gadreel,项目名称:divconq,代码行数:51,代码来源:DownloadHandler.java


示例13: saveCookies

import io.netty.handler.codec.http.cookie.ClientCookieDecoder; //导入依赖的package包/类
/**
 * Save session cookies from the HTTP response header to the cookie store.
 *
 * <p>Multiple cookies are </b>not</b> folded in to one {@code Set-Cookie} header per RFC 6265.
 *
 * @see <a href="https://tools.ietf.org/html/rfc6265#section-3">RFC 6265 3.Overview</a>
 */
private void saveCookies(FullHttpResponse response) {
  for (String cookieString : response.headers().getAll(HttpHeaderNames.SET_COOKIE)) {
    Cookie cookie = ClientCookieDecoder.STRICT.decode(cookieString);
    cookieStore.put(cookie.name(), cookie);
  }
}
 
开发者ID:google,项目名称:nomulus,代码行数:14,代码来源:HttpsRelayServiceHandler.java



注:本文中的io.netty.handler.codec.http.cookie.ClientCookieDecoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectAdapterFactory类代码示例发布时间:2022-05-22
下一篇:
Java USLPort类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap