Merge remote-tracking branch 'origin/master' into servlet-3.1-api
This commit is contained in:
commit
2a2215cf0b
|
@ -21,13 +21,6 @@ package org.eclipse.jetty.embedded;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* A {@link ContextHandler} provides a common environment for multiple Handlers,
|
||||
* such as: URI context path, class loader, static resource base.
|
||||
*
|
||||
* Typically a ContextHandler is used only when multiple contexts are likely.
|
||||
*/
|
||||
public class OneContext
|
||||
{
|
||||
public static void main(String[] args) throws Exception
|
||||
|
@ -38,10 +31,10 @@ public class OneContext
|
|||
context.setContextPath("/");
|
||||
context.setResourceBase(".");
|
||||
context.setClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
server.setHandler(context);
|
||||
|
||||
context.setHandler(new HelloHandler());
|
||||
|
||||
server.setHandler(context);
|
||||
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.net.URLClassLoader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.jar.JarEntry;
|
||||
|
||||
import org.eclipse.jetty.util.Loader;
|
||||
|
@ -807,7 +808,7 @@ public class AnnotationParser
|
|||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase().endsWith(".class"))
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
if ((resolver == null)
|
||||
|
@ -853,7 +854,7 @@ public class AnnotationParser
|
|||
try
|
||||
{
|
||||
String name = entry.getName();
|
||||
if (name.toLowerCase().endsWith(".class"))
|
||||
if (name.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
String shortName = name.replace('/', '.').substring(0,name.length()-6);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.annotations;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Locale;
|
||||
import javax.annotation.Resource;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NameNotFoundException;
|
||||
|
@ -261,7 +262,7 @@ public class ResourceAnnotationHandler extends AbstractIntrospectableAnnotationH
|
|||
|
||||
//default name is the javabean property name
|
||||
String name = method.getName().substring(3);
|
||||
name = name.substring(0,1).toLowerCase()+name.substring(1);
|
||||
name = name.substring(0,1).toLowerCase(Locale.ENGLISH)+name.substring(1);
|
||||
name = clazz.getCanonicalName()+"/"+name;
|
||||
|
||||
name = (resource.name()!=null && !resource.name().trim().equals("")? resource.name(): name);
|
||||
|
|
|
@ -79,14 +79,14 @@ public class AuthenticationProtocolHandler implements ProtocolHandler
|
|||
public void onComplete(Result result)
|
||||
{
|
||||
Request request = result.getRequest();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
Response.Listener listener = conversation.getExchanges().peekFirst().getResponseListener();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
List<Response.ResponseListener> listeners = conversation.getExchanges().peekFirst().getResponseListeners();
|
||||
ContentResponse response = new HttpContentResponse(result.getResponse(), getContent(), getEncoding());
|
||||
if (result.isFailed())
|
||||
{
|
||||
Throwable failure = result.getFailure();
|
||||
LOG.debug("Authentication challenge failed {}", failure);
|
||||
notifier.forwardFailureComplete(listener, request, result.getRequestFailure(), response, result.getResponseFailure());
|
||||
notifier.forwardFailureComplete(listeners, request, result.getRequestFailure(), response, result.getResponseFailure());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class AuthenticationProtocolHandler implements ProtocolHandler
|
|||
if (wwwAuthenticates.isEmpty())
|
||||
{
|
||||
LOG.debug("Authentication challenge without WWW-Authenticate header");
|
||||
notifier.forwardFailureComplete(listener, request, null, response, new HttpResponseException("HTTP protocol violation: 401 without WWW-Authenticate header", response));
|
||||
notifier.forwardFailureComplete(listeners, request, null, response, new HttpResponseException("HTTP protocol violation: 401 without WWW-Authenticate header", response));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class AuthenticationProtocolHandler implements ProtocolHandler
|
|||
if (authentication == null)
|
||||
{
|
||||
LOG.debug("No authentication available for {}", request);
|
||||
notifier.forwardSuccessComplete(listener, request, response);
|
||||
notifier.forwardSuccessComplete(listeners, request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -121,19 +121,20 @@ public class AuthenticationProtocolHandler implements ProtocolHandler
|
|||
LOG.debug("Authentication result {}", authnResult);
|
||||
if (authnResult == null)
|
||||
{
|
||||
notifier.forwardSuccessComplete(listener, request, response);
|
||||
notifier.forwardSuccessComplete(listeners, request, response);
|
||||
return;
|
||||
}
|
||||
|
||||
authnResult.apply(request);
|
||||
request.send(new Response.Listener.Empty()
|
||||
Request newRequest = client.copyRequest(request, request.getURI());
|
||||
authnResult.apply(newRequest);
|
||||
newRequest.onResponseSuccess(new Response.SuccessListener()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Response response)
|
||||
{
|
||||
client.getAuthenticationStore().addAuthenticationResult(authnResult);
|
||||
}
|
||||
});
|
||||
}).send(null);
|
||||
}
|
||||
|
||||
private List<WWWAuthenticate> parseWWWAuthenticate(Response response)
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.client.util.BufferingResponseListener;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpHeaderValue;
|
||||
|
@ -41,7 +44,8 @@ public class ContinueProtocolHandler implements ProtocolHandler
|
|||
public boolean accept(Request request, Response response)
|
||||
{
|
||||
boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
|
||||
boolean handled100 = client.getConversation(request.getConversationID()).getAttribute(ATTRIBUTE) != null;
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
boolean handled100 = conversation != null && conversation.getAttribute(ATTRIBUTE) != null;
|
||||
return expect100 && !handled100;
|
||||
}
|
||||
|
||||
|
@ -60,20 +64,20 @@ public class ContinueProtocolHandler implements ProtocolHandler
|
|||
// Handling of success must be done here and not from onComplete(),
|
||||
// since the onComplete() is not invoked because the request is not completed yet.
|
||||
|
||||
HttpConversation conversation = client.getConversation(response.getConversationID());
|
||||
HttpConversation conversation = client.getConversation(response.getConversationID(), false);
|
||||
// Mark the 100 Continue response as handled
|
||||
conversation.setAttribute(ATTRIBUTE, Boolean.TRUE);
|
||||
|
||||
HttpExchange exchange = conversation.getExchanges().peekLast();
|
||||
assert exchange.getResponse() == response;
|
||||
Response.Listener listener = exchange.getResponseListener();
|
||||
List<Response.ResponseListener> listeners = exchange.getResponseListeners();
|
||||
switch (response.getStatus())
|
||||
{
|
||||
case 100:
|
||||
{
|
||||
// All good, continue
|
||||
exchange.resetResponse(true);
|
||||
conversation.setResponseListener(listener);
|
||||
conversation.setResponseListeners(listeners);
|
||||
exchange.proceed(true);
|
||||
break;
|
||||
}
|
||||
|
@ -81,8 +85,8 @@ public class ContinueProtocolHandler implements ProtocolHandler
|
|||
{
|
||||
// Server either does not support 100 Continue, or it does and wants to refuse the request content
|
||||
HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding());
|
||||
notifier.forwardSuccess(listener, contentResponse);
|
||||
conversation.setResponseListener(listener);
|
||||
notifier.forwardSuccess(listeners, contentResponse);
|
||||
conversation.setResponseListeners(listeners);
|
||||
exchange.proceed(false);
|
||||
break;
|
||||
}
|
||||
|
@ -92,15 +96,20 @@ public class ContinueProtocolHandler implements ProtocolHandler
|
|||
@Override
|
||||
public void onFailure(Response response, Throwable failure)
|
||||
{
|
||||
HttpConversation conversation = client.getConversation(response.getConversationID());
|
||||
HttpConversation conversation = client.getConversation(response.getConversationID(), false);
|
||||
// Mark the 100 Continue response as handled
|
||||
conversation.setAttribute(ATTRIBUTE, Boolean.TRUE);
|
||||
|
||||
HttpExchange exchange = conversation.getExchanges().peekLast();
|
||||
assert exchange.getResponse() == response;
|
||||
Response.Listener listener = exchange.getResponseListener();
|
||||
List<Response.ResponseListener> listeners = exchange.getResponseListeners();
|
||||
HttpContentResponse contentResponse = new HttpContentResponse(response, getContent(), getEncoding());
|
||||
notifier.forwardFailureComplete(listener, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure);
|
||||
notifier.forwardFailureComplete(listeners, exchange.getRequest(), exchange.getRequestFailure(), contentResponse, failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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.client;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
|
||||
public class DoubleResponseListener implements Response.Listener
|
||||
{
|
||||
private final ResponseNotifier responseNotifier;
|
||||
private final Response.Listener listener1;
|
||||
private final Response.Listener listener2;
|
||||
|
||||
public DoubleResponseListener(ResponseNotifier responseNotifier, Response.Listener listener1, Response.Listener listener2)
|
||||
{
|
||||
this.responseNotifier = responseNotifier;
|
||||
this.listener1 = listener1;
|
||||
this.listener2 = listener2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBegin(Response response)
|
||||
{
|
||||
responseNotifier.notifyBegin(listener1, response);
|
||||
responseNotifier.notifyBegin(listener2, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHeaders(Response response)
|
||||
{
|
||||
responseNotifier.notifyHeaders(listener1, response);
|
||||
responseNotifier.notifyHeaders(listener2, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContent(Response response, ByteBuffer content)
|
||||
{
|
||||
responseNotifier.notifyContent(listener1, response, content);
|
||||
responseNotifier.notifyContent(listener2, response, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Response response)
|
||||
{
|
||||
responseNotifier.notifySuccess(listener1, response);
|
||||
responseNotifier.notifySuccess(listener2, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Response response, Throwable failure)
|
||||
{
|
||||
responseNotifier.notifyFailure(listener1, response, failure);
|
||||
responseNotifier.notifyFailure(listener2, response, failure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
responseNotifier.notifyComplete(listener1, result);
|
||||
responseNotifier.notifyComplete(listener2, result);
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -45,6 +46,8 @@ import org.eclipse.jetty.client.api.CookieStore;
|
|||
import org.eclipse.jetty.client.api.Destination;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
@ -86,7 +89,7 @@ import org.eclipse.jetty.util.thread.TimerScheduler;
|
|||
*
|
||||
* // Asynchronously
|
||||
* HttpClient client = new HttpClient();
|
||||
* client.newRequest("http://localhost:8080").send(new Response.Listener.Adapter()
|
||||
* client.newRequest("http://localhost:8080").send(new Response.Listener.Empty()
|
||||
* {
|
||||
* @Override
|
||||
* public void onSuccess(Response response)
|
||||
|
@ -265,9 +268,21 @@ public class HttpClient extends ContainerLifeCycle
|
|||
return new HttpRequest(this, uri);
|
||||
}
|
||||
|
||||
protected Request newRequest(long id, String uri)
|
||||
protected Request copyRequest(Request oldRequest, String newURI)
|
||||
{
|
||||
return new HttpRequest(this, id, URI.create(uri));
|
||||
Request newRequest = new HttpRequest(this, oldRequest.getConversationID(), URI.create(newURI));
|
||||
newRequest.method(oldRequest.getMethod())
|
||||
.version(oldRequest.getVersion())
|
||||
.content(oldRequest.getContent());
|
||||
for (HttpFields.Field header : oldRequest.getHeaders())
|
||||
{
|
||||
// We have a new URI, so skip the host header if present
|
||||
if (HttpHeader.HOST == header.getHeader())
|
||||
continue;
|
||||
|
||||
newRequest.header(header.getName(), header.getValue());
|
||||
}
|
||||
return newRequest;
|
||||
}
|
||||
|
||||
private String address(String scheme, String host, int port)
|
||||
|
@ -307,9 +322,9 @@ public class HttpClient extends ContainerLifeCycle
|
|||
return new ArrayList<Destination>(destinations.values());
|
||||
}
|
||||
|
||||
protected void send(final Request request, Response.Listener listener)
|
||||
protected void send(final Request request, List<Response.ResponseListener> listeners)
|
||||
{
|
||||
String scheme = request.getScheme().toLowerCase();
|
||||
String scheme = request.getScheme().toLowerCase(Locale.ENGLISH);
|
||||
if (!Arrays.asList("http", "https").contains(scheme))
|
||||
throw new IllegalArgumentException("Invalid protocol " + scheme);
|
||||
|
||||
|
@ -317,11 +332,12 @@ public class HttpClient extends ContainerLifeCycle
|
|||
if (port < 0)
|
||||
port = "https".equals(scheme) ? 443 : 80;
|
||||
|
||||
if (listener instanceof ResponseListener.Timed)
|
||||
((ResponseListener.Timed)listener).schedule(scheduler);
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Schedulable)
|
||||
((Schedulable)listener).schedule(scheduler);
|
||||
|
||||
HttpDestination destination = provideDestination(scheme, request.getHost(), port);
|
||||
destination.send(request, listener);
|
||||
destination.send(request, listeners);
|
||||
}
|
||||
|
||||
protected void newConnection(HttpDestination destination, Callback<Connection> callback)
|
||||
|
@ -365,10 +381,10 @@ public class HttpClient extends ContainerLifeCycle
|
|||
}
|
||||
}
|
||||
|
||||
protected HttpConversation getConversation(long id)
|
||||
protected HttpConversation getConversation(long id, boolean create)
|
||||
{
|
||||
HttpConversation conversation = conversations.get(id);
|
||||
if (conversation == null)
|
||||
if (conversation == null && create)
|
||||
{
|
||||
conversation = new HttpConversation(this, id);
|
||||
HttpConversation existing = conversations.putIfAbsent(id, conversation);
|
||||
|
@ -395,7 +411,7 @@ public class HttpClient extends ContainerLifeCycle
|
|||
{
|
||||
for (ProtocolHandler handler : getProtocolHandlers())
|
||||
{
|
||||
if (handler.accept(request, response))
|
||||
if (handler.accept(request, response))
|
||||
return handler;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -102,7 +103,12 @@ public class HttpConnection extends AbstractConnection implements Connection
|
|||
}
|
||||
|
||||
@Override
|
||||
public void send(Request request, Response.Listener listener)
|
||||
public void send(Request request, Response.CompleteListener listener)
|
||||
{
|
||||
send(request, Collections.<Response.ResponseListener>singletonList(listener));
|
||||
}
|
||||
|
||||
public void send(Request request, List<Response.ResponseListener> listeners)
|
||||
{
|
||||
normalizeRequest(request);
|
||||
|
||||
|
@ -111,13 +117,14 @@ public class HttpConnection extends AbstractConnection implements Connection
|
|||
idleTimeout = endPoint.getIdleTimeout();
|
||||
endPoint.setIdleTimeout(request.getIdleTimeout());
|
||||
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
HttpExchange exchange = new HttpExchange(conversation, this, request, listener);
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), true);
|
||||
HttpExchange exchange = new HttpExchange(conversation, this, request, listeners);
|
||||
setExchange(exchange);
|
||||
conversation.getExchanges().offer(exchange);
|
||||
|
||||
if (listener instanceof ResponseListener.Timed)
|
||||
((ResponseListener.Timed)listener).schedule(client.getScheduler());
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Schedulable)
|
||||
((Schedulable)listener).schedule(client.getScheduler());
|
||||
|
||||
sender.send(exchange);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
|
@ -46,9 +47,9 @@ public class HttpContentResponse implements ContentResponse
|
|||
}
|
||||
|
||||
@Override
|
||||
public Listener getListener()
|
||||
public <T extends ResponseListener> List<T> getListeners(Class<T> listenerClass)
|
||||
{
|
||||
return response.getListener();
|
||||
return response.getListeners(listenerClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.client;
|
|||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
@ -34,8 +35,7 @@ public class HttpConversation implements Attributes
|
|||
private final Deque<HttpExchange> exchanges = new ConcurrentLinkedDeque<>();
|
||||
private final HttpClient client;
|
||||
private final long id;
|
||||
private volatile Response.Listener listener;
|
||||
private volatile HttpExchange last;
|
||||
private volatile List<Response.ResponseListener> listeners;
|
||||
|
||||
public HttpConversation(HttpClient client, long id)
|
||||
{
|
||||
|
@ -53,35 +53,14 @@ public class HttpConversation implements Attributes
|
|||
return exchanges;
|
||||
}
|
||||
|
||||
public Response.Listener getResponseListener()
|
||||
public List<Response.ResponseListener> getResponseListeners()
|
||||
{
|
||||
return listener;
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public void setResponseListener(Response.Listener listener)
|
||||
public void setResponseListeners(List<Response.ResponseListener> listeners)
|
||||
{
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the exchange that has been identified as the last of this conversation
|
||||
* @see #last
|
||||
*/
|
||||
public HttpExchange getLastExchange()
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remembers the given {@code exchange} as the last of this conversation.
|
||||
*
|
||||
* @param exchange the exchange that is the last of this conversation
|
||||
* @see #last
|
||||
*/
|
||||
public void setLastExchange(HttpExchange exchange)
|
||||
{
|
||||
if (last == null)
|
||||
last = exchange;
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public void complete()
|
||||
|
|
|
@ -44,7 +44,7 @@ public class HttpCookieParser
|
|||
|
||||
public static List<HttpCookie> parseCookies(String headerValue)
|
||||
{
|
||||
if (headerValue.toLowerCase().contains("expires="))
|
||||
if (headerValue.toLowerCase(Locale.ENGLISH).contains("expires="))
|
||||
{
|
||||
HttpCookie cookie = parseCookie(headerValue, 0);
|
||||
if (cookie != null)
|
||||
|
@ -111,7 +111,7 @@ public class HttpCookieParser
|
|||
try
|
||||
{
|
||||
String[] attributeParts = cookieParts[i].split("=", 2);
|
||||
String attributeName = attributeParts[0].trim().toLowerCase();
|
||||
String attributeName = attributeParts[0].trim().toLowerCase(Locale.ENGLISH);
|
||||
String attributeValue = attributeParts.length < 2 ? "" : attributeParts[1].trim();
|
||||
switch (attributeName)
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
private final String scheme;
|
||||
private final String host;
|
||||
private final int port;
|
||||
private final Queue<RequestPair> requests;
|
||||
private final Queue<RequestContext> requests;
|
||||
private final BlockingQueue<Connection> idleConnections;
|
||||
private final BlockingQueue<Connection> activeConnections;
|
||||
private final RequestNotifier requestNotifier;
|
||||
|
@ -97,7 +97,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
return port;
|
||||
}
|
||||
|
||||
public void send(Request request, Response.Listener listener)
|
||||
public void send(Request request, List<Response.ResponseListener> listeners)
|
||||
{
|
||||
if (!scheme.equals(request.getScheme()))
|
||||
throw new IllegalArgumentException("Invalid request scheme " + request.getScheme() + " for destination " + this);
|
||||
|
@ -107,12 +107,12 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
if (port >= 0 && this.port != port)
|
||||
throw new IllegalArgumentException("Invalid request port " + port + " for destination " + this);
|
||||
|
||||
RequestPair requestPair = new RequestPair(request, listener);
|
||||
RequestContext requestContext = new RequestContext(request, listeners);
|
||||
if (client.isRunning())
|
||||
{
|
||||
if (requests.offer(requestPair))
|
||||
if (requests.offer(requestContext))
|
||||
{
|
||||
if (!client.isRunning() && requests.remove(requestPair))
|
||||
if (!client.isRunning() && requests.remove(requestContext))
|
||||
{
|
||||
throw new RejectedExecutionException(client + " is stopping");
|
||||
}
|
||||
|
@ -202,15 +202,15 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
|
||||
private void drain(Throwable x)
|
||||
{
|
||||
RequestPair pair;
|
||||
while ((pair = requests.poll()) != null)
|
||||
RequestContext requestContext;
|
||||
while ((requestContext = requests.poll()) != null)
|
||||
{
|
||||
Request request = pair.request;
|
||||
Request request = requestContext.request;
|
||||
requestNotifier.notifyFailure(request, x);
|
||||
Response.Listener listener = pair.listener;
|
||||
HttpResponse response = new HttpResponse(request, listener);
|
||||
responseNotifier.notifyFailure(listener, response, x);
|
||||
responseNotifier.notifyComplete(listener, new Result(request, x, response, x));
|
||||
List<Response.ResponseListener> listeners = requestContext.listeners;
|
||||
HttpResponse response = new HttpResponse(request, listeners);
|
||||
responseNotifier.notifyFailure(listeners, response, x);
|
||||
responseNotifier.notifyComplete(listeners, new Result(request, x, response, x));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,37 +223,40 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
*
|
||||
* @param connection the new connection
|
||||
*/
|
||||
protected void process(final Connection connection, boolean dispatch)
|
||||
protected void process(Connection connection, boolean dispatch)
|
||||
{
|
||||
RequestPair requestPair = requests.poll();
|
||||
if (requestPair == null)
|
||||
// Ugly cast, but lack of generic reification forces it
|
||||
final HttpConnection httpConnection = (HttpConnection)connection;
|
||||
|
||||
RequestContext requestContext = requests.poll();
|
||||
if (requestContext == null)
|
||||
{
|
||||
LOG.debug("{} idle", connection);
|
||||
if (!idleConnections.offer(connection))
|
||||
LOG.debug("{} idle", httpConnection);
|
||||
if (!idleConnections.offer(httpConnection))
|
||||
{
|
||||
LOG.debug("{} idle overflow");
|
||||
connection.close();
|
||||
httpConnection.close();
|
||||
}
|
||||
if (!client.isRunning())
|
||||
{
|
||||
LOG.debug("{} is stopping", client);
|
||||
remove(connection);
|
||||
connection.close();
|
||||
remove(httpConnection);
|
||||
httpConnection.close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final Request request = requestPair.request;
|
||||
final Response.Listener listener = requestPair.listener;
|
||||
if (request.aborted())
|
||||
final Request request = requestContext.request;
|
||||
final List<Response.ResponseListener> listeners = requestContext.listeners;
|
||||
if (request.isAborted())
|
||||
{
|
||||
abort(request, listener, "Aborted");
|
||||
abort(request, listeners, "Aborted");
|
||||
LOG.debug("Aborted {} before processing", request);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("{} active", connection);
|
||||
if (!activeConnections.offer(connection))
|
||||
LOG.debug("{} active", httpConnection);
|
||||
if (!activeConnections.offer(httpConnection))
|
||||
{
|
||||
LOG.warn("{} active overflow");
|
||||
}
|
||||
|
@ -264,13 +267,13 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
connection.send(request, listener);
|
||||
httpConnection.send(request, listeners);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.send(request, listener);
|
||||
httpConnection.send(request, listeners);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -333,14 +336,14 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
|
||||
public boolean abort(Request request, String reason)
|
||||
{
|
||||
for (RequestPair pair : requests)
|
||||
for (RequestContext requestContext : requests)
|
||||
{
|
||||
if (pair.request == request)
|
||||
if (requestContext.request == request)
|
||||
{
|
||||
if (requests.remove(pair))
|
||||
if (requests.remove(requestContext))
|
||||
{
|
||||
// We were able to remove the pair, so it won't be processed
|
||||
abort(request, pair.listener, reason);
|
||||
abort(request, requestContext.listeners, reason);
|
||||
LOG.debug("Aborted {} while queued", request);
|
||||
return true;
|
||||
}
|
||||
|
@ -349,13 +352,13 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
return false;
|
||||
}
|
||||
|
||||
private void abort(Request request, Response.Listener listener, String reason)
|
||||
private void abort(Request request, List<Response.ResponseListener> listeners, String reason)
|
||||
{
|
||||
HttpResponse response = new HttpResponse(request, listener);
|
||||
HttpResponse response = new HttpResponse(request, listeners);
|
||||
HttpResponseException responseFailure = new HttpResponseException(reason, response);
|
||||
responseNotifier.notifyFailure(listener, response, responseFailure);
|
||||
responseNotifier.notifyFailure(listeners, response, responseFailure);
|
||||
HttpRequestException requestFailure = new HttpRequestException(reason, request);
|
||||
responseNotifier.notifyComplete(listener, new Result(request, requestFailure, response, responseFailure));
|
||||
responseNotifier.notifyComplete(listeners, new Result(request, requestFailure, response, responseFailure));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -382,15 +385,15 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
|
|||
return String.format("%s(%s://%s:%d)", HttpDestination.class.getSimpleName(), getScheme(), getHost(), getPort());
|
||||
}
|
||||
|
||||
private static class RequestPair
|
||||
private static class RequestContext
|
||||
{
|
||||
private final Request request;
|
||||
private final Response.Listener listener;
|
||||
private final List<Response.ResponseListener> listeners;
|
||||
|
||||
private RequestPair(Request request, Response.Listener listener)
|
||||
private RequestContext(Request request, List<Response.ResponseListener> listeners)
|
||||
{
|
||||
this.request = request;
|
||||
this.listener = listener;
|
||||
this.listeners = listeners;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicMarkableReference;
|
||||
|
@ -37,18 +38,19 @@ public class HttpExchange
|
|||
private final HttpConversation conversation;
|
||||
private final HttpConnection connection;
|
||||
private final Request request;
|
||||
private final Response.Listener listener;
|
||||
private final List<Response.ResponseListener> listeners;
|
||||
private final HttpResponse response;
|
||||
private volatile boolean last;
|
||||
private volatile Throwable requestFailure;
|
||||
private volatile Throwable responseFailure;
|
||||
|
||||
public HttpExchange(HttpConversation conversation, HttpConnection connection, Request request, Response.Listener listener)
|
||||
public HttpExchange(HttpConversation conversation, HttpConnection connection, Request request, List<Response.ResponseListener> listeners)
|
||||
{
|
||||
this.conversation = conversation;
|
||||
this.connection = connection;
|
||||
this.request = request;
|
||||
this.listener = listener;
|
||||
this.response = new HttpResponse(request, listener);
|
||||
this.listeners = listeners;
|
||||
this.response = new HttpResponse(request, listeners);
|
||||
}
|
||||
|
||||
public HttpConversation getConversation()
|
||||
|
@ -66,9 +68,9 @@ public class HttpExchange
|
|||
return requestFailure;
|
||||
}
|
||||
|
||||
public Response.Listener getResponseListener()
|
||||
public List<Response.ResponseListener> getResponseListeners()
|
||||
{
|
||||
return listener;
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public HttpResponse getResponse()
|
||||
|
@ -81,6 +83,22 @@ public class HttpExchange
|
|||
return responseFailure;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this exchange is the last in the conversation
|
||||
*/
|
||||
public boolean isLast()
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param last whether this exchange is the last in the conversation
|
||||
*/
|
||||
public void setLast(boolean last)
|
||||
{
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public void receive()
|
||||
{
|
||||
connection.receive();
|
||||
|
@ -159,12 +177,13 @@ public class HttpExchange
|
|||
{
|
||||
// Request and response completed
|
||||
LOG.debug("{} complete", this);
|
||||
if (conversation.getLastExchange() == this)
|
||||
if (isLast())
|
||||
{
|
||||
HttpExchange first = conversation.getExchanges().peekFirst();
|
||||
Response.Listener listener = first.getResponseListener();
|
||||
if (listener instanceof ResponseListener.Timed)
|
||||
((ResponseListener.Timed)listener).cancel();
|
||||
List<Response.ResponseListener> listeners = first.getResponseListeners();
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Schedulable)
|
||||
((Schedulable)listener).cancel();
|
||||
conversation.complete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@ package org.eclipse.jetty.client;
|
|||
|
||||
import java.io.EOFException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicMarkableReference;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -139,30 +142,41 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
response.version(version).status(status).reason(reason);
|
||||
|
||||
// Probe the protocol handlers
|
||||
Response.Listener currentListener = exchange.getResponseListener();
|
||||
Response.Listener initialListener = conversation.getExchanges().peekFirst().getResponseListener();
|
||||
HttpExchange initialExchange = conversation.getExchanges().peekFirst();
|
||||
HttpClient client = connection.getHttpClient();
|
||||
ProtocolHandler protocolHandler = client.findProtocolHandler(exchange.getRequest(), response);
|
||||
Response.Listener handlerListener = protocolHandler == null ? null : protocolHandler.getResponseListener();
|
||||
if (handlerListener == null)
|
||||
{
|
||||
conversation.setLastExchange(exchange);
|
||||
if (currentListener == initialListener)
|
||||
conversation.setResponseListener(initialListener);
|
||||
exchange.setLast(true);
|
||||
if (initialExchange == exchange)
|
||||
{
|
||||
conversation.setResponseListeners(exchange.getResponseListeners());
|
||||
}
|
||||
else
|
||||
conversation.setResponseListener(new DoubleResponseListener(responseNotifier, currentListener, initialListener));
|
||||
{
|
||||
List<Response.ResponseListener> listeners = new ArrayList<>(exchange.getResponseListeners());
|
||||
listeners.addAll(initialExchange.getResponseListeners());
|
||||
conversation.setResponseListeners(listeners);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("Found protocol handler {}", protocolHandler);
|
||||
if (currentListener == initialListener)
|
||||
conversation.setResponseListener(handlerListener);
|
||||
if (initialExchange == exchange)
|
||||
{
|
||||
conversation.setResponseListeners(Collections.<Response.ResponseListener>singletonList(handlerListener));
|
||||
}
|
||||
else
|
||||
conversation.setResponseListener(new DoubleResponseListener(responseNotifier, currentListener, handlerListener));
|
||||
{
|
||||
List<Response.ResponseListener> listeners = new ArrayList<>(exchange.getResponseListeners());
|
||||
listeners.add(handlerListener);
|
||||
conversation.setResponseListeners(listeners);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.debug("Receiving {}", response);
|
||||
responseNotifier.notifyBegin(conversation.getResponseListener(), response);
|
||||
responseNotifier.notifyBegin(conversation.getResponseListeners(), response);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -178,7 +192,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
if (exchange != null)
|
||||
{
|
||||
exchange.getResponse().getHeaders().add(name, value);
|
||||
switch (name.toLowerCase())
|
||||
switch (name.toLowerCase(Locale.ENGLISH))
|
||||
{
|
||||
case "set-cookie":
|
||||
case "set-cookie2":
|
||||
|
@ -212,7 +226,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
HttpConversation conversation = exchange.getConversation();
|
||||
HttpResponse response = exchange.getResponse();
|
||||
LOG.debug("Headers {}", response);
|
||||
responseNotifier.notifyHeaders(conversation.getResponseListener(), response);
|
||||
responseNotifier.notifyHeaders(conversation.getResponseListeners(), response);
|
||||
|
||||
Enumeration<String> contentEncodings = response.getHeaders().getValues(HttpHeader.CONTENT_ENCODING.asString(), ",");
|
||||
if (contentEncodings != null)
|
||||
|
@ -254,7 +268,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
LOG.debug("{} {}: {} bytes", decoder, response, buffer.remaining());
|
||||
}
|
||||
|
||||
responseNotifier.notifyContent(conversation.getResponseListener(), response, buffer);
|
||||
responseNotifier.notifyContent(conversation.getResponseListeners(), response, buffer);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -287,8 +301,8 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
exchange.terminateResponse();
|
||||
|
||||
HttpResponse response = exchange.getResponse();
|
||||
Response.Listener listener = exchange.getConversation().getResponseListener();
|
||||
responseNotifier.notifySuccess(listener, response);
|
||||
List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners();
|
||||
responseNotifier.notifySuccess(listeners, response);
|
||||
LOG.debug("Received {}", response);
|
||||
|
||||
Result result = completion.getReference();
|
||||
|
@ -296,7 +310,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
{
|
||||
connection.complete(exchange, !result.isFailed());
|
||||
|
||||
responseNotifier.notifyComplete(listener, result);
|
||||
responseNotifier.notifyComplete(listeners, result);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -330,7 +344,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
|
||||
HttpResponse response = exchange.getResponse();
|
||||
HttpConversation conversation = exchange.getConversation();
|
||||
responseNotifier.notifyFailure(conversation.getResponseListener(), response, failure);
|
||||
responseNotifier.notifyFailure(conversation.getResponseListeners(), response, failure);
|
||||
LOG.debug("Failed {} {}", response, failure);
|
||||
|
||||
Result result = completion.getReference();
|
||||
|
@ -338,7 +352,7 @@ public class HttpReceiver implements HttpParser.ResponseHandler<ByteBuffer>
|
|||
{
|
||||
connection.complete(exchange, false);
|
||||
|
||||
responseNotifier.notifyComplete(conversation.getResponseListener(), result);
|
||||
responseNotifier.notifyComplete(conversation.getResponseListeners(), result);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -50,7 +50,8 @@ public class HttpRequest implements Request
|
|||
private final HttpFields headers = new HttpFields();
|
||||
private final Fields params = new Fields();
|
||||
private final Map<String, Object> attributes = new HashMap<>();
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
private final List<RequestListener> requestListeners = new ArrayList<>();
|
||||
private final List<Response.ResponseListener> responseListeners = new ArrayList<>();
|
||||
private final HttpClient client;
|
||||
private final long conversation;
|
||||
private final String host;
|
||||
|
@ -240,15 +241,89 @@ public class HttpRequest implements Request
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Listener> getListeners()
|
||||
public <T extends RequestListener> List<T> getRequestListeners(Class<T> type)
|
||||
{
|
||||
return listeners;
|
||||
ArrayList<T> result = new ArrayList<>();
|
||||
for (RequestListener listener : requestListeners)
|
||||
if (type == null || type.isInstance(listener))
|
||||
result.add((T)listener);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request listener(Request.Listener listener)
|
||||
{
|
||||
this.listeners.add(listener);
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onRequestQueued(QueuedListener listener)
|
||||
{
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onRequestBegin(BeginListener listener)
|
||||
{
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onRequestHeaders(HeadersListener listener)
|
||||
{
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onRequestSuccess(SuccessListener listener)
|
||||
{
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onRequestFailure(FailureListener listener)
|
||||
{
|
||||
this.requestListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onResponseBegin(Response.BeginListener listener)
|
||||
{
|
||||
this.responseListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onResponseHeaders(Response.HeadersListener listener)
|
||||
{
|
||||
this.responseListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onResponseContent(Response.ContentListener listener)
|
||||
{
|
||||
this.responseListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onResponseSuccess(Response.SuccessListener listener)
|
||||
{
|
||||
this.responseListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request onResponseFailure(Response.FailureListener listener)
|
||||
{
|
||||
this.responseListeners.add(listener);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -320,9 +395,11 @@ public class HttpRequest implements Request
|
|||
}
|
||||
|
||||
@Override
|
||||
public void send(final Response.Listener listener)
|
||||
public void send(Response.CompleteListener listener)
|
||||
{
|
||||
client.send(this, listener);
|
||||
if (listener != null)
|
||||
responseListeners.add(listener);
|
||||
client.send(this, responseListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -331,12 +408,12 @@ public class HttpRequest implements Request
|
|||
aborted = true;
|
||||
if (client.provideDestination(getScheme(), getHost(), getPort()).abort(this, reason))
|
||||
return true;
|
||||
HttpConversation conversation = client.getConversation(getConversationID());
|
||||
return conversation.abort(reason);
|
||||
HttpConversation conversation = client.getConversation(getConversationID(), false);
|
||||
return conversation != null && conversation.abort(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean aborted()
|
||||
public boolean isAborted()
|
||||
{
|
||||
return aborted;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
|
@ -27,15 +30,15 @@ public class HttpResponse implements Response
|
|||
{
|
||||
private final HttpFields headers = new HttpFields();
|
||||
private final Request request;
|
||||
private final Listener listener;
|
||||
private final List<ResponseListener> listeners;
|
||||
private HttpVersion version;
|
||||
private int status;
|
||||
private String reason;
|
||||
|
||||
public HttpResponse(Request request, Listener listener)
|
||||
public HttpResponse(Request request, List<ResponseListener> listeners)
|
||||
{
|
||||
this.request = request;
|
||||
this.listener = listener;
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public HttpVersion getVersion()
|
||||
|
@ -85,9 +88,13 @@ public class HttpResponse implements Response
|
|||
}
|
||||
|
||||
@Override
|
||||
public Listener getListener()
|
||||
public <T extends ResponseListener> List<T> getListeners(Class<T> type)
|
||||
{
|
||||
return listener;
|
||||
ArrayList<T> result = new ArrayList<>();
|
||||
for (ResponseListener listener : listeners)
|
||||
if (type == null || type.isInstance(listener))
|
||||
result.add((T)listener);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,8 +19,10 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicMarkableReference;
|
||||
|
@ -67,15 +69,20 @@ public class HttpSender
|
|||
|
||||
// Arrange the listeners, so that if there is a request failure the proper listeners are notified
|
||||
HttpConversation conversation = exchange.getConversation();
|
||||
Response.Listener currentListener = exchange.getResponseListener();
|
||||
Response.Listener initialListener = conversation.getExchanges().peekFirst().getResponseListener();
|
||||
if (initialListener == currentListener)
|
||||
conversation.setResponseListener(initialListener);
|
||||
HttpExchange initialExchange = conversation.getExchanges().peekFirst();
|
||||
if (initialExchange == exchange)
|
||||
{
|
||||
conversation.setResponseListeners(exchange.getResponseListeners());
|
||||
}
|
||||
else
|
||||
conversation.setResponseListener(new DoubleResponseListener(responseNotifier, currentListener, initialListener));
|
||||
{
|
||||
List<Response.ResponseListener> listeners = new ArrayList<>(exchange.getResponseListeners());
|
||||
listeners.addAll(initialExchange.getResponseListeners());
|
||||
conversation.setResponseListeners(listeners);
|
||||
}
|
||||
|
||||
Request request = exchange.getRequest();
|
||||
if (request.aborted())
|
||||
if (request.isAborted())
|
||||
{
|
||||
exchange.abort(null);
|
||||
}
|
||||
|
@ -123,7 +130,7 @@ public class HttpSender
|
|||
return;
|
||||
|
||||
final Request request = exchange.getRequest();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
HttpConversation conversation = exchange.getConversation();
|
||||
HttpGenerator.RequestInfo requestInfo = null;
|
||||
|
||||
boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
|
||||
|
@ -359,7 +366,7 @@ public class HttpSender
|
|||
connection.complete(exchange, !result.isFailed());
|
||||
|
||||
HttpConversation conversation = exchange.getConversation();
|
||||
responseNotifier.notifyComplete(conversation.getResponseListener(), result);
|
||||
responseNotifier.notifyComplete(conversation.getResponseListeners(), result);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -393,7 +400,7 @@ public class HttpSender
|
|||
|
||||
Result result = completion.getReference();
|
||||
boolean notCommitted = current == State.IDLE || current == State.SEND;
|
||||
if (result == null && notCommitted && !request.aborted())
|
||||
if (result == null && notCommitted && !request.isAborted())
|
||||
{
|
||||
result = exchange.responseComplete(failure).getReference();
|
||||
exchange.terminateResponse();
|
||||
|
@ -405,7 +412,7 @@ public class HttpSender
|
|||
connection.complete(exchange, false);
|
||||
|
||||
HttpConversation conversation = exchange.getConversation();
|
||||
responseNotifier.notifyComplete(conversation.getResponseListener(), result);
|
||||
responseNotifier.notifyComplete(conversation.getResponseListeners(), result);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -18,10 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
|
||||
public class RedirectProtocolHandler extends Response.Listener.Empty implements ProtocolHandler
|
||||
|
@ -105,7 +106,7 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
|
|||
private void redirect(Result result, HttpMethod method, String location)
|
||||
{
|
||||
final Request request = result.getRequest();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
Integer redirects = (Integer)conversation.getAttribute(ATTRIBUTE);
|
||||
if (redirects == null)
|
||||
redirects = 0;
|
||||
|
@ -115,31 +116,22 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
|
|||
++redirects;
|
||||
conversation.setAttribute(ATTRIBUTE, redirects);
|
||||
|
||||
Request redirect = client.newRequest(request.getConversationID(), location);
|
||||
Request redirect = client.copyRequest(request, location);
|
||||
|
||||
// Use given method
|
||||
redirect.method(method);
|
||||
|
||||
redirect.version(request.getVersion());
|
||||
|
||||
// Copy headers
|
||||
for (HttpFields.Field header : request.getHeaders())
|
||||
redirect.header(header.getName(), header.getValue());
|
||||
|
||||
// Copy content
|
||||
redirect.content(request.getContent());
|
||||
|
||||
redirect.listener(new Request.Listener.Empty()
|
||||
redirect.onRequestBegin(new Request.BeginListener()
|
||||
{
|
||||
@Override
|
||||
public void onBegin(Request redirect)
|
||||
{
|
||||
if (request.aborted())
|
||||
if (request.isAborted())
|
||||
redirect.abort(null);
|
||||
}
|
||||
});
|
||||
|
||||
redirect.send(new Response.Listener.Empty());
|
||||
redirect.send(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -151,10 +143,10 @@ public class RedirectProtocolHandler extends Response.Listener.Empty implements
|
|||
{
|
||||
Request request = result.getRequest();
|
||||
Response response = result.getResponse();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
Response.Listener listener = conversation.getExchanges().peekFirst().getResponseListener();
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
List<Response.ResponseListener> listeners = conversation.getExchanges().peekFirst().getResponseListeners();
|
||||
// TODO: should we replay all events, or just the failure ?
|
||||
notifier.notifyFailure(listener, response, failure);
|
||||
notifier.notifyComplete(listener, new Result(request, response, failure));
|
||||
notifier.notifyFailure(listeners, response, failure);
|
||||
notifier.notifyComplete(listeners, new Result(request, response, failure));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,13 +35,13 @@ public class RequestNotifier
|
|||
|
||||
public void notifyQueued(Request request)
|
||||
{
|
||||
for (Request.Listener listener : request.getListeners())
|
||||
for (Request.QueuedListener listener : request.getRequestListeners(Request.QueuedListener.class))
|
||||
notifyQueued(listener, request);
|
||||
for (Request.Listener listener : client.getRequestListeners())
|
||||
notifyQueued(listener, request);
|
||||
}
|
||||
|
||||
private void notifyQueued(Request.Listener listener, Request request)
|
||||
private void notifyQueued(Request.QueuedListener listener, Request request)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -56,13 +56,13 @@ public class RequestNotifier
|
|||
|
||||
public void notifyBegin(Request request)
|
||||
{
|
||||
for (Request.Listener listener : request.getListeners())
|
||||
for (Request.BeginListener listener : request.getRequestListeners(Request.BeginListener.class))
|
||||
notifyBegin(listener, request);
|
||||
for (Request.Listener listener : client.getRequestListeners())
|
||||
notifyBegin(listener, request);
|
||||
}
|
||||
|
||||
private void notifyBegin(Request.Listener listener, Request request)
|
||||
private void notifyBegin(Request.BeginListener listener, Request request)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -77,13 +77,13 @@ public class RequestNotifier
|
|||
|
||||
public void notifyHeaders(Request request)
|
||||
{
|
||||
for (Request.Listener listener : request.getListeners())
|
||||
for (Request.HeadersListener listener : request.getRequestListeners(Request.HeadersListener.class))
|
||||
notifyHeaders(listener, request);
|
||||
for (Request.Listener listener : client.getRequestListeners())
|
||||
notifyHeaders(listener, request);
|
||||
}
|
||||
|
||||
private void notifyHeaders(Request.Listener listener, Request request)
|
||||
private void notifyHeaders(Request.HeadersListener listener, Request request)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -98,13 +98,13 @@ public class RequestNotifier
|
|||
|
||||
public void notifySuccess(Request request)
|
||||
{
|
||||
for (Request.Listener listener : request.getListeners())
|
||||
for (Request.SuccessListener listener : request.getRequestListeners(Request.SuccessListener.class))
|
||||
notifySuccess(listener, request);
|
||||
for (Request.Listener listener : client.getRequestListeners())
|
||||
notifySuccess(listener, request);
|
||||
}
|
||||
|
||||
private void notifySuccess(Request.Listener listener, Request request)
|
||||
private void notifySuccess(Request.SuccessListener listener, Request request)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -119,13 +119,13 @@ public class RequestNotifier
|
|||
|
||||
public void notifyFailure(Request request, Throwable failure)
|
||||
{
|
||||
for (Request.Listener listener : request.getListeners())
|
||||
for (Request.FailureListener listener : request.getRequestListeners(Request.FailureListener.class))
|
||||
notifyFailure(listener, request, failure);
|
||||
for (Request.Listener listener : client.getRequestListeners())
|
||||
notifyFailure(listener, request, failure);
|
||||
}
|
||||
|
||||
private void notifyFailure(Request.Listener listener, Request request, Throwable failure)
|
||||
private void notifyFailure(Request.FailureListener listener, Request request, Throwable failure)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.api.ContentResponse;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
|
@ -37,12 +38,18 @@ public class ResponseNotifier
|
|||
this.client = client;
|
||||
}
|
||||
|
||||
public void notifyBegin(Response.Listener listener, Response response)
|
||||
public void notifyBegin(List<Response.ResponseListener> listeners, Response response)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.BeginListener)
|
||||
notifyBegin((Response.BeginListener)listener, response);
|
||||
}
|
||||
|
||||
private void notifyBegin(Response.BeginListener listener, Response response)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onBegin(response);
|
||||
listener.onBegin(response);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -50,12 +57,18 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyHeaders(Response.Listener listener, Response response)
|
||||
public void notifyHeaders(List<Response.ResponseListener> listeners, Response response)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.HeadersListener)
|
||||
notifyHeaders((Response.HeadersListener)listener, response);
|
||||
}
|
||||
|
||||
private void notifyHeaders(Response.HeadersListener listener, Response response)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onHeaders(response);
|
||||
listener.onHeaders(response);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -63,12 +76,19 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyContent(Response.Listener listener, Response response, ByteBuffer buffer)
|
||||
public void notifyContent(List<Response.ResponseListener> listeners, Response response, ByteBuffer buffer)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.ContentListener)
|
||||
notifyContent((Response.ContentListener)listener, response, buffer);
|
||||
|
||||
}
|
||||
|
||||
private void notifyContent(Response.ContentListener listener, Response response, ByteBuffer buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onContent(response, buffer);
|
||||
listener.onContent(response, buffer);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -76,12 +96,18 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void notifySuccess(Response.Listener listener, Response response)
|
||||
public void notifySuccess(List<Response.ResponseListener> listeners, Response response)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.SuccessListener)
|
||||
notifySuccess((Response.SuccessListener)listener, response);
|
||||
}
|
||||
|
||||
private void notifySuccess(Response.SuccessListener listener, Response response)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onSuccess(response);
|
||||
listener.onSuccess(response);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -89,12 +115,18 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyFailure(Response.Listener listener, Response response, Throwable failure)
|
||||
public void notifyFailure(List<Response.ResponseListener> listeners, Response response, Throwable failure)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.FailureListener)
|
||||
notifyFailure((Response.FailureListener)listener, response, failure);
|
||||
}
|
||||
|
||||
private void notifyFailure(Response.FailureListener listener, Response response, Throwable failure)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onFailure(response, failure);
|
||||
listener.onFailure(response, failure);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -102,12 +134,18 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void notifyComplete(Response.Listener listener, Result result)
|
||||
public void notifyComplete(List<Response.ResponseListener> listeners, Result result)
|
||||
{
|
||||
for (Response.ResponseListener listener : listeners)
|
||||
if (listener instanceof Response.CompleteListener)
|
||||
notifyComplete((Response.CompleteListener)listener, result);
|
||||
}
|
||||
|
||||
private void notifyComplete(Response.CompleteListener listener, Result result)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (listener != null)
|
||||
listener.onComplete(result);
|
||||
listener.onComplete(result);
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
|
@ -115,37 +153,37 @@ public class ResponseNotifier
|
|||
}
|
||||
}
|
||||
|
||||
public void forwardSuccess(Response.Listener listener, Response response)
|
||||
public void forwardSuccess(List<Response.ResponseListener> listeners, Response response)
|
||||
{
|
||||
notifyBegin(listener, response);
|
||||
notifyHeaders(listener, response);
|
||||
notifyBegin(listeners, response);
|
||||
notifyHeaders(listeners, response);
|
||||
if (response instanceof ContentResponse)
|
||||
notifyContent(listener, response, ByteBuffer.wrap(((ContentResponse)response).getContent()));
|
||||
notifySuccess(listener, response);
|
||||
notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()));
|
||||
notifySuccess(listeners, response);
|
||||
}
|
||||
|
||||
public void forwardSuccessComplete(Response.Listener listener, Request request, Response response)
|
||||
public void forwardSuccessComplete(List<Response.ResponseListener> listeners, Request request, Response response)
|
||||
{
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
forwardSuccess(listener, response);
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
forwardSuccess(listeners, response);
|
||||
conversation.complete();
|
||||
notifyComplete(listener, new Result(request, response));
|
||||
notifyComplete(listeners, new Result(request, response));
|
||||
}
|
||||
|
||||
public void forwardFailure(Response.Listener listener, Response response, Throwable failure)
|
||||
public void forwardFailure(List<Response.ResponseListener> listeners, Response response, Throwable failure)
|
||||
{
|
||||
notifyBegin(listener, response);
|
||||
notifyHeaders(listener, response);
|
||||
notifyBegin(listeners, response);
|
||||
notifyHeaders(listeners, response);
|
||||
if (response instanceof ContentResponse)
|
||||
notifyContent(listener, response, ByteBuffer.wrap(((ContentResponse)response).getContent()));
|
||||
notifyFailure(listener, response, failure);
|
||||
notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()));
|
||||
notifyFailure(listeners, response, failure);
|
||||
}
|
||||
|
||||
public void forwardFailureComplete(Response.Listener listener, Request request, Throwable requestFailure, Response response, Throwable responseFailure)
|
||||
public void forwardFailureComplete(List<Response.ResponseListener> listeners, Request request, Throwable requestFailure, Response response, Throwable responseFailure)
|
||||
{
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID());
|
||||
forwardFailure(listener, response, responseFailure);
|
||||
HttpConversation conversation = client.getConversation(request.getConversationID(), false);
|
||||
forwardFailure(listeners, response, responseFailure);
|
||||
conversation.complete();
|
||||
notifyComplete(listener, new Result(request, requestFailure, response, responseFailure));
|
||||
notifyComplete(listeners, new Result(request, requestFailure, response, responseFailure));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,15 +18,11 @@
|
|||
|
||||
package org.eclipse.jetty.client;
|
||||
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
|
||||
public interface ResponseListener extends Response.Listener
|
||||
public interface Schedulable
|
||||
{
|
||||
public interface Timed extends Response.Listener
|
||||
{
|
||||
public boolean schedule(Scheduler scheduler);
|
||||
public boolean schedule(Scheduler scheduler);
|
||||
|
||||
public boolean cancel();
|
||||
}
|
||||
public boolean cancel();
|
||||
}
|
|
@ -37,7 +37,7 @@ public interface Connection extends AutoCloseable
|
|||
* @param request the request to send
|
||||
* @param listener the response listener
|
||||
*/
|
||||
void send(Request request, Response.Listener listener);
|
||||
void send(Request request, Response.CompleteListener listener);
|
||||
|
||||
@Override
|
||||
void close();
|
||||
|
|
|
@ -20,12 +20,12 @@ package org.eclipse.jetty.client.api;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.client.util.InputStreamResponseListener;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
|
@ -207,16 +207,77 @@ public interface Request
|
|||
Request followRedirects(boolean follow);
|
||||
|
||||
/**
|
||||
* @return the listener for request events
|
||||
* @param listenerClass the class of the listener, or null for all listeners classes
|
||||
* @return the listeners for request events of the given class
|
||||
*/
|
||||
List<Listener> getListeners();
|
||||
<T extends RequestListener> List<T> getRequestListeners(Class<T> listenerClass);
|
||||
|
||||
/**
|
||||
* @param listener the listener for request events
|
||||
* @param listener a listener for request events
|
||||
* @return this request object
|
||||
*/
|
||||
Request listener(Listener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for request queued event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onRequestQueued(QueuedListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for request begin event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onRequestBegin(BeginListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for request headers event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onRequestHeaders(HeadersListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for request success event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onRequestSuccess(SuccessListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for request failure event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onRequestFailure(FailureListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for response begin event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onResponseBegin(Response.BeginListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for response headers event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onResponseHeaders(Response.HeadersListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for response content events
|
||||
* @return this request object
|
||||
*/
|
||||
Request onResponseContent(Response.ContentListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for response success event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onResponseSuccess(Response.SuccessListener listener);
|
||||
|
||||
/**
|
||||
* @param listener a listener for response failure event
|
||||
* @return this request object
|
||||
*/
|
||||
Request onResponseFailure(Response.FailureListener listener);
|
||||
|
||||
/**
|
||||
* Sends this request and returns a {@link Future} that can be used to wait for the
|
||||
* request and the response to be completed (either with a success or a failure).
|
||||
|
@ -242,7 +303,7 @@ public interface Request
|
|||
*
|
||||
* @param listener the listener that receives response events
|
||||
*/
|
||||
void send(Response.Listener listener);
|
||||
void send(Response.CompleteListener listener);
|
||||
|
||||
/**
|
||||
* Attempts to abort the send of this request.
|
||||
|
@ -255,12 +316,13 @@ public interface Request
|
|||
/**
|
||||
* @return whether {@link #abort(String)} was called
|
||||
*/
|
||||
boolean aborted();
|
||||
boolean isAborted();
|
||||
|
||||
/**
|
||||
* Listener for request events
|
||||
*/
|
||||
public interface Listener
|
||||
public interface RequestListener extends EventListener
|
||||
{
|
||||
}
|
||||
|
||||
public interface QueuedListener extends RequestListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request is queued, waiting to be sent
|
||||
|
@ -268,7 +330,10 @@ public interface Request
|
|||
* @param request the request being queued
|
||||
*/
|
||||
public void onQueued(Request request);
|
||||
}
|
||||
|
||||
public interface BeginListener extends RequestListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request begins being processed in order to be sent.
|
||||
* This is the last opportunity to modify the request.
|
||||
|
@ -276,7 +341,10 @@ public interface Request
|
|||
* @param request the request that begins being processed
|
||||
*/
|
||||
public void onBegin(Request request);
|
||||
}
|
||||
|
||||
public interface HeadersListener extends RequestListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request headers (and perhaps small content) have been sent.
|
||||
* The request is now committed, and in transit to the server, and further modifications to the
|
||||
|
@ -284,21 +352,33 @@ public interface Request
|
|||
* @param request the request that has been committed
|
||||
*/
|
||||
public void onHeaders(Request request);
|
||||
}
|
||||
|
||||
public interface SuccessListener extends RequestListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request has been successfully sent.
|
||||
*
|
||||
* @param request the request sent
|
||||
*/
|
||||
public void onSuccess(Request request);
|
||||
}
|
||||
|
||||
public interface FailureListener extends RequestListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request has failed to be sent
|
||||
* @param request the request that failed
|
||||
* @param failure the failure
|
||||
*/
|
||||
public void onFailure(Request request, Throwable failure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for all request events
|
||||
*/
|
||||
public interface Listener extends QueuedListener, BeginListener, HeadersListener, SuccessListener, FailureListener
|
||||
{
|
||||
/**
|
||||
* An empty implementation of {@link Listener}
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.eclipse.jetty.client.api;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.EventListener;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.client.util.BufferingResponseListener;
|
||||
import org.eclipse.jetty.http.HttpFields;
|
||||
|
@ -42,9 +44,9 @@ public interface Response
|
|||
long getConversationID();
|
||||
|
||||
/**
|
||||
* @return the response listener passed to {@link Request#send(Listener)}
|
||||
* @return the response listener passed to {@link Request#send(CompleteListener)}
|
||||
*/
|
||||
Listener getListener();
|
||||
<T extends ResponseListener> List<T> getListeners(Class<T> listenerClass);
|
||||
|
||||
/**
|
||||
* @return the HTTP version of this response, such as "HTTP/1.1"
|
||||
|
@ -74,10 +76,11 @@ public interface Response
|
|||
*/
|
||||
boolean abort(String reason);
|
||||
|
||||
/**
|
||||
* Listener for response events
|
||||
*/
|
||||
public interface Listener
|
||||
public interface ResponseListener extends EventListener
|
||||
{
|
||||
}
|
||||
|
||||
public interface BeginListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the response line containing HTTP version,
|
||||
|
@ -88,14 +91,20 @@ public interface Response
|
|||
* @param response the response containing the response line data
|
||||
*/
|
||||
public void onBegin(Response response);
|
||||
}
|
||||
|
||||
public interface HeadersListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the response headers have been received and parsed.
|
||||
*
|
||||
* @param response the response containing the response line data and the headers
|
||||
*/
|
||||
public void onHeaders(Response response);
|
||||
}
|
||||
|
||||
public interface ContentListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the response content has been received.
|
||||
* This method may be invoked multiple times, and the {@code content} buffer must be consumed
|
||||
|
@ -105,14 +114,20 @@ public interface Response
|
|||
* @param content the content bytes received
|
||||
*/
|
||||
public void onContent(Response response, ByteBuffer content);
|
||||
}
|
||||
|
||||
public interface SuccessListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the whole response has been successfully received.
|
||||
*
|
||||
* @param response the response containing the response line data and the headers
|
||||
*/
|
||||
public void onSuccess(Response response);
|
||||
}
|
||||
|
||||
public interface FailureListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the response has failed in the process of being received
|
||||
*
|
||||
|
@ -120,7 +135,10 @@ public interface Response
|
|||
* @param failure the failure happened
|
||||
*/
|
||||
public void onFailure(Response response, Throwable failure);
|
||||
}
|
||||
|
||||
public interface CompleteListener extends ResponseListener
|
||||
{
|
||||
/**
|
||||
* Callback method invoked when the request <em><b>and</b></em> the response have been processed,
|
||||
* either successfully or not.
|
||||
|
@ -129,13 +147,20 @@ public interface Response
|
|||
* <p/>
|
||||
* Requests may complete <em>after</em> response, for example in case of big uploads that are
|
||||
* discarded or read asynchronously by the server.
|
||||
* This method is always invoked <em>after</em> {@link #onSuccess(Response)} or
|
||||
* {@link #onFailure(Response, Throwable)}, and only when request indicates that it is completed.
|
||||
* This method is always invoked <em>after</em> {@link SuccessListener#onSuccess(Response)} or
|
||||
* {@link FailureListener#onFailure(Response, Throwable)}, and only when request indicates that
|
||||
* it is completed.
|
||||
*
|
||||
* @param result the result of the request / response exchange
|
||||
*/
|
||||
public void onComplete(Result result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener for response events
|
||||
*/
|
||||
public interface Listener extends BeginListener, HeadersListener, ContentListener, SuccessListener, FailureListener, CompleteListener
|
||||
{
|
||||
/**
|
||||
* An empty implementation of {@link Listener}
|
||||
*/
|
||||
|
|
|
@ -46,7 +46,6 @@ public class BlockingResponseListener extends BufferingResponseListener implemen
|
|||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
super.onComplete(result);
|
||||
response = new HttpContentResponse(result.getResponse(), getContent(), getEncoding());
|
||||
failure = result.getFailure();
|
||||
latch.countDown();
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.client.util;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
|
@ -33,7 +34,7 @@ import org.eclipse.jetty.http.HttpHeader;
|
|||
* <p>The content may be retrieved from {@link #onSuccess(Response)} or {@link #onComplete(Result)}
|
||||
* via {@link #getContent()} or {@link #getContentAsString()}.</p>
|
||||
*/
|
||||
public class BufferingResponseListener extends Response.Listener.Empty
|
||||
public abstract class BufferingResponseListener extends Response.Listener.Empty
|
||||
{
|
||||
private final int maxLength;
|
||||
private volatile byte[] buffer = new byte[0];
|
||||
|
@ -69,7 +70,7 @@ public class BufferingResponseListener extends Response.Listener.Empty
|
|||
if (contentType != null)
|
||||
{
|
||||
String charset = "charset=";
|
||||
int index = contentType.toLowerCase().indexOf(charset);
|
||||
int index = contentType.toLowerCase(Locale.ENGLISH).indexOf(charset);
|
||||
if (index > 0)
|
||||
{
|
||||
String encoding = contentType.substring(index + charset.length());
|
||||
|
@ -95,6 +96,9 @@ public class BufferingResponseListener extends Response.Listener.Empty
|
|||
buffer = newBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void onComplete(Result result);
|
||||
|
||||
public String getEncoding()
|
||||
{
|
||||
return encoding;
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -108,7 +109,7 @@ public class DigestAuthentication implements Authentication
|
|||
Matcher matcher = PARAM_PATTERN.matcher(part);
|
||||
if (matcher.matches())
|
||||
{
|
||||
String name = matcher.group(1).trim().toLowerCase();
|
||||
String name = matcher.group(1).trim().toLowerCase(Locale.ENGLISH);
|
||||
String value = matcher.group(2).trim();
|
||||
if (value.startsWith("\"") && value.endsWith("\""))
|
||||
value = value.substring(1, value.length() - 1);
|
||||
|
@ -251,7 +252,7 @@ public class DigestAuthentication implements Authentication
|
|||
private String nextNonceCount()
|
||||
{
|
||||
String padding = "00000000";
|
||||
String next = Integer.toHexString(nonceCount.incrementAndGet()).toLowerCase();
|
||||
String next = Integer.toHexString(nonceCount.incrementAndGet()).toLowerCase(Locale.ENGLISH);
|
||||
return padding.substring(0, padding.length() - next.length()) + next;
|
||||
}
|
||||
|
||||
|
@ -265,7 +266,7 @@ public class DigestAuthentication implements Authentication
|
|||
|
||||
private String toHexString(byte[] bytes)
|
||||
{
|
||||
return TypeUtil.toHexString(bytes).toLowerCase();
|
||||
return TypeUtil.toHexString(bytes).toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.nio.ByteBuffer;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.eclipse.jetty.client.ResponseListener;
|
||||
import org.eclipse.jetty.client.Schedulable;
|
||||
import org.eclipse.jetty.client.api.Request;
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
|
@ -30,7 +30,7 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
|
||||
public class TimedResponseListener implements ResponseListener.Timed, Runnable
|
||||
public class TimedResponseListener implements Response.Listener, Schedulable, Runnable
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(TimedResponseListener.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.client.api.Response;
|
||||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExternalSiteTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
private HttpClient client;
|
||||
|
||||
@Before
|
||||
public void prepare() throws Exception
|
||||
{
|
||||
client = new HttpClient();
|
||||
client.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void dispose() throws Exception
|
||||
{
|
||||
client.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExternalSite() throws Exception
|
||||
{
|
||||
String host = "wikipedia.org";
|
||||
int port = 80;
|
||||
|
||||
// Verify that we have connectivity
|
||||
try
|
||||
{
|
||||
new Socket(host, port);
|
||||
}
|
||||
catch (IOException x)
|
||||
{
|
||||
Assume.assumeNoException(x);
|
||||
}
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
client.newRequest(host, port).send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
if (!result.isFailed() && result.getResponse().getStatus() == 200)
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ import java.nio.charset.Charset;
|
|||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -33,6 +35,9 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
public class GZIPContentDecoderTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
@Test
|
||||
public void testStreamNoBlocks() throws Exception
|
||||
{
|
||||
|
|
|
@ -99,14 +99,16 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
|
|||
public void test_BasicAuthentication() throws Exception
|
||||
{
|
||||
startBasic(new EmptyServerHandler());
|
||||
test_Authentication(new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic"));
|
||||
String uri = scheme + "://localhost:" + connector.getLocalPort();
|
||||
test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DigestAuthentication() throws Exception
|
||||
{
|
||||
startDigest(new EmptyServerHandler());
|
||||
test_Authentication(new DigestAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "digest", "digest"));
|
||||
String uri = scheme + "://localhost:" + connector.getLocalPort();
|
||||
test_Authentication(new DigestAuthentication(uri, realm, "digest", "digest"));
|
||||
}
|
||||
|
||||
private void test_Authentication(Authentication authentication) throws Exception
|
||||
|
@ -189,7 +191,8 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
|
|||
}
|
||||
});
|
||||
|
||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic"));
|
||||
String uri = scheme + "://localhost:" + connector.getLocalPort();
|
||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "basic", "basic"));
|
||||
|
||||
final CountDownLatch requests = new CountDownLatch(3);
|
||||
Request.Listener.Empty requestListener = new Request.Listener.Empty()
|
||||
|
@ -227,7 +230,8 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
|
|||
}
|
||||
});
|
||||
|
||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic"));
|
||||
String uri = scheme + "://localhost:" + connector.getLocalPort();
|
||||
client.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "basic", "basic"));
|
||||
|
||||
final CountDownLatch requests = new CountDownLatch(3);
|
||||
Request.Listener.Empty requestListener = new Request.Listener.Empty()
|
||||
|
@ -268,7 +272,8 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
|
|||
client.getRequestListeners().add(requestListener);
|
||||
|
||||
AuthenticationStore authenticationStore = client.getAuthenticationStore();
|
||||
BasicAuthentication authentication = new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic");
|
||||
String uri = scheme + "://localhost:" + connector.getLocalPort();
|
||||
BasicAuthentication authentication = new BasicAuthentication(uri, realm, "basic", "basic");
|
||||
authenticationStore.addAuthentication(authentication);
|
||||
|
||||
Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure");
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.ByteBuffer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -67,7 +68,7 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest
|
|||
client.setMaxQueueSizePerAddress(1024 * 1024);
|
||||
client.setDispatchIO(false);
|
||||
|
||||
Random random = new Random(1000L);
|
||||
Random random = new Random();
|
||||
int iterations = 500;
|
||||
CountDownLatch latch = new CountDownLatch(iterations);
|
||||
List<String> failures = new ArrayList<>();
|
||||
|
@ -132,15 +133,15 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest
|
|||
else if (!ssl && random.nextBoolean())
|
||||
request.header("X-Close", "true");
|
||||
|
||||
int contentLength = random.nextInt(maxContentLength) + 1;
|
||||
switch (method)
|
||||
{
|
||||
case GET:
|
||||
// Randomly ask the server to download data upon this GET request
|
||||
if (random.nextBoolean())
|
||||
request.header("X-Download", String.valueOf(random.nextInt(maxContentLength) + 1));
|
||||
request.header("X-Download", String.valueOf(contentLength));
|
||||
break;
|
||||
case POST:
|
||||
int contentLength = random.nextInt(maxContentLength) + 1;
|
||||
request.header("X-Upload", String.valueOf(contentLength));
|
||||
request.content(new BytesContentProvider(new byte[contentLength]));
|
||||
break;
|
||||
|
@ -184,7 +185,7 @@ public class HttpClientLoadTest extends AbstractHttpClientServerTest
|
|||
@Override
|
||||
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
String method = request.getMethod().toUpperCase();
|
||||
String method = request.getMethod().toUpperCase(Locale.ENGLISH);
|
||||
switch (method)
|
||||
{
|
||||
case "GET":
|
||||
|
|
|
@ -72,7 +72,7 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest
|
|||
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.file(upload)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestSuccess(new Request.SuccessListener()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Request request)
|
||||
|
|
|
@ -289,7 +289,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch successLatch = new CountDownLatch(2);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestBegin(new Request.BeginListener()
|
||||
{
|
||||
@Override
|
||||
public void onBegin(Request request)
|
||||
|
@ -316,7 +316,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestQueued(new Request.QueuedListener()
|
||||
{
|
||||
@Override
|
||||
public void onQueued(Request request)
|
||||
|
@ -371,18 +371,19 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
latch.countDown();
|
||||
}
|
||||
})
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseFailure(new Response.FailureListener()
|
||||
{
|
||||
@Override
|
||||
public void onFailure(Response response, Throwable failure)
|
||||
{
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
})
|
||||
.send(null);
|
||||
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseSuccess(new Response.SuccessListener()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Response response)
|
||||
|
@ -390,7 +391,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
Assert.assertEquals(200, response.getStatus());
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
})
|
||||
.send(null);
|
||||
|
||||
Assert.assertTrue(latch.await(5 * idleTimeout, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
@ -419,7 +421,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.file(file)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestSuccess(new Request.SuccessListener()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Request request)
|
||||
|
@ -529,7 +531,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
final int port = connector.getLocalPort();
|
||||
client.newRequest(host, port)
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestBegin(new Request.BeginListener()
|
||||
{
|
||||
@Override
|
||||
public void onBegin(Request request)
|
||||
|
@ -621,8 +623,4 @@ public class HttpClientTest extends AbstractHttpClientServerTest
|
|||
Assert.assertNotNull(response);
|
||||
Assert.assertEquals(200, response.getStatus());
|
||||
}
|
||||
|
||||
// TODO: add a test to idle timeout a request that is in the queue...
|
||||
// TODO: even though "idle timeout" only applies to connections
|
||||
// TODO: so do we still need a "global" timeout that takes in count queue time + send time + receive time ?
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public class HttpClientTimeoutTest extends AbstractHttpClientServerTest
|
|||
|
||||
TimeUnit.MILLISECONDS.sleep(2 * timeout);
|
||||
|
||||
Assert.assertFalse(request.aborted());
|
||||
Assert.assertFalse(request.isAborted());
|
||||
}
|
||||
|
||||
@Slow
|
||||
|
@ -208,7 +208,7 @@ public class HttpClientTimeoutTest extends AbstractHttpClientServerTest
|
|||
|
||||
TimeUnit.MILLISECONDS.sleep(2 * timeout);
|
||||
|
||||
Assert.assertFalse(request.aborted());
|
||||
Assert.assertFalse(request.isAborted());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch successLatch = new CountDownLatch(3);
|
||||
client.newRequest(host, port)
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestSuccess(new Request.SuccessListener()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Request request)
|
||||
|
@ -76,7 +76,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
|
|||
successLatch.countDown();
|
||||
}
|
||||
})
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseHeaders(new Response.HeadersListener()
|
||||
{
|
||||
@Override
|
||||
public void onHeaders(Response response)
|
||||
|
@ -85,7 +85,9 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
|
|||
Assert.assertEquals(1, activeConnections.size());
|
||||
headersLatch.countDown();
|
||||
}
|
||||
|
||||
})
|
||||
.send(new Response.Listener.Empty()
|
||||
{
|
||||
@Override
|
||||
public void onSuccess(Response response)
|
||||
{
|
||||
|
@ -308,7 +310,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch failureLatch = new CountDownLatch(2);
|
||||
client.newRequest(host, port)
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestFailure(new Request.FailureListener()
|
||||
{
|
||||
@Override
|
||||
public void onFailure(Request request, Throwable failure)
|
||||
|
|
|
@ -21,11 +21,16 @@ package org.eclipse.jetty.client;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.http.HttpCookie;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpCookieParserTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
@Test
|
||||
public void testParseCookie1() throws Exception
|
||||
{
|
||||
|
|
|
@ -23,11 +23,16 @@ import java.util.List;
|
|||
import org.eclipse.jetty.client.api.CookieStore;
|
||||
import org.eclipse.jetty.client.api.Destination;
|
||||
import org.eclipse.jetty.http.HttpCookie;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpCookieStoreTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
private HttpClient client = new HttpClient();
|
||||
|
||||
@Test
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.EOFException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
@ -34,13 +35,18 @@ import org.eclipse.jetty.http.HttpFields;
|
|||
import org.eclipse.jetty.http.HttpHeader;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.io.ByteArrayEndPoint;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpReceiverTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
private HttpClient client;
|
||||
private HttpDestination destination;
|
||||
private ByteArrayEndPoint endPoint;
|
||||
|
@ -68,7 +74,7 @@ public class HttpReceiverTest
|
|||
{
|
||||
HttpRequest request = new HttpRequest(client, URI.create("http://localhost"));
|
||||
BlockingResponseListener listener = new BlockingResponseListener(request);
|
||||
HttpExchange exchange = new HttpExchange(conversation, connection, request, listener);
|
||||
HttpExchange exchange = new HttpExchange(conversation, connection, request, Collections.<Response.ResponseListener>singletonList(listener));
|
||||
conversation.getExchanges().offer(exchange);
|
||||
connection.setExchange(exchange);
|
||||
exchange.requestComplete(null);
|
||||
|
@ -84,7 +90,7 @@ public class HttpReceiverTest
|
|||
"Content-length: 0\r\n" +
|
||||
"\r\n");
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
|
||||
Response response = listener.get(5, TimeUnit.SECONDS);
|
||||
|
@ -108,7 +114,7 @@ public class HttpReceiverTest
|
|||
"\r\n" +
|
||||
content);
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
|
||||
Response response = listener.get(5, TimeUnit.SECONDS);
|
||||
|
@ -135,7 +141,7 @@ public class HttpReceiverTest
|
|||
"\r\n" +
|
||||
content1);
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
endPoint.setInputEOF();
|
||||
exchange.receive();
|
||||
|
@ -159,7 +165,7 @@ public class HttpReceiverTest
|
|||
"Content-length: 1\r\n" +
|
||||
"\r\n");
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
// Simulate an idle timeout
|
||||
connection.idleTimeout();
|
||||
|
@ -183,7 +189,7 @@ public class HttpReceiverTest
|
|||
"Content-length: A\r\n" +
|
||||
"\r\n");
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
|
||||
try
|
||||
|
@ -214,7 +220,7 @@ public class HttpReceiverTest
|
|||
"Content-Encoding: gzip\r\n" +
|
||||
"\r\n");
|
||||
HttpExchange exchange = newExchange();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListener();
|
||||
BlockingResponseListener listener = (BlockingResponseListener)exchange.getResponseListeners().get(0);
|
||||
exchange.receive();
|
||||
endPoint.reset();
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
{
|
||||
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestHeaders(new Request.HeadersListener()
|
||||
{
|
||||
@Override
|
||||
public void onHeaders(Request request)
|
||||
|
@ -191,7 +191,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest
|
|||
{
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.listener(new Request.Listener.Empty()
|
||||
.onRequestHeaders(new Request.HeadersListener()
|
||||
{
|
||||
@Override
|
||||
public void onHeaders(Request request)
|
||||
|
|
|
@ -55,14 +55,16 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseBegin(new Response.BeginListener()
|
||||
{
|
||||
@Override
|
||||
public void onBegin(Response response)
|
||||
{
|
||||
response.abort(null);
|
||||
}
|
||||
|
||||
})
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
|
@ -81,13 +83,16 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseHeaders(new Response.HeadersListener()
|
||||
{
|
||||
@Override
|
||||
public void onHeaders(Response response)
|
||||
{
|
||||
response.abort(null);
|
||||
}
|
||||
})
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
|
@ -126,14 +131,16 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest
|
|||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
client.newRequest("localhost", connector.getLocalPort())
|
||||
.scheme(scheme)
|
||||
.send(new Response.Listener.Empty()
|
||||
.onResponseContent(new Response.ContentListener()
|
||||
{
|
||||
@Override
|
||||
public void onContent(Response response, ByteBuffer content)
|
||||
{
|
||||
response.abort(null);
|
||||
}
|
||||
|
||||
})
|
||||
.send(new Response.CompleteListener()
|
||||
{
|
||||
@Override
|
||||
public void onComplete(Result result)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.client;
|
|||
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -28,14 +29,19 @@ import org.eclipse.jetty.client.api.Response;
|
|||
import org.eclipse.jetty.client.api.Result;
|
||||
import org.eclipse.jetty.client.util.ByteBufferContentProvider;
|
||||
import org.eclipse.jetty.io.ByteArrayEndPoint;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.eclipse.jetty.toolchain.test.annotation.Slow;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HttpSenderTest
|
||||
{
|
||||
@Rule
|
||||
public final TestTracker tracker = new TestTracker();
|
||||
|
||||
private HttpClient client;
|
||||
|
||||
@Before
|
||||
|
@ -74,7 +80,7 @@ public class HttpSenderTest
|
|||
successLatch.countDown();
|
||||
}
|
||||
});
|
||||
connection.send(request, null);
|
||||
connection.send(request, (Response.CompleteListener)null);
|
||||
|
||||
String requestString = endPoint.takeOutputString();
|
||||
Assert.assertTrue(requestString.startsWith("GET "));
|
||||
|
@ -91,7 +97,7 @@ public class HttpSenderTest
|
|||
HttpDestination destination = new HttpDestination(client, "http", "localhost", 8080);
|
||||
HttpConnection connection = new HttpConnection(client, endPoint, destination);
|
||||
Request request = client.newRequest(URI.create("http://localhost/"));
|
||||
connection.send(request, null);
|
||||
connection.send(request, (Response.CompleteListener)null);
|
||||
|
||||
// This take will free space in the buffer and allow for the write to complete
|
||||
StringBuilder builder = new StringBuilder(endPoint.takeOutputString());
|
||||
|
@ -202,7 +208,7 @@ public class HttpSenderTest
|
|||
successLatch.countDown();
|
||||
}
|
||||
});
|
||||
connection.send(request, null);
|
||||
connection.send(request, (Response.CompleteListener)null);
|
||||
|
||||
String requestString = endPoint.takeOutputString();
|
||||
Assert.assertTrue(requestString.startsWith("GET "));
|
||||
|
@ -237,7 +243,7 @@ public class HttpSenderTest
|
|||
successLatch.countDown();
|
||||
}
|
||||
});
|
||||
connection.send(request, null);
|
||||
connection.send(request, (Response.CompleteListener)null);
|
||||
|
||||
String requestString = endPoint.takeOutputString();
|
||||
Assert.assertTrue(requestString.startsWith("GET "));
|
||||
|
@ -279,12 +285,12 @@ public class HttpSenderTest
|
|||
successLatch.countDown();
|
||||
}
|
||||
});
|
||||
connection.send(request, null);
|
||||
connection.send(request, (Response.CompleteListener)null);
|
||||
|
||||
String requestString = endPoint.takeOutputString();
|
||||
Assert.assertTrue(requestString.startsWith("GET "));
|
||||
String content = Integer.toHexString(content1.length()).toUpperCase() + "\r\n" + content1 + "\r\n";
|
||||
content += Integer.toHexString(content2.length()).toUpperCase() + "\r\n" + content2 + "\r\n";
|
||||
String content = Integer.toHexString(content1.length()).toUpperCase(Locale.ENGLISH) + "\r\n" + content1 + "\r\n";
|
||||
content += Integer.toHexString(content2.length()).toUpperCase(Locale.ENGLISH) + "\r\n" + content2 + "\r\n";
|
||||
content += "0\r\n\r\n";
|
||||
Assert.assertTrue(requestString.endsWith("\r\n\r\n" + content));
|
||||
Assert.assertTrue(headersLatch.await(5, TimeUnit.SECONDS));
|
||||
|
|
|
@ -43,6 +43,16 @@
|
|||
<Set name="defaultsDescriptor"><Property name="jetty.home" default="." />/etc/webdefault.xml</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="extractWars">true</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<!-- file of context configuration properties
|
||||
<Set name="file"><SystemProperty name="jetty.home"/>/etc/some.properties</Set>
|
||||
-->
|
||||
<!-- set a context configuration property
|
||||
<Call name="put"><Arg>name</Arg><Arg>value</Arg></Call>
|
||||
-->
|
||||
</New>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
|
|
@ -21,10 +21,15 @@ package org.eclipse.jetty.deploy;
|
|||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
/**
|
||||
|
@ -32,42 +37,55 @@ import org.eclipse.jetty.util.resource.Resource;
|
|||
*
|
||||
* Supplies properties defined in a file.
|
||||
*/
|
||||
public class FileConfigurationManager implements ConfigurationManager
|
||||
@ManagedObject("Configure deployed webapps via properties")
|
||||
public class PropertiesConfigurationManager implements ConfigurationManager
|
||||
{
|
||||
private Resource _file;
|
||||
private Map<String,String> _map = new HashMap<String,String>();
|
||||
private String _properties;
|
||||
private final Map<String,String> _map = new HashMap<String,String>();
|
||||
|
||||
public FileConfigurationManager()
|
||||
public PropertiesConfigurationManager(String properties)
|
||||
{
|
||||
}
|
||||
|
||||
public PropertiesConfigurationManager()
|
||||
{
|
||||
}
|
||||
|
||||
public void setFile(String filename) throws MalformedURLException, IOException
|
||||
@ManagedAttribute("A file or URL of properties")
|
||||
public void setFile(String resource) throws MalformedURLException, IOException
|
||||
{
|
||||
_file = Resource.newResource(filename);
|
||||
_properties=resource;
|
||||
_map.clear();
|
||||
loadProperties(_properties);
|
||||
}
|
||||
|
||||
public String getFile()
|
||||
{
|
||||
return _properties;
|
||||
}
|
||||
|
||||
@ManagedOperation("Set a property")
|
||||
public void put(@Name("name")String name, @Name("value")String value)
|
||||
{
|
||||
_map.put(name,value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.deploy.ConfigurationManager#getProperties()
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getProperties()
|
||||
{
|
||||
try
|
||||
{
|
||||
loadProperties();
|
||||
return _map;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new HashMap<>(_map);
|
||||
}
|
||||
|
||||
private void loadProperties() throws FileNotFoundException, IOException
|
||||
{
|
||||
if (_map.isEmpty() && _file!=null)
|
||||
private void loadProperties(String resource) throws FileNotFoundException, IOException
|
||||
{
|
||||
Resource file=Resource.newResource(resource);
|
||||
if (file!=null && file.exists())
|
||||
{
|
||||
Properties properties = new Properties();
|
||||
properties.load(_file.getInputStream());
|
||||
properties.load(file.getInputStream());
|
||||
for (Map.Entry<Object, Object> entry : properties.entrySet())
|
||||
_map.put(entry.getKey().toString(),String.valueOf(entry.getValue()));
|
||||
}
|
|
@ -22,6 +22,7 @@ import java.io.File;
|
|||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.deploy.App;
|
||||
import org.eclipse.jetty.deploy.ConfigurationManager;
|
||||
|
@ -77,7 +78,7 @@ public class WebAppProvider extends ScanningAppProvider
|
|||
{
|
||||
return false;
|
||||
}
|
||||
String lowername = name.toLowerCase();
|
||||
String lowername = name.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
File file = new File(dir,name);
|
||||
|
||||
|
@ -299,9 +300,9 @@ public class WebAppProvider extends ScanningAppProvider
|
|||
{
|
||||
context = URIUtil.SLASH;
|
||||
}
|
||||
else if (context.toLowerCase().startsWith("root-"))
|
||||
else if (context.toLowerCase(Locale.ENGLISH).startsWith("root-"))
|
||||
{
|
||||
int dash=context.toLowerCase().indexOf('-');
|
||||
int dash=context.toLowerCase(Locale.ENGLISH).indexOf('-');
|
||||
String virtual = context.substring(dash+1);
|
||||
wah.setVirtualHosts(new String[]{virtual});
|
||||
context = URIUtil.SLASH;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.eclipse.jetty.deploy.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Simple, yet surprisingly common utility methods for identifying various file types commonly seen and worked with in a
|
||||
|
@ -38,7 +39,7 @@ public class FileID
|
|||
{
|
||||
if (path.isFile())
|
||||
{
|
||||
String name = path.getName().toLowerCase();
|
||||
String name = path.getName().toLowerCase(Locale.ENGLISH);
|
||||
return (name.endsWith(".war") || name.endsWith(".jar"));
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class FileID
|
|||
return false;
|
||||
}
|
||||
|
||||
String name = path.getName().toLowerCase();
|
||||
String name = path.getName().toLowerCase(Locale.ENGLISH);
|
||||
return (name.endsWith(".war") || name.endsWith(".jar"));
|
||||
}
|
||||
|
||||
|
@ -73,7 +74,7 @@ public class FileID
|
|||
return false;
|
||||
}
|
||||
|
||||
String name = path.getName().toLowerCase();
|
||||
String name = path.getName().toLowerCase(Locale.ENGLISH);
|
||||
return name.endsWith(".xml");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<Set name="monitoredDirName"><SystemProperty name="jetty.home" />/webapps</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.FileConfigurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<Set name="file">
|
||||
<SystemProperty name="jetty.home"/>/xml-configured-jetty.properties
|
||||
</Set>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<Set name="monitoredDirName"><SystemProperty name="jetty.home" />/webapps</Set>
|
||||
<Set name="scanInterval">1</Set>
|
||||
<Set name="configurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.FileConfigurationManager">
|
||||
<New class="org.eclipse.jetty.deploy.PropertiesConfigurationManager">
|
||||
<Set name="file">
|
||||
<SystemProperty name="jetty.home"/>/xml-configured-jetty.properties
|
||||
</Set>
|
||||
|
|
|
@ -364,6 +364,12 @@
|
|||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-jaas</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-annotations</artifactId>
|
||||
|
@ -381,11 +387,6 @@
|
|||
<artifactId>jetty-jndi</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-client</artifactId>
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<!--
|
||||
Configure a custom context for the javadoc.
|
||||
|
||||
This context contains only a ServletHandler with a default servlet
|
||||
to serve static html files and images.
|
||||
-->
|
||||
|
||||
<!--Configure a context for the javadoc -->
|
||||
<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
|
||||
<Set name="contextPath">/javadoc</Set>
|
||||
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/javadoc/</Set>
|
||||
|
@ -21,6 +15,5 @@ to serve static html files and images.
|
|||
<Set name="cacheControl">max-age=3600,public</Set>
|
||||
</New>
|
||||
</Set>
|
||||
|
||||
</Configure>
|
||||
|
||||
|
|
|
@ -810,7 +810,7 @@ public class HttpFields implements Iterable<HttpFields.Field>
|
|||
{
|
||||
hasDomain = true;
|
||||
buf.append(";Domain=");
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(),delim);
|
||||
QuotedStringTokenizer.quoteIfNeeded(buf,domain.toLowerCase(Locale.ENGLISH),delim);
|
||||
}
|
||||
|
||||
if (maxAge >= 0)
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.charset.Charset;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
@ -70,7 +71,7 @@ public class MimeTypes
|
|||
_string=s;
|
||||
_buffer=BufferUtil.toBuffer(s);
|
||||
|
||||
int i=s.toLowerCase().indexOf("charset=");
|
||||
int i=s.toLowerCase(Locale.ENGLISH).indexOf("charset=");
|
||||
_charset=(i>0)?Charset.forName(s.substring(i+8)):null;
|
||||
}
|
||||
|
||||
|
|
|
@ -171,6 +171,7 @@ xhtml=application/xhtml+xml
|
|||
xls=application/vnd.ms-excel
|
||||
xml=application/xml
|
||||
xpm=image/x-xpixmap
|
||||
xsd=application/xml
|
||||
xsl=application/xml
|
||||
xslt=application/xslt+xml
|
||||
xul=application/vnd.mozilla.xul+xml
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.http;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
|
@ -385,7 +386,7 @@ public class HttpFieldsTest
|
|||
{
|
||||
Set<String> s=new HashSet<String>();
|
||||
while(e.hasMoreElements())
|
||||
s.add(e.nextElement().toLowerCase());
|
||||
s.add(e.nextElement().toLowerCase(Locale.ENGLISH));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
|
@ -63,7 +62,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
<!-- always include the sources to be able to prepare the eclipse-jetty-SDK feature
|
||||
with a snapshot. -->
|
||||
<plugin>
|
||||
|
|
|
@ -14,17 +14,4 @@
|
|||
<Arg><SystemProperty name="jetty.home" default="." />/etc/login.conf</Arg>
|
||||
</Call>
|
||||
|
||||
|
||||
<!-- ======================================================== -->
|
||||
<!-- An example JAAS realm setup -->
|
||||
<!-- ======================================================== -->
|
||||
<Call name="addBean">
|
||||
<Arg>
|
||||
<New class="org.eclipse.jetty.jaas.JAASLoginService">
|
||||
<Set name="Name">Test JAAS Realm</Set>
|
||||
<Set name="LoginModuleName">xyz</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
|
@ -22,6 +22,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.naming.Context;
|
||||
|
@ -652,12 +653,12 @@ public class LdapLoginModule extends AbstractLoginModule
|
|||
|
||||
public static String convertCredentialJettyToLdap(String encryptedPassword)
|
||||
{
|
||||
if ("MD5:".startsWith(encryptedPassword.toUpperCase()))
|
||||
if ("MD5:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
|
||||
{
|
||||
return "{MD5}" + encryptedPassword.substring("MD5:".length(), encryptedPassword.length());
|
||||
}
|
||||
|
||||
if ("CRYPT:".startsWith(encryptedPassword.toUpperCase()))
|
||||
if ("CRYPT:".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
|
||||
{
|
||||
return "{CRYPT}" + encryptedPassword.substring("CRYPT:".length(), encryptedPassword.length());
|
||||
}
|
||||
|
@ -672,12 +673,12 @@ public class LdapLoginModule extends AbstractLoginModule
|
|||
return encryptedPassword;
|
||||
}
|
||||
|
||||
if ("{MD5}".startsWith(encryptedPassword.toUpperCase()))
|
||||
if ("{MD5}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
|
||||
{
|
||||
return "MD5:" + encryptedPassword.substring("{MD5}".length(), encryptedPassword.length());
|
||||
}
|
||||
|
||||
if ("{CRYPT}".startsWith(encryptedPassword.toUpperCase()))
|
||||
if ("{CRYPT}".startsWith(encryptedPassword.toUpperCase(Locale.ENGLISH)))
|
||||
{
|
||||
return "CRYPT:" + encryptedPassword.substring("{CRYPT}".length(), encryptedPassword.length());
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.jmx;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
|
@ -164,7 +165,7 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
|
|||
domain = obj.getClass().getPackage().getName();
|
||||
|
||||
|
||||
String type = obj.getClass().getName().toLowerCase();
|
||||
String type = obj.getClass().getName().toLowerCase(Locale.ENGLISH);
|
||||
int dot = type.lastIndexOf('.');
|
||||
if (dot >= 0)
|
||||
type = type.substring(dot + 1);
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.management.Attribute;
|
||||
|
@ -622,7 +623,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
convert = true;
|
||||
}
|
||||
|
||||
String uName = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
String uName = name.substring(0, 1).toUpperCase(Locale.ENGLISH) + name.substring(1);
|
||||
Class<?> oClass = onMBean ? this.getClass() : _managed.getClass();
|
||||
|
||||
LOG.debug("defineAttribute {} {}:{}:{}:{}",name,onMBean,readonly,oClass,description);
|
||||
|
@ -862,7 +863,7 @@ public class ObjectMBean implements DynamicMBean
|
|||
variableName = variableName.substring(2);
|
||||
}
|
||||
|
||||
variableName = variableName.substring(0,1).toLowerCase() + variableName.substring(1);
|
||||
variableName = variableName.substring(0,1).toLowerCase(Locale.ENGLISH) + variableName.substring(1);
|
||||
|
||||
return variableName;
|
||||
}
|
||||
|
|
|
@ -483,7 +483,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
|||
if (connectors == null || connectors.length == 0)
|
||||
{
|
||||
//if a SystemProperty -Djetty.port=<portnum> has been supplied, use that as the default port
|
||||
this.connectors = new Connector[] { this.server.createDefaultConnector(server, System.getProperty(PORT_SYSPROPERTY, null)) };
|
||||
this.connectors = new Connector[] { this.server.createDefaultConnector(System.getProperty(PORT_SYSPROPERTY, null)) };
|
||||
this.server.setConnectors(this.connectors);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,58 +16,55 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConsoleScanner extends Thread
|
||||
public class ConsoleScanner extends Thread
|
||||
{
|
||||
|
||||
|
||||
private final AbstractJettyMojo mojo;
|
||||
|
||||
public ConsoleScanner(AbstractJettyMojo mojo)
|
||||
|
||||
public ConsoleScanner(AbstractJettyMojo mojo)
|
||||
{
|
||||
this.mojo = mojo;
|
||||
setName("Console scanner");
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
while (true)
|
||||
{
|
||||
checkSystemInput();
|
||||
getSomeSleep();
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
mojo.getLog().warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void getSomeSleep()
|
||||
|
||||
private void getSomeSleep()
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
mojo.getLog().debug(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSystemInput() throws IOException
|
||||
{
|
||||
|
||||
private void checkSystemInput() throws IOException
|
||||
{
|
||||
while (System.in.available() > 0) {
|
||||
int inputByte = System.in.read();
|
||||
if (inputByte >= 0)
|
||||
if (inputByte >= 0)
|
||||
{
|
||||
char c = (char)inputByte;
|
||||
if (c == '\n') {
|
||||
|
@ -76,12 +73,12 @@ public class ConsoleScanner extends Thread
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Skip buffered bytes of system console.
|
||||
*/
|
||||
private void clearInputBuffer()
|
||||
private void clearInputBuffer()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -101,9 +98,9 @@ public class ConsoleScanner extends Thread
|
|||
catch (IOException e)
|
||||
{
|
||||
mojo.getLog().warn("Error discarding console input buffer", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void restartWebApp()
|
||||
{
|
||||
try
|
||||
|
|
|
@ -1,46 +1,45 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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.maven.plugin;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This goal is used to run Jetty with a pre-assembled war.
|
||||
* </p>
|
||||
* <p>
|
||||
* It accepts exactly the same options as the <a href="run-war-mojo.html">run-war</a> goal.
|
||||
* However, it doesn't assume that the current artifact is a
|
||||
* webapp and doesn't try to assemble it into a war before its execution.
|
||||
* So using it makes sense only when used in conjunction with the
|
||||
* <a href="run-war-mojo.html#webApp">webApp</a> configuration parameter pointing to a pre-built WAR.
|
||||
* </p>
|
||||
* <p>
|
||||
* This goal is useful e.g. for launching a web app in Jetty as a target for unit-tested
|
||||
* HTTP client components.
|
||||
* </p>
|
||||
*
|
||||
* @goal deploy-war
|
||||
* @requiresDependencyResolution runtime
|
||||
* @execute phase="validate"
|
||||
* @description Deploy a pre-assembled war
|
||||
*
|
||||
*/
|
||||
public class JettyDeployWar extends JettyRunWarMojo
|
||||
{
|
||||
}
|
||||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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.maven.plugin;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This goal is used to run Jetty with a pre-assembled war.
|
||||
* </p>
|
||||
* <p>
|
||||
* It accepts exactly the same options as the <a href="run-war-mojo.html">run-war</a> goal.
|
||||
* However, it doesn't assume that the current artifact is a
|
||||
* webapp and doesn't try to assemble it into a war before its execution.
|
||||
* So using it makes sense only when used in conjunction with the
|
||||
* <a href="run-war-mojo.html#webApp">webApp</a> configuration parameter pointing to a pre-built WAR.
|
||||
* </p>
|
||||
* <p>
|
||||
* This goal is useful e.g. for launching a web app in Jetty as a target for unit-tested
|
||||
* HTTP client components.
|
||||
* </p>
|
||||
*
|
||||
* @goal deploy-war
|
||||
* @requiresDependencyResolution runtime
|
||||
* @execute phase="validate"
|
||||
* @description Deploy a pre-assembled war
|
||||
*
|
||||
*/
|
||||
public class JettyDeployWar extends JettyRunWarMojo
|
||||
{
|
||||
}
|
||||
|
|
|
@ -18,23 +18,33 @@
|
|||
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
|
@ -42,7 +52,10 @@ import org.apache.maven.plugin.MojoExecutionException;
|
|||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.component.repository.ComponentDependency;
|
||||
import org.eclipse.jetty.server.RequestLog;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -64,7 +77,7 @@ import org.eclipse.jetty.util.IO;
|
|||
* There is a <a href="run-war-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
|
||||
* with examples in the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/">Configuration Guide</a>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @goal run-forked
|
||||
* @requiresDependencyResolution compile+runtime
|
||||
* @execute phase="test-compile"
|
||||
|
@ -72,17 +85,17 @@ import org.eclipse.jetty.util.IO;
|
|||
*
|
||||
*/
|
||||
public class JettyRunForkedMojo extends AbstractMojo
|
||||
{
|
||||
{
|
||||
public String PORT_SYSPROPERTY = "jetty.port";
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not to include dependencies on the plugin's classpath with <scope>provided</scope>
|
||||
* Use WITH CAUTION as you may wind up with duplicate jars/classes.
|
||||
* @parameter default-value="false"
|
||||
*/
|
||||
protected boolean useProvidedScope;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The maven project.
|
||||
*
|
||||
|
@ -91,9 +104,9 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
* @readonly
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If true, the <testOutputDirectory>
|
||||
* and the dependencies of <scope>test<scope>
|
||||
|
@ -101,27 +114,27 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
* @parameter alias="useTestClasspath" default-value="false"
|
||||
*/
|
||||
private boolean useTestScope;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The default location of the web.xml file. Will be used
|
||||
* if <webAppConfig><descriptor> is not set.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${basedir}/src/main/webapp/WEB-INF/web.xml"
|
||||
* @readonly
|
||||
*/
|
||||
private String webXml;
|
||||
|
||||
|
||||
/**
|
||||
* The target directory
|
||||
*
|
||||
*
|
||||
* @parameter expression="${project.build.directory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected File target;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The temporary directory to use for the webapp.
|
||||
* Defaults to target/tmp
|
||||
|
@ -132,26 +145,26 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
*/
|
||||
protected File tmpDirectory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The directory containing generated classes.
|
||||
*
|
||||
* @parameter expression="${project.build.outputDirectory}"
|
||||
* @required
|
||||
*
|
||||
*
|
||||
*/
|
||||
private File classesDirectory;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The directory containing generated test classes.
|
||||
*
|
||||
*
|
||||
* @parameter expression="${project.build.testOutputDirectory}"
|
||||
* @required
|
||||
*/
|
||||
private File testClassesDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* Root directory for all html/jsp etc files
|
||||
*
|
||||
|
@ -159,34 +172,34 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
*
|
||||
*/
|
||||
private File webAppSourceDirectory;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Directories that contain static resources
|
||||
* for the webapp. Optional.
|
||||
*
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
private File[] resourceBases;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If true, the webAppSourceDirectory will be first on the list of
|
||||
* resources that form the resource base for the webapp. If false,
|
||||
* If true, the webAppSourceDirectory will be first on the list of
|
||||
* resources that form the resource base for the webapp. If false,
|
||||
* it will be last.
|
||||
*
|
||||
*
|
||||
* @parameter default-value="true"
|
||||
*/
|
||||
private boolean baseAppFirst;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Location of jetty xml configuration files whose contents
|
||||
* Location of jetty xml configuration files whose contents
|
||||
* will be applied before any plugin configuration. Optional.
|
||||
* @parameter
|
||||
*/
|
||||
private String jettyXml;
|
||||
|
||||
|
||||
/**
|
||||
* The context path for the webapp. Defaults to the
|
||||
* name of the webapp's artifact.
|
||||
|
@ -205,71 +218,71 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
*/
|
||||
private String contextXml;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @parameter expression="${jetty.skip}" default-value="false"
|
||||
*/
|
||||
private boolean skip;
|
||||
|
||||
/**
|
||||
* Port to listen to stop jetty on executing -DSTOP.PORT=<stopPort>
|
||||
* Port to listen to stop jetty on executing -DSTOP.PORT=<stopPort>
|
||||
* -DSTOP.KEY=<stopKey> -jar start.jar --stop
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
protected int stopPort;
|
||||
|
||||
|
||||
/**
|
||||
* Key to provide when stopping jetty on executing java -DSTOP.KEY=<stopKey>
|
||||
* Key to provide when stopping jetty on executing java -DSTOP.KEY=<stopKey>
|
||||
* -DSTOP.PORT=<stopPort> -jar start.jar --stop
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
protected String stopKey;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Arbitrary jvm args to pass to the forked process
|
||||
* @parameter
|
||||
*/
|
||||
private String jvmArgs;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @parameter expression="${plugin.artifacts}"
|
||||
* @readonly
|
||||
*/
|
||||
private List pluginArtifacts;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @parameter expression="${plugin}"
|
||||
* @readonly
|
||||
*/
|
||||
private PluginDescriptor plugin;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @parameter expression="true" default-value="true"
|
||||
*/
|
||||
private boolean waitForChild;
|
||||
|
||||
|
||||
|
||||
private Process forkedProcess;
|
||||
|
||||
|
||||
private Random random;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public class ShutdownThread extends Thread
|
||||
{
|
||||
public ShutdownThread()
|
||||
{
|
||||
super("RunForkedShutdown");
|
||||
}
|
||||
|
||||
|
||||
public void run ()
|
||||
{
|
||||
if (forkedProcess != null && waitForChild)
|
||||
|
@ -278,7 +291,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.plugin.Mojo#execute()
|
||||
*/
|
||||
|
@ -295,20 +308,20 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
random = new Random();
|
||||
startJettyRunner();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<String> getProvidedJars() throws MojoExecutionException
|
||||
{
|
||||
{
|
||||
//if we are configured to include the provided dependencies on the plugin's classpath
|
||||
//(which mimics being on jetty's classpath vs being on the webapp's classpath), we first
|
||||
//try and filter out ones that will clash with jars that are plugin dependencies, then
|
||||
//create a new classloader that we setup in the parent chain.
|
||||
if (useProvidedScope)
|
||||
{
|
||||
|
||||
List<String> provided = new ArrayList<String>();
|
||||
|
||||
List<String> provided = new ArrayList<String>();
|
||||
for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); )
|
||||
{
|
||||
{
|
||||
Artifact artifact = iter.next();
|
||||
if (Artifact.SCOPE_PROVIDED.equals(artifact.getScope()) && !isPluginArtifact(artifact))
|
||||
{
|
||||
|
@ -322,16 +335,16 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public File prepareConfiguration() throws MojoExecutionException
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
//work out the configuration based on what is configured in the pom
|
||||
File propsFile = new File (target, "fork.props");
|
||||
if (propsFile.exists())
|
||||
propsFile.delete();
|
||||
propsFile.delete();
|
||||
|
||||
propsFile.createNewFile();
|
||||
//propsFile.deleteOnExit();
|
||||
|
@ -358,9 +371,9 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
//sort out base dir of webapp
|
||||
if (webAppSourceDirectory != null)
|
||||
props.put("base.dir", webAppSourceDirectory.getAbsolutePath());
|
||||
|
||||
|
||||
//sort out the resource base directories of the webapp
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (baseAppFirst)
|
||||
{
|
||||
add((webAppSourceDirectory==null?null:webAppSourceDirectory.getAbsolutePath()), builder);
|
||||
|
@ -371,7 +384,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if (resourceBases != null)
|
||||
{
|
||||
for (File resDir:resourceBases)
|
||||
|
@ -380,7 +393,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
add((webAppSourceDirectory==null?null:webAppSourceDirectory.getAbsolutePath()), builder);
|
||||
}
|
||||
props.put("res.dirs", builder.toString());
|
||||
|
||||
|
||||
|
||||
//web-inf classes
|
||||
List<File> classDirs = getClassesDirs();
|
||||
|
@ -397,7 +410,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
{
|
||||
props.put("classes.dir", classesDirectory.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
if (useTestScope && testClassesDirectory != null)
|
||||
{
|
||||
props.put("testClasses.dir", testClassesDirectory.getAbsolutePath());
|
||||
|
@ -435,7 +448,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
throw new MojoExecutionException("Prepare webapp configuration", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void add (String string, StringBuilder builder)
|
||||
{
|
||||
if (string == null)
|
||||
|
@ -448,62 +461,62 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
private List<File> getClassesDirs ()
|
||||
{
|
||||
List<File> classesDirs = new ArrayList<File>();
|
||||
|
||||
|
||||
//if using the test classes, make sure they are first
|
||||
//on the list
|
||||
if (useTestScope && (testClassesDirectory != null))
|
||||
classesDirs.add(testClassesDirectory);
|
||||
|
||||
|
||||
if (classesDirectory != null)
|
||||
classesDirs.add(classesDirectory);
|
||||
|
||||
|
||||
return classesDirs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private List<File> getOverlays()
|
||||
throws MalformedURLException, IOException
|
||||
{
|
||||
List<File> overlays = new ArrayList<File>();
|
||||
for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) iter.next();
|
||||
|
||||
Artifact artifact = (Artifact) iter.next();
|
||||
|
||||
if (artifact.getType().equals("war"))
|
||||
overlays.add(artifact.getFile());
|
||||
}
|
||||
|
||||
return overlays;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private List<File> getDependencyFiles ()
|
||||
{
|
||||
List<File> dependencyFiles = new ArrayList<File>();
|
||||
|
||||
|
||||
for ( Iterator<Artifact> iter = project.getArtifacts().iterator(); iter.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) iter.next();
|
||||
|
||||
if (((!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) && (!Artifact.SCOPE_TEST.equals( artifact.getScope())))
|
||||
|
||||
if (((!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) && (!Artifact.SCOPE_TEST.equals( artifact.getScope())))
|
||||
||
|
||||
(useTestScope && Artifact.SCOPE_TEST.equals( artifact.getScope())))
|
||||
{
|
||||
dependencyFiles.add(artifact.getFile());
|
||||
getLog().debug( "Adding artifact " + artifact.getFile().getName() + " for WEB-INF/lib " );
|
||||
getLog().debug( "Adding artifact " + artifact.getFile().getName() + " for WEB-INF/lib " );
|
||||
}
|
||||
}
|
||||
|
||||
return dependencyFiles;
|
||||
|
||||
return dependencyFiles;
|
||||
}
|
||||
|
||||
|
||||
public boolean isPluginArtifact(Artifact artifact)
|
||||
{
|
||||
if (pluginArtifacts == null || pluginArtifacts.isEmpty())
|
||||
return false;
|
||||
|
||||
|
||||
boolean isPluginArtifact = false;
|
||||
for (Iterator<Artifact> iter = pluginArtifacts.iterator(); iter.hasNext() && !isPluginArtifact; )
|
||||
{
|
||||
|
@ -512,18 +525,18 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
if (pluginArtifact.getGroupId().equals(artifact.getGroupId()) && pluginArtifact.getArtifactId().equals(artifact.getArtifactId()))
|
||||
isPluginArtifact = true;
|
||||
}
|
||||
|
||||
|
||||
return isPluginArtifact;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Set<Artifact> getExtraJars()
|
||||
throws Exception
|
||||
{
|
||||
Set<Artifact> extraJars = new HashSet<Artifact>();
|
||||
|
||||
|
||||
|
||||
|
||||
List l = pluginArtifacts;
|
||||
Artifact pluginArtifact = null;
|
||||
|
||||
|
@ -531,7 +544,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
{
|
||||
Iterator itor = l.iterator();
|
||||
while (itor.hasNext() && pluginArtifact == null)
|
||||
{
|
||||
{
|
||||
Artifact a = (Artifact)itor.next();
|
||||
if (a.getArtifactId().equals(plugin.getArtifactId())) //get the jetty-maven-plugin jar
|
||||
{
|
||||
|
@ -543,18 +556,18 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
return extraJars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void startJettyRunner() throws MojoExecutionException
|
||||
{
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
File props = prepareConfiguration();
|
||||
|
||||
|
||||
List<String> cmd = new ArrayList<String>();
|
||||
cmd.add(getJavaBin());
|
||||
|
||||
|
||||
if (jvmArgs != null)
|
||||
{
|
||||
String[] args = jvmArgs.split(" ");
|
||||
|
@ -564,7 +577,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
cmd.add(args[i].trim());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String classPath = getClassPath();
|
||||
if (classPath != null && classPath.length() > 0)
|
||||
{
|
||||
|
@ -572,7 +585,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
cmd.add(classPath);
|
||||
}
|
||||
cmd.add(Starter.class.getCanonicalName());
|
||||
|
||||
|
||||
if (stopPort > 0 && stopKey != null)
|
||||
{
|
||||
cmd.add("--stop-port");
|
||||
|
@ -585,26 +598,26 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
cmd.add("--jetty-xml");
|
||||
cmd.add(jettyXml);
|
||||
}
|
||||
|
||||
|
||||
if (contextXml != null)
|
||||
{
|
||||
cmd.add("--context-xml");
|
||||
cmd.add(contextXml);
|
||||
}
|
||||
|
||||
|
||||
cmd.add("--props");
|
||||
cmd.add(props.getAbsolutePath());
|
||||
|
||||
|
||||
String token = createToken();
|
||||
cmd.add("--token");
|
||||
cmd.add(token);
|
||||
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder(cmd);
|
||||
builder.directory(project.getBasedir());
|
||||
|
||||
|
||||
if (PluginLog.getLog().isDebugEnabled())
|
||||
PluginLog.getLog().debug(Arrays.toString(cmd.toArray()));
|
||||
|
||||
|
||||
forkedProcess = builder.start();
|
||||
PluginLog.getLog().info("Forked process starting");
|
||||
|
||||
|
@ -612,7 +625,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
{
|
||||
startPump("STDOUT",forkedProcess.getInputStream());
|
||||
startPump("STDERR",forkedProcess.getErrorStream());
|
||||
int exitcode = forkedProcess.waitFor();
|
||||
int exitcode = forkedProcess.waitFor();
|
||||
PluginLog.getLog().info("Forked execution exit: "+exitcode);
|
||||
}
|
||||
else
|
||||
|
@ -652,20 +665,20 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
{
|
||||
if (forkedProcess != null && waitForChild)
|
||||
forkedProcess.destroy();
|
||||
|
||||
|
||||
throw new MojoExecutionException("Failed to start Jetty within time limit");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (forkedProcess != null && waitForChild)
|
||||
forkedProcess.destroy();
|
||||
|
||||
|
||||
throw new MojoExecutionException("Failed to create Jetty process", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getClassPath() throws Exception
|
||||
{
|
||||
StringBuilder classPath = new StringBuilder();
|
||||
|
@ -682,16 +695,16 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Any jars that we need from the plugin environment (like the ones containing Starter class)
|
||||
Set<Artifact> extraJars = getExtraJars();
|
||||
for (Artifact a:extraJars)
|
||||
{
|
||||
{
|
||||
classPath.append(File.pathSeparator);
|
||||
classPath.append(a.getFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Any jars that we need from the project's dependencies because we're useProvided
|
||||
List<String> providedJars = getProvidedJars();
|
||||
if (providedJars != null && !providedJars.isEmpty())
|
||||
|
@ -703,7 +716,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
if (getLog().isDebugEnabled()) getLog().debug("Adding provided jar: "+jar);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return classPath.toString();
|
||||
}
|
||||
|
||||
|
@ -724,7 +737,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
|
||||
return "java";
|
||||
}
|
||||
|
||||
|
||||
public static String fileSeparators(String path)
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
|
@ -759,13 +772,13 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
return ret.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String createToken ()
|
||||
{
|
||||
return Long.toString(random.nextLong()^System.currentTimeMillis(), 36).toUpperCase();
|
||||
return Long.toString(random.nextLong()^System.currentTimeMillis(), 36).toUpperCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void startPump(String mode, InputStream inputStream)
|
||||
{
|
||||
ConsoleStreamer pump = new ConsoleStreamer(mode,inputStream);
|
||||
|
@ -774,7 +787,7 @@ public class JettyRunForkedMojo extends AbstractMojo
|
|||
thread.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,6 +63,9 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
*/
|
||||
public class JettyRunMojo extends AbstractJettyMojo
|
||||
{
|
||||
public static final String DEFAULT_WEBAPP_SRC = "src"+File.separator+"main"+File.separator+"webapp";
|
||||
|
||||
|
||||
/**
|
||||
* If true, the <testOutputDirectory>
|
||||
* and the dependencies of <scope>test<scope>
|
||||
|
@ -134,12 +137,13 @@ public class JettyRunMojo extends AbstractJettyMojo
|
|||
*/
|
||||
private List<File> extraScanTargets;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Verify the configuration given in the pom.
|
||||
*
|
||||
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
* @see org.mortbay.jetty.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
*/
|
||||
public void checkPomConfiguration () throws MojoExecutionException
|
||||
{
|
||||
|
@ -147,9 +151,10 @@ public class JettyRunMojo extends AbstractJettyMojo
|
|||
try
|
||||
{
|
||||
if ((getWebAppSourceDirectory() == null) || !getWebAppSourceDirectory().exists())
|
||||
{
|
||||
webAppSourceDirectory = new File (project.getBasedir(), "src"+File.separator+"main"+File.separator+"webapp");
|
||||
getLog().info("webAppSourceDirectory "+getWebAppSourceDirectory() +" does not exist. Defaulting to "+webAppSourceDirectory.getAbsolutePath());
|
||||
{
|
||||
File defaultWebAppSrcDir = new File (project.getBasedir(), DEFAULT_WEBAPP_SRC);
|
||||
getLog().info("webAppSourceDirectory"+(getWebAppSourceDirectory()==null?" not set.":" does not exist.")+" Defaulting to "+defaultWebAppSrcDir.getAbsolutePath());
|
||||
webAppSourceDirectory = defaultWebAppSrcDir;
|
||||
}
|
||||
else
|
||||
getLog().info( "Webapp source directory = " + getWebAppSourceDirectory().getCanonicalPath());
|
||||
|
@ -441,6 +446,7 @@ public class JettyRunMojo extends AbstractJettyMojo
|
|||
for ( Iterator<Artifact> iter = projectArtifacts.iterator(); iter.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) iter.next();
|
||||
|
||||
// Include runtime and compile time libraries, and possibly test libs too
|
||||
if(artifact.getType().equals("war"))
|
||||
{
|
||||
|
@ -448,6 +454,7 @@ public class JettyRunMojo extends AbstractJettyMojo
|
|||
{
|
||||
Resource r=Resource.newResource("jar:"+Resource.toURL(artifact.getFile()).toString()+"!/");
|
||||
overlays.add(r);
|
||||
getLog().info("Adding overlay for war project artifact "+artifact.getId());
|
||||
getExtraScanTargets().add(artifact.getFile());
|
||||
}
|
||||
catch(Exception e)
|
||||
|
|
|
@ -25,19 +25,21 @@ import java.util.List;
|
|||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.eclipse.jetty.util.Scanner;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This goal is used to assemble your webapp into an exploded war and automatically deploy it to Jetty.
|
||||
* </p>
|
||||
* <p>
|
||||
* Once invoked, the plugin can be configured to run continuously, scanning for changes in the pom.xml and
|
||||
* to WEB-INF/web.xml, WEB-INF/classes or WEB-INF/lib and hot redeploy when a change is detected.
|
||||
* Once invoked, the plugin can be configured to run continuously, scanning for changes in the pom.xml and
|
||||
* to WEB-INF/web.xml, WEB-INF/classes or WEB-INF/lib and hot redeploy when a change is detected.
|
||||
* </p>
|
||||
* <p>
|
||||
* You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration.
|
||||
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
|
||||
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
|
||||
* </p>
|
||||
* <p>
|
||||
* There is a <a href="run-exploded-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
|
||||
|
@ -51,24 +53,24 @@ import org.eclipse.jetty.util.Scanner;
|
|||
public class JettyRunWarExplodedMojo extends AbstractJettyMojo
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The location of the war file.
|
||||
*
|
||||
*
|
||||
* @parameter alias="webApp" expression="${project.build.directory}/${project.build.finalName}"
|
||||
* @required
|
||||
*/
|
||||
private File war;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
*
|
||||
* @see org.mortbay.jetty.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
*/
|
||||
public void checkPomConfiguration() throws MojoExecutionException
|
||||
{
|
||||
|
@ -76,7 +78,7 @@ public class JettyRunWarExplodedMojo extends AbstractJettyMojo
|
|||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#configureScanner()
|
||||
* @see org.mortbay.jetty.plugin.AbstractJettyMojo#configureScanner()
|
||||
*/
|
||||
public void configureScanner() throws MojoExecutionException
|
||||
{
|
||||
|
@ -93,7 +95,7 @@ public class JettyRunWarExplodedMojo extends AbstractJettyMojo
|
|||
scanList.add(new File(webInfDir, "classes"));
|
||||
scanList.add(new File(webInfDir, "lib"));
|
||||
setScanList(scanList);
|
||||
|
||||
|
||||
ArrayList<Scanner.BulkListener> listeners = new ArrayList<Scanner.BulkListener>();
|
||||
listeners.add(new Scanner.BulkListener()
|
||||
{
|
||||
|
@ -113,10 +115,10 @@ public class JettyRunWarExplodedMojo extends AbstractJettyMojo
|
|||
setScannerListeners(listeners);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void restartWebApp(boolean reconfigureScanner) throws Exception
|
||||
|
||||
|
||||
|
||||
public void restartWebApp(boolean reconfigureScanner) throws Exception
|
||||
{
|
||||
getLog().info("Restarting webapp");
|
||||
getLog().debug("Stopping webapp ...");
|
||||
|
@ -152,20 +154,20 @@ public class JettyRunWarExplodedMojo extends AbstractJettyMojo
|
|||
getLog().info("Restart completed.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void configureWebApplication () throws Exception
|
||||
{
|
||||
super.configureWebApplication();
|
||||
super.configureWebApplication();
|
||||
webApp.setWar(war.getCanonicalPath());
|
||||
}
|
||||
|
||||
|
||||
public void execute () throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
super.execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -21,10 +21,14 @@ package org.eclipse.jetty.maven.plugin;
|
|||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.eclipse.jetty.util.Scanner;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -32,18 +36,18 @@ import org.eclipse.jetty.util.Scanner;
|
|||
* </p>
|
||||
* <p>
|
||||
* Once invoked, the plugin can be configured to run continuously, scanning for changes in the project and to the
|
||||
* war file and automatically performing a
|
||||
* hot redeploy when necessary.
|
||||
* war file and automatically performing a
|
||||
* hot redeploy when necessary.
|
||||
* </p>
|
||||
* <p>
|
||||
* You may also specify the location of a jetty.xml file whose contents will be applied before any plugin configuration.
|
||||
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
|
||||
* This can be used, for example, to deploy a static webapp that is not part of your maven build.
|
||||
* </p>
|
||||
* <p>
|
||||
* There is a <a href="run-war-mojo.html">reference guide</a> to the configuration parameters for this plugin, and more detailed information
|
||||
* with examples in the <a href="http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin/">Configuration Guide</a>.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @goal run-war
|
||||
* @requiresDependencyResolution compile+runtime
|
||||
* @execute phase="package"
|
||||
|
@ -61,13 +65,13 @@ public class JettyRunWarMojo extends AbstractJettyMojo
|
|||
private File war;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.plugin.Mojo#execute()
|
||||
*/
|
||||
public void execute() throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
super.execute();
|
||||
super.execute();
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,18 +79,18 @@ public class JettyRunWarMojo extends AbstractJettyMojo
|
|||
public void configureWebApplication () throws Exception
|
||||
{
|
||||
super.configureWebApplication();
|
||||
|
||||
|
||||
webApp.setWar(war.getCanonicalPath());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.maven.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
* @see org.mortbay.jetty.plugin.AbstractJettyMojo#checkPomConfiguration()
|
||||
*/
|
||||
public void checkPomConfiguration() throws MojoExecutionException
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -100,7 +104,7 @@ public class JettyRunWarMojo extends AbstractJettyMojo
|
|||
scanList.add(getProject().getFile());
|
||||
scanList.add(war);
|
||||
setScanList(scanList);
|
||||
|
||||
|
||||
ArrayList listeners = new ArrayList();
|
||||
listeners.add(new Scanner.BulkListener()
|
||||
{
|
||||
|
@ -117,11 +121,11 @@ public class JettyRunWarMojo extends AbstractJettyMojo
|
|||
}
|
||||
}
|
||||
});
|
||||
setScannerListeners(listeners);
|
||||
setScannerListeners(listeners);
|
||||
}
|
||||
|
||||
|
||||
public void restartWebApp(boolean reconfigureScanner) throws Exception
|
||||
public void restartWebApp(boolean reconfigureScanner) throws Exception
|
||||
{
|
||||
getLog().info("Restarting webapp ...");
|
||||
getLog().debug("Stopping webapp ...");
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.jetty.server.Connector;
|
|||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.RequestLog;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
|
@ -33,20 +32,20 @@ import org.eclipse.jetty.webapp.WebAppContext;
|
|||
|
||||
/**
|
||||
* JettyServer
|
||||
*
|
||||
*
|
||||
* Maven jetty plugin version of a wrapper for the Server class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JettyServer extends org.eclipse.jetty.server.Server
|
||||
{
|
||||
public static int DEFAULT_PORT = 8080;
|
||||
public static int DEFAULT_MAX_IDLE_TIME = 30000;
|
||||
|
||||
|
||||
|
||||
private RequestLog requestLog;
|
||||
private ContextHandlerCollection contexts;
|
||||
|
||||
|
||||
|
||||
|
||||
public JettyServer()
|
||||
{
|
||||
super();
|
||||
|
@ -55,7 +54,7 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
|||
Resource.setDefaultUseCaches(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setRequestLog (RequestLog requestLog)
|
||||
{
|
||||
this.requestLog = requestLog;
|
||||
|
@ -69,16 +68,16 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
|||
super.doStart();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.server.handler.HandlerCollection#addHandler(org.eclipse.jetty.server.Handler)
|
||||
*/
|
||||
public void addWebApplication(WebAppContext webapp) throws Exception
|
||||
{
|
||||
{
|
||||
contexts.addHandler (webapp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set up the handler structure to receive a webapp.
|
||||
* Also put in a DefaultHandler so we get a nice page
|
||||
|
@ -86,43 +85,43 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
|||
* context isn't at root.
|
||||
* @throws Exception
|
||||
*/
|
||||
public void configureHandlers () throws Exception
|
||||
public void configureHandlers () throws Exception
|
||||
{
|
||||
DefaultHandler defaultHandler = new DefaultHandler();
|
||||
RequestLogHandler requestLogHandler = new RequestLogHandler();
|
||||
if (this.requestLog != null)
|
||||
requestLogHandler.setRequestLog(this.requestLog);
|
||||
|
||||
|
||||
contexts = (ContextHandlerCollection)super.getChildHandlerByClass(ContextHandlerCollection.class);
|
||||
if (contexts==null)
|
||||
{
|
||||
{
|
||||
contexts = new ContextHandlerCollection();
|
||||
HandlerCollection handlers = (HandlerCollection)super.getChildHandlerByClass(HandlerCollection.class);
|
||||
if (handlers==null)
|
||||
{
|
||||
handlers = new HandlerCollection();
|
||||
super.setHandler(handlers);
|
||||
handlers = new HandlerCollection();
|
||||
super.setHandler(handlers);
|
||||
handlers.setHandlers(new Handler[]{contexts, defaultHandler, requestLogHandler});
|
||||
}
|
||||
else
|
||||
{
|
||||
handlers.addHandler(contexts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Connector createDefaultConnector(Server server, String portnum) throws Exception
|
||||
|
||||
|
||||
|
||||
|
||||
public Connector createDefaultConnector(String portnum) throws Exception
|
||||
{
|
||||
ServerConnector connector = new ServerConnector(server);
|
||||
ServerConnector connector = new ServerConnector(this);
|
||||
int port = ((portnum==null||portnum.equals(""))?DEFAULT_PORT:Integer.parseInt(portnum.trim()));
|
||||
connector.setPort(port);
|
||||
connector.setIdleTimeout(DEFAULT_MAX_IDLE_TIME);
|
||||
|
||||
// connector.setMaxIdleTime(DEFAULT_MAX_IDLE_TIME);
|
||||
|
||||
return connector;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
||||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
@ -39,8 +38,8 @@ import org.eclipse.jetty.webapp.Configuration;
|
|||
import org.eclipse.jetty.webapp.FragmentConfiguration;
|
||||
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
|
||||
import org.eclipse.jetty.webapp.MetaInfConfiguration;
|
||||
import org.eclipse.jetty.webapp.TagLibConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.webapp.WebInfConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebXmlConfiguration;
|
||||
|
||||
/**
|
||||
|
@ -56,6 +55,7 @@ public class JettyWebAppContext extends WebAppContext
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(JettyWebAppContext.class);
|
||||
|
||||
private static final String DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN = ".*/javax.servlet-[^/]*\\.jar$|.*/servlet-api-[^/]*\\.jar$";
|
||||
private static final String WEB_INF_CLASSES_PREFIX = "/WEB-INF/classes";
|
||||
private static final String WEB_INF_LIB_PREFIX = "/WEB-INF/lib";
|
||||
|
||||
|
@ -73,6 +73,19 @@ public class JettyWebAppContext extends WebAppContext
|
|||
* @deprecated The value of this parameter will be ignored by the plugin. Overlays will always be unpacked.
|
||||
*/
|
||||
private boolean unpackOverlays;
|
||||
|
||||
/**
|
||||
* Set the "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" with a pattern for matching jars on
|
||||
* container classpath to scan. This is analogous to the WebAppContext.setAttribute() call.
|
||||
*/
|
||||
private String containerIncludeJarPattern = null;
|
||||
|
||||
/**
|
||||
* Set the "org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern" with a pattern for matching jars on
|
||||
* webapp's classpath to scan. This is analogous to the WebAppContext.setAttribute() call.
|
||||
*/
|
||||
private String webInfIncludeJarPattern = null;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated The value of this parameter will be ignored by the plugin. This option will be always disabled.
|
||||
|
@ -91,14 +104,34 @@ public class JettyWebAppContext extends WebAppContext
|
|||
new MetaInfConfiguration(),
|
||||
new FragmentConfiguration(),
|
||||
envConfig = new EnvConfiguration(),
|
||||
new AnnotationConfiguration(),
|
||||
new org.eclipse.jetty.plus.webapp.PlusConfiguration(),
|
||||
new JettyWebXmlConfiguration(),
|
||||
new TagLibConfiguration()
|
||||
new MavenAnnotationConfiguration(),
|
||||
new JettyWebXmlConfiguration()
|
||||
});
|
||||
// Turn off copyWebInf option as it is not applicable for plugin.
|
||||
super.setCopyWebInf(false);
|
||||
}
|
||||
public void setContainerIncludeJarPattern(String pattern)
|
||||
{
|
||||
containerIncludeJarPattern = pattern;
|
||||
}
|
||||
|
||||
public String getContainerIncludeJarPattern()
|
||||
{
|
||||
return containerIncludeJarPattern;
|
||||
}
|
||||
|
||||
|
||||
public String getWebInfIncludeJarPattern()
|
||||
{
|
||||
return webInfIncludeJarPattern;
|
||||
}
|
||||
public void setWebInfIncludeJarPattern(String pattern)
|
||||
{
|
||||
webInfIncludeJarPattern = pattern;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean getUnpackOverlays()
|
||||
{
|
||||
|
@ -218,17 +251,21 @@ public class JettyWebAppContext extends WebAppContext
|
|||
{
|
||||
//Set up the pattern that tells us where the jars are that need scanning for
|
||||
//stuff like taglibs so we can tell jasper about it (see TagLibConfiguration)
|
||||
String tmp = (String)getAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern");
|
||||
|
||||
tmp = addPattern(tmp, ".*/.*jsp-api-[^/]*\\.jar$");
|
||||
tmp = addPattern(tmp, ".*/.*jsp-[^/]*\\.jar$");
|
||||
tmp = addPattern(tmp, ".*/.*taglibs[^/]*\\.jar$");
|
||||
tmp = addPattern(tmp, ".*/.*jstl[^/]*\\.jar$");
|
||||
tmp = addPattern(tmp, ".*/.*jsf-impl-[^/]*\\.jar$"); // add in 2 most popular jsf impls
|
||||
tmp = addPattern(tmp, ".*/.*javax.faces-[^/]*\\.jar$");
|
||||
tmp = addPattern(tmp, ".*/.*myfaces-impl-[^/]*\\.jar$");
|
||||
|
||||
setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", tmp);
|
||||
//Allow user to set up pattern for names of jars from the container classpath
|
||||
//that will be scanned - note that by default NO jars are scanned
|
||||
String tmp = containerIncludeJarPattern;
|
||||
if (tmp==null || "".equals(tmp))
|
||||
tmp = (String)getAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN);
|
||||
|
||||
tmp = addPattern(tmp, DEFAULT_CONTAINER_INCLUDE_JAR_PATTERN);
|
||||
setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, tmp);
|
||||
|
||||
//Allow user to set up pattern of jar names from WEB-INF that will be scanned.
|
||||
//Note that by default ALL jars considered to be in WEB-INF will be scanned - setting
|
||||
//a pattern restricts scanning
|
||||
if (webInfIncludeJarPattern != null)
|
||||
setAttribute(WebInfConfiguration.WEBINF_JAR_PATTERN, webInfIncludeJarPattern);
|
||||
|
||||
//Set up the classes dirs that comprises the equivalent of WEB-INF/classes
|
||||
if (testClasses != null)
|
||||
|
@ -241,7 +278,6 @@ public class JettyWebAppContext extends WebAppContext
|
|||
classpathFiles.addAll(webInfClasses);
|
||||
classpathFiles.addAll(webInfJars);
|
||||
|
||||
|
||||
// Initialize map containing all jars in /WEB-INF/lib
|
||||
webInfJarMap.clear();
|
||||
for (File file : webInfJars)
|
||||
|
@ -255,13 +291,28 @@ public class JettyWebAppContext extends WebAppContext
|
|||
if (this.jettyEnvXml != null)
|
||||
envConfig.setJettyEnvXml(Resource.toURL(new File(this.jettyEnvXml)));
|
||||
|
||||
//setShutdown(false);
|
||||
// CHECK setShutdown(false);
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
public void doStop () throws Exception
|
||||
{
|
||||
//setShutdown(true);
|
||||
if (classpathFiles != null)
|
||||
classpathFiles.clear();
|
||||
classpathFiles = null;
|
||||
|
||||
classes = null;
|
||||
testClasses = null;
|
||||
|
||||
if (webInfJarMap != null)
|
||||
webInfJarMap.clear();
|
||||
|
||||
webInfClasses.clear();
|
||||
webInfJars.clear();
|
||||
|
||||
|
||||
|
||||
// CHECK setShutdown(true);
|
||||
//just wait a little while to ensure no requests are still being processed
|
||||
Thread.currentThread().sleep(500L);
|
||||
super.doStop();
|
||||
|
@ -344,37 +395,40 @@ public class JettyWebAppContext extends WebAppContext
|
|||
@Override
|
||||
public Set<String> getResourcePaths(String path)
|
||||
{
|
||||
// Try to get regular resource paths
|
||||
// Try to get regular resource paths - this will get appropriate paths from any overlaid wars etc
|
||||
Set<String> paths = super.getResourcePaths(path);
|
||||
|
||||
// If no paths are returned check for virtual paths /WEB-INF/classes and /WEB-INF/lib
|
||||
if (paths.isEmpty() && path != null)
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
path = URIUtil.canonicalPath(path);
|
||||
TreeSet<String> allPaths = new TreeSet<String>();
|
||||
allPaths.addAll(paths);
|
||||
|
||||
//add in the dependency jars as a virtual WEB-INF/lib entry
|
||||
if (path.startsWith(WEB_INF_LIB_PREFIX))
|
||||
{
|
||||
paths = new TreeSet<String>();
|
||||
for (String fileName : webInfJarMap.keySet())
|
||||
{
|
||||
// Return all jar files from class path
|
||||
paths.add(WEB_INF_LIB_PREFIX + "/" + fileName);
|
||||
allPaths.add(WEB_INF_LIB_PREFIX + "/" + fileName);
|
||||
}
|
||||
}
|
||||
else if (path.startsWith(WEB_INF_CLASSES_PREFIX))
|
||||
{
|
||||
int i=0;
|
||||
|
||||
while (paths.isEmpty() && (i < webInfClasses.size()))
|
||||
while (i < webInfClasses.size())
|
||||
{
|
||||
String newPath = path.replace(WEB_INF_CLASSES_PREFIX, webInfClasses.get(i).getPath());
|
||||
paths = super.getResourcePaths(newPath);
|
||||
allPaths.addAll(super.getResourcePaths(newPath));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return allPaths;
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
|
||||
public String addPattern (String s, String pattern)
|
||||
{
|
||||
if (s == null)
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2012 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.maven.plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.jetty.annotations.AbstractDiscoverableAnnotationHandler;
|
||||
import org.eclipse.jetty.annotations.AnnotationConfiguration;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.DiscoverableAnnotationHandler;
|
||||
import org.eclipse.jetty.annotations.ClassNameResolver;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.webapp.MetaData;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class MavenAnnotationConfiguration extends AnnotationConfiguration
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(MavenAnnotationConfiguration.class);
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void parseWebInfClasses(final WebAppContext context, final AnnotationParser parser) throws Exception
|
||||
{
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
if (jwac.getClassPathFiles() == null || jwac.getClassPathFiles().size() == 0)
|
||||
super.parseWebInfClasses (context, parser);
|
||||
else
|
||||
{
|
||||
LOG.debug("Scanning classes ");
|
||||
//Look for directories on the classpath and process each one of those
|
||||
|
||||
MetaData metaData = context.getMetaData();
|
||||
if (metaData == null)
|
||||
throw new IllegalStateException ("No metadata");
|
||||
|
||||
parser.clearHandlers();
|
||||
for (DiscoverableAnnotationHandler h:_discoverableAnnotationHandlers)
|
||||
{
|
||||
if (h instanceof AbstractDiscoverableAnnotationHandler)
|
||||
((AbstractDiscoverableAnnotationHandler)h).setResource(null); //
|
||||
}
|
||||
parser.registerHandlers(_discoverableAnnotationHandlers);
|
||||
parser.registerHandler(_classInheritanceHandler);
|
||||
parser.registerHandlers(_containerInitializerAnnotationHandlers);
|
||||
|
||||
|
||||
for (File f:jwac.getClassPathFiles())
|
||||
{
|
||||
//scan the equivalent of the WEB-INF/classes directory that has been synthesised by the plugin
|
||||
if (f.isDirectory() && f.exists())
|
||||
{
|
||||
doParse(context, parser, Resource.newResource(f.toURL()));
|
||||
}
|
||||
}
|
||||
|
||||
//if an actual WEB-INF/classes directory also exists (eg because of overlayed wars) then scan that
|
||||
//too
|
||||
if (context.getWebInf() != null && context.getWebInf().exists())
|
||||
{
|
||||
Resource classesDir = context.getWebInf().addPath("classes/");
|
||||
if (classesDir.exists())
|
||||
{
|
||||
doParse(context, parser, classesDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void doParse (final WebAppContext context, final AnnotationParser parser, Resource resource)
|
||||
throws Exception
|
||||
{
|
||||
parser.parse(resource, new ClassNameResolver()
|
||||
{
|
||||
public boolean isExcluded (String name)
|
||||
{
|
||||
if (context.isSystemClass(name)) return true;
|
||||
if (context.isServerClass(name)) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldOverride (String name)
|
||||
{
|
||||
//looking at webapp classpath, found already-parsed class of same name - did it come from system or duplicate in webapp?
|
||||
if (context.isParentLoaderPriority())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -24,8 +24,10 @@ import java.net.URLClassLoader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.util.IO;
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -40,8 +42,8 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
|
||||
protected Resource _originalResourceBase;
|
||||
protected Resource[] _unpackedOverlays;
|
||||
|
||||
|
||||
|
||||
|
||||
public void configure(WebAppContext context) throws Exception
|
||||
{
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
|
@ -54,11 +56,11 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
while (itor.hasNext())
|
||||
((WebAppClassLoader)context.getClassLoader()).addClassPath(((File)itor.next()).getCanonicalPath());
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Classpath = "+((URLClassLoader)context.getClassLoader()).getURLs());
|
||||
//if (LOG.isDebugEnabled())
|
||||
//LOG.debug("Classpath = "+LazyList.array2List(((URLClassLoader)context.getClassLoader()).getURLs()));
|
||||
}
|
||||
super.configure(context);
|
||||
|
||||
|
||||
// knock out environmental maven and plexus classes from webAppContext
|
||||
String[] existingServerClasses = context.getServerClasses();
|
||||
String[] newServerClasses = new String[2+(existingServerClasses==null?0:existingServerClasses.length)];
|
||||
|
@ -71,7 +73,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
for (int i=0;i<newServerClasses.length;i++)
|
||||
LOG.debug(newServerClasses[i]);
|
||||
}
|
||||
context.setServerClasses( newServerClasses );
|
||||
context.setServerClasses( newServerClasses );
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,6 +81,53 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
{
|
||||
super.preConfigure(context);
|
||||
|
||||
}
|
||||
|
||||
public void postConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
super.postConfigure(context);
|
||||
}
|
||||
|
||||
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
|
||||
//remove the unpacked wars
|
||||
if (_unpackedOverlays != null && _unpackedOverlays.length>0)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i=0; i<_unpackedOverlays.length; i++)
|
||||
{
|
||||
IO.delete(_unpackedOverlays[i].getFile());
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
super.deconfigure(context);
|
||||
//restore whatever the base resource was before we might have included overlaid wars
|
||||
context.setBaseResource(_originalResourceBase);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jetty.webapp.WebInfConfiguration#unpack(org.eclipse.jetty.webapp.WebAppContext)
|
||||
*/
|
||||
@Override
|
||||
public void unpack(WebAppContext context) throws IOException
|
||||
{
|
||||
//Unpack and find base resource as normal
|
||||
super.unpack(context);
|
||||
|
||||
|
||||
//Add in any overlays as a resource collection for the base
|
||||
_originalResourceBase = context.getBaseResource();
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
|
||||
|
@ -102,7 +151,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
origSize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int overlaySize = jwac.getOverlays().size();
|
||||
Resource[] newResources = new Resource[origSize + overlaySize];
|
||||
|
||||
|
@ -112,7 +161,6 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
if (jwac.getBaseAppFirst())
|
||||
{
|
||||
System.arraycopy(origResources,0,newResources,0,origSize);
|
||||
|
||||
offset = origSize;
|
||||
}
|
||||
else
|
||||
|
@ -120,53 +168,23 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
System.arraycopy(origResources,0,newResources,overlaySize,origSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Overlays are always unpacked
|
||||
_unpackedOverlays = new Resource[overlaySize];
|
||||
List<Resource> overlays = jwac.getOverlays();
|
||||
for (int idx=0; idx<overlaySize; idx++)
|
||||
{
|
||||
{
|
||||
LOG.info("Unpacking overlay: " + overlays.get(idx));
|
||||
_unpackedOverlays[idx] = unpackOverlay(context, overlays.get(idx));
|
||||
newResources[idx+offset] = _unpackedOverlays[idx];
|
||||
|
||||
LOG.info("Adding overlay: " + _unpackedOverlays[idx]);
|
||||
}
|
||||
|
||||
|
||||
jwac.setBaseResource(new ResourceCollection(newResources));
|
||||
}
|
||||
}
|
||||
|
||||
public void postConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
super.postConfigure(context);
|
||||
}
|
||||
|
||||
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
JettyWebAppContext jwac = (JettyWebAppContext)context;
|
||||
|
||||
//remove the unpacked wars
|
||||
if (_unpackedOverlays != null && _unpackedOverlays.length>0)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i=0; i<_unpackedOverlays.length; i++)
|
||||
{
|
||||
IO.delete(_unpackedOverlays[i].getFile());
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOG.ignore(e);
|
||||
}
|
||||
}
|
||||
super.deconfigure(context);
|
||||
//restore whatever the base resource was before we might have included overlaid wars
|
||||
context.setBaseResource(_originalResourceBase);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the jars to examine from the files from which we have
|
||||
|
@ -175,6 +193,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
* @param context
|
||||
* @return the list of jars found
|
||||
*/
|
||||
@Override
|
||||
protected List<Resource> findJars (WebAppContext context)
|
||||
throws Exception
|
||||
{
|
||||
|
@ -184,7 +203,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
{
|
||||
for (File f: jwac.getClassPathFiles())
|
||||
{
|
||||
if (f.getName().toLowerCase().endsWith(".jar"))
|
||||
if (f.getName().toLowerCase(Locale.ENGLISH).endsWith(".jar"))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -203,14 +222,16 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
list.addAll(superList);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected Resource unpackOverlay (WebAppContext context, Resource overlay)
|
||||
throws IOException
|
||||
{
|
||||
//resolve if not already resolved
|
||||
resolveTempDirectory(context);
|
||||
|
||||
|
||||
|
||||
|
||||
//Get the name of the overlayed war and unpack it to a dir of the
|
||||
//same name in the temporary directory
|
||||
String name = overlay.getName();
|
||||
|
@ -225,6 +246,4 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
Resource unpackedOverlay = Resource.newResource(dir.getCanonicalPath());
|
||||
return unpackedOverlay;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
// ========================================================================
|
||||
//
|
||||
|
||||
|
||||
package org.eclipse.jetty.maven.plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
@ -41,7 +41,7 @@ import org.eclipse.jetty.server.Server;
|
|||
* by stopping the Server instances. The choice of
|
||||
* behaviour is controlled by either passing true
|
||||
* (exit jvm) or false (stop Servers) in the constructor.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Monitor extends Thread
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ public class Monitor extends Thread
|
|||
ServerSocket _serverSocket;
|
||||
boolean _kill;
|
||||
|
||||
public Monitor(int port, String key, Server[] servers, boolean kill)
|
||||
public Monitor(int port, String key, Server[] servers, boolean kill)
|
||||
throws UnknownHostException, IOException
|
||||
{
|
||||
if (port <= 0)
|
||||
|
@ -64,7 +64,7 @@ public class Monitor extends Thread
|
|||
_kill = kill;
|
||||
setDaemon(true);
|
||||
setName("StopJettyPluginMonitor");
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", port);
|
||||
_serverSocket=new ServerSocket();
|
||||
_serverSocket.setReuseAddress(true);
|
||||
try
|
||||
|
@ -77,7 +77,7 @@ public class Monitor extends Thread
|
|||
throw x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void run()
|
||||
{
|
||||
while (_serverSocket != null)
|
||||
|
@ -88,7 +88,7 @@ public class Monitor extends Thread
|
|||
socket = _serverSocket.accept();
|
||||
socket.setSoLinger(false, 0);
|
||||
LineNumberReader lin = new LineNumberReader(new InputStreamReader(socket.getInputStream()));
|
||||
|
||||
|
||||
String key = lin.readLine();
|
||||
if (!_key.equals(key)) continue;
|
||||
String cmd = lin.readLine();
|
||||
|
@ -97,13 +97,13 @@ public class Monitor extends Thread
|
|||
try{socket.close();}catch (Exception e){e.printStackTrace();}
|
||||
try{socket.close();}catch (Exception e){e.printStackTrace();}
|
||||
try{_serverSocket.close();}catch (Exception e){e.printStackTrace();}
|
||||
|
||||
|
||||
_serverSocket = null;
|
||||
|
||||
|
||||
if (_kill)
|
||||
{
|
||||
System.out.println("Killing Jetty");
|
||||
System.exit(0);
|
||||
System.exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ public class Monitor extends Thread
|
|||
{
|
||||
try
|
||||
{
|
||||
System.out.println("Stopping server "+i);
|
||||
System.out.println("Stopping server "+i);
|
||||
_servers[i].stop();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -23,19 +23,23 @@ import java.io.FileInputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
public class Starter
|
||||
{
|
||||
{
|
||||
public static final String PORT_SYSPROPERTY = "jetty.port";
|
||||
private static final Logger LOG = Log.getLogger(Starter.class);
|
||||
|
||||
|
@ -45,21 +49,21 @@ public class Starter
|
|||
private JettyServer server;
|
||||
private JettyWebAppContext webApp;
|
||||
private Monitor monitor;
|
||||
|
||||
|
||||
private int stopPort=0;
|
||||
private String stopKey=null;
|
||||
private Properties props;
|
||||
private String token;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void configureJetty () throws Exception
|
||||
{
|
||||
LOG.debug("Starting Jetty Server ...");
|
||||
|
||||
this.server = new JettyServer();
|
||||
|
||||
//apply any configs from jetty.xml files first
|
||||
//apply any configs from jetty.xml files first
|
||||
applyJettyXml ();
|
||||
|
||||
// if the user hasn't configured a connector in the jetty.xml
|
||||
|
@ -68,7 +72,7 @@ public class Starter
|
|||
if (connectors == null|| connectors.length == 0)
|
||||
{
|
||||
//if a SystemProperty -Djetty.port=<portnum> has been supplied, use that as the default port
|
||||
connectors = new Connector[] { this.server.createDefaultConnector(server, System.getProperty(PORT_SYSPROPERTY, null)) };
|
||||
connectors = new Connector[] { this.server.createDefaultConnector(System.getProperty(PORT_SYSPROPERTY, null)) };
|
||||
this.server.setConnectors(connectors);
|
||||
}
|
||||
|
||||
|
@ -84,15 +88,15 @@ public class Starter
|
|||
this.server.configureHandlers();
|
||||
|
||||
webApp = new JettyWebAppContext();
|
||||
|
||||
|
||||
//configure webapp from properties file describing unassembled webapp
|
||||
configureWebApp();
|
||||
|
||||
|
||||
//set up the webapp from the context xml file provided
|
||||
//NOTE: just like jetty:run mojo this means that the context file can
|
||||
//potentially override settings made in the pom. Ideally, we'd like
|
||||
//the pom to override the context xml file, but as the other mojos all
|
||||
//configure a WebAppContext in the pom (the <webApp> element), it is
|
||||
//configure a WebAppContext in the pom (the <webApp> element), it is
|
||||
//already configured by the time the context xml file is applied.
|
||||
if (contextXml != null)
|
||||
{
|
||||
|
@ -109,30 +113,30 @@ public class Starter
|
|||
monitor = new Monitor(stopPort, stopKey, new Server[]{server}, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void configureWebApp ()
|
||||
throws Exception
|
||||
{
|
||||
if (props == null)
|
||||
return;
|
||||
|
||||
|
||||
//apply a properties file that defines the things that we configure in the jetty:run plugin:
|
||||
// - the context path
|
||||
String str = (String)props.get("context.path");
|
||||
if (str != null)
|
||||
webApp.setContextPath(str);
|
||||
|
||||
|
||||
// - web.xml
|
||||
str = (String)props.get("web.xml");
|
||||
if (str != null)
|
||||
webApp.setDescriptor(str);
|
||||
|
||||
|
||||
// - the tmp directory
|
||||
str = (String)props.getProperty("tmp.dir");
|
||||
if (str != null)
|
||||
webApp.setTempDirectory(new File(str.trim()));
|
||||
|
||||
|
||||
// - the base directory
|
||||
str = (String)props.getProperty("base.dir");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
|
@ -145,7 +149,7 @@ public class Starter
|
|||
ResourceCollection resources = new ResourceCollection(str);
|
||||
webApp.setBaseResource(resources);
|
||||
}
|
||||
|
||||
|
||||
// - overlays
|
||||
str = (String)props.getProperty("overlay.files");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
|
@ -163,8 +167,8 @@ public class Starter
|
|||
{
|
||||
webApp.setClasses(new File(str));
|
||||
}
|
||||
|
||||
str = (String)props.getProperty("testClasses.dir");
|
||||
|
||||
str = (String)props.getProperty("testClasses.dir");
|
||||
if (str != null && !"".equals(str.trim()))
|
||||
{
|
||||
webApp.setTestClasses(new File(str));
|
||||
|
@ -181,7 +185,7 @@ public class Starter
|
|||
jars.add(new File(names[j].trim()));
|
||||
webApp.setWebInfLib(jars);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void getConfiguration (String[] args)
|
||||
|
@ -205,7 +209,7 @@ public class Starter
|
|||
for (int j=0; names!= null && j < names.length; j++)
|
||||
{
|
||||
jettyXmls.add(new File(names[j].trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--context-xml
|
||||
|
@ -221,7 +225,7 @@ public class Starter
|
|||
props = new Properties();
|
||||
props.load(new FileInputStream(f));
|
||||
}
|
||||
|
||||
|
||||
//--token
|
||||
if ("--token".equals(args[i]))
|
||||
{
|
||||
|
@ -237,16 +241,16 @@ public class Starter
|
|||
monitor.start();
|
||||
|
||||
LOG.info("Started Jetty Server");
|
||||
server.start();
|
||||
server.start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void join () throws Exception
|
||||
{
|
||||
server.join();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void communicateStartupResult (Exception e)
|
||||
{
|
||||
if (token != null)
|
||||
|
@ -257,16 +261,16 @@ public class Starter
|
|||
System.out.println(token+"\t"+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void applyJettyXml() throws Exception
|
||||
{
|
||||
if (jettyXmls == null)
|
||||
return;
|
||||
|
||||
|
||||
for ( File xmlFile : jettyXmls )
|
||||
{
|
||||
LOG.info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
|
||||
LOG.info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
|
||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile));
|
||||
xmlConfiguration.configure(this.server);
|
||||
}
|
||||
|
@ -286,8 +290,8 @@ public class Starter
|
|||
System.arraycopy(existing, 0, children, 1, existing.length);
|
||||
handlers.setHandlers(children);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static final void main(String[] args)
|
||||
{
|
||||
if (args == null)
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.io.FilenameFilter;
|
|||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -116,7 +117,7 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider
|
|||
*/
|
||||
private static String getDeployedAppName(String contextFileName)
|
||||
{
|
||||
String lowername = contextFileName.toLowerCase();
|
||||
String lowername = contextFileName.toLowerCase(Locale.ENGLISH);
|
||||
if (lowername.endsWith(".xml"))
|
||||
{
|
||||
String contextName = contextFileName.substring(0, lowername.length() - ".xml".length());
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -109,7 +110,7 @@ public class LibExtClassLoaderHelper
|
|||
for (File f : jettyResources.listFiles())
|
||||
{
|
||||
jettyResFiles.put(f.getName(), f);
|
||||
if (f.getName().toLowerCase().startsWith("readme"))
|
||||
if (f.getName().toLowerCase(Locale.ENGLISH).startsWith("readme"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.plus.annotation;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
|
@ -140,7 +141,7 @@ public class Injection
|
|||
_resourceClass = resourceType;
|
||||
|
||||
//first look for a javabeans style setter matching the targetName
|
||||
String setter = "set"+target.substring(0,1).toUpperCase()+target.substring(1);
|
||||
String setter = "set"+target.substring(0,1).toUpperCase(Locale.ENGLISH)+target.substring(1);
|
||||
try
|
||||
{
|
||||
LOG.debug("Looking for method for setter: "+setter+" with arg "+_resourceClass);
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NamingException;
|
||||
|
@ -413,7 +414,7 @@ public class DataSourceLoginService extends MappedLoginService
|
|||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
|
||||
//check if tables exist
|
||||
String tableName = (metaData.storesLowerCaseIdentifiers()? _userTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_userTableName.toUpperCase(): _userTableName));
|
||||
String tableName = (metaData.storesLowerCaseIdentifiers()? _userTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_userTableName.toUpperCase(Locale.ENGLISH): _userTableName));
|
||||
ResultSet result = metaData.getTables(null, null, tableName, null);
|
||||
if (!result.next())
|
||||
{
|
||||
|
@ -431,7 +432,7 @@ public class DataSourceLoginService extends MappedLoginService
|
|||
|
||||
result.close();
|
||||
|
||||
tableName = (metaData.storesLowerCaseIdentifiers()? _roleTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_roleTableName.toUpperCase(): _roleTableName));
|
||||
tableName = (metaData.storesLowerCaseIdentifiers()? _roleTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_roleTableName.toUpperCase(Locale.ENGLISH): _roleTableName));
|
||||
result = metaData.getTables(null, null, tableName, null);
|
||||
if (!result.next())
|
||||
{
|
||||
|
@ -448,7 +449,7 @@ public class DataSourceLoginService extends MappedLoginService
|
|||
|
||||
result.close();
|
||||
|
||||
tableName = (metaData.storesLowerCaseIdentifiers()? _userRoleTableName.toLowerCase(): (metaData.storesUpperCaseIdentifiers()?_userRoleTableName.toUpperCase(): _userRoleTableName));
|
||||
tableName = (metaData.storesLowerCaseIdentifiers()? _userRoleTableName.toLowerCase(Locale.ENGLISH): (metaData.storesUpperCaseIdentifiers()?_userRoleTableName.toUpperCase(Locale.ENGLISH): _userRoleTableName));
|
||||
result = metaData.getTables(null, null, tableName, null);
|
||||
if (!result.next())
|
||||
{
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Collections;
|
|||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
|
@ -489,7 +490,7 @@ public class ProxyServlet implements Servlet
|
|||
protected void onResponseHeader(Buffer name, Buffer value) throws IOException
|
||||
{
|
||||
String nameString = name.toString();
|
||||
String s = nameString.toLowerCase();
|
||||
String s = nameString.toLowerCase(Locale.ENGLISH);
|
||||
if (!_DontProxyHeaders.contains(s) || (HttpHeader.CONNECTION.is(name) && HttpHeaderValue.CLOSE.is(value)))
|
||||
{
|
||||
if (debug != 0)
|
||||
|
@ -560,7 +561,7 @@ public class ProxyServlet implements Servlet
|
|||
String connectionHdr = request.getHeader("Connection");
|
||||
if (connectionHdr != null)
|
||||
{
|
||||
connectionHdr = connectionHdr.toLowerCase();
|
||||
connectionHdr = connectionHdr.toLowerCase(Locale.ENGLISH);
|
||||
if (connectionHdr.indexOf("keep-alive") < 0 && connectionHdr.indexOf("close") < 0)
|
||||
connectionHdr = null;
|
||||
}
|
||||
|
@ -578,7 +579,7 @@ public class ProxyServlet implements Servlet
|
|||
{
|
||||
// TODO could be better than this!
|
||||
String hdr = (String)enm.nextElement();
|
||||
String lhdr = hdr.toLowerCase();
|
||||
String lhdr = hdr.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (_DontProxyHeaders.contains(lhdr))
|
||||
continue;
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.io.IOException;
|
|||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -105,7 +106,7 @@ public abstract class AbstractConnectHandlerTest
|
|||
assertTrue(header.lookingAt());
|
||||
String headerName = header.group(1);
|
||||
String headerValue = header.group(2);
|
||||
headers.put(headerName.toLowerCase(), headerValue.toLowerCase());
|
||||
headers.put(headerName.toLowerCase(Locale.ENGLISH), headerValue.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
StringBuilder body;
|
||||
|
|
|
@ -79,6 +79,20 @@ public class RewriteHandlerTest extends AbstractRuleTestCase
|
|||
@Test
|
||||
public void test() throws Exception
|
||||
{
|
||||
_response.setStatus(200);
|
||||
_request.setHandled(false);
|
||||
_handler.setOriginalPathAttribute("/before");
|
||||
_handler.setRewriteRequestURI(true);
|
||||
_handler.setRewritePathInfo(true);
|
||||
_request.setRequestURI("/xxx/bar");
|
||||
_request.setPathInfo("/xxx/bar");
|
||||
_handler.handle("/xxx/bar",_request,_request, _response);
|
||||
assertEquals(201,_response.getStatus());
|
||||
assertEquals("/bar/zzz",_request.getAttribute("target"));
|
||||
assertEquals("/bar/zzz",_request.getAttribute("URI"));
|
||||
assertEquals("/bar/zzz",_request.getAttribute("info"));
|
||||
assertEquals(null,_request.getAttribute("before"));
|
||||
|
||||
_response.setStatus(200);
|
||||
_request.setHandled(false);
|
||||
_handler.setOriginalPathAttribute("/before");
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.security.authentication;
|
|||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Locale;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
@ -413,7 +414,7 @@ public class FormAuthenticator extends LoginAuthenticator
|
|||
@Override
|
||||
public long getDateHeader(String name)
|
||||
{
|
||||
if (name.toLowerCase().startsWith("if-"))
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith("if-"))
|
||||
return -1;
|
||||
return super.getDateHeader(name);
|
||||
}
|
||||
|
@ -421,7 +422,7 @@ public class FormAuthenticator extends LoginAuthenticator
|
|||
@Override
|
||||
public String getHeader(String name)
|
||||
{
|
||||
if (name.toLowerCase().startsWith("if-"))
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith("if-"))
|
||||
return null;
|
||||
return super.getHeader(name);
|
||||
}
|
||||
|
@ -435,7 +436,7 @@ public class FormAuthenticator extends LoginAuthenticator
|
|||
@Override
|
||||
public Enumeration<String> getHeaders(String name)
|
||||
{
|
||||
if (name.toLowerCase().startsWith("if-"))
|
||||
if (name.toLowerCase(Locale.ENGLISH).startsWith("if-"))
|
||||
return Collections.<String>enumeration(Collections.<String>emptyList());
|
||||
return super.getHeaders(name);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Executor;
|
||||
|
@ -314,7 +315,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
{
|
||||
synchronized (_factories)
|
||||
{
|
||||
return _factories.get(protocol.toLowerCase());
|
||||
return _factories.get(protocol.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,7 +338,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
ConnectionFactory old=_factories.remove(factory.getProtocol());
|
||||
if (old!=null)
|
||||
removeBean(old);
|
||||
_factories.put(factory.getProtocol().toLowerCase(), factory);
|
||||
_factories.put(factory.getProtocol().toLowerCase(Locale.ENGLISH), factory);
|
||||
addBean(factory);
|
||||
if (_defaultProtocol==null)
|
||||
_defaultProtocol=factory.getProtocol();
|
||||
|
@ -348,7 +349,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
{
|
||||
synchronized (_factories)
|
||||
{
|
||||
ConnectionFactory factory= _factories.remove(protocol.toLowerCase());
|
||||
ConnectionFactory factory= _factories.remove(protocol.toLowerCase(Locale.ENGLISH));
|
||||
removeBean(factory);
|
||||
return factory;
|
||||
}
|
||||
|
@ -403,7 +404,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
|
|||
|
||||
public void setDefaultProtocol(String defaultProtocol)
|
||||
{
|
||||
_defaultProtocol = defaultProtocol.toLowerCase();
|
||||
_defaultProtocol = defaultProtocol.toLowerCase(Locale.ENGLISH);
|
||||
if (isRunning())
|
||||
_defaultConnectionFactory=getConnectionFactory(_defaultProtocol);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
//
|
||||
|
||||
package org.eclipse.jetty.server;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
||||
import org.eclipse.jetty.util.LazyList;
|
||||
|
@ -283,7 +285,7 @@ public class CookieCutter
|
|||
{
|
||||
if (name.startsWith("$"))
|
||||
{
|
||||
String lowercaseName = name.toLowerCase();
|
||||
String lowercaseName = name.toLowerCase(Locale.ENGLISH);
|
||||
if ("$path".equals(lowercaseName))
|
||||
{
|
||||
if (cookie!=null)
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.Collection;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
@ -124,7 +125,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
public DatabaseAdaptor (DatabaseMetaData dbMeta)
|
||||
throws SQLException
|
||||
{
|
||||
_dbName = dbMeta.getDatabaseProductName().toLowerCase();
|
||||
_dbName = dbMeta.getDatabaseProductName().toLowerCase(Locale.ENGLISH);
|
||||
LOG.debug ("Using database {}",_dbName);
|
||||
_isLower = dbMeta.storesLowerCaseIdentifiers();
|
||||
_isUpper = dbMeta.storesUpperCaseIdentifiers();
|
||||
|
@ -140,9 +141,9 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
public String convertIdentifier (String identifier)
|
||||
{
|
||||
if (_isLower)
|
||||
return identifier.toLowerCase();
|
||||
return identifier.toLowerCase(Locale.ENGLISH);
|
||||
if (_isUpper)
|
||||
return identifier.toUpperCase();
|
||||
return identifier.toUpperCase(Locale.ENGLISH);
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.util.IO;
|
||||
|
@ -52,7 +53,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
|
||||
_handler.setSuspendFor(100);
|
||||
_handler.setResumeAfter(25);
|
||||
assertTrue(process(null).toUpperCase().contains("RESUMED"));
|
||||
assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("RESUMED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -66,7 +67,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
_server.start();
|
||||
|
||||
_handler.setSuspendFor(50);
|
||||
assertTrue(process(null).toUpperCase().contains("TIMEOUT"));
|
||||
assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("TIMEOUT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -81,7 +82,7 @@ public class SelectChannelTimeoutTest extends ConnectorTimeoutTest
|
|||
|
||||
_handler.setSuspendFor(100);
|
||||
_handler.setCompleteAfter(25);
|
||||
assertTrue(process(null).toUpperCase().contains("COMPLETED"));
|
||||
assertTrue(process(null).toUpperCase(Locale.ENGLISH).contains("COMPLETED"));
|
||||
}
|
||||
|
||||
private synchronized String process(String content) throws UnsupportedEncodingException, IOException, InterruptedException
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.net.Socket;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -153,7 +154,7 @@ public class IPAccessHandlerTest
|
|||
assertTrue(header.lookingAt());
|
||||
String headerName = header.group(1);
|
||||
String headerValue = header.group(2);
|
||||
headers.put(headerName.toLowerCase(), headerValue.toLowerCase());
|
||||
headers.put(headerName.toLowerCase(Locale.ENGLISH), headerValue.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
StringBuilder body = new StringBuilder();
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.servlet;
|
|||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -90,7 +91,7 @@ public class Invoker extends HttpServlet
|
|||
{
|
||||
String param=(String)e.nextElement();
|
||||
String value=getInitParameter(param);
|
||||
String lvalue=value.toLowerCase();
|
||||
String lvalue=value.toLowerCase(Locale.ENGLISH);
|
||||
if ("nonContextServlets".equals(param))
|
||||
{
|
||||
_nonContextServlets=value.length()>0 && lvalue.startsWith("t");
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
@ -138,7 +139,7 @@ public class CGI extends HttpServlet
|
|||
if (!_env.envMap.containsKey("SystemRoot"))
|
||||
{
|
||||
String os = System.getProperty("os.name");
|
||||
if (os != null && os.toLowerCase().indexOf("windows") != -1)
|
||||
if (os != null && os.toLowerCase(Locale.ENGLISH).indexOf("windows") != -1)
|
||||
{
|
||||
_env.set("SystemRoot","C:\\WINDOWS");
|
||||
}
|
||||
|
@ -255,7 +256,7 @@ public class CGI extends HttpServlet
|
|||
{
|
||||
String name = (String)enm.nextElement();
|
||||
String value = req.getHeader(name);
|
||||
env.set("HTTP_" + name.toUpperCase().replace('-','_'),value);
|
||||
env.set("HTTP_" + name.toUpperCase(Locale.ENGLISH).replace('-','_'),value);
|
||||
}
|
||||
|
||||
// these extra ones were from printenv on www.dev.nomura.co.uk
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.servlets;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -277,7 +278,7 @@ public class GzipFilter extends UserAgentFilter
|
|||
{
|
||||
for (int i=0; i< encodings.length; i++)
|
||||
{
|
||||
if (encodings[i].toLowerCase().contains(GZIP))
|
||||
if (encodings[i].toLowerCase(Locale.ENGLISH).contains(GZIP))
|
||||
{
|
||||
if (isEncodingAcceptable(encodings[i]))
|
||||
{
|
||||
|
@ -286,7 +287,7 @@ public class GzipFilter extends UserAgentFilter
|
|||
}
|
||||
}
|
||||
|
||||
if (encodings[i].toLowerCase().contains(DEFLATE))
|
||||
if (encodings[i].toLowerCase(Locale.ENGLISH).contains(DEFLATE))
|
||||
{
|
||||
if (isEncodingAcceptable(encodings[i]))
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Enumeration;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.net.URL;
|
|||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -62,7 +63,7 @@ public class PutFilterTest
|
|||
FilterHolder holder = tester.addFilter(PutFilter.class,"/*",EnumSet.of(DispatcherType.REQUEST));
|
||||
holder.setInitParameter("delAllowed","true");
|
||||
// Bloody Windows does not allow file renaming
|
||||
if (!System.getProperty("os.name").toLowerCase().contains("windows"))
|
||||
if (!System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows"))
|
||||
holder.setInitParameter("putAtomic","true");
|
||||
tester.start();
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class NextProtoNegoClientConnection extends AbstractConnection implements
|
|||
catch (IOException x)
|
||||
{
|
||||
LOG.debug(x);
|
||||
NextProtoNego.remove(engine);
|
||||
getEndPoint().close();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.spdy.generator;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.eclipse.jetty.spdy.CompressionDictionary;
|
||||
import org.eclipse.jetty.spdy.CompressionFactory;
|
||||
|
@ -45,7 +46,7 @@ public class HeadersBlockGenerator
|
|||
writeCount(version, buffer, headers.size());
|
||||
for (Fields.Field header : headers)
|
||||
{
|
||||
String name = header.name().toLowerCase();
|
||||
String name = header.name().toLowerCase(Locale.ENGLISH);
|
||||
byte[] nameBytes = name.getBytes(iso1);
|
||||
writeNameLength(version, buffer, nameBytes.length);
|
||||
buffer.write(nameBytes, 0, nameBytes.length);
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -206,7 +207,7 @@ public class ReferrerPushStrategy implements PushStrategy
|
|||
if (header == null)
|
||||
return true;
|
||||
|
||||
String contentType = header.value().toLowerCase();
|
||||
String contentType = header.value().toLowerCase(Locale.ENGLISH);
|
||||
for (String pushContentType : pushContentTypes)
|
||||
if (contentType.startsWith(pushContentType))
|
||||
return true;
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.eclipse.jetty.spdy.server.proxy;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -92,7 +93,7 @@ public class ProxyHTTPSPDYConnection extends HttpConnection implements HttpParse
|
|||
@Override
|
||||
public boolean parsedHeader(HttpHeader header, String headerName, String headerValue)
|
||||
{
|
||||
switch (headerName.toLowerCase())
|
||||
switch (headerName.toLowerCase(Locale.ENGLISH))
|
||||
{
|
||||
case "host":
|
||||
headers.put(HTTPSPDYHeader.HOST.name(version), headerValue);
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.net.ssl.SSLEngine;
|
|||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint;
|
||||
import org.eclipse.jetty.npn.NextProtoNego;
|
||||
import org.eclipse.jetty.server.ConnectionFactory;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
|
@ -93,6 +92,7 @@ public class NextProtoNegoServerConnection extends AbstractConnection implements
|
|||
catch (IOException x)
|
||||
{
|
||||
LOG.debug(x);
|
||||
NextProtoNego.remove(engine);
|
||||
getEndPoint().close();
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.Enumeration;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
@ -269,7 +270,7 @@ public class Config
|
|||
}
|
||||
else
|
||||
{
|
||||
String name = entry.getName().toLowerCase();
|
||||
String name = entry.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (name.endsWith(".jar") || name.endsWith(".zip"))
|
||||
{
|
||||
String jar = entry.getCanonicalPath();
|
||||
|
@ -796,7 +797,7 @@ public class Config
|
|||
}
|
||||
|
||||
// Add XML configuration
|
||||
if (subject.toLowerCase().endsWith(".xml"))
|
||||
if (subject.toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
||||
{
|
||||
// Config file
|
||||
File f = new File(fixPath(file));
|
||||
|
@ -807,7 +808,7 @@ public class Config
|
|||
}
|
||||
|
||||
// Set the main class to execute (overrides any previously set)
|
||||
if (subject.toLowerCase().endsWith(".class"))
|
||||
if (subject.toLowerCase(Locale.ENGLISH).endsWith(".class"))
|
||||
{
|
||||
// Class
|
||||
String cn = expand(subject.substring(0,subject.length() - 6));
|
||||
|
@ -820,7 +821,7 @@ public class Config
|
|||
}
|
||||
|
||||
// Add raw classpath entry
|
||||
if (subject.toLowerCase().endsWith(".path"))
|
||||
if (subject.toLowerCase(Locale.ENGLISH).endsWith(".path"))
|
||||
{
|
||||
// classpath (jetty.class.path?) to add to runtime classpath
|
||||
String cn = expand(subject.substring(0,subject.length() - 5));
|
||||
|
|
|
@ -46,6 +46,7 @@ import java.util.Collections;
|
|||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -365,7 +366,7 @@ public class Main
|
|||
return false;
|
||||
}
|
||||
|
||||
String name = path.getName().toLowerCase();
|
||||
String name = path.getName().toLowerCase(Locale.ENGLISH);
|
||||
return (name.startsWith("jetty") && name.endsWith(".xml"));
|
||||
}
|
||||
});
|
||||
|
@ -639,7 +640,7 @@ public class Main
|
|||
|
||||
private String resolveXmlConfig(String xmlFilename) throws FileNotFoundException
|
||||
{
|
||||
if (!xmlFilename.toLowerCase().endsWith(".xml"))
|
||||
if (!xmlFilename.toLowerCase(Locale.ENGLISH).endsWith(".xml"))
|
||||
{
|
||||
// Nothing to resolve.
|
||||
return xmlFilename;
|
||||
|
@ -853,7 +854,7 @@ public class Main
|
|||
|
||||
if (element.isFile())
|
||||
{
|
||||
String name = element.getName().toLowerCase();
|
||||
String name = element.getName().toLowerCase(Locale.ENGLISH);
|
||||
if (name.endsWith(".jar"))
|
||||
{
|
||||
return JarVersion.getVersion(element);
|
||||
|
@ -1105,7 +1106,7 @@ public class Main
|
|||
@Override
|
||||
public boolean accept(File dir, String name)
|
||||
{
|
||||
return name.toLowerCase().endsWith(".ini");
|
||||
return name.toLowerCase(Locale.ENGLISH).endsWith(".ini");
|
||||
}
|
||||
});
|
||||
Arrays.sort(inis);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -89,9 +90,9 @@ public class JSONObjectConvertor implements JSON.Convertor
|
|||
{
|
||||
String name=m.getName();
|
||||
if (name.startsWith("is"))
|
||||
name=name.substring(2,3).toLowerCase()+name.substring(3);
|
||||
name=name.substring(2,3).toLowerCase(Locale.ENGLISH)+name.substring(3);
|
||||
else if (name.startsWith("get"))
|
||||
name=name.substring(3,4).toLowerCase()+name.substring(4);
|
||||
name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4);
|
||||
else
|
||||
continue;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -122,9 +123,9 @@ public class JSONPojoConvertor implements JSON.Convertor
|
|||
if(m.getReturnType()!=null)
|
||||
{
|
||||
if (name.startsWith("is") && name.length()>2)
|
||||
name=name.substring(2,3).toLowerCase()+name.substring(3);
|
||||
name=name.substring(2,3).toLowerCase(Locale.ENGLISH)+name.substring(3);
|
||||
else if (name.startsWith("get") && name.length()>3)
|
||||
name=name.substring(3,4).toLowerCase()+name.substring(4);
|
||||
name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4);
|
||||
else
|
||||
break;
|
||||
if(includeField(name, m))
|
||||
|
@ -134,7 +135,7 @@ public class JSONPojoConvertor implements JSON.Convertor
|
|||
case 1:
|
||||
if (name.startsWith("set") && name.length()>3)
|
||||
{
|
||||
name=name.substring(3,4).toLowerCase()+name.substring(4);
|
||||
name=name.substring(3,4).toLowerCase(Locale.ENGLISH)+name.substring(4);
|
||||
if(includeField(name, m))
|
||||
addSetter(name, m);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Collections;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -93,7 +94,7 @@ public class Fields implements Iterable<Fields.Field>
|
|||
*/
|
||||
public Field get(String name)
|
||||
{
|
||||
return fields.get(name.trim().toLowerCase());
|
||||
return fields.get(name.trim().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,7 +108,7 @@ public class Fields implements Iterable<Fields.Field>
|
|||
name = name.trim();
|
||||
// Preserve the case for the field name
|
||||
Field field = new Field(name, value);
|
||||
fields.put(name.toLowerCase(), field);
|
||||
fields.put(name.toLowerCase(Locale.ENGLISH), field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,7 +119,7 @@ public class Fields implements Iterable<Fields.Field>
|
|||
public void put(Field field)
|
||||
{
|
||||
if (field != null)
|
||||
fields.put(field.name().toLowerCase(), field);
|
||||
fields.put(field.name().toLowerCase(Locale.ENGLISH), field);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,16 +132,16 @@ public class Fields implements Iterable<Fields.Field>
|
|||
public void add(String name, String value)
|
||||
{
|
||||
name = name.trim();
|
||||
Field field = fields.get(name.toLowerCase());
|
||||
Field field = fields.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (field == null)
|
||||
{
|
||||
field = new Field(name, value);
|
||||
fields.put(name.toLowerCase(), field);
|
||||
fields.put(name.toLowerCase(Locale.ENGLISH), field);
|
||||
}
|
||||
else
|
||||
{
|
||||
field = new Field(field.name(), field.values(), value);
|
||||
fields.put(name.toLowerCase(), field);
|
||||
fields.put(name.toLowerCase(Locale.ENGLISH), field);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +154,7 @@ public class Fields implements Iterable<Fields.Field>
|
|||
public Field remove(String name)
|
||||
{
|
||||
name = name.trim();
|
||||
return fields.remove(name.toLowerCase());
|
||||
return fields.remove(name.toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +235,7 @@ public class Fields implements Iterable<Fields.Field>
|
|||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = name.toLowerCase().hashCode();
|
||||
int result = name.toLowerCase(Locale.ENGLISH).hashCode();
|
||||
result = 31 * result + Arrays.hashCode(values);
|
||||
return result;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue