|
Java example source code file (WebSocketExtensionTestUtil.java)
The WebSocketExtensionTestUtil.java Java example source code/* * Copyright 2012 The Netty Project * * The Netty Project licenses this file to you under the Apache License, version * 2.0 (the "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package io.netty.handler.codec.http.websocketx.extensions; import java.util.List; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderValues; import org.easymock.EasyMock; import org.easymock.IArgumentMatcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; import io.netty.util.ReferenceCountUtil; public final class WebSocketExtensionTestUtil { public static HttpRequest newUpgradeRequest(String ext) { HttpRequest req = ReferenceCountUtil.releaseLater(new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, "/chat")); req.headers().set(HttpHeaderNames.HOST, "server.example.com"); req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET.toString().toLowerCase()); req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade"); req.headers().set(HttpHeaderNames.ORIGIN, "http://example.com"); if (ext != null) { req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS, ext); } return req; } public static HttpResponse newUpgradeResponse(String ext) { HttpResponse res = ReferenceCountUtil.releaseLater(new DefaultHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.SWITCHING_PROTOCOLS)); res.headers().set(HttpHeaderNames.HOST, "server.example.com"); res.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET.toString().toLowerCase()); res.headers().set(HttpHeaderNames.CONNECTION, "Upgrade"); res.headers().set(HttpHeaderNames.ORIGIN, "http://example.com"); if (ext != null) { res.headers().set(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS, ext); } return res; } public static WebSocketExtensionData webSocketExtensionDataEqual(String name) { EasyMock.reportMatcher(new WebSocketExtensionDataMatcher(name)); return null; } public static class WebSocketExtensionDataMatcher implements IArgumentMatcher { private final String name; public WebSocketExtensionDataMatcher(String name) { this.name = name; } @Override public void appendTo(StringBuffer buf) { buf.append("WebSocketExtensionData with name=" + name); } @Override public boolean matches(Object o) { return o instanceof WebSocketExtensionData && name.equals(((WebSocketExtensionData) o).name()); } } private WebSocketExtensionTestUtil() { // unused } static class DummyEncoder extends WebSocketExtensionEncoder { @Override protected void encode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception { // unused } } static class DummyDecoder extends WebSocketExtensionDecoder { @Override protected void decode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception { // unused } } static class Dummy2Encoder extends WebSocketExtensionEncoder { @Override protected void encode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception { // unused } } static class Dummy2Decoder extends WebSocketExtensionDecoder { @Override protected void decode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception { // unused } } } Other Java examples (source code examples)Here is a short list of links related to this Java WebSocketExtensionTestUtil.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.