Update to latest version of Netty.

This commit is contained in:
marcin.sciesinski
2020-05-06 02:48:44 -07:00
parent 8c8afe7458
commit 83172e7add
7 changed files with 43 additions and 36 deletions

View File

@@ -19,7 +19,7 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.6.10.Final</version>
<version>3.10.6.Final</version>
</dependency>
</dependencies>
<build>

View File

@@ -227,12 +227,12 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (headers != null) {
for (Map.Entry<String, String> header : headers.entrySet())
response.setHeader(header.getKey(), header.getValue());
response.headers().set(header.getKey(), header.getValue());
}
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
response.headers().set(CONTENT_LENGTH, response.getContent().readableBytes());
}
ChannelFuture future = e.getChannel().write(response);
@@ -253,7 +253,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (headers != null) {
for (Map.Entry<String, String> header : headers.entrySet())
response.setHeader(header.getKey(), header.getValue());
response.headers().set(header.getKey(), header.getValue());
}
response.setContent(ChannelBuffers.copiedBuffer(bytes));
@@ -262,7 +262,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, length);
response.headers().set(CONTENT_LENGTH, length);
}
// Write the response.
@@ -275,7 +275,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
response.headers().set(CONTENT_LENGTH, response.getContent().readableBytes());
}
// Write the response.
@@ -298,7 +298,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (headers != null) {
for (Map.Entry<String, String> header : headers.entrySet())
response.setHeader(header.getKey(), header.getValue());
response.headers().set(header.getKey(), header.getValue());
}
int length = 0;
@@ -312,18 +312,18 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
String responseString = writer.toString();
response.setContent(ChannelBuffers.copiedBuffer(responseString, CharsetUtil.UTF_8));
response.setHeader(CONTENT_TYPE, "application/xml; charset=UTF-8");
response.headers().set(CONTENT_TYPE, "application/xml; charset=UTF-8");
length = responseString.length();
} else {
response.setContent(ChannelBuffers.copiedBuffer("OK", CharsetUtil.UTF_8));
response.setHeader(CONTENT_TYPE, "text/plain");
response.headers().set(CONTENT_TYPE, "text/plain");
length = 2;
}
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, length);
response.headers().set(CONTENT_LENGTH, length);
}
// Write the response.
@@ -336,7 +336,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
response.headers().set(CONTENT_LENGTH, response.getContent().readableBytes());
}
// Write the response.
@@ -359,13 +359,13 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
response.setContent(ChannelBuffers.copiedBuffer(html, CharsetUtil.UTF_8));
response.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8");
response.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8");
int length = html.length();
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, length);
response.headers().set(CONTENT_LENGTH, length);
}
// Write the response.
@@ -378,7 +378,7 @@ public class LotroHttpRequestHandler extends SimpleChannelUpstreamHandler {
if (keepAlive) {
// Add 'Content-Length' header only for a keep-alive connection.
response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes());
response.headers().set(CONTENT_LENGTH, response.getContent().readableBytes());
}
// Write the response.

View File

