Drop deprecated dependencies on Log4j, JRuby, JExcel, Burlap, Commons Pool/DBCP
This commit also removes outdated support classes for Oracle, GlassFish, JBoss. Issue: SPR-14429
This commit is contained in:
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import com.caucho.burlap.client.BurlapProxyFactory;
|
||||
import com.caucho.burlap.client.BurlapRuntimeException;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.remoting.RemoteAccessException;
|
||||
import org.springframework.remoting.RemoteConnectFailureException;
|
||||
import org.springframework.remoting.RemoteLookupFailureException;
|
||||
import org.springframework.remoting.RemoteProxyFailureException;
|
||||
import org.springframework.remoting.support.UrlBasedRemoteAccessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link org.aopalliance.intercept.MethodInterceptor} for accessing a Burlap service.
|
||||
* Supports authentication via username and password.
|
||||
* The service URL must be an HTTP URL exposing a Burlap service.
|
||||
*
|
||||
* <p>Burlap is a slim, XML-based RPC protocol.
|
||||
* For information on Burlap, see the
|
||||
* <a href="http://www.caucho.com/burlap">Burlap website</a>
|
||||
*
|
||||
* <p>Note: There is no requirement for services accessed with this proxy factory
|
||||
* to have been exported using Spring's {@link BurlapServiceExporter}, as there is
|
||||
* no special handling involved. As a consequence, you can also access services that
|
||||
* have been exported using Caucho's {@link com.caucho.burlap.server.BurlapServlet}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 29.09.2003
|
||||
* @see #setServiceInterface
|
||||
* @see #setServiceUrl
|
||||
* @see #setUsername
|
||||
* @see #setPassword
|
||||
* @see BurlapServiceExporter
|
||||
* @see BurlapProxyFactoryBean
|
||||
* @see com.caucho.burlap.client.BurlapProxyFactory
|
||||
* @see com.caucho.burlap.server.BurlapServlet
|
||||
* @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
|
||||
* and is effectively retired (in contrast to its sibling Hessian)
|
||||
*/
|
||||
@Deprecated
|
||||
public class BurlapClientInterceptor extends UrlBasedRemoteAccessor implements MethodInterceptor {
|
||||
|
||||
private BurlapProxyFactory proxyFactory = new BurlapProxyFactory();
|
||||
|
||||
private Object burlapProxy;
|
||||
|
||||
|
||||
/**
|
||||
* Set the BurlapProxyFactory instance to use.
|
||||
* If not specified, a default BurlapProxyFactory will be created.
|
||||
* <p>Allows to use an externally configured factory instance,
|
||||
* in particular a custom BurlapProxyFactory subclass.
|
||||
*/
|
||||
public void setProxyFactory(BurlapProxyFactory proxyFactory) {
|
||||
this.proxyFactory = (proxyFactory != null ? proxyFactory : new BurlapProxyFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the username that this factory should use to access the remote service.
|
||||
* Default is none.
|
||||
* <p>The username will be sent by Burlap via HTTP Basic Authentication.
|
||||
* @see com.caucho.burlap.client.BurlapProxyFactory#setUser
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
this.proxyFactory.setUser(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password that this factory should use to access the remote service.
|
||||
* Default is none.
|
||||
* <p>The password will be sent by Burlap via HTTP Basic Authentication.
|
||||
* @see com.caucho.burlap.client.BurlapProxyFactory#setPassword
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
this.proxyFactory.setPassword(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether overloaded methods should be enabled for remote invocations.
|
||||
* Default is "false".
|
||||
* @see com.caucho.burlap.client.BurlapProxyFactory#setOverloadEnabled
|
||||
*/
|
||||
public void setOverloadEnabled(boolean overloadEnabled) {
|
||||
this.proxyFactory.setOverloadEnabled(overloadEnabled);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Burlap proxy for this interceptor.
|
||||
* @throws RemoteLookupFailureException if the service URL is invalid
|
||||
*/
|
||||
public void prepare() throws RemoteLookupFailureException {
|
||||
try {
|
||||
this.burlapProxy = createBurlapProxy(this.proxyFactory);
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new RemoteLookupFailureException("Service URL [" + getServiceUrl() + "] is invalid", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Burlap proxy that is wrapped by this interceptor.
|
||||
* @param proxyFactory the proxy factory to use
|
||||
* @return the Burlap proxy
|
||||
* @throws MalformedURLException if thrown by the proxy factory
|
||||
* @see com.caucho.burlap.client.BurlapProxyFactory#create
|
||||
*/
|
||||
protected Object createBurlapProxy(BurlapProxyFactory proxyFactory) throws MalformedURLException {
|
||||
Assert.notNull(getServiceInterface(), "Property 'serviceInterface' is required");
|
||||
return proxyFactory.create(getServiceInterface(), getServiceUrl());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
if (this.burlapProxy == null) {
|
||||
throw new IllegalStateException("BurlapClientInterceptor is not properly initialized - " +
|
||||
"invoke 'prepare' before attempting any operations");
|
||||
}
|
||||
|
||||
ClassLoader originalClassLoader = overrideThreadContextClassLoader();
|
||||
try {
|
||||
return invocation.getMethod().invoke(this.burlapProxy, invocation.getArguments());
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
Throwable targetEx = ex.getTargetException();
|
||||
if (targetEx instanceof BurlapRuntimeException) {
|
||||
Throwable cause = targetEx.getCause();
|
||||
throw convertBurlapAccessException(cause != null ? cause : targetEx);
|
||||
}
|
||||
else if (targetEx instanceof UndeclaredThrowableException) {
|
||||
UndeclaredThrowableException utex = (UndeclaredThrowableException) targetEx;
|
||||
throw convertBurlapAccessException(utex.getUndeclaredThrowable());
|
||||
}
|
||||
else {
|
||||
throw targetEx;
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new RemoteProxyFailureException(
|
||||
"Failed to invoke Burlap proxy for remote service [" + getServiceUrl() + "]", ex);
|
||||
}
|
||||
finally {
|
||||
resetThreadContextClassLoader(originalClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given Burlap access exception to an appropriate
|
||||
* Spring RemoteAccessException.
|
||||
* @param ex the exception to convert
|
||||
* @return the RemoteAccessException to throw
|
||||
*/
|
||||
protected RemoteAccessException convertBurlapAccessException(Throwable ex) {
|
||||
if (ex instanceof ConnectException) {
|
||||
return new RemoteConnectFailureException(
|
||||
"Cannot connect to Burlap remote service at [" + getServiceUrl() + "]", ex);
|
||||
}
|
||||
else {
|
||||
return new RemoteAccessException(
|
||||
"Cannot access Burlap remote service at [" + getServiceUrl() + "]", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.caucho.burlap.io.BurlapInput;
|
||||
import com.caucho.burlap.io.BurlapOutput;
|
||||
import com.caucho.burlap.server.BurlapSkeleton;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.remoting.support.RemoteExporter;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* General stream-based protocol exporter for a Burlap endpoint.
|
||||
*
|
||||
* <p>Burlap is a slim, XML-based RPC protocol.
|
||||
* For information on Burlap, see the
|
||||
* <a href="http://www.caucho.com/burlap">Burlap website</a>.
|
||||
* This exporter requires Burlap 3.x.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.1
|
||||
* @see #invoke(java.io.InputStream, java.io.OutputStream)
|
||||
* @see BurlapServiceExporter
|
||||
* @see SimpleBurlapServiceExporter
|
||||
* @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
|
||||
* and is effectively retired (in contrast to its sibling Hessian)
|
||||
*/
|
||||
@Deprecated
|
||||
public class BurlapExporter extends RemoteExporter implements InitializingBean {
|
||||
|
||||
private BurlapSkeleton skeleton;
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
prepare();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this service exporter.
|
||||
*/
|
||||
public void prepare() {
|
||||
checkService();
|
||||
checkServiceInterface();
|
||||
this.skeleton = new BurlapSkeleton(getProxyForService(), getServiceInterface());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform an invocation on the exported object.
|
||||
* @param inputStream the request stream
|
||||
* @param outputStream the response stream
|
||||
* @throws Throwable if invocation failed
|
||||
*/
|
||||
public void invoke(InputStream inputStream, OutputStream outputStream) throws Throwable {
|
||||
Assert.notNull(this.skeleton, "Burlap exporter has not been initialized");
|
||||
ClassLoader originalClassLoader = overrideThreadContextClassLoader();
|
||||
try {
|
||||
this.skeleton.invoke(new BurlapInput(inputStream), new BurlapOutput(outputStream));
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
resetThreadContextClassLoader(originalClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* {@link FactoryBean} for Burlap proxies. Exposes the proxied service
|
||||
* for use as a bean reference, using the specified service interface.
|
||||
*
|
||||
* <p>Burlap is a slim, XML-based RPC protocol.
|
||||
* For information on Burlap, see the
|
||||
* <a href="http://www.caucho.com/burlap">Burlap website</a>
|
||||
*
|
||||
* <p>The service URL must be an HTTP URL exposing a Burlap service.
|
||||
* For details, see the {@link BurlapClientInterceptor} javadoc.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 13.05.2003
|
||||
* @see #setServiceInterface
|
||||
* @see #setServiceUrl
|
||||
* @see BurlapClientInterceptor
|
||||
* @see BurlapServiceExporter
|
||||
* @see org.springframework.remoting.caucho.HessianProxyFactoryBean
|
||||
* @see org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean
|
||||
* @see org.springframework.remoting.rmi.RmiProxyFactoryBean
|
||||
* @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
|
||||
* and is effectively retired (in contrast to its sibling Hessian)
|
||||
*/
|
||||
@Deprecated
|
||||
public class BurlapProxyFactoryBean extends BurlapClientInterceptor implements FactoryBean<Object> {
|
||||
|
||||
private Object serviceProxy;
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
super.afterPropertiesSet();
|
||||
this.serviceProxy = new ProxyFactory(getServiceInterface(), this).getProxy(getBeanClassLoader());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return this.serviceProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return getServiceInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.HttpRequestHandler;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.util.NestedServletException;
|
||||
|
||||
/**
|
||||
* Servlet-API-based HTTP request handler that exports the specified service bean
|
||||
* as Burlap service endpoint, accessible via a Burlap proxy.
|
||||
*
|
||||
* <p><b>Note:</b> Spring also provides an alternative version of this exporter,
|
||||
* for Sun's JRE 1.6 HTTP server: {@link SimpleBurlapServiceExporter}.
|
||||
*
|
||||
* <p>Burlap is a slim, XML-based RPC protocol.
|
||||
* For information on Burlap, see the
|
||||
* <a href="http://www.caucho.com/burlap">Burlap website</a>.
|
||||
* This exporter requires Burlap 3.x.
|
||||
*
|
||||
* <p>Note: Burlap services exported with this class can be accessed by
|
||||
* any Burlap client, as there isn't any special handling involved.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 13.05.2003
|
||||
* @see BurlapClientInterceptor
|
||||
* @see BurlapProxyFactoryBean
|
||||
* @see org.springframework.remoting.caucho.HessianServiceExporter
|
||||
* @see org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter
|
||||
* @see org.springframework.remoting.rmi.RmiServiceExporter
|
||||
* @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
|
||||
* and is effectively retired (in contrast to its sibling Hessian)
|
||||
*/
|
||||
@Deprecated
|
||||
public class BurlapServiceExporter extends BurlapExporter implements HttpRequestHandler {
|
||||
|
||||
/**
|
||||
* Processes the incoming Burlap request and creates a Burlap response.
|
||||
*/
|
||||
@Override
|
||||
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
if (!"POST".equals(request.getMethod())) {
|
||||
throw new HttpRequestMethodNotSupportedException(request.getMethod(),
|
||||
new String[] {"POST"}, "BurlapServiceExporter only supports POST requests");
|
||||
}
|
||||
|
||||
try {
|
||||
invoke(request.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new NestedServletException("Burlap skeleton invocation failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.remoting.caucho;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
||||
import org.springframework.lang.UsesSunHttpServer;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* HTTP request handler that exports the specified service bean as
|
||||
* Burlap service endpoint, accessible via a Burlap proxy.
|
||||
* Designed for Sun's JRE 1.6 HTTP server, implementing the
|
||||
* {@link com.sun.net.httpserver.HttpHandler} interface.
|
||||
*
|
||||
* <p>Burlap is a slim, XML-based RPC protocol.
|
||||
* For information on Burlap, see the
|
||||
* <a href="http://www.caucho.com/burlap">Burlap website</a>.
|
||||
* This exporter requires Burlap 3.x.
|
||||
*
|
||||
* <p>Note: Burlap services exported with this class can be accessed by
|
||||
* any Burlap client, as there isn't any special handling involved.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5.1
|
||||
* @see org.springframework.remoting.caucho.BurlapClientInterceptor
|
||||
* @see org.springframework.remoting.caucho.BurlapProxyFactoryBean
|
||||
* @see SimpleHessianServiceExporter
|
||||
* @see org.springframework.remoting.httpinvoker.SimpleHttpInvokerServiceExporter
|
||||
* @deprecated as of Spring 4.0, since Burlap hasn't evolved in years
|
||||
* and is effectively retired (in contrast to its sibling Hessian)
|
||||
*/
|
||||
@Deprecated
|
||||
@UsesSunHttpServer
|
||||
public class SimpleBurlapServiceExporter extends BurlapExporter implements HttpHandler {
|
||||
|
||||
/**
|
||||
* Processes the incoming Burlap request and creates a Burlap response.
|
||||
*/
|
||||
@Override
|
||||
public void handle(HttpExchange exchange) throws IOException {
|
||||
if (!"POST".equals(exchange.getRequestMethod())) {
|
||||
exchange.getResponseHeaders().set("Allow", "POST");
|
||||
exchange.sendResponseHeaders(405, -1);
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream(1024);
|
||||
try {
|
||||
invoke(exchange.getRequestBody(), output);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
logger.error("Burlap skeleton invocation failed", ex);
|
||||
}
|
||||
|
||||
exchange.sendResponseHeaders(200, output.size());
|
||||
FileCopyUtils.copy(output.toByteArray(), exchange.getResponseBody());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.context.request;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.NDC;
|
||||
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
||||
/**
|
||||
* Request logging interceptor that adds a request context message to the
|
||||
* Log4J nested diagnostic context (NDC) before the request is processed,
|
||||
* removing it again after the request is processed.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.5
|
||||
* @see org.apache.log4j.NDC#push(String)
|
||||
* @see org.apache.log4j.NDC#pop()
|
||||
* @deprecated as of Spring 4.2.1, in favor of Apache Log4j 2
|
||||
* (following Apache's EOL declaration for log4j 1.x)
|
||||
*/
|
||||
@Deprecated
|
||||
public class Log4jNestedDiagnosticContextInterceptor implements AsyncWebRequestInterceptor {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Logger log4jLogger = Logger.getLogger(getClass());
|
||||
|
||||
private boolean includeClientInfo = false;
|
||||
|
||||
|
||||
/**
|
||||
* Set whether or not the session id and user name should be included
|
||||
* in the log message.
|
||||
*/
|
||||
public void setIncludeClientInfo(boolean includeClientInfo) {
|
||||
this.includeClientInfo = includeClientInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not the session id and user name should be included
|
||||
* in the log message.
|
||||
*/
|
||||
protected boolean isIncludeClientInfo() {
|
||||
return this.includeClientInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a message the Log4J NDC before the request is processed.
|
||||
*/
|
||||
@Override
|
||||
public void preHandle(WebRequest request) throws Exception {
|
||||
NDC.push(getNestedDiagnosticContextMessage(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the message to be pushed onto the Log4J nested diagnostic context.
|
||||
* <p>Default is the request object's {@code getDescription} result.
|
||||
* @param request current HTTP request
|
||||
* @return the message to be pushed onto the Log4J NDC
|
||||
* @see WebRequest#getDescription
|
||||
* @see #isIncludeClientInfo()
|
||||
*/
|
||||
protected String getNestedDiagnosticContextMessage(WebRequest request) {
|
||||
return request.getDescription(isIncludeClientInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHandle(WebRequest request, ModelMap model) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the log message from the Log4J NDC after the request is processed.
|
||||
*/
|
||||
@Override
|
||||
public void afterCompletion(WebRequest request, Exception ex) throws Exception {
|
||||
NDC.pop();
|
||||
if (NDC.getDepth() == 0) {
|
||||
NDC.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the log message from the Log4J NDC when the processing thread is
|
||||
* exited after the start of asynchronous request handling.
|
||||
*/
|
||||
@Override
|
||||
public void afterConcurrentHandlingStarted(WebRequest request) {
|
||||
NDC.pop();
|
||||
if (NDC.getDepth() == 0) {
|
||||
NDC.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.filter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.NDC;
|
||||
|
||||
/**
|
||||
* Request logging filter that adds the request log message to the Log4J
|
||||
* nested diagnostic context (NDC) before the request is processed,
|
||||
* removing it again after the request is processed.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rob Harrop
|
||||
* @since 1.2.5
|
||||
* @see #setIncludeQueryString
|
||||
* @see #setBeforeMessagePrefix
|
||||
* @see #setBeforeMessageSuffix
|
||||
* @see #setAfterMessagePrefix
|
||||
* @see #setAfterMessageSuffix
|
||||
* @see org.apache.log4j.NDC#push(String)
|
||||
* @see org.apache.log4j.NDC#pop()
|
||||
* @deprecated as of Spring 4.2.1, in favor of Apache Log4j 2
|
||||
* (following Apache's EOL declaration for log4j 1.x)
|
||||
*/
|
||||
@Deprecated
|
||||
public class Log4jNestedDiagnosticContextFilter extends AbstractRequestLoggingFilter {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Logger log4jLogger = Logger.getLogger(getClass());
|
||||
|
||||
|
||||
/**
|
||||
* Logs the before-request message through Log4J and
|
||||
* adds a message the Log4J NDC before the request is processed.
|
||||
*/
|
||||
@Override
|
||||
protected void beforeRequest(HttpServletRequest request, String message) {
|
||||
if (log4jLogger.isDebugEnabled()) {
|
||||
log4jLogger.debug(message);
|
||||
}
|
||||
NDC.push(getNestedDiagnosticContextMessage(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the message to be pushed onto the Log4J nested diagnostic context.
|
||||
* <p>Default is a plain request log message without prefix or suffix.
|
||||
* @param request current HTTP request
|
||||
* @return the message to be pushed onto the Log4J NDC
|
||||
* @see #createMessage
|
||||
*/
|
||||
protected String getNestedDiagnosticContextMessage(HttpServletRequest request) {
|
||||
return createMessage(request, "", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the log message from the Log4J NDC after the request is processed
|
||||
* and logs the after-request message through Log4J.
|
||||
*/
|
||||
@Override
|
||||
protected void afterRequest(HttpServletRequest request, String message) {
|
||||
NDC.pop();
|
||||
if (NDC.getDepth() == 0) {
|
||||
NDC.remove();
|
||||
}
|
||||
if (log4jLogger.isDebugEnabled()) {
|
||||
log4jLogger.debug(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
/**
|
||||
* Bootstrap listener for custom log4j initialization in a web environment.
|
||||
* Delegates to {@link Log4jWebConfigurer} (see its javadoc for configuration details).
|
||||
*
|
||||
* <b>WARNING: Assumes an expanded WAR file</b>, both for loading the configuration
|
||||
* file and for writing the log files. If you want to keep your WAR unexpanded or
|
||||
* don't need application-specific log files within the WAR directory, don't use
|
||||
* log4j setup within the application (thus, don't use Log4jConfigListener or
|
||||
* Log4jConfigServlet). Instead, use a global, VM-wide log4j setup (for example,
|
||||
* in JBoss) or JDK 1.4's {@code java.util.logging} (which is global too).
|
||||
*
|
||||
* <p>This listener should be registered before ContextLoaderListener in {@code web.xml}
|
||||
* when using custom log4j initialization.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 13.03.2003
|
||||
* @see Log4jWebConfigurer
|
||||
* @see org.springframework.web.context.ContextLoaderListener
|
||||
* @see WebAppRootListener
|
||||
* @deprecated as of Spring 4.2.1, in favor of Apache Log4j 2
|
||||
* (following Apache's EOL declaration for log4j 1.x)
|
||||
*/
|
||||
@Deprecated
|
||||
public class Log4jConfigListener implements ServletContextListener {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
Log4jWebConfigurer.initLogging(event.getServletContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
Log4jWebConfigurer.shutdownLogging(event.getServletContext());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Convenience class that performs custom log4j initialization for web environments,
|
||||
* allowing for log file paths within the web application, with the option to
|
||||
* perform automatic refresh checks (for runtime changes in logging configuration).
|
||||
*
|
||||
* <p><b>WARNING: Assumes an expanded WAR file</b>, both for loading the configuration
|
||||
* file and for writing the log files. If you want to keep your WAR unexpanded or
|
||||
* don't need application-specific log files within the WAR directory, don't use
|
||||
* log4j setup within the application (thus, don't use Log4jConfigListener or
|
||||
* Log4jConfigServlet). Instead, use a global, VM-wide log4j setup (for example,
|
||||
* in JBoss) or JDK 1.4's {@code java.util.logging} (which is global too).
|
||||
*
|
||||
* <p>Supports three init parameters at the servlet context level (that is,
|
||||
* context-param entries in web.xml):
|
||||
*
|
||||
* <ul>
|
||||
* <li><i>"log4jConfigLocation":</i><br>
|
||||
* Location of the log4j config file; either a "classpath:" location (e.g.
|
||||
* "classpath:myLog4j.properties"), an absolute file URL (e.g. "file:C:/log4j.properties),
|
||||
* or a plain path relative to the web application root directory (e.g.
|
||||
* "/WEB-INF/log4j.properties"). If not specified, default log4j initialization
|
||||
* will apply ("log4j.properties" or "log4j.xml" in the class path; see the
|
||||
* log4j documentation for details).
|
||||
* <li><i>"log4jRefreshInterval":</i><br>
|
||||
* Interval between config file refresh checks, in milliseconds. If not specified,
|
||||
* no refresh checks will happen, which avoids starting log4j's watchdog thread.
|
||||
* <li><i>"log4jExposeWebAppRoot":</i><br>
|
||||
* Whether the web app root system property should be exposed, allowing for log
|
||||
* file paths relative to the web application root directory. Default is "true";
|
||||
* specify "false" to suppress expose of the web app root system property. See
|
||||
* below for details on how to use this system property in log file locations.
|
||||
* </ul>
|
||||
*
|
||||
* <p>Note: {@code initLogging} should be called before any other Spring activity
|
||||
* (when using log4j), for proper initialization before any Spring logging attempts.
|
||||
*
|
||||
* <p>Log4j's watchdog thread will asynchronously check whether the timestamp
|
||||
* of the config file has changed, using the given interval between checks.
|
||||
* A refresh interval of 1000 milliseconds (one second), which allows to
|
||||
* do on-demand log level changes with immediate effect, is not unfeasible.
|
||||
|
||||
* <p><b>WARNING:</b> Log4j's watchdog thread does not terminate until VM shutdown;
|
||||
* in particular, it does not terminate on LogManager shutdown. Therefore, it is
|
||||
* recommended to <i>not</i> use config file refreshing in a production J2EE
|
||||
* environment; the watchdog thread would not stop on application shutdown there.
|
||||
*
|
||||
* <p>By default, this configurer automatically sets the web app root system property,
|
||||
* for "${key}" substitutions within log file locations in the log4j config file,
|
||||
* allowing for log file paths relative to the web application root directory.
|
||||
* The default system property key is "webapp.root", to be used in a log4j config
|
||||
* file like as follows:
|
||||
*
|
||||
* <p>{@code log4j.appender.myfile.File=${webapp.root}/WEB-INF/demo.log}
|
||||
*
|
||||
* <p>Alternatively, specify a unique context-param "webAppRootKey" per web application.
|
||||
* For example, with "webAppRootKey = "demo.root":
|
||||
*
|
||||
* <p>{@code log4j.appender.myfile.File=${demo.root}/WEB-INF/demo.log}
|
||||
*
|
||||
* <p><b>WARNING:</b> Some containers (like Tomcat) do <i>not</i> keep system properties
|
||||
* separate per web app. You have to use unique "webAppRootKey" context-params per web
|
||||
* app then, to avoid clashes. Other containers like Resin do isolate each web app's
|
||||
* system properties: Here you can use the default key (i.e. no "webAppRootKey"
|
||||
* context-param at all) without worrying.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Marten Deinum
|
||||
* @since 12.08.2003
|
||||
* @see org.springframework.util.Log4jConfigurer
|
||||
* @see Log4jConfigListener
|
||||
* @deprecated as of Spring 4.2.1, in favor of Apache Log4j 2
|
||||
* (following Apache's EOL declaration for log4j 1.x)
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class Log4jWebConfigurer {
|
||||
|
||||
/** Parameter specifying the location of the log4j config file */
|
||||
public static final String CONFIG_LOCATION_PARAM = "log4jConfigLocation";
|
||||
|
||||
/** Parameter specifying the refresh interval for checking the log4j config file */
|
||||
public static final String REFRESH_INTERVAL_PARAM = "log4jRefreshInterval";
|
||||
|
||||
/** Parameter specifying whether to expose the web app root system property */
|
||||
public static final String EXPOSE_WEB_APP_ROOT_PARAM = "log4jExposeWebAppRoot";
|
||||
|
||||
|
||||
/**
|
||||
* Initialize log4j, including setting the web app root system property.
|
||||
* @param servletContext the current ServletContext
|
||||
* @see WebUtils#setWebAppRootSystemProperty
|
||||
*/
|
||||
public static void initLogging(ServletContext servletContext) {
|
||||
// Expose the web app root system property.
|
||||
if (exposeWebAppRoot(servletContext)) {
|
||||
WebUtils.setWebAppRootSystemProperty(servletContext);
|
||||
}
|
||||
|
||||
// Only perform custom log4j initialization in case of a config file.
|
||||
String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
|
||||
if (location != null) {
|
||||
// Perform actual log4j initialization; else rely on log4j's default initialization.
|
||||
try {
|
||||
// Resolve property placeholders before potentially resolving a real path.
|
||||
location = ServletContextPropertyUtils.resolvePlaceholders(location, servletContext);
|
||||
|
||||
// Leave a URL (e.g. "classpath:" or "file:") as-is.
|
||||
if (!ResourceUtils.isUrl(location)) {
|
||||
// Consider a plain file path as relative to the web application root directory.
|
||||
location = WebUtils.getRealPath(servletContext, location);
|
||||
}
|
||||
|
||||
// Write log message to server log.
|
||||
servletContext.log("Initializing log4j from [" + location + "]");
|
||||
|
||||
// Check whether refresh interval was specified.
|
||||
String intervalString = servletContext.getInitParameter(REFRESH_INTERVAL_PARAM);
|
||||
if (StringUtils.hasText(intervalString)) {
|
||||
// Initialize with refresh interval, i.e. with log4j's watchdog thread,
|
||||
// checking the file in the background.
|
||||
try {
|
||||
long refreshInterval = Long.parseLong(intervalString);
|
||||
org.springframework.util.Log4jConfigurer.initLogging(location, refreshInterval);
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
throw new IllegalArgumentException("Invalid 'log4jRefreshInterval' parameter: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Initialize without refresh check, i.e. without log4j's watchdog thread.
|
||||
org.springframework.util.Log4jConfigurer.initLogging(location);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
throw new IllegalArgumentException("Invalid 'log4jConfigLocation' parameter: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down log4j, properly releasing all file locks
|
||||
* and resetting the web app root system property.
|
||||
* @param servletContext the current ServletContext
|
||||
* @see WebUtils#removeWebAppRootSystemProperty
|
||||
*/
|
||||
public static void shutdownLogging(ServletContext servletContext) {
|
||||
servletContext.log("Shutting down log4j");
|
||||
try {
|
||||
org.springframework.util.Log4jConfigurer.shutdownLogging();
|
||||
}
|
||||
finally {
|
||||
// Remove the web app root system property.
|
||||
if (exposeWebAppRoot(servletContext)) {
|
||||
WebUtils.removeWebAppRootSystemProperty(servletContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to expose the web app root system property,
|
||||
* checking the corresponding ServletContext init parameter.
|
||||
* @see #EXPOSE_WEB_APP_ROOT_PARAM
|
||||
*/
|
||||
private static boolean exposeWebAppRoot(ServletContext servletContext) {
|
||||
String exposeWebAppRootParam = servletContext.getInitParameter(EXPOSE_WEB_APP_ROOT_PARAM);
|
||||
return (exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user