Skip to content

Commit

Permalink
Merged branch 'jetty-9.2.x' into 'master'.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbordet committed Jan 9, 2015
2 parents 978a7e8 + bb2872b commit 8a27385
Show file tree
Hide file tree
Showing 24 changed files with 780 additions and 115 deletions.
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
.classpath
.project
.settings
.gitignore

# maven
target/
*/src/main/java/META-INF/
*.versionsBackup
*.releaseBackup
bin/

# common junk
*.log
*.swp
*.diff
*.patch
~*
*.sw[a-p]
*.bak
*.backup
*.debug
*.dump

# vim
.*.sw[a-p]
*~
~*

# intellij
# intellij / android studio
*.iml
*.ipr
*.iws
Expand All @@ -34,12 +41,5 @@ bin/
# netbeans
/nbproject

# vim
.*.sw[a-p]

# merge tooling
*.orig

#maven
*.versionsBackup
*.releaseBackup
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@ protected void normalizeRequest(Request request)
CookieStore cookieStore = getHttpClient().getCookieStore();
if (cookieStore != null)
{
StringBuilder cookies = convertCookies(cookieStore.get(request.getURI()), null);
cookies = convertCookies(request.getCookies(), cookies);
if (cookies != null)
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
URI uri = request.getURI();
if (uri != null)
{
StringBuilder cookies = convertCookies(cookieStore.get(uri), null);
cookies = convertCookies(request.getCookies(), cookies);
if (cookies != null)
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
}
}

// Authorization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.UnsupportedEncodingException;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -57,6 +58,8 @@

public class HttpRequest implements Request
{
private static final URI NULL_URI = URI.create("null:0");

private final HttpFields headers = new HttpFields();
private final Fields params = new Fields(true);
private final List<Response.ResponseListener> responseListeners = new ArrayList<>();
Expand Down Expand Up @@ -158,22 +161,30 @@ public String getPath()
@Override
public Request path(String path)
{
URI uri = URI.create(path);
String rawPath = uri.getRawPath();
if (uri.isOpaque())
rawPath = path;
if (rawPath == null)
rawPath = "";
this.path = rawPath;
String query = uri.getRawQuery();
if (query != null)
URI uri = newURI(path);
if (uri == null)
{
this.path = path;
this.query = null;
}
else
{
this.query = query;
params.clear();
extractParams(query);
String rawPath = uri.getRawPath();
if (uri.isOpaque())
rawPath = path;
if (rawPath == null)
rawPath = "";
this.path = rawPath;
String query = uri.getRawQuery();
if (query != null)
{
this.query = query;
params.clear();
extractParams(query);
}
if (uri.isAbsolute())
this.path = buildURI(false).toString();
}
if (uri.isAbsolute())
this.path = buildURI(false).toString();
this.uri = null;
return this;
}
Expand All @@ -187,9 +198,9 @@ public String getQuery()
@Override
public URI getURI()
{
if (uri != null)
return uri;
return uri = buildURI(true);
if (uri == null)
uri = buildURI(true);
return uri == NULL_URI ? null : uri;
}

@Override
Expand Down Expand Up @@ -762,12 +773,28 @@ private URI buildURI(boolean withQuery)
String query = getQuery();
if (query != null && withQuery)
path += "?" + query;
URI result = URI.create(path);
URI result = newURI(path);
if (result == null)
return NULL_URI;
if (!result.isAbsolute() && !result.isOpaque())
result = URI.create(new Origin(getScheme(), getHost(), getPort()).asString() + path);
return result;
}

private URI newURI(String uri)
{
try
{
return new URI(uri);
}
catch (URISyntaxException x)
{
// The "path" of a HTTP request may not be a URI,
// for example for CONNECT 127.0.0.1:8080 or OPTIONS *.
return null;
}
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ private void assumeConnectTimeout(String host, int port, int connectTimeout) thr
// Expected timeout during connect, continue the test.
Assume.assumeTrue(true);
}
catch (Throwable x)
{
// Abort if any other exception happens.
Assume.assumeTrue(false);
}
}

private class TimeoutHandler extends AbstractHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.eclipse.jetty.proxy;

