Merged branch 'master' into 'jetty-9.1'.
This commit is contained in:
commit
9d571af7b0
|
@ -2,7 +2,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<version>9.0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-http-spi</artifactId>
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.http.spi;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
|
||||
public class DelegatingThreadPool extends ContainerLifeCycle implements ThreadPool
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(DelegatingThreadPool.class);
|
||||
|
||||
private Executor _executor; // memory barrier provided by start/stop semantics
|
||||
|
||||
public DelegatingThreadPool(Executor executor)
|
||||
{
|
||||
_executor=executor;
|
||||
addBean(_executor);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Executor getExecutor()
|
||||
{
|
||||
return _executor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setExecutor(Executor executor)
|
||||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException(getState());
|
||||
updateBean(_executor,executor);
|
||||
_executor=executor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void execute(Runnable job)
|
||||
{
|
||||
_executor.execute(job);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean dispatch(Runnable job)
|
||||
{
|
||||
final Executor executor=_executor;
|
||||
if (executor instanceof ThreadPool)
|
||||
return ((ThreadPool)executor).dispatch(job);
|
||||
|
||||
try
|
||||
{
|
||||
_executor.execute(job);
|
||||
return true;
|
||||
}
|
||||
catch(RejectedExecutionException e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int getIdleThreads()
|
||||
{
|
||||
final Executor executor=_executor;
|
||||
if (executor instanceof ThreadPool)
|
||||
return ((ThreadPool)executor).getIdleThreads();
|
||||
|
||||
if (executor instanceof ThreadPoolExecutor)
|
||||
{
|
||||
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||
return tpe.getPoolSize() - tpe.getActiveCount();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public int getThreads()
|
||||
{
|
||||
final Executor executor=_executor;
|
||||
if (executor instanceof ThreadPool)
|
||||
return ((ThreadPool)executor).getThreads();
|
||||
|
||||
if (executor instanceof ThreadPoolExecutor)
|
||||
{
|
||||
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||
return tpe.getPoolSize();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public boolean isLowOnThreads()
|
||||
{
|
||||
final Executor executor=_executor;
|
||||
if (executor instanceof ThreadPool)
|
||||
return ((ThreadPool)executor).isLowOnThreads();
|
||||
|
||||
if (executor instanceof ThreadPoolExecutor)
|
||||
{
|
||||
final ThreadPoolExecutor tpe = (ThreadPoolExecutor)executor;
|
||||
// getActiveCount() locks the thread pool, so execute it last
|
||||
return tpe.getPoolSize() == tpe.getMaximumPoolSize() &&
|
||||
tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void join() throws InterruptedException
|
||||
{
|
||||
final Executor executor=_executor;
|
||||
if (executor instanceof ThreadPool)
|
||||
((ThreadPool)executor).join();
|
||||
else if (executor instanceof ExecutorService)
|
||||
((ExecutorService)executor).awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
else
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
super.doStop();
|
||||
if (!(_executor instanceof LifeCycle) && (_executor instanceof ExecutorService))
|
||||
((ExecutorService)_executor).shutdownNow();
|
||||
}
|
||||
|
||||
}
|
|
@ -20,18 +20,26 @@ package org.eclipse.jetty.http.spi;
|
|||
|
||||
import com.sun.net.httpserver.HttpContext;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.NetworkConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
@ -68,10 +76,10 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
|||
public void bind(InetSocketAddress addr, int backlog) throws IOException
|
||||
{
|
||||
// check if there is already a connector listening
|
||||
Connector[] connectors = _server.getConnectors();
|
||||
Collection<NetworkConnector> connectors = _server.getBeans(NetworkConnector.class);
|
||||
if (connectors != null)
|
||||
{
|
||||
for (Connector connector : connectors)
|
||||
for (NetworkConnector connector : connectors)
|
||||
{
|
||||
if (connector.getPort() == addr.getPort()) {
|
||||
if (LOG.isDebugEnabled()) LOG.debug("server already bound to port " + addr.getPort() + ", no need to rebind");
|
||||
|
@ -86,8 +94,7 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
|||
this._addr = addr;
|
||||
|
||||
if (LOG.isDebugEnabled()) LOG.debug("binding server to port " + addr.getPort());
|
||||
SelectChannelConnector connector = new SelectChannelConnector();
|
||||
connector.setAcceptors(1);
|
||||
ServerConnector connector = new ServerConnector(_server);
|
||||
connector.setPort(addr.getPort());
|
||||
connector.setHost(addr.getHostName());
|
||||
_server.addConnector(connector);
|
||||
|
@ -121,19 +128,20 @@ public class JettyHttpServer extends com.sun.net.httpserver.HttpServer
|
|||
{
|
||||
if (executor == null)
|
||||
throw new IllegalArgumentException("missing required 'executor' argument");
|
||||
|
||||
if (!(executor instanceof ThreadPoolExecutor))
|
||||
throw new IllegalArgumentException("only java.util.concurrent.ThreadPoolExecutor instances are allowed, got: " + executor.getClass().getName());
|
||||
|
||||
if (LOG.isDebugEnabled()) LOG.debug("using ThreadPoolExecutor for server thread pool");
|
||||
this._executor = (ThreadPoolExecutor) executor;
|
||||
_server.setThreadPool(new ThreadPoolExecutorAdapter(_executor));
|
||||
ThreadPool threadPool = _server.getThreadPool();
|
||||
if (threadPool instanceof DelegatingThreadPool)
|
||||
((DelegatingThreadPool)_server.getThreadPool()).setExecutor(executor);
|
||||
else
|
||||
throw new UnsupportedOperationException("!DelegatingThreadPool");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Executor getExecutor()
|
||||
{
|
||||
return _executor;
|
||||
ThreadPool threadPool = _server.getThreadPool();
|
||||
if (threadPool instanceof DelegatingThreadPool)
|
||||
return ((DelegatingThreadPool)_server.getThreadPool()).getExecutor();
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,6 +26,9 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
|
@ -53,11 +56,12 @@ public class JettyHttpServerProvider extends HttpServerProvider
|
|||
|
||||
if (server == null)
|
||||
{
|
||||
server = new Server();
|
||||
|
||||
HandlerCollection handlerCollection = new HandlerCollection();
|
||||
handlerCollection.setHandlers(new Handler[] {new ContextHandlerCollection(), new DefaultHandler()});
|
||||
server.setHandler(handlerCollection);
|
||||
ThreadPool threadPool = new DelegatingThreadPool(new QueuedThreadPool());
|
||||
server = new Server(threadPool);
|
||||
|
||||
HandlerCollection handlerCollection = new HandlerCollection();
|
||||
handlerCollection.setHandlers(new Handler[] {new ContextHandlerCollection(), new DefaultHandler()});
|
||||
server.setHandler(handlerCollection);
|
||||
|
||||
shared = false;
|
||||
}
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.http.spi;
|
||||
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
import org.eclipse.jetty.util.thread.ThreadPool;
|
||||
|
||||
/**
|
||||
* Jetty {@link ThreadPool} that bridges requests to a {@link ThreadPoolExecutor}.
|
||||
*/
|
||||
public class ThreadPoolExecutorAdapter extends AbstractLifeCycle implements ThreadPool
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ThreadPoolExecutorAdapter.class);
|
||||
|
||||
|
||||
private ThreadPoolExecutor executor;
|
||||
|
||||
public ThreadPoolExecutorAdapter(ThreadPoolExecutor executor)
|
||||
{
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public boolean dispatch(Runnable job)
|
||||
{
|
||||
try
|
||||
{
|
||||
executor.execute(job);
|
||||
return true;
|
||||
}
|
||||
catch(RejectedExecutionException e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int getIdleThreads()
|
||||
{
|
||||
return executor.getPoolSize()-executor.getActiveCount();
|
||||
}
|
||||
|
||||
public int getThreads()
|
||||
{
|
||||
return executor.getPoolSize();
|
||||
}
|
||||
|
||||
public boolean isLowOnThreads()
|
||||
{
|
||||
return executor.getActiveCount()>=executor.getMaximumPoolSize();
|
||||
}
|
||||
|
||||
public void join() throws InterruptedException
|
||||
{
|
||||
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean isFailed()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRunning()
|
||||
{
|
||||
return !executor.isTerminated() && !executor.isTerminating();
|
||||
}
|
||||
|
||||
public boolean isStarted()
|
||||
{
|
||||
return !executor.isTerminated() && !executor.isTerminating();
|
||||
}
|
||||
|
||||
public boolean isStarting()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStopped()
|
||||
{
|
||||
return executor.isTerminated();
|
||||
}
|
||||
|
||||
public boolean isStopping()
|
||||
{
|
||||
return executor.isTerminating();
|
||||
}
|
||||
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
if (executor.isTerminated() || executor.isTerminating() || executor.isShutdown())
|
||||
throw new IllegalStateException("Cannot restart");
|
||||
}
|
||||
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
executor.shutdown();
|
||||
if (!executor.awaitTermination(60, TimeUnit.SECONDS))
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
}
|
|
@ -67,8 +67,10 @@ public class HttpTester
|
|||
{
|
||||
Response r=new Response();
|
||||
HttpParser parser =new HttpParser(r);
|
||||
parser.parseNext(response);
|
||||
return r;
|
||||
if (parser.parseNext(response))
|
||||
return r;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.concurrent.CountDownLatch;
|
|||
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;
|
||||
|
|
|
@ -116,7 +116,6 @@ public class ServerConnector extends AbstractNetworkConnector
|
|||
this(server,null,null,null,acceptors,selectors,new HttpConnectionFactory());
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Generic Server Connection with default configuration.
|
||||
* <p>Construct a Server Connector with the passed Connection factories.</p>
|
||||
|
|
|
@ -39,8 +39,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
|
||||
/**
|
||||
* JSON Parser and Generator.
|
||||
*
|
||||
* <p>
|
||||
* <p />
|
||||
* This class provides some static methods to convert POJOs to and from JSON
|
||||
* notation. The mapping from JSON to java is:
|
||||
*
|
||||
|
@ -52,9 +51,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* null ==> null
|
||||
* bool ==> Boolean
|
||||
* </pre>
|
||||
*
|
||||
* </p>
|
||||
* <p>
|
||||
|
||||
* The java to JSON mapping is:
|
||||
*
|
||||
* <pre>
|
||||
|
@ -68,30 +65,27 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* Object --> string (dubious!)
|
||||
* </pre>
|
||||
*
|
||||
* </p>
|
||||
* <p>
|
||||
* The interface {@link JSON.Convertible} may be implemented by classes that
|
||||
* wish to externalize and initialize specific fields to and from JSON objects.
|
||||
* Only directed acyclic graphs of objects are supported.
|
||||
* </p>
|
||||
* <p>
|
||||
* <p />
|
||||
* The interface {@link JSON.Generator} may be implemented by classes that know
|
||||
* how to render themselves as JSON and the {@link #toString(Object)} method
|
||||
* will use {@link JSON.Generator#addJSON(Appendable)} to generate the JSON.
|
||||
* The class {@link JSON.Literal} may be used to hold pre-generated JSON object.
|
||||
* <p>
|
||||
* <p />
|
||||
* The interface {@link JSON.Convertor} may be implemented to provide static
|
||||
* convertors for objects that may be registered with
|
||||
* {@link #registerConvertor(Class, org.eclipse.jetty.util.ajax.JSON.Convertor)}
|
||||
* . These convertors are looked up by class, interface and super class by
|
||||
* converters for objects that may be registered with
|
||||
* {@link #registerConvertor(Class, Convertor)}.
|
||||
* These converters are looked up by class, interface and super class by
|
||||
* {@link #getConvertor(Class)}.
|
||||
* </p>
|
||||
* <p>If a JSON object has a "class" field, then a java class for that name is
|
||||
* looked up and the method {@link convertTo(Class,Map)} is used to find a
|
||||
* Convertor for that class. If a JSON object has a "x-class" field then a
|
||||
* direct lookup for a Convertor for that named x-class is done, so that none
|
||||
* java classes may be converted.
|
||||
* </p>
|
||||
* <p />
|
||||
* If a JSON object has a "class" field, then a java class for that name is
|
||||
* loaded and the method {@link #convertTo(Class,Map)} is used to find a
|
||||
* {@link JSON.Convertor} for that class.
|
||||
* <p />
|
||||
* If a JSON object has a "x-class" field then a direct lookup for a
|
||||
* {@link JSON.Convertor} for that class name is done (without loading the class).
|
||||
*/
|
||||
public class JSON
|
||||
{
|
||||
|
@ -105,7 +99,6 @@ public class JSON
|
|||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @return the initial stringBuffer size to use when creating JSON strings
|
||||
* (default 1024)
|
||||
|
@ -115,7 +108,6 @@ public class JSON
|
|||
return _stringBufferSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param stringBufferSize
|
||||
* the initial stringBuffer size to use when creating JSON
|
||||
|
@ -126,7 +118,6 @@ public class JSON
|
|||
_stringBufferSize = stringBufferSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Register a {@link Convertor} for a class or interface.
|
||||
*
|
||||
|
@ -140,19 +131,16 @@ public class JSON
|
|||
DEFAULT.addConvertor(forClass,convertor);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static JSON getDefault()
|
||||
{
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public static void setDefault(JSON json)
|
||||
{
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static String toString(Object object)
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
|
||||
|
@ -160,7 +148,6 @@ public class JSON
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static String toString(Map object)
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
|
||||
|
@ -168,7 +155,6 @@ public class JSON
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static String toString(Object[] array)
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder(DEFAULT.getStringBufferSize());
|
||||
|
@ -176,7 +162,6 @@ public class JSON
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param s
|
||||
* String containing JSON object or array.
|
||||
|
@ -187,7 +172,6 @@ public class JSON
|
|||
return DEFAULT.parse(new StringSource(s),false);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param s
|
||||
* String containing JSON object or array.
|
||||
|
@ -200,7 +184,6 @@ public class JSON
|
|||
return DEFAULT.parse(new StringSource(s),stripOuterComment);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param in
|
||||
* Reader containing JSON object or array.
|
||||
|
@ -211,7 +194,6 @@ public class JSON
|
|||
return DEFAULT.parse(new ReaderSource(in),false);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param in
|
||||
* Reader containing JSON object or array.
|
||||
|
@ -224,7 +206,6 @@ public class JSON
|
|||
return DEFAULT.parse(new ReaderSource(in),stripOuterComment);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @deprecated use {@link #parse(Reader)}
|
||||
* @param in
|
||||
|
@ -237,7 +218,6 @@ public class JSON
|
|||
return DEFAULT.parse(new StringSource(IO.toString(in)),false);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @deprecated use {@link #parse(Reader, boolean)}
|
||||
* @param in
|
||||
|
@ -252,7 +232,6 @@ public class JSON
|
|||
return DEFAULT.parse(new StringSource(IO.toString(in)),stripOuterComment);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Convert Object to JSON
|
||||
*
|
||||
|
@ -267,7 +246,6 @@ public class JSON
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Convert JSON to Object
|
||||
*
|
||||
|
@ -287,7 +265,6 @@ public class JSON
|
|||
append((Appendable)buffer,object);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Append object as JSON to string buffer.
|
||||
*
|
||||
|
@ -301,32 +278,58 @@ public class JSON
|
|||
try
|
||||
{
|
||||
if (object == null)
|
||||
{
|
||||
buffer.append("null");
|
||||
else if (object instanceof Convertible)
|
||||
appendJSON(buffer,(Convertible)object);
|
||||
else if (object instanceof Generator)
|
||||
appendJSON(buffer,(Generator)object);
|
||||
}
|
||||
// Most likely first
|
||||
else if (object instanceof Map)
|
||||
{
|
||||
appendMap(buffer,(Map)object);
|
||||
else if (object instanceof Collection)
|
||||
appendArray(buffer,(Collection)object);
|
||||
else if (object.getClass().isArray())
|
||||
appendArray(buffer,object);
|
||||
else if (object instanceof Number)
|
||||
appendNumber(buffer,(Number)object);
|
||||
else if (object instanceof Boolean)
|
||||
appendBoolean(buffer,(Boolean)object);
|
||||
else if (object instanceof Character)
|
||||
appendString(buffer,object.toString());
|
||||
}
|
||||
else if (object instanceof String)
|
||||
{
|
||||
appendString(buffer,(String)object);
|
||||
}
|
||||
else if (object instanceof Number)
|
||||
{
|
||||
appendNumber(buffer,(Number)object);
|
||||
}
|
||||
else if (object instanceof Boolean)
|
||||
{
|
||||
appendBoolean(buffer,(Boolean)object);
|
||||
}
|
||||
else if (object.getClass().isArray())
|
||||
{
|
||||
appendArray(buffer,object);
|
||||
}
|
||||
else if (object instanceof Character)
|
||||
{
|
||||
appendString(buffer,object.toString());
|
||||
}
|
||||
else if (object instanceof Convertible)
|
||||
{
|
||||
appendJSON(buffer,(Convertible)object);
|
||||
}
|
||||
else if (object instanceof Generator)
|
||||
{
|
||||
appendJSON(buffer,(Generator)object);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check Convertor before Collection to support JSONCollectionConvertor
|
||||
Convertor convertor = getConvertor(object.getClass());
|
||||
if (convertor != null)
|
||||
{
|
||||
appendJSON(buffer,convertor,object);
|
||||
}
|
||||
else if (object instanceof Collection)
|
||||
{
|
||||
appendArray(buffer,(Collection)object);
|
||||
}
|
||||
else
|
||||
{
|
||||
appendString(buffer,object.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -335,14 +338,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendNull(StringBuffer buffer)
|
||||
{
|
||||
appendNull((Appendable)buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendNull(Appendable buffer)
|
||||
{
|
||||
try
|
||||
|
@ -355,14 +356,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendJSON(final StringBuffer buffer, final Convertor convertor, final Object object)
|
||||
{
|
||||
appendJSON((Appendable)buffer,convertor,object);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendJSON(final Appendable buffer, final Convertor convertor, final Object object)
|
||||
{
|
||||
appendJSON(buffer,new Convertible()
|
||||
|
@ -378,14 +377,12 @@ public class JSON
|
|||
});
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendJSON(final StringBuffer buffer, Convertible converter)
|
||||
{
|
||||
appendJSON((Appendable)buffer,converter);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendJSON(final Appendable buffer, Convertible converter)
|
||||
{
|
||||
ConvertableOutput out=new ConvertableOutput(buffer);
|
||||
|
@ -393,27 +390,23 @@ public class JSON
|
|||
out.complete();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendJSON(StringBuffer buffer, Generator generator)
|
||||
{
|
||||
generator.addJSON(buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendJSON(Appendable buffer, Generator generator)
|
||||
{
|
||||
generator.addJSON(buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendMap(StringBuffer buffer, Map<?,?> map)
|
||||
{
|
||||
appendMap((Appendable)buffer,map);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendMap(Appendable buffer, Map<?,?> map)
|
||||
{
|
||||
try
|
||||
|
@ -444,14 +437,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendArray(StringBuffer buffer, Collection collection)
|
||||
{
|
||||
appendArray((Appendable)buffer,collection);
|
||||
appendArray((Appendable)buffer,collection);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendArray(Appendable buffer, Collection collection)
|
||||
{
|
||||
try
|
||||
|
@ -482,14 +473,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendArray(StringBuffer buffer, Object array)
|
||||
{
|
||||
appendArray((Appendable)buffer,array);
|
||||
appendArray((Appendable)buffer,array);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendArray(Appendable buffer, Object array)
|
||||
{
|
||||
try
|
||||
|
@ -518,14 +507,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendBoolean(StringBuffer buffer, Boolean b)
|
||||
{
|
||||
appendBoolean((Appendable)buffer,b);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendBoolean(Appendable buffer, Boolean b)
|
||||
{
|
||||
try
|
||||
|
@ -535,7 +522,7 @@ public class JSON
|
|||
appendNull(buffer);
|
||||
return;
|
||||
}
|
||||
buffer.append(b.booleanValue()?"true":"false");
|
||||
buffer.append(b?"true":"false");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@ -543,14 +530,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendNumber(StringBuffer buffer, Number number)
|
||||
{
|
||||
appendNumber((Appendable)buffer,number);
|
||||
appendNumber((Appendable)buffer,number);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendNumber(Appendable buffer, Number number)
|
||||
{
|
||||
try
|
||||
|
@ -568,14 +553,12 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Deprecated
|
||||
public void appendString(StringBuffer buffer, String string)
|
||||
{
|
||||
appendString((Appendable)buffer,string);
|
||||
appendString((Appendable)buffer,string);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void appendString(Appendable buffer, String string)
|
||||
{
|
||||
if (string == null)
|
||||
|
@ -589,37 +572,31 @@ public class JSON
|
|||
|
||||
// Parsing utilities
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected String toString(char[] buffer, int offset, int length)
|
||||
{
|
||||
return new String(buffer,offset,length);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Map<String, Object> newMap()
|
||||
{
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Object[] newArray(int size)
|
||||
{
|
||||
return new Object[size];
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected JSON contextForArray()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected JSON contextFor(String field)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Object convertTo(Class type, Map map)
|
||||
{
|
||||
if (type != null && Convertible.class.isAssignableFrom(type))
|
||||
|
@ -644,7 +621,6 @@ public class JSON
|
|||
return map;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Register a {@link Convertor} for a class or interface.
|
||||
*
|
||||
|
@ -658,7 +634,6 @@ public class JSON
|
|||
_convertors.put(forClass.getName(),convertor);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Lookup a convertor for a class.
|
||||
* <p>
|
||||
|
@ -677,7 +652,7 @@ public class JSON
|
|||
if (convertor == null && this != DEFAULT)
|
||||
convertor = DEFAULT.getConvertor(cls);
|
||||
|
||||
while (convertor == null && cls != null && cls != Object.class)
|
||||
while (convertor == null && cls != Object.class)
|
||||
{
|
||||
Class[] ifs = cls.getInterfaces();
|
||||
int i = 0;
|
||||
|
@ -692,7 +667,6 @@ public class JSON
|
|||
return convertor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Register a {@link JSON.Convertor} for a named class or interface.
|
||||
*
|
||||
|
@ -706,7 +680,6 @@ public class JSON
|
|||
_convertors.put(name,convertor);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Lookup a convertor for a named class.
|
||||
*
|
||||
|
@ -716,14 +689,12 @@ public class JSON
|
|||
*/
|
||||
public Convertor getConvertorFor(String name)
|
||||
{
|
||||
String clsName = name;
|
||||
Convertor convertor = _convertors.get(clsName);
|
||||
Convertor convertor = _convertors.get(name);
|
||||
if (convertor == null && this != DEFAULT)
|
||||
convertor = DEFAULT.getConvertorFor(clsName);
|
||||
convertor = DEFAULT.getConvertorFor(name);
|
||||
return convertor;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object parse(Source source, boolean stripOuterComment)
|
||||
{
|
||||
int comment_state = 0; // 0=no comment, 1="/", 2="/*", 3="/* *" -1="//"
|
||||
|
@ -811,7 +782,6 @@ public class JSON
|
|||
return o;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Object parse(Source source)
|
||||
{
|
||||
int comment_state = 0; // 0=no comment, 1="/", 2="/*", 3="/* *" -1="//"
|
||||
|
@ -911,13 +881,11 @@ public class JSON
|
|||
return null;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Object handleUnknown(Source source, char c)
|
||||
{
|
||||
throw new IllegalStateException("unknown char '" + c + "'(" + (int)c + ") in " + source);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Object parseObject(Source source)
|
||||
{
|
||||
if (source.next() != '{')
|
||||
|
@ -952,10 +920,10 @@ public class JSON
|
|||
String xclassname = (String)map.get("x-class");
|
||||
if (xclassname != null)
|
||||
{
|
||||
Convertor c = getConvertorFor(xclassname);
|
||||
if (c != null)
|
||||
return c.fromJSON(map);
|
||||
LOG.warn("no Convertor for xclassname '%s'", xclassname);
|
||||
Convertor c = getConvertorFor(xclassname);
|
||||
if (c != null)
|
||||
return c.fromJSON(map);
|
||||
LOG.warn("No Convertor for x-class '{}'", xclassname);
|
||||
}
|
||||
|
||||
String classname = (String)map.get("class");
|
||||
|
@ -968,14 +936,13 @@ public class JSON
|
|||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
LOG.warn("no Class for classname '%s'", classname);
|
||||
LOG.warn("No Class for '{}'", classname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected Object parseArray(Source source)
|
||||
{
|
||||
if (source.next() != '[')
|
||||
|
@ -1042,7 +1009,6 @@ public class JSON
|
|||
throw new IllegalStateException("unexpected end of array");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected String parseString(Source source)
|
||||
{
|
||||
if (source.next() != '"')
|
||||
|
@ -1110,7 +1076,6 @@ public class JSON
|
|||
else if (c == '\\')
|
||||
{
|
||||
escape = true;
|
||||
continue;
|
||||
}
|
||||
else if (c == '\"')
|
||||
{
|
||||
|
@ -1118,7 +1083,9 @@ public class JSON
|
|||
return toString(scratch,0,i);
|
||||
}
|
||||
else
|
||||
{
|
||||
scratch[i++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
// Missing end quote, but return string anyway ?
|
||||
|
@ -1175,17 +1142,19 @@ public class JSON
|
|||
else if (c == '\\')
|
||||
{
|
||||
escape = true;
|
||||
continue;
|
||||
}
|
||||
else if (c == '\"')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public Number parseNumber(Source source)
|
||||
{
|
||||
boolean minus = false;
|
||||
|
@ -1270,7 +1239,6 @@ public class JSON
|
|||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void seekTo(char seek, Source source)
|
||||
{
|
||||
while (source.hasNext())
|
||||
|
@ -1287,7 +1255,6 @@ public class JSON
|
|||
throw new IllegalStateException("Expected '" + seek + "'");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected char seekTo(String seek, Source source)
|
||||
{
|
||||
while (source.hasNext())
|
||||
|
@ -1306,7 +1273,6 @@ public class JSON
|
|||
throw new IllegalStateException("Expected one of '" + seek + "'");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected static void complete(String seek, Source source)
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -1398,7 +1364,7 @@ public class JSON
|
|||
_buffer.append(c);
|
||||
QuotedStringTokenizer.quote(_buffer,name);
|
||||
_buffer.append(':');
|
||||
appendNumber(_buffer,new Double(value));
|
||||
appendNumber(_buffer, value);
|
||||
c = ',';
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -1444,7 +1410,6 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public interface Source
|
||||
{
|
||||
boolean hasNext();
|
||||
|
@ -1456,7 +1421,6 @@ public class JSON
|
|||
char[] scratchBuffer();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class StringSource implements Source
|
||||
{
|
||||
private final String string;
|
||||
|
@ -1500,7 +1464,6 @@ public class JSON
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public static class ReaderSource implements Source
|
||||
{
|
||||
private Reader _reader;
|
||||
|
@ -1567,7 +1530,6 @@ public class JSON
|
|||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* JSON Output class for use by {@link Convertible}.
|
||||
*/
|
||||
|
@ -1586,7 +1548,6 @@ public class JSON
|
|||
public void add(String name, boolean value);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* JSON Convertible object. Object can implement this interface in a similar
|
||||
|
@ -1607,7 +1568,6 @@ public class JSON
|
|||
public void fromJSON(Map object);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Static JSON Convertor.
|
||||
* <p>
|
||||
|
@ -1626,7 +1586,6 @@ public class JSON
|
|||
public Object fromJSON(Map object);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* JSON Generator. A class that can add it's JSON representation directly to
|
||||
* a StringBuffer. This is useful for object instances that are frequently
|
||||
|
@ -1637,7 +1596,6 @@ public class JSON
|
|||
public void addJSON(Appendable buffer);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* A Literal JSON generator A utility instance of {@link JSON.Generator}
|
||||
* that holds a pre-generated string on JSON text.
|
||||
|
@ -1646,7 +1604,6 @@ public class JSON
|
|||
{
|
||||
private String _json;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Construct a literal JSON instance for use by
|
||||
* {@link JSON#toString(Object)}. If {@link Log#isDebugEnabled()} is
|
||||
|
|
|
@ -40,9 +40,10 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
public class JSONDateConvertor implements JSON.Convertor
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(JSONDateConvertor.class);
|
||||
private boolean _fromJSON;
|
||||
DateCache _dateCache;
|
||||
SimpleDateFormat _format;
|
||||
|
||||
private final boolean _fromJSON;
|
||||
private final DateCache _dateCache;
|
||||
private final SimpleDateFormat _format;
|
||||
|
||||
public JSONDateConvertor()
|
||||
{
|
||||
|
@ -53,7 +54,7 @@ public class JSONDateConvertor implements JSON.Convertor
|
|||
{
|
||||
this(DateCache.DEFAULT_FORMAT,TimeZone.getTimeZone("GMT"),fromJSON);
|
||||
}
|
||||
|
||||
|
||||
public JSONDateConvertor(String format,TimeZone zone,boolean fromJSON)
|
||||
{
|
||||
_dateCache=new DateCache(format);
|
||||
|
@ -62,7 +63,7 @@ public class JSONDateConvertor implements JSON.Convertor
|
|||
_format=new SimpleDateFormat(format);
|
||||
_format.setTimeZone(zone);
|
||||
}
|
||||
|
||||
|
||||
public JSONDateConvertor(String format, TimeZone zone, boolean fromJSON, Locale locale)
|
||||
{
|
||||
_dateCache = new DateCache(format, locale);
|
||||
|
@ -71,7 +72,7 @@ public class JSONDateConvertor implements JSON.Convertor
|
|||
_format = new SimpleDateFormat(format, new DateFormatSymbols(locale));
|
||||
_format.setTimeZone(zone);
|
||||
}
|
||||
|
||||
|
||||
public Object fromJSON(Map map)
|
||||
{
|
||||
if (!_fromJSON)
|
||||
|
@ -85,7 +86,7 @@ public class JSONDateConvertor implements JSON.Convertor
|
|||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
LOG.warn(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
* If fromJSON is true in the constructor, the JSON generated will
|
||||
* be of the form {class="com.acme.TrafficLight",value="Green"}
|
||||
* If fromJSON is false, then only the string value of the enum is generated.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JSONEnumConvertor implements JSON.Convertor
|
||||
|
@ -43,8 +43,8 @@ public class JSONEnumConvertor implements JSON.Convertor
|
|||
{
|
||||
try
|
||||
{
|
||||
Class e = Loader.loadClass(getClass(),"java.lang.Enum");
|
||||
_valueOf=e.getMethod("valueOf",new Class[]{Class.class,String.class});
|
||||
Class<?> e = Loader.loadClass(getClass(),"java.lang.Enum");
|
||||
_valueOf=e.getMethod("valueOf",Class.class,String.class);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -56,12 +56,12 @@ public class JSONEnumConvertor implements JSON.Convertor
|
|||
{
|
||||
this(false);
|
||||
}
|
||||
|
||||
|
||||
public JSONEnumConvertor(boolean fromJSON)
|
||||
{
|
||||
_fromJSON=fromJSON;
|
||||
}
|
||||
|
||||
|
||||
public Object fromJSON(Map map)
|
||||
{
|
||||
if (!_fromJSON)
|
||||
|
@ -69,11 +69,11 @@ public class JSONEnumConvertor implements JSON.Convertor
|
|||
try
|
||||
{
|
||||
Class c=Loader.loadClass(getClass(),(String)map.get("class"));
|
||||
return _valueOf.invoke(null,new Object[]{c,map.get("value")});
|
||||
return _valueOf.invoke(null,c,map.get("value"));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LOG.warn(e);
|
||||
LOG.warn(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -83,12 +83,11 @@ public class JSONEnumConvertor implements JSON.Convertor
|
|||
if (_fromJSON)
|
||||
{
|
||||
out.addClass(obj.getClass());
|
||||
out.add("value",obj.toString());
|
||||
out.add("value",((Enum)obj).name());
|
||||
}
|
||||
else
|
||||
{
|
||||
out.add(obj.toString());
|
||||
out.add(((Enum)obj).name());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util.ajax;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.util.Loader;
|
||||
|
||||
public class JSONCollectionConvertor implements JSON.Convertor
|
||||
{
|
||||
public void toJSON(Object obj, JSON.Output out)
|
||||
{
|
||||
out.addClass(obj.getClass());
|
||||
out.add("list", ((Collection)obj).toArray());
|
||||
}
|
||||
|
||||
public Object fromJSON(Map object)
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection result = (Collection)Loader.loadClass(getClass(), (String)object.get("class")).newInstance();
|
||||
Collections.addAll(result, (Object[])object.get("list"));
|
||||
return result;
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
if (x instanceof RuntimeException)
|
||||
throw (RuntimeException)x;
|
||||
throw new RuntimeException(x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.util.ajax;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class JSONCollectionConvertorTest
|
||||
{
|
||||
@Test
|
||||
public void testArrayList() throws Exception
|
||||
{
|
||||
List<String> list = new ArrayList<String>();
|
||||
Collections.addAll(list, "one", "two");
|
||||
testList(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLinkedList() throws Exception
|
||||
{
|
||||
List<String> list = new LinkedList<String>();
|
||||
Collections.addAll(list, "one", "two");
|
||||
testList(list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyOnWriteArrayList() throws Exception
|
||||
{
|
||||
List<String> list = new CopyOnWriteArrayList<String>();
|
||||
Collections.addAll(list, "one", "two");
|
||||
testList(list);
|
||||
}
|
||||
|
||||
private void testList(List<String> list1) throws Exception
|
||||
{
|
||||
JSON json = new JSON();
|
||||
json.addConvertor(List.class, new JSONCollectionConvertor());
|
||||
|
||||
Map<String, Object> object1 = new HashMap<String, Object>();
|
||||
String field = "field";
|
||||
object1.put(field, list1);
|
||||
|
||||
String string = json.toJSON(object1);
|
||||
Assert.assertTrue(string.contains(list1.getClass().getName()));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> object2 = (Map<String, Object>)json.parse(new JSON.StringSource(string));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> list2 = (List<String>)object2.get(field);
|
||||
|
||||
Assert.assertSame(list1.getClass(), list2.getClass());
|
||||
Assert.assertEquals(list1, list2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashSet() throws Exception
|
||||
{
|
||||
Set<String> set = new HashSet<String>();
|
||||
Collections.addAll(set, "one", "two", "three");
|
||||
testSet(set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTreeSet() throws Exception
|
||||
{
|
||||
Set<String> set = new TreeSet<String>();
|
||||
Collections.addAll(set, "one", "two", "three");
|
||||
testSet(set);
|
||||
}
|
||||
|
||||
private void testSet(Set<String> set1)
|
||||
{
|
||||
JSON json = new JSON();
|
||||
json.addConvertor(Set.class, new JSONCollectionConvertor());
|
||||
|
||||
String string = json.toJSON(set1);
|
||||
Assert.assertTrue(string.contains(set1.getClass().getName()));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<String> set2 = (Set<String>)json.parse(new JSON.StringSource(string));
|
||||
|
||||
Assert.assertSame(set1.getClass(), set2.getClass());
|
||||
Assert.assertEquals(set1, set2);
|
||||
}
|
||||
}
|
2
pom.xml
2
pom.xml
|
@ -419,10 +419,10 @@
|
|||
<module>jetty-distribution</module>
|
||||
<module>jetty-runner</module>
|
||||
<module>jetty-monitor</module>
|
||||
<module>jetty-http-spi</module>
|
||||
|
||||
<!-- modules that need fixed and added back, or simply dropped and not maintained
|
||||
<module>jetty-rhttp</module>
|
||||
<module>jetty-http-spi</module>
|
||||
-->
|
||||
<module>jetty-overlay-deployer</module>
|
||||
</modules>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<parent>
|
||||
<groupId>org.eclipse.jetty.tests</groupId>
|
||||
<artifactId>tests-parent</artifactId>
|
||||
<version>9.0.0-SNAPSHOT</version>
|
||||
<version>9.0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>test-integration</artifactId>
|
||||
|
@ -110,8 +110,6 @@
|
|||
<artifactId>jetty-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
<artifactId>jetty-test-helper</artifactId>
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
|
@ -27,9 +29,9 @@ import java.net.URLConnection;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.test.support.TestableJettyServer;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpRequestTester;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpSocketImpl;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
@ -55,6 +57,7 @@ public class DefaultHandlerTest
|
|||
server = new TestableJettyServer();
|
||||
server.setScheme(HttpScheme.HTTP.asString());
|
||||
server.addConfiguration("DefaultHandler.xml");
|
||||
server.addConfiguration("NIOHttp.xml");
|
||||
|
||||
server.load();
|
||||
server.start();
|
||||
|
@ -107,14 +110,15 @@ public class DefaultHandlerTest
|
|||
// Collect response
|
||||
String rawResponse = IO.toString(sock.getInputStream());
|
||||
DEBUG("--raw-response--\n" + rawResponse);
|
||||
HttpResponseTester response = new HttpResponseTester();
|
||||
response.parse(rawResponse);
|
||||
|
||||
HttpTester.Response response = HttpTester.parseResponse(rawResponse);
|
||||
|
||||
response.assertStatusOK();
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
|
||||
response.assertBody("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
|
||||
assertTrue(response.getContent().contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"));
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testMultiGET_Raw() throws Exception
|
||||
{
|
||||
|
@ -131,38 +135,43 @@ public class DefaultHandlerTest
|
|||
rawRequests.append("\r\n");
|
||||
|
||||
HttpTesting http = new HttpTesting(new HttpSocketImpl(),serverPort);
|
||||
|
||||
|
||||
List<HttpResponseTester> responses = http.requests(rawRequests);
|
||||
List<HttpTester.Response> responses = http.requests(rawRequests);
|
||||
|
||||
HttpResponseTester response = responses.get(0);
|
||||
response.assertStatusOK();
|
||||
response.assertBody("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
|
||||
HttpTester.Response response = responses.get(0);
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(response.getContent().contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"));
|
||||
|
||||
response = responses.get(1);
|
||||
response.assertStatusOK();
|
||||
response.assertBody("Host=Default\nResource=R1\n");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(response.getContent().contains("Host=Default\nResource=R1\n"));
|
||||
|
||||
response = responses.get(2);
|
||||
response.assertStatusOK();
|
||||
response.assertBody("Host=Default\nResource=R1\n");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(response.getContent().contains("Host=Default\nResource=R1\n"));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testGET_HttpTesting() throws Exception
|
||||
{
|
||||
HttpRequestTester request = new HttpRequestTester();
|
||||
HttpTester.Request request = HttpTester.newRequest();
|
||||
request.setMethod("GET");
|
||||
request.setURI("/tests/alpha.txt");
|
||||
request.addHeader("Host","localhost");
|
||||
request.addHeader("Connection","close");
|
||||
request.put("Host","localhost");
|
||||
request.put("Connection","close");
|
||||
// request.setContent(null);
|
||||
|
||||
HttpTesting testing = new HttpTesting(new HttpSocketImpl(),serverPort);
|
||||
HttpResponseTester response = testing.request(request);
|
||||
HttpTester.Response response = testing.request(request);
|
||||
|
||||
response.assertStatusOK();
|
||||
response.assertContentType("text/plain");
|
||||
response.assertBody("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals("text/plain", response.get("Content-Type"));
|
||||
assertTrue(response.getContent().contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"));
|
||||
}
|
||||
|
||||
private void DEBUG(String msg)
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.test;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -230,14 +231,15 @@ public class DigestPostTest
|
|||
try
|
||||
{
|
||||
AuthenticationStore authStore = client.getAuthenticationStore();
|
||||
authStore.addAuthentication(new DigestAuthentication(srvUrl, "test", "testuser", "password"));
|
||||
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
|
||||
client.start();
|
||||
|
||||
Request request = client.newRequest(srvUrl);
|
||||
request.method(HttpMethod.POST);
|
||||
request.content(new BytesContentProvider(__message.getBytes("UTF8")));
|
||||
_received=null;
|
||||
ContentResponse response = request.send().get(5, TimeUnit.SECONDS);
|
||||
request = request.timeout(5, TimeUnit.SECONDS);
|
||||
ContentResponse response = request.send();
|
||||
Assert.assertEquals(__message,_received);
|
||||
Assert.assertEquals(200,response.getStatus());
|
||||
}
|
||||
|
@ -255,7 +257,7 @@ public class DigestPostTest
|
|||
try
|
||||
{
|
||||
AuthenticationStore authStore = client.getAuthenticationStore();
|
||||
authStore.addAuthentication(new DigestAuthentication(srvUrl, "test", "testuser", "password"));
|
||||
authStore.addAuthentication(new DigestAuthentication(new URI(srvUrl), "test", "testuser", "password"));
|
||||
client.start();
|
||||
|
||||
String sent = IO.toString(new FileInputStream("src/test/resources/message.txt"));
|
||||
|
@ -264,7 +266,8 @@ public class DigestPostTest
|
|||
request.method(HttpMethod.POST);
|
||||
request.content(new StringContentProvider(sent));
|
||||
_received=null;
|
||||
ContentResponse response = request.send().get(5, TimeUnit.SECONDS);
|
||||
request = request.timeout(5, TimeUnit.SECONDS);
|
||||
ContentResponse response = request.send();
|
||||
|
||||
Assert.assertEquals(200,response.getStatus());
|
||||
Assert.assertEquals(sent,_received);
|
||||
|
|
|
@ -33,9 +33,9 @@ import java.util.TimeZone;
|
|||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.test.support.StringUtil;
|
||||
import org.eclipse.jetty.test.support.TestableJettyServer;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpResponseTester;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;
|
||||
import org.eclipse.jetty.test.support.rawhttp.HttpTesting;
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
|
@ -56,8 +56,6 @@ public abstract class RFC2616BaseTest
|
|||
/** STRICT RFC TESTS */
|
||||
private static final boolean STRICT = false;
|
||||
private static TestableJettyServer server;
|
||||
private List<HttpResponseTester> responses;
|
||||
private HttpResponseTester response;
|
||||
private HttpTesting http;
|
||||
|
||||
class TestFile
|
||||
|
@ -167,8 +165,9 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("123\r\n\r\n");
|
||||
req1.append("0;\r\n\r\n");
|
||||
|
||||
response = http.request(req1);
|
||||
response.assertStatus("3.6 Transfer Coding / Bad 400",HttpStatus.BAD_REQUEST_400);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
assertEquals("3.6 Transfer Coding / Bad 400",HttpStatus.BAD_REQUEST_400,response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,20 +207,20 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
responses = http.requests(req2);
|
||||
List<HttpTester.Response> responses = http.requests(req2);
|
||||
Assert.assertEquals("Response Count",3,responses.size());
|
||||
|
||||
response = responses.get(0); // Response 1
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
|
||||
response.assertBody("3.6.1 Transfer Codings / Chunked String","12345\n");
|
||||
HttpTester.Response response = responses.get(0); // Response 1
|
||||
assertEquals("3.6.1 Transfer Codings / Response 1 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / Chunked String", response.getContent().contains("12345\n"));
|
||||
|
||||
response = responses.get(1); // Response 2
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 2 Code");
|
||||
response.assertBody("3.6.1 Transfer Codings / Chunked String","6789abcde\n");
|
||||
assertEquals("3.6.1 Transfer Codings / Response 2 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / Chunked String",response.getContent().contains("6789abcde\n"));
|
||||
|
||||
response = responses.get(2); // Response 3
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 3 Code");
|
||||
response.assertNoBody("3.6.1 Transfer Codings / No Body");
|
||||
assertEquals("3.6.1 Transfer Codings / Response 3 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / No Body",response.getContent() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,20 +260,20 @@ public abstract class RFC2616BaseTest
|
|||
req3.append("Connection: close\n");
|
||||
req3.append("\n");
|
||||
|
||||
responses = http.requests(req3);
|
||||
List<HttpTester.Response> responses = http.requests(req3);
|
||||
Assert.assertEquals("Response Count",3,responses.size());
|
||||
|
||||
response = responses.get(0); // Response 1
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
|
||||
response.assertBody("3.6.1 Transfer Codings / Chunked String","fghIjk\n"); // Complete R1 string
|
||||
HttpTester.Response response = responses.get(0); // Response 1
|
||||
assertEquals("3.6.1 Transfer Codings / Response 1 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / Chunked String", response.getContent().contains("fghIjk\n")); // Complete R1 string
|
||||
|
||||
response = responses.get(1); // Response 2
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 2 Code");
|
||||
response.assertBody("3.6.1 Transfer Codings / Chunked String","lmnoPqrst\n"); // Complete R2 string
|
||||
assertEquals("3.6.1 Transfer Codings / Response 2 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / Chunked String", response.getContent().contains("lmnoPqrst\n")); // Complete R2 string
|
||||
|
||||
response = responses.get(2); // Response 3
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 3 Code");
|
||||
response.assertNoBody("3.6.1 Transfer Codings / No Body");
|
||||
assertEquals("3.6.1 Transfer Codings / Response 3 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / No Body", response.getContent() == null);
|
||||
|
||||
}
|
||||
|
||||
|
@ -305,16 +304,16 @@ public abstract class RFC2616BaseTest
|
|||
req4.append("Connection: close\n"); // close
|
||||
req4.append("\n");
|
||||
|
||||
responses = http.requests(req4);
|
||||
List<HttpTester.Response> responses = http.requests(req4);
|
||||
Assert.assertEquals("Response Count",2,responses.size());
|
||||
|
||||
response = responses.get(0); // Response 1
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 1 Code");
|
||||
response.assertBody("3.6.1 Transfer Codings / Chunked String","123456\n"); // Complete R1 string
|
||||
HttpTester.Response response = responses.get(0); // Response 1
|
||||
assertEquals("3.6.1 Transfer Codings / Response 1 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / Chunked String", response.getContent().contains("123456\n")); // Complete R1 string
|
||||
|
||||
response = responses.get(1); // Response 2
|
||||
response.assertStatusOK("3.6.1 Transfer Codings / Response 2 Code");
|
||||
response.assertNoBody("3.6.1 Transfer Codings / No Body");
|
||||
assertEquals("3.6.1 Transfer Codings / Response 2 Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("3.6.1 Transfer Codings / No Body", response.getContent() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,15 +363,15 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
responses = http.requests(req1);
|
||||
List<HttpTester.Response> responses = http.requests(req1);
|
||||
Assert.assertEquals("Response Count",2,responses.size());
|
||||
|
||||
response = responses.get(0);
|
||||
response.assertStatusOK("4.4.2 Message Length / Response Code");
|
||||
response.assertBody("4.4.2 Message Length / Body","123\n");
|
||||
HttpTester.Response response = responses.get(0);
|
||||
assertEquals("4.4.2 Message Length / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("4.4.2 Message Length / Body",response.getContent().contains("123\n"));
|
||||
response = responses.get(1);
|
||||
response.assertStatusOK("4.4.2 Message Length / Response Code");
|
||||
response.assertNoBody("4.4.2 Message Length / No Body");
|
||||
assertEquals("4.4.2 Message Length / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("4.4.2 Message Length / No Body", response.getContent() == null);
|
||||
|
||||
// 4.4.3 -
|
||||
// Client - do not send 'Content-Length' if entity-length
|
||||
|
@ -405,11 +404,11 @@ public abstract class RFC2616BaseTest
|
|||
Assert.assertEquals("Response Count",2,responses.size());
|
||||
|
||||
response = responses.get(0); // response 1
|
||||
response.assertStatusOK("4.4.3 Ignore Content-Length / Response Code");
|
||||
response.assertBody("4.4.3 Ignore Content-Length / Body","123456\n");
|
||||
assertEquals("4.4.3 Ignore Content-Length / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("4.4.3 Ignore Content-Length / Body", response.getContent().contains("123456\n"));
|
||||
response = responses.get(1); // response 2
|
||||
response.assertStatusOK("4.4.3 Ignore Content-Length / Response Code");
|
||||
response.assertBody("4.4.3 Ignore Content-Length / Body","7890AB\n");
|
||||
assertEquals("4.4.3 Ignore Content-Length / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("4.4.3 Ignore Content-Length / Body", response.getContent().contains("7890AB\n"));
|
||||
|
||||
// 4.4 - Server can request valid Content-Length from client if client
|
||||
// fails to provide a Content-Length.
|
||||
|
@ -430,8 +429,8 @@ public abstract class RFC2616BaseTest
|
|||
|
||||
response = http.request(req3);
|
||||
|
||||
response.assertStatus("4.4 Valid Content-Length Required",HttpStatus.LENGTH_REQUIRED_411);
|
||||
response.assertNoBody("4.4 Valid Content-Length Required");
|
||||
assertEquals("4.4 Valid Content-Length Required",HttpStatus.LENGTH_REQUIRED_411, response.getStatus());
|
||||
assertTrue("4.4 Valid Content-Length Required", response.getContent() == null);
|
||||
|
||||
StringBuffer req4 = new StringBuffer();
|
||||
req4.append("GET /echo/R2 HTTP/1.0\n");
|
||||
|
@ -441,8 +440,8 @@ public abstract class RFC2616BaseTest
|
|||
|
||||
response = http.request(req4);
|
||||
|
||||
response.assertStatus("4.4 Valid Content-Length Required",HttpStatus.LENGTH_REQUIRED_411);
|
||||
response.assertNoBody("4.4 Valid Content-Length Required");
|
||||
assertEquals("4.4 Valid Content-Length Required",HttpStatus.LENGTH_REQUIRED_411, response.getStatus());
|
||||
assertTrue("4.4 Valid Content-Length Required", response.getContent() == null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,10 +461,10 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\r\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK("5.2 Default Host");
|
||||
response.assertBodyContains("5.2 Default Host","Default DOCRoot");
|
||||
assertEquals("5.2 Default Host", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("5.2 Default Host",response.getContent().contains("Default DOCRoot"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -484,10 +483,10 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\r\n");
|
||||
|
||||
response = http.request(req2);
|
||||
HttpTester.Response response = http.request(req2);
|
||||
|
||||
response.assertStatusOK("5.2 Virtual Host");
|
||||
response.assertBodyContains("5.2 Virtual Host","VirtualHost DOCRoot");
|
||||
assertEquals("5.2 Virtual Host", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("5.2 Virtual Host",response.getContent().contains("VirtualHost DOCRoot"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -506,10 +505,10 @@ public abstract class RFC2616BaseTest
|
|||
req3.append("Connection: close\n");
|
||||
req3.append("\n");
|
||||
|
||||
response = http.request(req3);
|
||||
HttpTester.Response response = http.request(req3);
|
||||
|
||||
response.assertStatusOK("5.2 Virtual Host (mixed case)");
|
||||
response.assertBodyContains("5.2 Virtual Host (mixed case)","VirtualHost DOCRoot");
|
||||
assertEquals("5.2 Virtual Host (mixed case)", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("5.2 Virtual Host (mixed case)",response.getContent().contains("VirtualHost DOCRoot"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -527,10 +526,10 @@ public abstract class RFC2616BaseTest
|
|||
req4.append("Connection: close\n");
|
||||
req4.append("\n"); // no virtual host
|
||||
|
||||
response = http.request(req4);
|
||||
HttpTester.Response response = http.request(req4);
|
||||
|
||||
response.assertStatus("5.2 No Host",HttpStatus.BAD_REQUEST_400);
|
||||
response.assertNoBody("5.2 No Host");
|
||||
assertEquals("5.2 No Host",HttpStatus.BAD_REQUEST_400,response.getStatus());
|
||||
assertEquals("5.2 No Host","", response.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -549,10 +548,10 @@ public abstract class RFC2616BaseTest
|
|||
req5.append("Connection: close\n");
|
||||
req5.append("\n");
|
||||
|
||||
response = http.request(req5);
|
||||
HttpTester.Response response = http.request(req5);
|
||||
|
||||
response.assertStatusOK("5.2 Bad Host");
|
||||
response.assertBodyContains("5.2 Bad Host","Default DOCRoot"); // served by default context
|
||||
assertEquals("5.2 Bad Host",HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("5.2 Bad Host",response.getContent().contains("Default DOCRoot")); // served by default context
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -570,10 +569,10 @@ public abstract class RFC2616BaseTest
|
|||
req6.append("Connection: close\n");
|
||||
req6.append("\n");
|
||||
|
||||
response = http.request(req6);
|
||||
HttpTester.Response response = http.request(req6);
|
||||
|
||||
// No host header should always return a 400 Bad Request.
|
||||
response.assertStatus("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.1)",HttpStatus.BAD_REQUEST_400);
|
||||
assertEquals("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.1)",HttpStatus.BAD_REQUEST_400,response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -591,10 +590,10 @@ public abstract class RFC2616BaseTest
|
|||
req6.append("Connection: close\n");
|
||||
req6.append("\n");
|
||||
|
||||
response = http.request(req6);
|
||||
HttpTester.Response response = http.request(req6);
|
||||
|
||||
response.assertStatusOK("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.0)");
|
||||
response.assertBodyContains("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.1)","VirtualHost DOCRoot");
|
||||
assertEquals("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.0)",HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("5.2 Virtual Host as AbsoluteURI (No Host Header / HTTP 1.1)",response.getContent().contains("VirtualHost DOCRoot"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -613,10 +612,11 @@ public abstract class RFC2616BaseTest
|
|||
req7.append("Connection: close\n");
|
||||
req7.append("\n");
|
||||
|
||||
response = http.request(req7);
|
||||
HttpTester.Response response = http.request(req7);
|
||||
|
||||
response.assertStatusOK("5.2 Virtual Host as AbsoluteURI (and Host header)");
|
||||
response.assertBodyContains("5.2 Virtual Host as AbsoluteURI (and Host header)","VirtualHost DOCRoot");
|
||||
assertEquals("5.2 Virtual Host as AbsoluteURI (and Host header)", HttpStatus.OK_200, response.getStatus());
|
||||
System.err.println(response.getContent());
|
||||
assertTrue("5.2 Virtual Host as AbsoluteURI (and Host header)",response.getContent().contains("VirtualHost DOCRoot"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -633,11 +633,11 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK("8.1 Persistent Connections");
|
||||
response.assertHeaderExists("8.1 Persistent Connections","Content-Length");
|
||||
response.assertBodyContains("8.1 Persistent Connections","Resource=R1");
|
||||
assertEquals("8.1 Persistent Connections", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("8.1 Persistent Connections", response.get("Content-Length") != null);
|
||||
assertTrue("8.1 Persistent Connections",response.getContent().contains("Resource=R1"));
|
||||
|
||||
StringBuffer req2 = new StringBuffer();
|
||||
req2.append("GET /tests/R1.txt HTTP/1.1\n");
|
||||
|
@ -654,19 +654,19 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
responses = http.requests(req2);
|
||||
List<HttpTester.Response> responses = http.requests(req2);
|
||||
Assert.assertEquals("Response Count",2,responses.size()); // Should not have a R3 response.
|
||||
|
||||
response = responses.get(0); // response 1
|
||||
response.assertStatusOK("8.1 Persistent Connections");
|
||||
response.assertHeaderExists("8.1 Persistent Connections","Content-Length");
|
||||
response.assertBodyContains("8.1 Peristent Connections","Resource=R1");
|
||||
assertEquals("8.1 Persistent Connections", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("8.1 Persistent Connections",response.get("Content-Length") != null);
|
||||
assertTrue("8.1 Peristent Connections", response.getContent().contains("Resource=R1"));
|
||||
|
||||
response = responses.get(1); // response 2
|
||||
response.assertStatusOK("8.1.2.2 Persistent Connections / Pipeline");
|
||||
response.assertHeaderExists("8.1.2.2 Persistent Connections / Pipeline","Content-Length");
|
||||
response.assertHeader("8.1.2.2 Persistent Connections / Pipeline","Connection","close");
|
||||
response.assertBodyContains("8.1.2.2 Peristent Connections / Pipeline","Resource=R2");
|
||||
assertEquals("8.1.2.2 Persistent Connections / Pipeline", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("8.1.2.2 Persistent Connections / Pipeline", response.get("Content-Length") != null);
|
||||
assertEquals("8.1.2.2 Persistent Connections / Pipeline","close", response.get("Connection"));
|
||||
assertTrue("8.1.2.2 Peristent Connections / Pipeline", response.getContent().contains("Resource=R2"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -688,9 +688,9 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("\n");
|
||||
req2.append("12345678\n");
|
||||
|
||||
response = http.request(req2);
|
||||
HttpTester.Response response = http.request(req2);
|
||||
|
||||
response.assertStatus("8.2.3 expect failure",HttpStatus.EXPECTATION_FAILED_417);
|
||||
assertEquals("8.2.3 expect failure",HttpStatus.EXPECTATION_FAILED_417, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -715,9 +715,9 @@ public abstract class RFC2616BaseTest
|
|||
|
||||
// Should only expect 1 response.
|
||||
// The existence of 2 responses usually means a bad "HTTP/1.1 100" was received.
|
||||
response = http.request(req3);
|
||||
HttpTester.Response response = http.request(req3);
|
||||
|
||||
response.assertStatusOK("8.2.3 expect 100");
|
||||
assertEquals("8.2.3 expect 100", HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
|
||||
|
||||
|
@ -748,19 +748,19 @@ public abstract class RFC2616BaseTest
|
|||
req3.append("\n");
|
||||
req3.append("87654321"); // Body
|
||||
|
||||
List<HttpResponseTester> responses = http.requests(req3);
|
||||
List<HttpTester.Response> responses = http.requests(req3);
|
||||
|
||||
// System.err.println(responses);
|
||||
|
||||
response=responses.get(0);
|
||||
HttpTester.Response response=responses.get(0);
|
||||
// System.err.println(response.getRawResponse());
|
||||
|
||||
response.assertStatus("8.2.3 ignored no 100",302);
|
||||
assertEquals("8.2.3 ignored no 100",302, response.getStatus());
|
||||
|
||||
response=responses.get(1);
|
||||
// System.err.println(response.getRawResponse());
|
||||
response.assertStatus("8.2.3 ignored no 100",200);
|
||||
response.assertBody("87654321\n");
|
||||
assertEquals("8.2.3 ignored no 100",200, response.getStatus());
|
||||
assertTrue(response.getContent().contains("87654321\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -788,14 +788,14 @@ public abstract class RFC2616BaseTest
|
|||
http.send(sock,req4);
|
||||
|
||||
http.setTimeoutMillis(2000);
|
||||
response = http.readAvailable(sock);
|
||||
response.assertStatus("8.2.3 expect 100",HttpStatus.CONTINUE_100);
|
||||
HttpTester.Response response = http.readAvailable(sock);
|
||||
assertEquals("8.2.3 expect 100",HttpStatus.CONTINUE_100,response.getStatus());
|
||||
|
||||
http.send(sock,"654321\n"); // Now send the data
|
||||
response = http.read(sock);
|
||||
|
||||
response.assertStatusOK("8.2.3 expect 100");
|
||||
response.assertBody("8.2.3 expect 100","654321\n");
|
||||
assertEquals("8.2.3 expect 100", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("8.2.3 expect 100",response.getContent().contains("654321\n"));
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -825,20 +825,20 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Host: localhost\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK("9.2 OPTIONS");
|
||||
response.assertHeaderExists("9.2 OPTIONS","Allow");
|
||||
assertEquals("9.2 OPTIONS", HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue("9.2 OPTIONS",response.get("Allow") != null);
|
||||
// Header expected ...
|
||||
// Allow: GET, HEAD, POST, PUT, DELETE, MOVE, OPTIONS, TRACE
|
||||
String allow = response.getHeader("Allow");
|
||||
String allow = response.get("Allow");
|
||||
String expectedMethods[] =
|
||||
{ "GET", "HEAD", "POST", "PUT", "DELETE", "MOVE", "OPTIONS", "TRACE" };
|
||||
for (String expectedMethod : expectedMethods)
|
||||
{
|
||||
assertThat(allow,containsString(expectedMethod));
|
||||
}
|
||||
response.assertHeader("9.2 OPTIONS","Content-Length","0"); // Required if no response body.
|
||||
assertEquals("9.2 OPTIONS","0", response.get("Content-Length")); // Required if no response body.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -870,15 +870,15 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n"); // Close this second request
|
||||
req2.append("\n");
|
||||
|
||||
responses = http.requests(req2);
|
||||
List<HttpTester.Response> responses = http.requests(req2);
|
||||
|
||||
Assert.assertEquals("Response Count",2,responses.size()); // Should have 2 responses
|
||||
|
||||
response = responses.get(0); // Only interested in first response
|
||||
response.assertHeaderExists("9.2 OPTIONS","Allow");
|
||||
HttpTester.Response response = responses.get(0); // Only interested in first response
|
||||
assertTrue("9.2 OPTIONS", response.get("Allow") != null);
|
||||
// Header expected ...
|
||||
// Allow: GET, HEAD, POST, TRACE, OPTIONS
|
||||
String allow = response.getHeader("Allow");
|
||||
String allow = response.get("Allow");
|
||||
String expectedMethods[] =
|
||||
{ "GET", "HEAD", "POST", "OPTIONS", "TRACE" };
|
||||
for (String expectedMethod : expectedMethods)
|
||||
|
@ -886,7 +886,7 @@ public abstract class RFC2616BaseTest
|
|||
assertThat(allow,containsString(expectedMethod));
|
||||
}
|
||||
|
||||
response.assertHeader("9.2 OPTIONS","Content-Length","0"); // Required if no response body.
|
||||
assertEquals("9.2 OPTIONS","0", response.get("Content-Length")); // Required if no response body.
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -905,12 +905,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK("9.4 GET / Response Code");
|
||||
response.assertHeader("9.4 GET / Content Type","Content-Type","text/plain");
|
||||
response.assertHeader("9.4 HEAD / Content Type","Content-Length","25");
|
||||
response.assertBody("9.4 GET / Body","Host=Default\nResource=R1\n");
|
||||
assertEquals("9.4 GET / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals("9.4 GET / Content Type","text/plain", response.get("Content-Type"));
|
||||
assertEquals("9.4 HEAD / Content Type","25", response.get("Content-Length"));
|
||||
assertTrue("9.4 GET / Body", response.getContent().contains("Host=Default\nResource=R1\n"));
|
||||
|
||||
/* Test HEAD next. (should have no body) */
|
||||
|
||||
|
@ -930,7 +930,7 @@ public abstract class RFC2616BaseTest
|
|||
String rawHeadResponse = http.readRaw(sock);
|
||||
int headResponseLength = rawHeadResponse.length();
|
||||
// Only interested in the response header from the GET request above.
|
||||
String rawGetResponse = response.getRawResponse().toString().substring(0,headResponseLength);
|
||||
String rawGetResponse = response.toString().substring(0,headResponseLength);
|
||||
|
||||
// As there is a possibility that the time between GET and HEAD requests
|
||||
// can cross the second mark. (eg: GET at 11:00:00.999 and HEAD at 11:00:01.001)
|
||||
|
@ -968,12 +968,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
HttpResponseTester response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK("9.8 TRACE / Response Code");
|
||||
response.assertHeader("9.8 TRACE / Content Type","Content-Type","message/http");
|
||||
response.assertBodyContains("9.8 TRACE / echo","TRACE /rfc2616-webapp/httpmethods HTTP/1.1");
|
||||
response.assertBodyContains("9.8 TRACE / echo","Host: localhost");
|
||||
assertEquals("9.8 TRACE / Response Code", HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals("9.8 TRACE / Content Type", "message/http", response.get("Content-Type"));
|
||||
assertTrue("9.8 TRACE / echo", response.getContent().contains("TRACE /rfc2616-webapp/httpmethods HTTP/1.1"));
|
||||
assertTrue("9.8 TRACE / echo", response.getContent().contains("Host: localhost"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -996,10 +996,10 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
boolean noRangeHasContentLocation = response.hasHeader("Content-Location");
|
||||
boolean noRangeHasETag = response.hasHeader("ETag");
|
||||
boolean noRangeHasContentLocation = (response.get("Content-Location") != null);
|
||||
boolean noRangeHasETag = (response.get("ETag") != null);
|
||||
|
||||
// now try again for the same resource but this time WITH range header
|
||||
|
||||
|
@ -1012,7 +1012,7 @@ public abstract class RFC2616BaseTest
|
|||
|
||||
response = http.request(req2);
|
||||
|
||||
response.assertStatus("10.2.7 Partial Content",HttpStatus.PARTIAL_CONTENT_206);
|
||||
assertEquals("10.2.7 Partial Content",HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
|
||||
// (point 1) A 206 response MUST contain either a Content-Range header
|
||||
// field (section 14.16) indicating the range included with this
|
||||
|
@ -1021,28 +1021,28 @@ public abstract class RFC2616BaseTest
|
|||
// in the response, its value MUST match the actual number of OCTETs
|
||||
// transmitted in the message-body.
|
||||
|
||||
if (response.hasHeader("Content-Range"))
|
||||
if (response.get("Content-Range") != null)
|
||||
{
|
||||
response.assertHeader("10.2.7 Partial Content / Response / Content Range","Content-Range","bytes 1-3/27");
|
||||
assertEquals("10.2.7 Partial Content / Response / Content Range","bytes 1-3/27",response.get("Content-Range"));
|
||||
}
|
||||
|
||||
if (response.hasHeader("Content-Length"))
|
||||
if (response.get("Content-Length") != null)
|
||||
{
|
||||
response.assertHeader("10.2.7 Patial Content / Response / Content Length","Content-Length","3");
|
||||
assertEquals("10.2.7 Patial Content / Response / Content Length","3", response.get("Content-Length"));
|
||||
}
|
||||
|
||||
// (point 2) A 206 response MUST contain a Date header
|
||||
response.assertHeaderExists("10.2.7 Partial Content / Response / Date","Date");
|
||||
assertTrue("10.2.7 Partial Content / Response / Date", response.get("Date") != null);
|
||||
|
||||
// (point 3) A 206 response MUST contain ETag and/or Content-Location,
|
||||
// if the header would have been sent in a 200 response to the same request
|
||||
if (noRangeHasContentLocation)
|
||||
{
|
||||
response.assertHeaderExists("10.2.7 Partial Content / Content-Location","Content-Location");
|
||||
assertTrue("10.2.7 Partial Content / Content-Location", response.get("Content-Location") != null);
|
||||
}
|
||||
if (noRangeHasETag)
|
||||
{
|
||||
response.assertHeaderExists("10.2.7 Partial Content / Content-Location","ETag");
|
||||
assertTrue("10.2.7 Partial Content / Content-Location", response.get("ETag") != null);
|
||||
}
|
||||
|
||||
// (point 4) A 206 response MUST contain Expires, Cache-Control, and/or Vary,
|
||||
|
@ -1052,7 +1052,7 @@ public abstract class RFC2616BaseTest
|
|||
// TODO: Not sure how to test this condition.
|
||||
|
||||
// Test the body sent
|
||||
response.assertBody("10.2.7 Partial Content","BCD"); // should only have bytes 1-3
|
||||
assertTrue("10.2.7 Partial Content",response.getContent().contains("BCD")); // should only have bytes 1-3
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1074,11 +1074,11 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: Close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
specId = "10.3 Redirection HTTP/1.0 - basic";
|
||||
response.assertStatus(specId,HttpStatus.FOUND_302);
|
||||
response.assertHeader(specId,"Location",serverURI + "/tests/");
|
||||
assertEquals(specId,HttpStatus.FOUND_302, response.getStatus());
|
||||
assertEquals(specId,serverURI + "/tests/", response.get("Location"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1101,20 +1101,19 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
responses = http.requests(req2);
|
||||
List<HttpTester.Response> responses = http.requests(req2);
|
||||
Assert.assertEquals("Response Count",2,responses.size());
|
||||
|
||||
response = responses.get(0);
|
||||
HttpTester.Response response = responses.get(0);
|
||||
String specId = "10.3 Redirection HTTP/1.1 - basic (response 1)";
|
||||
response.assertStatus(specId,HttpStatus.FOUND_302);
|
||||
response.assertHeader(specId,"Location",server.getScheme() + "://localhost/tests/");
|
||||
assertEquals(specId,HttpStatus.FOUND_302, response.getStatus());
|
||||
assertEquals(specId,server.getScheme() + "://localhost/tests/", response.get("Location"));
|
||||
|
||||
response = responses.get(1);
|
||||
specId = "10.3 Redirection HTTP/1.1 - basic (response 2)";
|
||||
response.assertStatus(specId,HttpStatus.FOUND_302);
|
||||
response.assertHeader(specId,"Location",server.getScheme() + "://localhost/tests/");
|
||||
response.assertHeader(specId,"Connection","close");
|
||||
|
||||
assertEquals(specId,HttpStatus.FOUND_302, response.getStatus());
|
||||
assertEquals(specId,server.getScheme() + "://localhost/tests/", response.get("Location"));
|
||||
assertEquals(specId,"close", response.get("Connection"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1133,11 +1132,11 @@ public abstract class RFC2616BaseTest
|
|||
req3.append("Connection: close\n");
|
||||
req3.append("\n");
|
||||
|
||||
response = http.request(req3);
|
||||
HttpTester.Response response = http.request(req3);
|
||||
|
||||
String specId = "10.3 Redirection HTTP/1.0 w/content";
|
||||
response.assertStatus(specId,HttpStatus.FOUND_302);
|
||||
response.assertHeader(specId,"Location",server.getScheme() + "://localhost/tests/R1.txt");
|
||||
assertEquals(specId,HttpStatus.FOUND_302, response.getStatus());
|
||||
assertEquals(specId,server.getScheme() + "://localhost/tests/R1.txt", response.get("Location"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1156,13 +1155,13 @@ public abstract class RFC2616BaseTest
|
|||
req4.append("Connection: close\n");
|
||||
req4.append("\n");
|
||||
|
||||
response = http.request(req4);
|
||||
HttpTester.Response response = http.request(req4);
|
||||
|
||||
String specId = "10.3 Redirection HTTP/1.1 w/content";
|
||||
response.assertStatus(specId,HttpStatus.FOUND_302);
|
||||
response.assertHeader(specId,"Location",server.getScheme() + "://localhost/tests/R2.txt");
|
||||
response.assertHeader(specId,"Connection","close");
|
||||
response.assertHeaderNotPresent(specId,"Content-Length");
|
||||
assertEquals(specId,HttpStatus.FOUND_302, response.getStatus());
|
||||
assertEquals(specId,server.getScheme() + "://localhost/tests/R2.txt", response.get("Location"));
|
||||
assertEquals(specId,"close", response.get("Connection"));
|
||||
assertTrue(specId,response.get("Content-Length") == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1184,11 +1183,11 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
specId = "14.3 Accept-Encoding Header";
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeader(specId,"Content-Encoding","gzip");
|
||||
response.assertHeader(specId,"Content-Type","text/html");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals(specId,"gzip", response.get("Content-Encoding"));
|
||||
assertEquals(specId,"text/html", response.get("Content-Type"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1210,10 +1209,10 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatusOK();
|
||||
response.assertBody(ALPHA);
|
||||
assertEquals(HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(response.getContent().contains(ALPHA));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1229,12 +1228,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial Range: '" + rangedef + "'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
response.assertHeader(msg,"Content-Range","bytes " + expectedRange);
|
||||
response.assertBody(msg,expectedBody);
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
assertEquals(msg,"bytes " + expectedRange, response.get("Content-Range"));
|
||||
assertTrue(msg,response.getContent().contains(expectedBody));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1288,12 +1287,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("\n");
|
||||
|
||||
http.setTimeoutMillis(60000);
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial Range (Mixed): 'bytes=a-b,5-8'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
response.assertHeader(msg,"Content-Range","bytes 5-8/27");
|
||||
response.assertBody(msg,alpha.substring(5,8 + 1));
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
assertEquals(msg,"bytes 5-8/27", response.get("Content-Range"));
|
||||
assertTrue(msg,response.getContent().contains(alpha.substring(5,8 + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1328,12 +1327,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial Range (Mixed): 'bytes=a-b,bytes=5-8'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
response.assertHeader(msg,"Content-Range","bytes 5-8/27");
|
||||
response.assertBody(msg,alpha.substring(5,8 + 1));
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
assertEquals(msg,"bytes 5-8/27", response.get("Content-Range"));
|
||||
assertTrue(msg,response.getContent().contains(alpha.substring(5,8 + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1369,12 +1368,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial Range (Mixed): 'bytes=a-b' 'bytes=5-8'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
response.assertHeader(msg,"Content-Range","bytes 5-8/27");
|
||||
response.assertBody(msg,alpha.substring(5,8 + 1));
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
assertEquals(msg,"bytes 5-8/27", response.get("Content-Range"));
|
||||
assertTrue(msg,response.getContent().contains(alpha.substring(5,8 + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1385,8 +1384,6 @@ public abstract class RFC2616BaseTest
|
|||
@Test
|
||||
public void test14_23_Http10_NoHostHeader() throws Exception
|
||||
{
|
||||
HttpResponseTester response;
|
||||
|
||||
// HTTP/1.0 OK with no host
|
||||
|
||||
StringBuffer req1 = new StringBuffer();
|
||||
|
@ -1394,8 +1391,8 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
response.assertStatusOK("14.23 HTTP/1.0 - No Host");
|
||||
HttpTester.Response response = http.request(req1);
|
||||
assertEquals("14.23 HTTP/1.0 - No Host", HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1413,8 +1410,8 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
response = http.request(req2);
|
||||
response.assertStatus("14.23 HTTP/1.1 - No Host",HttpStatus.BAD_REQUEST_400);
|
||||
HttpTester.Response response = http.request(req2);
|
||||
assertEquals("14.23 HTTP/1.1 - No Host",HttpStatus.BAD_REQUEST_400, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1433,8 +1430,8 @@ public abstract class RFC2616BaseTest
|
|||
req3.append("Connection: close\n");
|
||||
req3.append("\n");
|
||||
|
||||
response = http.request(req3);
|
||||
response.assertStatusOK("14.23 HTTP/1.1 - Valid Host");
|
||||
HttpTester.Response response = http.request(req3);
|
||||
assertEquals("14.23 HTTP/1.1 - Valid Host", HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1453,8 +1450,8 @@ public abstract class RFC2616BaseTest
|
|||
req4.append("Connection: close\n");
|
||||
req4.append("\n");
|
||||
|
||||
response = http.request(req4);
|
||||
response.assertStatusOK("14.23 HTTP/1.1 - Empty Host");
|
||||
HttpTester.Response response = http.request(req4);
|
||||
assertEquals("14.23 HTTP/1.1 - Empty Host", HttpStatus.OK_200, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1476,14 +1473,14 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial (Byte) Range: '" + rangedef + "'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
// It might be strange to see a "Content-Range' response header to a 'Range' request,
|
||||
// but this is appropriate per the RFC2616 spec.
|
||||
response.assertHeader(msg,"Content-Range","bytes " + expectedRange);
|
||||
response.assertBody(msg,expectedBody);
|
||||
assertEquals(msg,"bytes " + expectedRange, response.get("Content-Range"));
|
||||
assertTrue(msg,response.getContent().contains(expectedBody));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1532,12 +1529,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial (Byte) Range: '" + rangedef + "'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206, response.getStatus());
|
||||
|
||||
String contentType = response.getHeader("Content-Type");
|
||||
String contentType = response.get("Content-Type");
|
||||
// RFC states that multiple parts should result in multipart/byteranges Content type.
|
||||
StringAssert.assertContains(msg + " Content-Type",contentType,"multipart/byteranges");
|
||||
|
||||
|
@ -1557,20 +1554,20 @@ public abstract class RFC2616BaseTest
|
|||
Assert.assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
|
||||
|
||||
// Find boundary offsets within body
|
||||
List<HttpResponseTester> multiparts = response.findBodyMultiparts(boundary);
|
||||
List<HttpTester.Response> multiparts = HttpTesting.getParts(boundary, response);
|
||||
Assert.assertEquals(msg + " multiparts in body (count)",2,multiparts.size());
|
||||
|
||||
// Validate multipart #1
|
||||
HttpResponseTester multipart1 = multiparts.get(0);
|
||||
multipart1.assertHeader(msg + " Multipart 1","Content-Type","text/plain");
|
||||
multipart1.assertHeader(msg + " Multipart 1","Content-Range","bytes 23-23/27");
|
||||
multipart1.assertBody(msg + " Multipart 1","X");
|
||||
HttpTester.Response multipart1 = multiparts.get(0);
|
||||
assertEquals(msg + " Multipart 1","text/plain", multipart1.get("Content-Type"));
|
||||
assertEquals(msg + " Multipart 1","bytes 23-23/27", multipart1.get("Content-Range"));
|
||||
assertTrue(msg + " Multipart 1", multipart1.getContent().contains("X"));
|
||||
|
||||
// Validate multipart #2
|
||||
HttpResponseTester multipart2 = multiparts.get(1);
|
||||
multipart2.assertHeader(msg + " Multipart 2","Content-Type","text/plain");
|
||||
multipart2.assertHeader(msg + " Multipart 2","Content-Range","bytes 25-26/27");
|
||||
multipart2.assertBody(msg + " Multipart 2","Z\n");
|
||||
HttpTester.Response multipart2 = multiparts.get(1);
|
||||
assertEquals(msg + " Multipart 2","text/plain", multipart2.get("Content-Type"));
|
||||
assertEquals(msg + " Multipart 2","bytes 25-26/27", multipart2.get("Content-Range"));
|
||||
assertTrue(msg + " Multipart 2", multipart2.getContent().contains("Z\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1593,12 +1590,12 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
String msg = "Partial (Byte) Range: '" + rangedef + "'";
|
||||
response.assertStatus(msg,HttpStatus.PARTIAL_CONTENT_206);
|
||||
assertEquals(msg,HttpStatus.PARTIAL_CONTENT_206,response.getStatus());
|
||||
|
||||
String contentType = response.getHeader("Content-Type");
|
||||
String contentType = response.get("Content-Type");
|
||||
// RFC states that multiple parts should result in multipart/byteranges Content type.
|
||||
StringAssert.assertContains(msg + " Content-Type",contentType,"multipart/byteranges");
|
||||
|
||||
|
@ -1618,26 +1615,26 @@ public abstract class RFC2616BaseTest
|
|||
Assert.assertNotNull(msg + " Should have found boundary in Content-Type header",boundary);
|
||||
|
||||
// Find boundary offsets within body
|
||||
List<HttpResponseTester> multiparts = response.findBodyMultiparts(boundary);
|
||||
List<HttpTester.Response> multiparts = HttpTesting.getParts(boundary, response);
|
||||
Assert.assertEquals(msg + " multiparts in body (count)",3,multiparts.size());
|
||||
|
||||
// Validate multipart #1
|
||||
HttpResponseTester multipart1 = multiparts.get(0);
|
||||
multipart1.assertHeader(msg + " Multipart 1","Content-Type","text/plain");
|
||||
multipart1.assertHeader(msg + " Multipart 1","Content-Range","bytes 26-26/27");
|
||||
multipart1.assertBody(msg + " Multipart 1","\n");
|
||||
HttpTester.Response multipart1 = multiparts.get(0);
|
||||
assertEquals(msg + " Multipart 1", "text/plain", multipart1.get("Content-Type"));
|
||||
assertEquals(msg + " Multipart 1","bytes 26-26/27", multipart1.get("Content-Range"));
|
||||
assertTrue(msg + " Multipart 1",multipart1.getContent().contains("\n"));
|
||||
|
||||
// Validate multipart #2
|
||||
HttpResponseTester multipart2 = multiparts.get(1);
|
||||
multipart2.assertHeader(msg + " Multipart 2","Content-Type","text/plain");
|
||||
multipart2.assertHeader(msg + " Multipart 2","Content-Range","bytes 25-26/27");
|
||||
multipart2.assertBody(msg + " Multipart 2","Z\n");
|
||||
HttpTester.Response multipart2 = multiparts.get(1);
|
||||
assertEquals(msg + " Multipart 2","text/plain", multipart2.get("Content-Type"));
|
||||
assertEquals(msg + " Multipart 2","bytes 25-26/27", multipart2.get("Content-Range"));
|
||||
assertTrue(msg + " Multipart 2", multipart2.getContent().contains("Z\n"));
|
||||
|
||||
// Validate multipart #3
|
||||
HttpResponseTester multipart3 = multiparts.get(2);
|
||||
multipart3.assertHeader(msg + " Multipart 3","Content-Type","text/plain");
|
||||
multipart3.assertHeader(msg + " Multipart 3","Content-Range","bytes 24-26/27");
|
||||
multipart3.assertBody(msg + " Multipart 3","YZ\n");
|
||||
HttpTester.Response multipart3 = multiparts.get(2);
|
||||
assertEquals(msg + " Multipart 3","text/plain", multipart3.get("Content-Type"));
|
||||
assertEquals(msg + " Multipart 3","bytes 24-26/27", multipart3.get("Content-Range"));
|
||||
assertTrue(msg + " Multipart 3", multipart3.getContent().contains("YZ\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1671,9 +1668,9 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
|
||||
response.assertStatus("BadByteRange: '" + rangedef + "'",HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE_416);
|
||||
assertEquals("BadByteRange: '" + rangedef + "'",HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE_416, response.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1714,10 +1711,10 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("Connection: close\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
specId = "14.39 TE Header";
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeader(specId,"Transfer-Encoding","gzip");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals(specId,"gzip", response.get("Transfer-Encoding"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1741,9 +1738,9 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
response = http.request(req2);
|
||||
HttpTester.Response response = http.request(req2);
|
||||
specId = "14.39 TE Header";
|
||||
response.assertStatus(specId,HttpStatus.NOT_IMPLEMENTED_501); // Error on TE (deflate not supported)
|
||||
assertEquals(specId,HttpStatus.NOT_IMPLEMENTED_501, response.getStatus()); // Error on TE (deflate not supported)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1755,8 +1752,7 @@ public abstract class RFC2616BaseTest
|
|||
@Test
|
||||
public void test19_6() throws Exception
|
||||
{
|
||||
List<HttpResponseTester> responses;
|
||||
HttpResponseTester response;
|
||||
|
||||
String specId;
|
||||
|
||||
/* Compatibility with HTTP/1.0 */
|
||||
|
@ -1765,10 +1761,10 @@ public abstract class RFC2616BaseTest
|
|||
req1.append("GET /tests/R1.txt HTTP/1.0\n");
|
||||
req1.append("\n");
|
||||
|
||||
response = http.request(req1);
|
||||
HttpTester.Response response = http.request(req1);
|
||||
specId = "19.6 Compatibility with HTTP/1.0 - simple request";
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeaderNotPresent(specId + " - connection closed not assumed","Connection");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(specId + " - connection closed not assumed",response.get("Connection") == null);
|
||||
|
||||
/* Compatibility with HTTP/1.0 */
|
||||
|
||||
|
@ -1783,26 +1779,25 @@ public abstract class RFC2616BaseTest
|
|||
req2.append("Connection: close\n"); // Connection closed here
|
||||
req2.append("\n");
|
||||
|
||||
req2.append("GET /tests/R3.txt HTTP/1.0\n"); // This request should not
|
||||
// be handled
|
||||
req2.append("GET /tests/R3.txt HTTP/1.0\n"); // This request should not be handled
|
||||
req2.append("Host: localhost\n");
|
||||
req2.append("Connection: close\n");
|
||||
req2.append("\n");
|
||||
|
||||
responses = http.requests(req2);
|
||||
List<HttpTester.Response> responses = http.requests(req2);
|
||||
// Since R2 closes the connection, should only get 2 responses (R1 &
|
||||
// R2), not (R3)
|
||||
Assert.assertEquals("Response Count",2,responses.size());
|
||||
|
||||
response = responses.get(0); // response 1
|
||||
specId = "19.6.2 Compatibility with previous HTTP - Keep-alive";
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeader(specId,"Connection","keep-alive");
|
||||
response.assertBodyContains(specId,"Resource=R1");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals(specId,"keep-alive", response.get("Connection"));
|
||||
assertTrue(specId,response.getContent().contains("Resource=R1"));
|
||||
|
||||
response = responses.get(1); // response 2
|
||||
response.assertStatusOK(specId);
|
||||
response.assertBodyContains(specId,"Resource=R2");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(specId,response.getContent().contains("Resource=R2"));
|
||||
|
||||
/* Compatibility with HTTP/1.0 */
|
||||
|
||||
|
@ -1836,18 +1831,18 @@ public abstract class RFC2616BaseTest
|
|||
|
||||
specId = "19.6.2 Compatibility with HTTP/1.0- Keep-alive";
|
||||
response = responses.get(0);
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeader(specId,"Connection","keep-alive");
|
||||
response.assertBody(specId,"1234567890\n");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals(specId,"keep-alive", response.get("Connection"));
|
||||
assertTrue(specId, response.getContent().contains("1234567890\n"));
|
||||
|
||||
response = responses.get(1);
|
||||
response.assertStatusOK(specId);
|
||||
response.assertHeader(specId,"Connection","keep-alive");
|
||||
response.assertBody(specId,"ABCDEFGHIJ\n");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertEquals(specId, "keep-alive", response.get("Connection"));
|
||||
assertTrue(specId,response.getContent().contains("ABCDEFGHIJ\n"));
|
||||
|
||||
response = responses.get(2);
|
||||
response.assertStatusOK(specId);
|
||||
response.assertBody(specId,"Host=Default\nResource=R2\n");
|
||||
assertEquals(specId, HttpStatus.OK_200, response.getStatus());
|
||||
assertTrue(specId,response.getContent().contains("Host=Default\nResource=R2\n"));
|
||||
}
|
||||
|
||||
protected void assertDate(String msg, Calendar expectedTime, long actualTime)
|
||||
|
|
|
@ -120,6 +120,7 @@ public class TestableJettyServer
|
|||
for (int i = 0; i < this._xmlConfigurations.size(); i++)
|
||||
{
|
||||
URL configURL = this._xmlConfigurations.get(i);
|
||||
System.err.println("configuring: "+configURL);
|
||||
XmlConfiguration configuration = new XmlConfiguration(configURL);
|
||||
if (last != null)
|
||||
{
|
||||
|
@ -176,18 +177,8 @@ public class TestableJettyServer
|
|||
_server.start();
|
||||
|
||||
// Find the active server port.
|
||||
this._serverPort = (-1);
|
||||
Connector connectors[] = _server.getConnectors();
|
||||
for (int i = 0; i < connectors.length; i++)
|
||||
{
|
||||
NetworkConnector connector = (NetworkConnector)connectors[i];
|
||||
if (connector.getLocalPort() > 0)
|
||||
{
|
||||
this._serverPort = connector.getLocalPort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this._serverPort = ((NetworkConnector)_server.getConnectors()[0]).getPort();
|
||||
System.err.println("Server Port="+_serverPort);
|
||||
Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + _serverPort + ">",(1 <= this._serverPort) && (this._serverPort <= 65535));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,235 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.support.rawhttp;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpGenerator;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Assist in Generating Proper Raw HTTP Requests. If you want ultimate control
|
||||
* over the Raw HTTP Request, to test non-standard behavior, or partial HTTP
|
||||
* Requests, do not use this class.
|
||||
*
|
||||
* <pre>
|
||||
* HttpRequestTester request = new HttpRequestTester();
|
||||
*
|
||||
* request.setMethod("GET");
|
||||
* request.setURI("/uri");
|
||||
* request.setHost("fakehost");
|
||||
* request.setConnectionClosed();
|
||||
*
|
||||
* String rawRequest = request.generate();
|
||||
*
|
||||
* System.out.println("--raw-request--\n" + rawRequest);
|
||||
* </pre>
|
||||
*
|
||||
* <pre>
|
||||
* --raw-request--
|
||||
* GET /uri HTTP/1.1
|
||||
* Host: fakehost
|
||||
* Connection: close
|
||||
* </pre>
|
||||
*/
|
||||
public class HttpRequestTester
|
||||
{
|
||||
private HttpFields fields = new HttpFields();
|
||||
private String method;
|
||||
private String uri;
|
||||
private String version;
|
||||
private byte[] content;
|
||||
private String charset;
|
||||
private String defaultCharset;
|
||||
private String contentType;
|
||||
|
||||
public HttpRequestTester()
|
||||
{
|
||||
this("UTF-8");
|
||||
}
|
||||
|
||||
public HttpRequestTester(String defCharset)
|
||||
{
|
||||
this.defaultCharset = defCharset;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setHost(String host)
|
||||
{
|
||||
addHeader("Host",host);
|
||||
}
|
||||
|
||||
public void setMethod(String method)
|
||||
{
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getURI()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setURI(String uri)
|
||||
{
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version)
|
||||
{
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getCharset()
|
||||
{
|
||||
return charset;
|
||||
}
|
||||
|
||||
public void setCharset(String charset)
|
||||
{
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
public String getContentType()
|
||||
{
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType)
|
||||
{
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public void setConnectionClosed()
|
||||
{
|
||||
fields.add("Connection","close");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param value
|
||||
* @throws IllegalArgumentException
|
||||
* @see org.eclipse.jetty.http.HttpFields#add(java.lang.String,
|
||||
* java.lang.String)
|
||||
*/
|
||||
public void addHeader(String name, String value) throws IllegalArgumentException
|
||||
{
|
||||
fields.add(name,value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param date
|
||||
* @see org.eclipse.jetty.http.HttpFields#addDateField(java.lang.String,
|
||||
* long)
|
||||
*/
|
||||
public void addDateHeader(String name, long date)
|
||||
{
|
||||
fields.addDateField(name,date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param cookie
|
||||
* @see org.eclipse.jetty.http.HttpFields#addSetCookie(org.eclipse.jetty.http.HttpCookie)
|
||||
*/
|
||||
public void addSetCookie(Cookie cookie)
|
||||
{
|
||||
fields.addSetCookie(cookie.getName(),cookie.getValue(),cookie.getDomain(),cookie.getPath(),cookie.getMaxAge(),cookie.getComment(),cookie.getSecure(),
|
||||
false,cookie.getVersion());
|
||||
}
|
||||
|
||||
public String generate() throws IOException
|
||||
{
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ByteBuffer header = null;
|
||||
ByteBuffer chunk = null;
|
||||
ByteBuffer content = null;
|
||||
HttpVersion httpVersion = null;
|
||||
if (version == null)
|
||||
{
|
||||
httpVersion = HttpVersion.HTTP_1_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
httpVersion = httpVersion.fromString(version);
|
||||
}
|
||||
|
||||
HttpGenerator.RequestInfo info = new HttpGenerator.RequestInfo(httpVersion,fields,0,method,uri);
|
||||
|
||||
HttpGenerator generator = new HttpGenerator();
|
||||
loop: while(!generator.isEnd())
|
||||
{
|
||||
HttpGenerator.Result result = generator.generateRequest(info, header, chunk, content, true);
|
||||
switch(result)
|
||||
{
|
||||
case NEED_HEADER:
|
||||
header=BufferUtil.allocate(8192);
|
||||
continue;
|
||||
|
||||
case NEED_CHUNK:
|
||||
chunk=BufferUtil.allocate(HttpGenerator.CHUNK_SIZE);
|
||||
continue;
|
||||
|
||||
case NEED_INFO:
|
||||
throw new IllegalStateException();
|
||||
|
||||
case FLUSH:
|
||||
if (BufferUtil.hasContent(header))
|
||||
{
|
||||
out.write(BufferUtil.toArray(header));
|
||||
BufferUtil.clear(header);
|
||||
}
|
||||
if (BufferUtil.hasContent(chunk))
|
||||
{
|
||||
out.write(BufferUtil.toArray(chunk));
|
||||
BufferUtil.clear(chunk);
|
||||
}
|
||||
if (BufferUtil.hasContent(content))
|
||||
{
|
||||
out.write(BufferUtil.toArray(content));
|
||||
BufferUtil.clear(content);
|
||||
}
|
||||
break;
|
||||
|
||||
case SHUTDOWN_OUT:
|
||||
break loop;
|
||||
}
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
}
|
|
@ -19,7 +19,11 @@
|
|||
package org.eclipse.jetty.test.support.rawhttp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -28,42 +32,45 @@ public class HttpRequestTesterTest
|
|||
@Test
|
||||
public void testBasicHttp10Request() throws IOException
|
||||
{
|
||||
HttpRequestTester request = new HttpRequestTester();
|
||||
HttpTester.Request request = HttpTester.newRequest();
|
||||
request.setMethod("GET");
|
||||
request.setURI("/uri");
|
||||
request.setVersion("HTTP/1.0");
|
||||
request.setHost("fakehost");
|
||||
request.put("Host","fakehost");
|
||||
|
||||
String rawRequest = request.generate();
|
||||
ByteBuffer bBuff = request.generate();
|
||||
|
||||
StringBuffer expectedRequest = new StringBuffer();
|
||||
expectedRequest.append("GET /uri HTTP/1.0\r\n");
|
||||
expectedRequest.append("Host: fakehost\r\n");
|
||||
expectedRequest.append("\r\n");
|
||||
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),BufferUtil.toString(bBuff));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicHttp11Request() throws IOException
|
||||
{
|
||||
HttpRequestTester request = new HttpRequestTester();
|
||||
HttpTester.Request request = HttpTester.newRequest();
|
||||
request.setMethod("GET");
|
||||
request.setVersion(HttpVersion.HTTP_1_1);
|
||||
request.setURI("/uri");
|
||||
request.setHost("fakehost");
|
||||
request.setConnectionClosed();
|
||||
request.put("Host","fakehost");
|
||||
request.put("Connection", "close");
|
||||
request.setContent("aaa");
|
||||
|
||||
|
||||
String rawRequest = request.generate();
|
||||
ByteBuffer bBuff = request.generate();
|
||||
|
||||
StringBuffer expectedRequest = new StringBuffer();
|
||||
expectedRequest.append("GET /uri HTTP/1.1\r\n");
|
||||
expectedRequest.append("Host: fakehost\r\n");
|
||||
expectedRequest.append("Connection: close\r\n");
|
||||
expectedRequest.append("Transfer-Encoding: chunked\r\n");
|
||||
expectedRequest.append("\r\n");
|
||||
expectedRequest.append("0\r\n");
|
||||
expectedRequest.append("Content-Length: 3\r\n");
|
||||
expectedRequest.append("\r\n");
|
||||
expectedRequest.append("aaa");
|
||||
|
||||
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),rawRequest);
|
||||
Assert.assertEquals("Basic Request",expectedRequest.toString(),BufferUtil.toString(bBuff));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,461 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.test.support.rawhttp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpHeaders;
|
||||
import org.eclipse.jetty.http.HttpParser;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.MimeTypes;
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.io.ByteArrayBuffer;
|
||||
import org.eclipse.jetty.io.View;
|
||||
import org.eclipse.jetty.test.support.StringUtil;
|
||||
import org.eclipse.jetty.toolchain.test.StringAssert;
|
||||
import org.eclipse.jetty.util.ByteArrayOutputStream2;
|
||||
|
||||
/**
|
||||
* Assists in testing of HTTP Responses.
|
||||
*/
|
||||
public class HttpResponseTester
|
||||
{
|
||||
private class PH extends HttpParser.EventHandler
|
||||
{
|
||||
@Override
|
||||
public void content(Buffer ref) throws IOException
|
||||
{
|
||||
if (content == null)
|
||||
content = new ByteArrayOutputStream2();
|
||||
content.write(ref.asArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headerComplete() throws IOException
|
||||
{
|
||||
contentType = fields.get(HttpHeaders.CONTENT_TYPE_BUFFER);
|
||||
if (contentType != null)
|
||||
{
|
||||
String calcCharset = MimeTypes.getCharsetFromContentType(contentType);
|
||||
if (calcCharset != null)
|
||||
{
|
||||
charset = calcCharset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageComplete(long contextLength) throws IOException
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsedHeader(Buffer name, Buffer value) throws IOException
|
||||
{
|
||||
fields.add(name,value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startRequest(Buffer method, Buffer url, Buffer version) throws IOException
|
||||
{
|
||||
reset();
|
||||
HttpResponseTester.this.method = getString(method);
|
||||
HttpResponseTester.this.uri = getString(url);
|
||||
HttpResponseTester.this.version = getString(version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startResponse(Buffer version, int status, Buffer reason) throws IOException
|
||||
{
|
||||
reset();
|
||||
HttpResponseTester.this.version = getString(version);
|
||||
HttpResponseTester.this.status = status;
|
||||
HttpResponseTester.this.reason = getString(reason);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<HttpResponseTester> parseMulti(CharSequence rawHTTP) throws IOException
|
||||
{
|
||||
List<HttpResponseTester> responses = new ArrayList<HttpResponseTester>();
|
||||
String parse = rawHTTP.toString();
|
||||
while (StringUtil.isNotBlank(parse))
|
||||
{
|
||||
HttpResponseTester response = new HttpResponseTester();
|
||||
parse = response.parse(parse);
|
||||
responses.add(response);
|
||||
}
|
||||
|
||||
return responses;
|
||||
}
|
||||
|
||||
private HttpFields fields = new HttpFields();
|
||||
private CharSequence rawResponse;
|
||||
private String method;
|
||||
private String uri;
|
||||
private String version;
|
||||
private int status;
|
||||
private String reason;
|
||||
private Buffer contentType;
|
||||
private ByteArrayOutputStream2 content;
|
||||
private String charset;
|
||||
private String defaultCharset;
|
||||
|
||||
public HttpResponseTester()
|
||||
{
|
||||
this("UTF-8");
|
||||
}
|
||||
|
||||
public HttpResponseTester(String defCharset)
|
||||
{
|
||||
this.defaultCharset = defCharset;
|
||||
}
|
||||
|
||||
public String getMethod()
|
||||
{
|
||||
return method;
|
||||
}
|
||||
|
||||
public String getURI()
|
||||
{
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return version;
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
{
|
||||
return status;
|
||||
}
|
||||
|
||||
public CharSequence getRawResponse()
|
||||
{
|
||||
return rawResponse;
|
||||
}
|
||||
|
||||
public String getReason()
|
||||
{
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String getContentType()
|
||||
{
|
||||
if (contentType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return contentType.toString();
|
||||
}
|
||||
|
||||
public ByteArrayOutputStream2 getContentBytes()
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getContent()
|
||||
{
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
public String getBody()
|
||||
{
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
private byte[] getByteArray(CharSequence str)
|
||||
{
|
||||
if (charset == null)
|
||||
{
|
||||
return str.toString().getBytes();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return str.toString().getBytes(charset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return str.toString().getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
private String getString(Buffer buffer)
|
||||
{
|
||||
return getString(buffer.asArray());
|
||||
}
|
||||
|
||||
private String getString(byte[] b)
|
||||
{
|
||||
if (charset == null)
|
||||
{
|
||||
return new String(b);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return new String(b,charset);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new String(b);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return the header value as a date
|
||||
* @see org.eclipse.jetty.http.HttpFields#getDateField(java.lang.String)
|
||||
*/
|
||||
public long getDateHeader(String name)
|
||||
{
|
||||
return fields.getDateField(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return the header value as a long
|
||||
* @throws NumberFormatException
|
||||
* @see org.eclipse.jetty.http.HttpFields#getLongField(java.lang.String)
|
||||
*/
|
||||
public long getLongHeader(String name) throws NumberFormatException
|
||||
{
|
||||
return fields.getLongField(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return the header value
|
||||
* @see org.eclipse.jetty.http.HttpFields#getStringField(java.lang.String)
|
||||
*/
|
||||
public String getHeader(String name)
|
||||
{
|
||||
return fields.getStringField(name);
|
||||
}
|
||||
|
||||
public boolean hasHeader(String headerKey)
|
||||
{
|
||||
return fields.containsKey(headerKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse on HTTP Response
|
||||
*
|
||||
* @param rawHTTP
|
||||
* Raw HTTP to parse
|
||||
* @return Any unparsed data in the rawHTTP (eg pipelined requests)
|
||||
* @throws IOException
|
||||
*/
|
||||
public String parse(CharSequence rawHTTP) throws IOException
|
||||
{
|
||||
this.charset = defaultCharset;
|
||||
this.rawResponse = rawHTTP;
|
||||
ByteArrayBuffer buf = new ByteArrayBuffer(getByteArray(rawHTTP));
|
||||
View view = new View(buf);
|
||||
HttpParser parser = new HttpParser(view,new PH());
|
||||
parser.parse();
|
||||
return getString(view.asArray());
|
||||
}
|
||||
|
||||
public void reset()
|
||||
{
|
||||
fields.clear();
|
||||
method = null;
|
||||
uri = null;
|
||||
version = null;
|
||||
status = 0;
|
||||
reason = null;
|
||||
content = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that status code is "OK"
|
||||
*/
|
||||
public void assertStatusOK()
|
||||
{
|
||||
assertStatus(HttpStatus.OK_200,"OK");
|
||||
}
|
||||
|
||||
public void assertStatusOK(String msg)
|
||||
{
|
||||
assertStatus(msg,HttpStatus.OK_200,"OK");
|
||||
}
|
||||
|
||||
public void assertStatus(int expectedStatus, String expectedReason)
|
||||
{
|
||||
Assert.assertEquals("Response.status",expectedStatus,this.status);
|
||||
Assert.assertEquals("Response.reason",expectedReason,this.reason);
|
||||
}
|
||||
|
||||
public void assertStatus(String msg, int expectedStatus, String expectedReason)
|
||||
{
|
||||
Assert.assertEquals(msg + ": Response.status",expectedStatus,this.status);
|
||||
Assert.assertEquals(msg + ": Response.reason",expectedReason,this.reason);
|
||||
}
|
||||
|
||||
public void assertStatus(String msg, int expectedStatus)
|
||||
{
|
||||
assertStatus(msg,expectedStatus,HttpStatus.getMessage(expectedStatus));
|
||||
}
|
||||
|
||||
public void assertContentType(String expectedType)
|
||||
{
|
||||
assertHeader("Content-Type",expectedType);
|
||||
}
|
||||
|
||||
private void assertHeader(String headerKey, String expectedValue)
|
||||
{
|
||||
String actual = fields.getStringField(headerKey);
|
||||
Assert.assertNotNull("Response[" + headerKey + "] should not be null",actual);
|
||||
Assert.assertEquals("Response[" + headerKey + "]",expectedValue,actual);
|
||||
}
|
||||
|
||||
public void assertHeader(String msg, String headerKey, String expectedValue)
|
||||
{
|
||||
String actual = fields.getStringField(headerKey);
|
||||
Assert.assertNotNull(msg + ": Response[" + headerKey + "] should not be null, expecting <" + expectedValue + ">",actual);
|
||||
Assert.assertEquals(msg + ": Response[" + headerKey + "]",expectedValue,actual);
|
||||
}
|
||||
|
||||
public void assertBody(String expected)
|
||||
{
|
||||
Assert.assertNotNull("Response.content should not be null",this.content);
|
||||
String actual = this.content.toString();
|
||||
Assert.assertEquals("Response.content",expected,actual);
|
||||
}
|
||||
|
||||
public void assertBody(String msg, String expected)
|
||||
{
|
||||
Assert.assertNotNull(msg + ": Response.content should not be null",this.content);
|
||||
String actual = this.content.toString();
|
||||
Assert.assertEquals(msg + ": Response.content",expected,actual);
|
||||
}
|
||||
|
||||
public void assertNoBody(String msg)
|
||||
{
|
||||
Assert.assertNull(msg + ": Response.content should be null",this.content);
|
||||
}
|
||||
|
||||
public void assertBodyContains(String msg, String expectedNeedle)
|
||||
{
|
||||
StringAssert.assertContains(msg + ": Response Content",this.content.toString(),expectedNeedle);
|
||||
}
|
||||
|
||||
public void assertHeaderExists(String msg, String expectedHeaderKey)
|
||||
{
|
||||
Assert.assertTrue(msg + ": header <" + expectedHeaderKey + "> should exist",fields.containsKey(expectedHeaderKey));
|
||||
}
|
||||
|
||||
public void assertHeaderNotPresent(String msg, String headerKey)
|
||||
{
|
||||
Assert.assertFalse(msg + ": header <" + headerKey + "> should NOT exist",fields.containsKey(headerKey));
|
||||
}
|
||||
|
||||
public List<HttpResponseTester> findBodyMultiparts(String boundary) throws IOException
|
||||
{
|
||||
List<HttpResponseTester> multiparts = new ArrayList<HttpResponseTester>();
|
||||
|
||||
BufferedReader buf = new BufferedReader(new StringReader(getBody()));
|
||||
String line;
|
||||
String startBoundary = "--" + boundary;
|
||||
String endBoundary = "--" + boundary + "--";
|
||||
HttpResponseTester resp = null;
|
||||
boolean parsingHeader = true;
|
||||
boolean previousBodyLine = false;
|
||||
|
||||
while ((line = buf.readLine()) != null)
|
||||
{
|
||||
if (line.equals(startBoundary))
|
||||
{
|
||||
// end of multipart, start a new one.
|
||||
if (resp != null)
|
||||
{
|
||||
multiparts.add(resp);
|
||||
}
|
||||
resp = new HttpResponseTester();
|
||||
parsingHeader = true;
|
||||
previousBodyLine = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.equals(endBoundary))
|
||||
{
|
||||
if (resp != null)
|
||||
{
|
||||
multiparts.add(resp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (parsingHeader)
|
||||
{
|
||||
if (line.equals(""))
|
||||
{
|
||||
parsingHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
resp.parseHeader(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (previousBodyLine)
|
||||
{
|
||||
resp.appendBody("\n");
|
||||
}
|
||||
resp.appendBody(line);
|
||||
previousBodyLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
return multiparts;
|
||||
}
|
||||
|
||||
public void parseHeader(String line)
|
||||
{
|
||||
int idx = line.indexOf(":");
|
||||
String key = line.substring(0,idx).trim();
|
||||
String val = line.substring(idx + 1).trim();
|
||||
|
||||
fields.add(key,val);
|
||||
}
|
||||
|
||||
public void appendBody(String s) throws IOException
|
||||
{
|
||||
appendBody(s.getBytes());
|
||||
}
|
||||
|
||||
public void appendBody(byte buf[]) throws IOException
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
content = new ByteArrayOutputStream2();
|
||||
}
|
||||
|
||||
content.write(buf);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,9 @@ import static org.junit.Assert.assertThat;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -45,16 +48,15 @@ public class HttpResponseTesterTest
|
|||
rawResponse.append("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n");
|
||||
rawResponse.append("\n");
|
||||
|
||||
HttpResponseTester response = new HttpResponseTester();
|
||||
response.parse(rawResponse);
|
||||
HttpTester.Response response = HttpTester.parseResponse(rawResponse.toString());
|
||||
|
||||
Assert.assertEquals("Response.version","HTTP/1.1",response.getVersion());
|
||||
Assert.assertEquals("Response.version","HTTP/1.1",response.getVersion().asString());
|
||||
Assert.assertEquals("Response.status",200,response.getStatus());
|
||||
Assert.assertEquals("Response.reason","OK",response.getReason());
|
||||
|
||||
Assert.assertEquals("Response[Content-Type]","text/plain",response.getContentType());
|
||||
Assert.assertEquals("Response[Content-Length]",28,response.getLongHeader("Content-Length"));
|
||||
Assert.assertEquals("Response[Connection]","close",response.getHeader("Connection"));
|
||||
Assert.assertEquals("Response[Content-Type]","text/plain",response.get(HttpHeader.CONTENT_TYPE));
|
||||
Assert.assertEquals("Response[Content-Length]",28,response.getLongField("Content-Length"));
|
||||
Assert.assertEquals("Response[Connection]","close",response.get("Connection"));
|
||||
|
||||
String expected = "ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n";
|
||||
|
||||
|
@ -73,6 +75,7 @@ public class HttpResponseTesterTest
|
|||
rawResponse.append("Server: Jetty(7.0.y.z-SNAPSHOT)\n");
|
||||
rawResponse.append("\n");
|
||||
rawResponse.append("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n");
|
||||
|
||||
rawResponse.append("HTTP/1.1 200 OK\n");
|
||||
rawResponse.append("Date: Mon, 08 Jun 2009 23:05:26 GMT\n");
|
||||
rawResponse.append("Content-Type: text/plain\n");
|
||||
|
@ -82,6 +85,7 @@ public class HttpResponseTesterTest
|
|||
rawResponse.append("\n");
|
||||
rawResponse.append("Host=Default\n");
|
||||
rawResponse.append("Resource=R1\n");
|
||||
|
||||
rawResponse.append("HTTP/1.1 200 OK\n");
|
||||
rawResponse.append("Date: Mon, 08 Jun 2009 23:05:26 GMT\n");
|
||||
rawResponse.append("Content-Type: text/plain\n");
|
||||
|
@ -93,27 +97,32 @@ public class HttpResponseTesterTest
|
|||
rawResponse.append("Host=Default\n");
|
||||
rawResponse.append("Resource=R2\n");
|
||||
rawResponse.append("\n");
|
||||
|
||||
|
||||
List<HttpTester.Response> responses = HttpTesting.readResponses(rawResponse.toString());
|
||||
|
||||
List<HttpResponseTester> responses = HttpResponseTester.parseMulti(rawResponse);
|
||||
Assert.assertNotNull("Responses should not be null",responses);
|
||||
Assert.assertEquals("Responses.size",3,responses.size());
|
||||
|
||||
HttpResponseTester resp1 = responses.get(0);
|
||||
resp1.assertStatusOK();
|
||||
resp1.assertContentType("text/plain");
|
||||
resp1.assertBody("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n");
|
||||
assertThat(resp1.getHeader("Connection"),is(not("close")));
|
||||
HttpTester.Response resp1 = responses.get(0);
|
||||
System.err.println(resp1.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp1.getStatus());
|
||||
Assert.assertEquals("text/plain", resp1.get("Content-Type"));
|
||||
Assert.assertTrue(resp1.getContent().contains("ABCDEFGHIJKLMNOPQRSTTUVWXYZ\n"));
|
||||
assertThat(resp1.get("Connection"),is(not("close")));
|
||||
|
||||
HttpResponseTester resp2 = responses.get(1);
|
||||
resp2.assertStatusOK();
|
||||
resp2.assertContentType("text/plain");
|
||||
resp2.assertBody("Host=Default\nResource=R1\n");
|
||||
assertThat(resp2.getHeader("Connection"),is(not("close")));
|
||||
HttpTester.Response resp2 = responses.get(1);
|
||||
System.err.println(resp2.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp2.getStatus());
|
||||
Assert.assertEquals("text/plain", resp2.get("Content-Type"));
|
||||
Assert.assertTrue(resp2.getContent().contains("Host=Default\nResource=R1\n"));
|
||||
assertThat(resp2.get("Connection"),is(not("close")));
|
||||
|
||||
HttpResponseTester resp3 = responses.get(2);
|
||||
resp3.assertStatusOK();
|
||||
resp3.assertContentType("text/plain");
|
||||
resp3.assertBody("Host=Default\nResource=R2\n");
|
||||
assertThat(resp3.getHeader("Connection"),is("close"));
|
||||
HttpTester.Response resp3 = responses.get(2);
|
||||
System.err.println(resp3.toString());
|
||||
Assert.assertEquals(HttpStatus.OK_200, resp3.getStatus());
|
||||
Assert.assertEquals("text/plain", resp3.get("Content-Type"));
|
||||
Assert.assertTrue(resp3.getContent().contains("Host=Default\nResource=R2\n"));
|
||||
assertThat(resp3.get("Connection"),is("close"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,25 @@
|
|||
|
||||
package org.eclipse.jetty.test.support.rawhttp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.test.support.StringUtil;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
|
||||
/**
|
||||
* Testing utility for performing RAW HTTP request/response.
|
||||
|
@ -42,6 +48,102 @@ public class HttpTesting
|
|||
private InetAddress serverHost;
|
||||
private int serverPort;
|
||||
private int timeoutMillis = 5000;
|
||||
|
||||
|
||||
public static List<HttpTester.Response> getParts (String boundary, HttpTester.Response response) throws IOException
|
||||
{
|
||||
List<HttpTester.Response> parts = new ArrayList<HttpTester.Response>();
|
||||
|
||||
BufferedReader buf = new BufferedReader(new StringReader(response.getContent()));
|
||||
String line;
|
||||
String startBoundary = "--" + boundary;
|
||||
String endBoundary = "--" + boundary + "--";
|
||||
|
||||
StringBuffer partBuff = null;
|
||||
boolean parsingHeader = true;
|
||||
boolean previousBodyLine = false;
|
||||
|
||||
while ((line = buf.readLine()) != null)
|
||||
{
|
||||
if (line.equals(startBoundary))
|
||||
{
|
||||
// end of multipart, start a new one.
|
||||
if (partBuff != null)
|
||||
{
|
||||
HttpTester.Response part = HttpTester.parseResponse(partBuff.toString());
|
||||
parts.add(part);
|
||||
}
|
||||
partBuff = new StringBuffer();
|
||||
parsingHeader = true;
|
||||
previousBodyLine = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.equals(endBoundary))
|
||||
{
|
||||
if (partBuff != null)
|
||||
{
|
||||
HttpTester.Response part = HttpTester.parseResponse(partBuff.toString());
|
||||
parts.add(part);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (parsingHeader)
|
||||
{
|
||||
if (line.equals(""))
|
||||
{
|
||||
parsingHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
partBuff.append(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (previousBodyLine)
|
||||
{
|
||||
partBuff.append("\n");
|
||||
}
|
||||
partBuff.append(line);
|
||||
previousBodyLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<HttpTester.Response> readResponses(ByteBuffer buffer) throws IOException
|
||||
{
|
||||
List<HttpTester.Response> list = new ArrayList<>();
|
||||
|
||||
while(BufferUtil.hasContent(buffer))
|
||||
{
|
||||
HttpTester.Response response = HttpTester.parseResponse(buffer);
|
||||
if (response == null)
|
||||
break;
|
||||
list.add(HttpTester.parseResponse(buffer));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<HttpTester.Response> readResponses(String string) throws IOException
|
||||
{
|
||||
List<HttpTester.Response> list = new ArrayList<>();
|
||||
|
||||
ByteBuffer buffer = BufferUtil.toBuffer(string);
|
||||
while(BufferUtil.hasContent(buffer))
|
||||
{
|
||||
HttpTester.Response response = HttpTester.parseResponse(buffer);
|
||||
if (response == null)
|
||||
break;
|
||||
list.add(response);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public HttpTesting(HttpSocket httpSocket, InetAddress host, int port)
|
||||
{
|
||||
|
@ -115,11 +217,25 @@ public class HttpTesting
|
|||
* @return the response object
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponseTester read(Socket sock) throws IOException
|
||||
public HttpTester.Response read(Socket sock) throws IOException
|
||||
{
|
||||
HttpResponseTester response = new HttpResponseTester();
|
||||
response.parse(readRaw(sock));
|
||||
return response;
|
||||
return HttpTester.parseResponse(readRaw(sock));
|
||||
}
|
||||
|
||||
|
||||
public List<HttpTester.Response> readResponses(Socket sock) throws IOException
|
||||
{
|
||||
List<HttpTester.Response> list = new ArrayList<>();
|
||||
String r = readRaw(sock);
|
||||
ByteBuffer buffer = BufferUtil.toBuffer(r);
|
||||
while(BufferUtil.hasContent(buffer))
|
||||
{
|
||||
HttpTester.Response response = HttpTester.parseResponse(buffer);
|
||||
if (response == null)
|
||||
break;
|
||||
list.add(response);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,16 +246,15 @@ public class HttpTesting
|
|||
* @return the response object
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponseTester readAvailable(Socket sock) throws IOException
|
||||
public HttpTester.Response readAvailable(Socket sock) throws IOException
|
||||
{
|
||||
HttpResponseTester response = new HttpResponseTester();
|
||||
|
||||
String rawResponse = readRawAvailable(sock);
|
||||
if (StringUtil.isBlank(rawResponse))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
response.parse(rawResponse);
|
||||
return response;
|
||||
return HttpTester.parseResponse(rawResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,7 +314,7 @@ public class HttpTesting
|
|||
* @return the response
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponseTester request(CharSequence rawRequest) throws IOException
|
||||
public HttpTester.Response request(CharSequence rawRequest) throws IOException
|
||||
{
|
||||
Socket sock = open();
|
||||
try
|
||||
|
@ -223,10 +338,10 @@ public class HttpTesting
|
|||
* @return the response
|
||||
* @throws IOException
|
||||
*/
|
||||
public HttpResponseTester request(HttpRequestTester request) throws IOException
|
||||
public HttpTester.Response request(HttpTester.Request request) throws IOException
|
||||
{
|
||||
String rawRequest = request.generate();
|
||||
return request(rawRequest);
|
||||
ByteBuffer byteBuff = request.generate();
|
||||
return request(BufferUtil.toString(byteBuff));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +352,7 @@ public class HttpTesting
|
|||
* @return the responses.
|
||||
* @throws IOException
|
||||
*/
|
||||
public List<HttpResponseTester> requests(CharSequence rawRequests) throws IOException
|
||||
public List<HttpTester.Response> requests(CharSequence rawRequests) throws IOException
|
||||
{
|
||||
Socket sock = open();
|
||||
try
|
||||
|
@ -247,7 +362,7 @@ public class HttpTesting
|
|||
// Collect response
|
||||
String rawResponses = IO.toString(sock.getInputStream());
|
||||
DEBUG("--raw-response--\n" + rawResponses);
|
||||
return HttpResponseTester.parseMulti(rawResponses);
|
||||
return readResponses(rawResponses);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -255,24 +370,6 @@ public class HttpTesting
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a multiple HTTP requests, parse the responses
|
||||
*
|
||||
* @param requests
|
||||
* the request objects.
|
||||
* @return the response objects.
|
||||
* @throws IOException
|
||||
*/
|
||||
public List<HttpResponseTester> requests(List<HttpRequestTester> requests) throws IOException
|
||||
{
|
||||
StringBuffer rawRequest = new StringBuffer();
|
||||
for (HttpRequestTester request : requests)
|
||||
{
|
||||
rawRequest.append(request.generate());
|
||||
}
|
||||
|
||||
return requests(rawRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a data (as request) to open socket.
|
||||
|
|
|
@ -12,32 +12,23 @@
|
|||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Server Thread Pool -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="ThreadPool">
|
||||
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
|
||||
<Set name="minThreads">10</Set>
|
||||
<Set name="maxThreads">200</Set>
|
||||
</New>
|
||||
</Set>
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
<Set name="headerCacheSize">512</Set>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set connectors -->
|
||||
<!-- =========================================================== -->
|
||||
<!-- Uncomment to enable handling of X-Forwarded- style headers
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
-->
|
||||
</New>
|
||||
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
<!--<Set name="confidentialPort">8443</Set>-->
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set handler Collection Structure -->
|
||||
|
|
|
@ -6,17 +6,27 @@
|
|||
<!-- =========================================================== -->
|
||||
<!-- Set connectors -->
|
||||
<!-- =========================================================== -->
|
||||
|
||||
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg name="server"><Ref refid="Server" /></Arg>
|
||||
<Arg name="factories">
|
||||
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
|
||||
<Arg name="config"><Ref refid="httpConfig" /></Arg>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="host"><Property name="jetty.host" /></Set>
|
||||
<Set name="port"><Property name="jetty.port" default="8080" /></Set>
|
||||
<Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
|
||||
</Configure>
|
||||
|
|
|
@ -5,21 +5,33 @@
|
|||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set connectors -->
|
||||
<!-- =========================================================== -->
|
||||
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
<Set name="keystore"><Property name="test.resourcesdir" default="src/test/resources" />/keystore</Set>
|
||||
<Set name="password">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
|
||||
<Set name="keyPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
<!-- =========================================================== -->
|
||||
<Call id="httpsConnector" name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Arg name="server"><Ref refid="Server" /></Arg>
|
||||
<Arg name="factories">
|
||||
<Array type="org.eclipse.jetty.server.ConnectionFactory">
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.SslConnectionFactory">
|
||||
<Arg name="next">http/1.1</Arg>
|
||||
<Arg name="sslContextFactory"><Ref refid="sslContextFactory"/></Arg>
|
||||
</New>
|
||||
</Item>
|
||||
<Item>
|
||||
<New class="org.eclipse.jetty.server.HttpConnectionFactory">
|
||||
<Arg name="config"><Ref refid="sslHttpConfig"/></Arg>
|
||||
</New>
|
||||
</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
<Set name="host"><Property name="jetty.host" /></Set>
|
||||
<Set name="port"><Property name="jetty.https.port" default="8443" /></Set>
|
||||
<Set name="idleTimeout">30000</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
|
||||
</Configure>
|
||||
|
|
|
@ -12,38 +12,22 @@
|
|||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Server Thread Pool -->
|
||||
<!-- =========================================================== -->
|
||||
<Set name="ThreadPool">
|
||||
<New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
|
||||
<Set name="minThreads">10</Set>
|
||||
<Set name="maxThreads">200</Set>
|
||||
</New>
|
||||
</Set>
|
||||
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Set name="secureScheme">https</Set>
|
||||
<Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
|
||||
<Set name="outputBufferSize">32768</Set>
|
||||
<Set name="requestHeaderSize">8192</Set>
|
||||
<Set name="responseHeaderSize">8192</Set>
|
||||
<Set name="sendServerVersion">true</Set>
|
||||
<Set name="sendDateHeader">false</Set>
|
||||
<Set name="headerCacheSize">512</Set>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- No connectors Set Here. -->
|
||||
<!-- See: -->
|
||||
<!-- BIOHttp.xml -->
|
||||
<!-- BIOHttps.xml -->
|
||||
<!-- NIOHttp.xml -->
|
||||
<!-- NIOHttps.xml -->
|
||||
<!-- =========================================================== -->
|
||||
|
||||
<!--
|
||||
<Call name="addConnector">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.server.ServerConnector">
|
||||
<Set name="host"><SystemProperty name="jetty.host" /></Set>
|
||||
<Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
|
||||
<Set name="idleTimeout">300000</Set>
|
||||
<Set name="Acceptors">2</Set>
|
||||
<Set name="statsOn">false</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
-->
|
||||
<!-- Uncomment to enable handling of X-Forwarded- style headers
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
-->
|
||||
</New>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Set handler Collection Structure -->
|
||||
|
@ -88,52 +72,37 @@
|
|||
</New>
|
||||
</Set>
|
||||
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.ContextDeployer">
|
||||
<Set name="contexts"><Ref refid="WebappContexts"/></Set>
|
||||
<Set name="configurationDir"><Property name="test.resourcesdir" default="src/test/resources"/>/webapp-contexts/RFC2616</Set>
|
||||
<Set name="scanInterval">0</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<Set name="file"><Property name="test.targetdir" default="target"/>/testable-jetty-server-config.properties</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New id="DeploymentManager" class="org.eclipse.jetty.deploy.DeploymentManager">
|
||||
<Set name="contexts">
|
||||
<Ref refid="Contexts" />
|
||||
</Set>
|
||||
<Call name="setContextAttribute">
|
||||
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
|
||||
<Arg>.*/servlet-api-[^/]*\.jar$</Arg>
|
||||
</Call>
|
||||
|
||||
<Call id="webappprovider" name="addAppProvider">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.providers.WebAppProvider">
|
||||
<Set name="monitoredDirName"><Property name="test.resourcesdir" default="src/test/resources" />/webapps-contexts/RFC2616</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="extractWars">true</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<Set name="file"><Property name="test.targetdir" default="target"/>/testable-jetty-server-config.properties</Set>
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Configure the webapp deployer. -->
|
||||
<!-- A webapp deployer will deploy standard webapps discovered -->
|
||||
<!-- in a directory at startup, without the need for additional -->
|
||||
<!-- configuration files. It does not support hot deploy or -->
|
||||
<!-- non standard contexts (see ContextDeployer above). -->
|
||||
<!-- -->
|
||||
<!-- This deployer is configured to deploy webapps from the -->
|
||||
<!-- $JETTY_HOME/webapps directory -->
|
||||
<!-- -->
|
||||
<!-- Normally only one type of deployer need be used. -->
|
||||
<!-- -->
|
||||
<!-- =========================================================== -->
|
||||
<!--
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.deploy.WebAppDeployer">
|
||||
<Set name="contexts"><Ref refid="WebappContexts"/></Set>
|
||||
<Set name="webAppDir"><Property name="test.targetdir" default="target"/>/webapps</Set>
|
||||
<Set name="parentLoaderPriority">false</Set>
|
||||
<Set name="extract">true</Set>
|
||||
<Set name="allowDuplicates">false</Set>
|
||||
<Set name="defaultsDescriptor"><Property name="test.resourcesdir" default="src/test/resources"/>/webdefault.xml</Set>
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
|
||||
<Arg>.*/jsp-api-[^/]*\.jar$|.*/jsp-[^/]*\.jar$</Arg>
|
||||
</Call>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
-->
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- extra options -->
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
|
||||
<Set name="KeyStorePath"><Property name="jetty.home" default="." />/<Property name="jetty.keystore" default="keystore"/></Set>
|
||||
<Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
||||
<Set name="KeyManagerPassword"><Property name="jetty.keymanager.password" default="OBF:1u2u1wml1z7s1z7a1wnl1u2g"/></Set>
|
||||
<Set name="TrustStorePath"><Property name="jetty.home" default="." />/<Property name="jetty.truststore" default="keystore"/></Set>
|
||||
<Set name="TrustStorePassword"><Property name="jetty.truststore.password" default="OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"/></Set>
|
||||
<Set name="EndpointIdentificationAlgorithm"></Set>
|
||||
<Set name="ExcludeCipherSuites">
|
||||
<Array type="String">
|
||||
<Item>SSL_RSA_WITH_DES_CBC_SHA</Item>
|
||||
<Item>SSL_DHE_RSA_WITH_DES_CBC_SHA</Item>
|
||||
<Item>SSL_DHE_DSS_WITH_DES_CBC_SHA</Item>
|
||||
<Item>SSL_RSA_EXPORT_WITH_RC4_40_MD5</Item>
|
||||
<Item>SSL_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
|
||||
<Item>SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA</Item>
|
||||
<Item>SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Create a TLS specific HttpConfiguration based on the -->
|
||||
<!-- common HttpConfiguration defined in jetty.xml -->
|
||||
<!-- Add a SecureRequestCustomizer to extract certificate and -->
|
||||
<!-- session information -->
|
||||
<!-- =========================================================== -->
|
||||
<New id="sslHttpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
|
||||
<Arg><Ref refid="httpConfig"/></Arg>
|
||||
<Call name="addCustomizer">
|
||||
<Arg><New class="org.eclipse.jetty.server.SecureRequestCustomizer"/></Arg>
|
||||
</Call>
|
||||
</New>
|
||||
|
||||
</Configure>
|
Loading…
Reference in New Issue