@@ -16,7 +16,12 @@ import com.gempukku.lotro.game.state.GameEvent;
import com.gempukku.polling.LongPollingResource;
import com.gempukku.polling.LongPollingSystem;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.*;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.jboss.netty.handler.codec.http.cookie.Cookie;
import org.jboss.netty.handler.codec.http.cookie.ServerCookieDecoder;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -221,13 +226,13 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri
}
private Set<Phase> getAutoPassPhases(HttpRequest request) {
CookieDecoder cookieDecoder = new CookieDecoder();
String cookieHeader = request.getHeader(HttpHeaders.Names.COOKIE);
ServerCookieDecoder cookieDecoder = ServerCookieDecoder.STRICT;
String cookieHeader = request.headers().get(HttpHeaders.Names.COOKIE);
if (cookieHeader != null) {
Set<Cookie> cookies = cookieDecoder.decode(cookieHeader);
for (Cookie cookie : cookies) {
if (cookie.getName().equals("autoPassPhases")) {
final String[] phases = cookie.getValue().split("0");
if (cookie.name().equals("autoPassPhases")) {
final String[] phases = cookie.value().split("0");
Set<Phase> result = new HashSet<Phase>();
for (String phase : phases)
result.add(Phase.valueOf(phase));
@@ -235,7 +240,7 @@ public class GameRequestHandler extends LotroServerRequestHandler implements Uri
}
}
for (Cookie cookie : cookies) {
if (cookie.getName().equals("autoPass") && cookie.getValue().equals("false"))
if (cookie.name().equals("autoPass") && cookie.value().equals("false"))
return Collections.emptySet();
}
}

View File

@@ -10,9 +10,16 @@ import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.service.LoggedUserHolder;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.*;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.COOKIE;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.SET_COOKIE;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.QueryStringDecoder;
import org.jboss.netty.handler.codec.http.cookie.Cookie;
import org.jboss.netty.handler.codec.http.cookie.CookieEncoder;
import org.jboss.netty.handler.codec.http.cookie.DefaultCookie;
import org.jboss.netty.handler.codec.http.cookie.ServerCookieDecoder;
import org.jboss.netty.handler.codec.http.cookie.ServerCookieEncoder;
import org.jboss.netty.handler.codec.http.multipart.Attribute;
import org.jboss.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
import org.jboss.netty.handler.codec.http.multipart.InterfaceHttpData;
@@ -62,13 +69,13 @@ public class LotroServerRequestHandler {
}
private String getLoggedUser(HttpRequest request) {
CookieDecoder cookieDecoder = new CookieDecoder();
String cookieHeader = request.getHeader(COOKIE);
ServerCookieDecoder cookieDecoder = ServerCookieDecoder.STRICT;
String cookieHeader = request.headers().get(COOKIE);
if (cookieHeader != null) {
Set<Cookie> cookies = cookieDecoder.decode(cookieHeader);
for (Cookie cookie : cookies) {
if (cookie.getName().equals("loggedUser")) {
String value = cookie.getValue();
if (cookie.name().equals("loggedUser")) {
String value = cookie.value();
if (value != null) {
return _loggedUserHolder.getLoggedUser(value);
}
@@ -162,10 +169,7 @@ public class LotroServerRequestHandler {
protected Map<String, String> logUserReturningHeaders(MessageEvent e, String login) throws SQLException {
_playerDao.updateLastLoginIp(login, ((InetSocketAddress) e.getRemoteAddress()).getAddress().getHostAddress());
CookieEncoder cookieEncoder = new CookieEncoder(true);
for (Map.Entry<String, String> cookie : _loggedUserHolder.logUser(login).entrySet())
cookieEncoder.addCookie(cookie.getKey(), cookie.getValue());
return Collections.singletonMap(SET_COOKIE, cookieEncoder.encode());
String sessionId = _loggedUserHolder.logUser(login);
return Collections.singletonMap(SET_COOKIE, ServerCookieEncoder.STRICT.encode("loggedUser", sessionId));
}
}

View File

@@ -74,7 +74,7 @@ public class RootUriRequestHandler implements UriRequestHandler {
} else if (uri.equals(_serverContextPath)) {
_statusRequestHandler.handleRequest(uri.substring(_serverContextPath.length()), request, context, responseWriter, e);
} else {
String origin = request.getHeader("Origin");
String origin = request.headers().get("Origin");
if (origin != null) {
if (!originPattern.matcher(origin).matches())
throw new HttpProcessingException(403);

View File

@@ -49,7 +49,7 @@ public class WebRequestHandler implements UriRequestHandler {
}
private boolean clientHasCurrentVersion(HttpRequest request, String etag) {
String ifNoneMatch = request.getHeader(IF_NONE_MATCH);
String ifNoneMatch = request.headers().get(IF_NONE_MATCH);
if (ifNoneMatch != null) {
String[] clientKnownVersions = ifNoneMatch.split(",");
for (String clientKnownVersion : clientKnownVersions) {

View File

@@ -39,14 +39,12 @@ public class LoggedUserHolder {
return null;
}
public Map<String, String> logUser(String userName) {
public String logUser(String userName) {
_readWriteLock.writeLock().lock();
try {
Map<String, String> cookies = new HashMap<String, String>();
String userValue = insertValueForUser(userName);
cookies.put("loggedUser", userValue);
_lastAccess.put(userValue, System.currentTimeMillis());
return cookies;
return userValue;
} finally {
_readWriteLock.writeLock().unlock();
}