import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.net.ConnectException;
import java.net.Socket;
Expand All @@ -28,7 +26,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -64,6 +61,8 @@
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ProxyTunnellingTest
{
@Rule
Expand Down Expand Up @@ -148,8 +147,10 @@ public void testOneExchangeViaSSL() throws Exception

try
{
// Use a numeric host to test the URI of the CONNECT request.
String host = "127.0.0.1";
String body = "BODY";
ContentResponse response = httpClient.newRequest("localhost", serverConnector.getLocalPort())
ContentResponse response = httpClient.newRequest(host, serverConnector.getLocalPort())
.scheme(HttpScheme.HTTPS.asString())
.method(HttpMethod.GET)
.path("/echo?body=" + URLEncoder.encode(body, "UTF-8"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void callOpen(Object websocket, EndpointConfig config)
onOpen.call(websocket,config);
}

public void callPong(RemoteEndpoint.Async endpoint, Object websocket, ByteBuffer pong) throws DecodeException, IOException
public void callPong(RemoteEndpoint.Async endpoint, Object websocket, ByteBuffer pong)
{
if (onPong == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.lang.reflect.Method;
import java.nio.ByteBuffer;

import javax.websocket.DecodeException;

import org.eclipse.jetty.websocket.jsr356.JsrPongMessage;
import org.eclipse.jetty.websocket.jsr356.JsrSession;
import org.eclipse.jetty.websocket.jsr356.annotations.Param.Role;
Expand All @@ -45,7 +43,7 @@ public OnMessagePongCallable(OnMessageCallable copy)
super(copy);
}

public Object call(Object endpoint, ByteBuffer buf) throws DecodeException
public Object call(Object endpoint, ByteBuffer buf)
{
super.args[idxMessageObject] = new JsrPongMessage(buf);
return super.call(endpoint,super.args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.Reader;
import java.nio.ByteBuffer;
import java.util.Map;

import javax.websocket.CloseReason;
import javax.websocket.DecodeException;

Expand Down Expand Up @@ -123,7 +124,7 @@ public void run()
{
events.callBinaryStream(jsrsession.getAsyncRemote(),websocket,stream);
}
catch (DecodeException | IOException e)
catch (Throwable e)
{
onFatalError(e);
}
Expand Down Expand Up @@ -167,7 +168,7 @@ public void onBinaryMessage(byte[] data)
// FIN is always true here
events.callBinary(jsrsession.getAsyncRemote(),websocket,buf,true);
}
catch (DecodeException e)
catch (Throwable e)
{
onFatalError(e);
}
Expand All @@ -188,7 +189,15 @@ public void onConnect()
@Override
public void onError(Throwable cause)
{
events.callError(websocket,cause);
try
{
events.callError(websocket,cause);
}
catch (Throwable e)
{
LOG.warn("Unable to call onError with cause", cause);
LOG.warn("Call to onError resulted in exception", e);
}
}

private void onFatalError(Throwable t)
Expand All @@ -203,15 +212,15 @@ public void onFrame(Frame frame)
}

@Override
public void onInputStream(InputStream stream)
public void onInputStream(InputStream stream) throws IOException
{
try
{
events.callBinaryStream(jsrsession.getAsyncRemote(),websocket,stream);
}
catch (DecodeException | IOException e)
catch (DecodeException e)
{
onFatalError(e);
throw new RuntimeException("Unable decode input stream", e);
}
}

Expand All @@ -223,7 +232,7 @@ public void onPartialBinaryMessage(ByteBuffer buffer, boolean fin)
}
catch (DecodeException e)
{
onFatalError(e);
throw new RuntimeException("Unable decode partial binary message", e);
}
}

Expand All @@ -235,46 +244,33 @@ public void onPartialTextMessage(String message, boolean fin)
}
catch (DecodeException e)
{
onFatalError(e);
throw new RuntimeException("Unable decode partial text message", e);
}
}

@Override
public void onPing(ByteBuffer buffer)
{
try
{
events.callPong(jsrsession.getAsyncRemote(),websocket,buffer);
}
catch (DecodeException | IOException e)
{
onFatalError(e);
}
// Call pong, as there is no "onPing" method in the JSR
events.callPong(jsrsession.getAsyncRemote(),websocket,buffer);
}

@Override
public void onPong(ByteBuffer buffer)
{
try
{
events.callPong(jsrsession.getAsyncRemote(),websocket,buffer);
}
catch (DecodeException | IOException e)
{
onFatalError(e);
}
events.callPong(jsrsession.getAsyncRemote(),websocket,buffer);
}

@Override
public void onReader(Reader reader)
public void onReader(Reader reader) throws IOException
{
try
{
events.callTextStream(jsrsession.getAsyncRemote(),websocket,reader);
}
catch (DecodeException | IOException e)
catch (DecodeException e)
{
onFatalError(e);
throw new RuntimeException("Unable decode reader", e);
}
}

Expand Down Expand Up @@ -343,7 +339,7 @@ public void run()
{
events.callTextStream(jsrsession.getAsyncRemote(),websocket,stream);
}
catch (DecodeException | IOException e)
catch (Throwable e)
{
onFatalError(e);
}
Expand Down Expand Up @@ -380,7 +376,7 @@ public void onTextMessage(String message)
// FIN is always true here
events.callText(jsrsession.getAsyncRemote(),websocket,message,true);
}
catch (DecodeException e)
catch (Throwable e)
{
onFatalError(e);
}
Expand Down
Loading

0 comments on commit 8a27385

Please sign in to comment.