You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/02/25 14:43:34 UTC
svn commit: r1293600 [6/9] - in /chemistry/opencmis/branches/android: ./
chemistry-opencmis-client/chemistry-opencmis-client-bindings/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindi...
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrServiceFactory.java Sat Feb 25 13:43:31 2012
@@ -29,8 +29,8 @@ import org.apache.chemistry.opencmis.jcr
import org.apache.chemistry.opencmis.jcr.impl.DefaultUnversionedDocumentTypeHandler;
import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.imageio.spi.ServiceRegistry;
import javax.jcr.Repository;
@@ -48,7 +48,7 @@ import java.util.Map;
* A {@link CmisServiceFactory} implementation which returns {@link JcrService} instances.
*/
public class JcrServiceFactory extends AbstractServiceFactory {
- private static final Log log = LogFactory.getLog(JcrServiceFactory.class);
+ private static final Logger log = LoggerFactory.getLogger(JcrServiceFactory.class);
public static final String MOUNT_PATH_CONFIG = "mount-path";
public static final String PREFIX_JCR_CONFIG = "jcr.";
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrTypeManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrTypeManager.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrTypeManager.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrTypeManager.java Sat Feb 25 13:43:31 2012
@@ -45,8 +45,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionContainerImpl;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.TypeDefinitionListImpl;
import org.apache.chemistry.opencmis.server.support.TypeManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.util.ArrayList;
@@ -59,7 +59,7 @@ import java.util.Map;
* Type Manager.
*/
public class JcrTypeManager implements TypeManager {
- private static final Log log = LogFactory.getLog(JcrTypeManager.class);
+ private static final Logger log = LoggerFactory.getLogger(JcrTypeManager.class);
public static final String DOCUMENT_TYPE_ID = "cmis:document";
public static final String FOLDER_TYPE_ID = "cmis:folder";
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/JcrVersionBase.java Sat Feb 25 13:43:31 2012
@@ -29,8 +29,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
import org.apache.chemistry.opencmis.commons.impl.server.ObjectInfoImpl;
import org.apache.chemistry.opencmis.jcr.type.JcrTypeHandlerManager;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -47,7 +47,7 @@ import java.util.Set;
* JCR <code>Node</code>.
*/
public abstract class JcrVersionBase extends JcrDocument {
- private static final Log log = LogFactory.getLog(JcrVersionBase.class);
+ private static final Logger log = LoggerFactory.getLogger(JcrVersionBase.class);
protected JcrVersionBase(Node node, JcrTypeManager typeManager, PathManager pathManager, JcrTypeHandlerManager typeHandlerManager) {
super(node, typeManager, pathManager, typeHandlerManager);
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/PathManager.java Sat Feb 25 13:43:31 2012
@@ -21,8 +21,8 @@ package org.apache.chemistry.opencmis.jc
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -31,7 +31,7 @@ import javax.jcr.RepositoryException;
* Utility class for mapping JCR paths to CMIS paths
*/
public class PathManager {
- private static final Log log = LogFactory.getLog(PathManager.class);
+ private static final Logger log = LoggerFactory.getLogger(PathManager.class);
/**
* Identifier of the root folder
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultDocumentTypeHandler.java Sat Feb 25 13:43:31 2012
@@ -35,8 +35,8 @@ import org.apache.chemistry.opencmis.jcr
import org.apache.chemistry.opencmis.jcr.JcrVersionBase;
import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
import org.apache.chemistry.opencmis.jcr.type.JcrDocumentTypeHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jcr.Binary;
import javax.jcr.Node;
@@ -53,7 +53,7 @@ import java.io.IOException;
*/
public class DefaultDocumentTypeHandler extends AbstractJcrTypeHandler implements JcrDocumentTypeHandler {
- private static final Log log = LogFactory.getLog(JcrFolder.class);
+ private static final Logger log = LoggerFactory.getLogger(JcrFolder.class);
public String getTypeId() {
return BaseTypeId.CMIS_DOCUMENT.value();
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/impl/DefaultFolderTypeHandler.java Sat Feb 25 13:43:31 2012
@@ -27,8 +27,8 @@ import org.apache.chemistry.opencmis.jcr
import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
import org.apache.chemistry.opencmis.jcr.type.JcrFolderTypeHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -39,7 +39,7 @@ import javax.jcr.nodetype.NodeType;
*/
public class DefaultFolderTypeHandler extends AbstractJcrTypeHandler implements JcrFolderTypeHandler {
- private static final Log log = LogFactory.getLog(DefaultFolderTypeHandler.class);
+ private static final Logger log = LoggerFactory.getLogger(DefaultFolderTypeHandler.class);
private static class FolderIdentifierMap extends DefaultIdentifierMapBase {
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/main/java/org/apache/chemistry/opencmis/jcr/type/JcrTypeHandlerManager.java Sat Feb 25 13:43:31 2012
@@ -25,8 +25,8 @@ import org.apache.chemistry.opencmis.jcr
import org.apache.chemistry.opencmis.jcr.PathManager;
import org.apache.chemistry.opencmis.jcr.query.IdentifierMap;
import org.apache.chemistry.opencmis.jcr.util.Predicate;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
@@ -38,7 +38,7 @@ import java.util.Map;
*/
public class JcrTypeHandlerManager {
- private static final Log log = LogFactory.getLog(JcrTypeHandlerManager.class);
+ private static final Logger log = LoggerFactory.getLogger(JcrTypeHandlerManager.class);
private final PathManager pathManager;
private final JcrTypeManager typeManager;
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/antlr3/org/apache/chemistry/opencmis/server/support/query/CmisQueryWalker.g Sat Feb 25 13:43:31 2012
@@ -61,12 +61,12 @@ options {
package org.apache.chemistry.opencmis.server.support.query;
import java.math.BigDecimal;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
}
@members {
- private static Log LOG = LogFactory.getLog(CmisQueryWalker.class);
+ private static final Logger log = LoggerFactory.getLogger(CmisQueryWalker.class);
private QueryObject queryObj;
private Tree wherePredicateTree;
@@ -298,7 +298,9 @@ search_condition
}
| value_expression
{
- LOG.debug(" add node to where: " + $value_expression.start + " id: " + System.identityHashCode($value_expression.start));
+ if (log.isDebugEnabled()) {
+ log.debug(" add node to where: " + $value_expression.start + " id: " + System.identityHashCode($value_expression.start));
+ }
queryObj.addWhereReference($value_expression.start, $value_expression.result);
}
| literal
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/CmisServiceWrapper.java Sat Feb 25 13:43:31 2012
@@ -53,8 +53,8 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.server.CmisService;
import org.apache.chemistry.opencmis.commons.server.ObjectInfo;
import org.apache.chemistry.opencmis.commons.spi.Holder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Service wrapper.
@@ -63,7 +63,7 @@ public class CmisServiceWrapper<T extend
public static final BigInteger MINUS_ONE = BigInteger.valueOf(-1);
- private static final Log log = LogFactory.getLog(CmisServiceWrapper.class);
+ private static final Logger log = LoggerFactory.getLogger(CmisServiceWrapper.class);
private BigInteger defaultTypesMaxItems = null;
private BigInteger defaultTypesDepth = MINUS_ONE;
@@ -134,7 +134,7 @@ public class CmisServiceWrapper<T extend
} else {
// should not happen if the connector works correctly
// it's alarming enough to log the exception
- log.warn(e);
+ log.warn(e.toString(), e);
return new CmisRuntimeException(e.getMessage(), e);
}
@@ -316,9 +316,8 @@ public class CmisServiceWrapper<T extend
}
/**
- * Returns the
- * <code>AclPropagation.REPOSITORYDETERMINED</code> if <code>value</code> is
- * <code>null</code>.
+ * Returns the <code>AclPropagation.REPOSITORYDETERMINED</code> if
+ * <code>value</code> is <code>null</code>.
*/
protected AclPropagation getDefault(AclPropagation value) {
if (value == null) {
@@ -329,9 +328,8 @@ public class CmisServiceWrapper<T extend
}
/**
- * Returns the
- * <code>RelationshipDirection.SOURCE</code> if <code>value</code> is
- * <code>null</code> .
+ * Returns the <code>RelationshipDirection.SOURCE</code> if
+ * <code>value</code> is <code>null</code> .
*/
protected RelationshipDirection getDefault(RelationshipDirection value) {
if (value == null) {
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java Sat Feb 25 13:43:31 2012
@@ -29,8 +29,6 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.data.Acl;
import org.apache.chemistry.opencmis.commons.data.Properties;
import org.apache.chemistry.opencmis.commons.data.PropertyData;
-import org.apache.chemistry.opencmis.commons.data.PropertyDecimal;
-import org.apache.chemistry.opencmis.commons.data.PropertyInteger;
import org.apache.chemistry.opencmis.commons.definitions.Choice;
import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDecimalDefinition;
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java Sat Feb 25 13:43:31 2012
@@ -1,602 +1,600 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.apache.chemistry.opencmis.server.support.filter;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Scanner;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpServletResponseWrapper;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class LoggingFilter implements Filter {
-
- private static final Log log = LogFactory.getLog(LoggingFilter.class);
- private static int REQUEST_NO = 0;
- private static final SimpleDateFormat FORMAT = new SimpleDateFormat("EEE MMM dd hh:mm:ss a z yyyy", Locale.US);
- private String logDir;
- private boolean prettyPrint = true;
- private boolean logHeaders = true;
- private int indent = -1;
-
- public void init(FilterConfig cfg) throws ServletException {
-
- String val;
- logDir = cfg.getInitParameter("LogDir");
- if (null == logDir || logDir.length() == 0)
- logDir = System.getProperty("java.io.tmpdir");
- if (null == logDir|| logDir.length() == 0)
- logDir = "." + File.separator;
-
- if (!logDir.endsWith(File.separator))
- logDir += File.separator;
-
- val = cfg.getInitParameter("Indent");
- if (null != val)
- indent = Integer.parseInt(val);
- if (indent < 0)
- indent = 4;
-
- val = cfg.getInitParameter("PrettyPrint");
- if (null != val)
- prettyPrint = Boolean.parseBoolean(val);
-
- val = cfg.getInitParameter("LogHeaders");
- if (null != val)
- logHeaders = Boolean.parseBoolean(val);
- }
-
- public void destroy() {
- }
-
- public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
- ServletException {
- log.debug("Logging filter doFilter");
-
- if (resp instanceof HttpServletResponse && req instanceof HttpServletRequest) {
- LoggingRequestWrapper logReq = new LoggingRequestWrapper((HttpServletRequest)req);
- LoggingResponseWrapper logResponse = new LoggingResponseWrapper((HttpServletResponse)resp);
-
- chain.doFilter(logReq, logResponse);
-
- int reqNo = getNextRequestNumber();
- String requestFileName = getRequestFileName(reqNo);
- String cType = logReq.getContentType();
- String xmlRequest = logReq.getPayload();
- StringBuffer sb = new StringBuffer();
-
- if (logHeaders)
- logHeaders(logReq, sb);
-
- if (xmlRequest == null || xmlRequest.length() == 0)
- xmlRequest = "";
-
- if (prettyPrint && cType != null) {
- if (cType.startsWith("multipart")) {
- xmlRequest = processMultipart(cType, xmlRequest);
- } else if (cType.contains("xml")) {
- xmlRequest = prettyPrintXml(xmlRequest, indent);
- }
- }
-
- xmlRequest = sb.toString() + xmlRequest;
- log.debug("Found request: " + requestFileName + ": " + xmlRequest);
- writeTextToFile(requestFileName, xmlRequest);
-
-
- sb = new StringBuffer();
- cType = logResponse.getContentType();
- String xmlResponse = logResponse.getPayload();
- String responseFileName = getResponseFileName(reqNo);
-
- if (logHeaders) {
- logHeaders(logResponse, req.getProtocol(), sb);
- }
-
- if (xmlResponse == null || xmlResponse.length() == 0)
- xmlResponse = "";
-
- if (prettyPrint && cType != null) {
- if (cType.startsWith("multipart")) {
- xmlResponse = processMultipart(cType, xmlResponse);
- } else if (cType.contains("xml")) {
- xmlResponse = prettyPrintXml(xmlResponse, indent);
- } else if (cType.contains("json")) {
- xmlResponse = prettyPrintJson(xmlResponse, indent);
- }
- }
-
- xmlResponse = sb.toString() + xmlResponse;
- log.debug("Found response: " + responseFileName + ": " + xmlResponse);
- writeTextToFile(responseFileName, xmlResponse);
- } else {
- chain.doFilter(req, resp);
- }
- }
-
- private void writeTextToFile(String filename, String content) {
- PrintWriter pw = null;
- FileWriter fw = null;
- try {
- fw = new FileWriter(filename);
- pw = new PrintWriter(fw);
-
- Scanner scanner = new Scanner(content);
- while (scanner.hasNextLine()) {
- String line = scanner.nextLine();
- pw.println(line);
- }
-
- pw.flush();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (pw != null)
- pw.close();
- if (fw != null)
- try {
- fw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- private static String prettyPrintXml(String input, int indent) {
- try {
- Source xmlInput = new StreamSource(new StringReader(input));
- StringWriter stringWriter = new StringWriter();
- StreamResult xmlOutput = new StreamResult(stringWriter);
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- transformerFactory.setAttribute("indent-number", indent);
- Transformer transformer = transformerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.transform(xmlInput, xmlOutput);
- return xmlOutput.getWriter().toString();
- } catch (Exception e) {
- throw new RuntimeException(e); // simple exception handling, please review it
- }
- }
-
- private static String prettyPrintJson(String input, int indent) {
- JsonPrettyPrinter pp = new JsonPrettyPrinter(indent);
- return pp.prettyPrint(input);
- }
-
- private String processMultipart(String cType, String messageBody) throws IOException {
- int beginIndex = cType.indexOf("boundary=\"") + 10;
- int endIndex = cType.indexOf("\"", beginIndex);
- if (endIndex < 0)
- endIndex = cType.length();
- String boundary = "--" + cType.substring(beginIndex, endIndex);
- log.debug("Boundary = " + boundary);
- BufferedReader in = new BufferedReader(new StringReader(messageBody));
- StringBuffer out = new StringBuffer();
- String line;
- ByteArrayOutputStream xmlBodyBuffer = new ByteArrayOutputStream();
- boolean boundaryFound;
-
- boolean inXmlOrJsonBody = false;
- boolean inXmlOrJsonPart = false;
- boolean isXml;
- while ((line = in.readLine()) != null) {
- if (inXmlOrJsonPart) {
- if (line.startsWith("<?xml") || line.startsWith("{")) {
- inXmlOrJsonBody = true;
- isXml = line.startsWith("<?xml");
- xmlBodyBuffer.write(line.getBytes(), 0, line.length());
- while (inXmlOrJsonBody) {
- line = in.readLine();
- boundaryFound = line.startsWith(boundary);
- if (boundaryFound) {
- log.debug("Leaving XML body: " + line);
- inXmlOrJsonBody = false;
- inXmlOrJsonPart = false;
- if (isXml)
- out.append(prettyPrintXml(xmlBodyBuffer.toString(), indent));
- else
- out.append(prettyPrintJson(xmlBodyBuffer.toString(), indent));
- out.append(line).append("\n");
- } else
- xmlBodyBuffer.write(line.getBytes(), 0, line.length());
- }
- } else {
- log.debug("in XML part is: " + line);
- out.append(line).append("\n");
- }
-
- } else {
- log.debug("not in XML part: " + line);
- out.append(line).append("\n");
- boundaryFound = line.startsWith(boundary);
- if (boundaryFound) {
- log.debug("Boundardy found!");
- inXmlOrJsonPart = true;
- }
- }
- }
- in.close();
- log.debug("End parsing multipart.");
-
- return out.toString();
- }
-
- @SuppressWarnings("rawtypes")
- private void logHeaders(LoggingRequestWrapper req, StringBuffer sb) {
- sb.append(req.getMethod());
- sb.append(" ");
- sb.append(req.getRequestURI());
- String queryString = req.getQueryString();
- if (null != queryString && queryString.length() > 0) {
- sb.append("?");
- sb.append(queryString);
- }
- sb.append(" ");
- sb.append(req.getProtocol());
- sb.append("\n");
- Enumeration headerNames = req.getHeaderNames();
- while (headerNames.hasMoreElements()) {
- String headerName = headerNames.nextElement().toString();
- headerName = headerName.substring(0, 1).toUpperCase() + headerName.substring(1);
- sb.append(headerName + ": ");
- sb.append(req.getHeader(headerName));
- sb.append("\n");
- }
- sb.append("\n");
- }
-
- private void logHeaders(LoggingResponseWrapper resp, String protocol, StringBuffer sb) {
- sb.append(protocol);
- sb.append(" ");
- sb.append(String.valueOf(resp.getStatus()));
- sb.append("\n");
- Map<String, String> headers = resp.getHeaders();
- for ( Map.Entry<String, String> header: headers.entrySet()) {
- sb.append(header.getKey());
- sb.append(": ");
- sb.append(header.getValue());
- sb.append("\n");
- }
- sb.append("\n");
- }
-
- private String getRequestFileName(int no) {
- return logDir + String.format("%05d-request.log", no);
- }
-
- private String getResponseFileName(int no) {
- return logDir + String.format("%05d-response.log", no);
- }
-
- private static synchronized int getNextRequestNumber() {
- return REQUEST_NO++;
- }
-
- private class LoggingRequestWrapper extends HttpServletRequestWrapper {
-
- private LoggingInputStream is;
-
- public LoggingRequestWrapper(HttpServletRequest request) throws IOException {
- super(request);
- }
-
- @Override
- public ServletInputStream getInputStream() throws IOException {
- this.is = new LoggingInputStream(super.getInputStream());
- return is;
- }
-
- public String getPayload() {
- return null == is ? "" : is.getPayload();
- }
- }
-
- private class LoggingInputStream extends ServletInputStream {
-
- private ByteArrayOutputStream baous = new ByteArrayOutputStream();
- private ServletInputStream is;
-
- public LoggingInputStream(ServletInputStream is) {
- super();
- this.is = is;
- }
-
- // Since we are not sure which method is used just overwrite all 4 of them:
- @Override
- public int read() throws IOException {
- int ch = is.read();
- if (ch != -1) {
- baous.write(ch);
- }
- return ch;
- }
-
- @Override
- public int read(byte[] b) throws IOException {
- int ch = is.read(b);
- if (ch != -1) {
- baous.write(b, 0, ch);
- }
- return ch;
- }
-
- @Override
- public int read(byte[] b, int o, int l) throws IOException {
- int ch = is.read(b, o, l);
- if (ch != -1) {
- baous.write(b, o, ch);
- }
- return ch;
- }
-
- @Override
- public int readLine(byte[] b, int o, int l) throws IOException {
- int ch = is.readLine(b, o, l);
- if (ch != -1) {
- baous.write(b, o, ch);
- }
- return ch;
- }
-
- public String getPayload() {
- return baous.toString();
- }
- }
-
- private class LoggingResponseWrapper extends HttpServletResponseWrapper {
-
- private LoggingOutputStream os;
- private PrintWriter writer;
- private int statusCode;
- private Map<String, String> headers = new HashMap<String, String>();
- String encoding;
-
- public LoggingResponseWrapper(HttpServletResponse response) throws IOException {
- super(response);
- this.os = new LoggingOutputStream(response.getOutputStream());
- }
-
- @Override
- public PrintWriter getWriter() {
- try {
- if (null == writer)
- writer = new PrintWriter(this.getOutputStream());
- return writer;
- } catch (IOException e) {
- log.error("Failed to get PrintWriter in LoggingFilter: "+ e);
- e.printStackTrace();
- return null;
- }
- }
-
- @Override
- public ServletOutputStream getOutputStream() throws IOException {
- return os;
- }
-
- public String getPayload() {
- return os.getPayload();
- }
-
- @Override
- public void addCookie(Cookie cookie) {
- super.addCookie(cookie);
- String value;
- if (headers.containsKey("Cookie")) {
- value = headers.get("Cookie") + "; " + cookie.toString();
- } else
- value = cookie.toString();
- headers.put("Cookie", value);
- }
-
- @Override
- public void setContentType(String type) {
- super.setContentType(type);
- if (headers.containsKey("Content-Type")) {
- String cType = headers.get("Content-Type");
- int pos = cType.indexOf(";charset=");
- if (pos < 0 && encoding != null)
- type = cType + ";charset=" + encoding;
- else if (pos >= 0)
- encoding = null;
- }
- headers.put("Content-Type", type);
- }
-
- @Override
- public void setCharacterEncoding(java.lang.String charset) {
- super.setCharacterEncoding(charset);
- encoding = charset;
- if (headers.containsKey("Content-Type")) {
- String cType = headers.get("Content-Type");
- int pos = cType.indexOf(";charset=");
- if (pos >=0)
- cType = cType.substring(0, pos) + ";charset=" + encoding;
- else
- cType = cType + ";charset=" + encoding;
- headers.put("Content-Type", cType);
- }
- }
-
- @Override
- public void setContentLength(int len) {
- super.setContentLength(len);
- headers.put("Content-Length", String.valueOf(len));
- }
-
- private String getDateString(long date) {
- return FORMAT.format(new Date(date));
- }
-
- @Override
- public void setDateHeader(String name, long date) {
- super.setDateHeader(name, date);
- headers.put(name, String.valueOf(getDateString(date)));
- }
-
- @Override
- public void addDateHeader(String name, long date) {
- super.addDateHeader(name, date);
- if (headers.containsKey(name)) {
- headers.put(name, headers.get(name) + "; " + getDateString(date));
- } else {
- headers.put(name, String.valueOf(getDateString(date)));
- }
- }
-
- @Override
- public void setHeader(String name, String value) {
- super.setHeader(name, value);
- headers.put(name, String.valueOf(value));
- }
-
- @Override
- public void addHeader(String name, String value) {
- super.addHeader(name, value);
- if (headers.containsKey(name)) {
- headers.put(name, headers.get(name) + "; " + value);
- } else {
- headers.put(name, String.valueOf(value));
- }
- }
-
- @Override
- public void setIntHeader(String name, int value) {
- super.setIntHeader(name, value);
- headers.put(name, String.valueOf(value));
- }
-
- @Override
- public void addIntHeader(String name, int value) {
- super.addIntHeader(name, value);
- if (headers.containsKey(name)) {
- headers.put(name, headers.get(name) + "; " + String.valueOf(value));
- } else {
- headers.put(name, String.valueOf(value));
- }
- }
-
- @Override
- public void sendError(int sc) throws IOException {
- statusCode = sc;
- super.sendError(sc);
- }
-
- @Override
- public void sendError(int sc, String msg) throws IOException {
- statusCode = sc;
- super.sendError(sc, msg);
- }
-
- @Override
- public void sendRedirect(String location) throws IOException {
- statusCode = 302;
- super.sendRedirect(location);
- }
-
- @Override
- public void setStatus(int sc) {
- statusCode = sc;
- super.setStatus(sc);
- }
-
- public int getStatus() {
- return statusCode;
- }
-
- public Map<String, String> getHeaders() {
- return headers;
- }
- }
-
- private class LoggingOutputStream extends ServletOutputStream {
- private ByteArrayOutputStream baous = new ByteArrayOutputStream();
- private ServletOutputStream os;
-
- public LoggingOutputStream(ServletOutputStream os) {
- super();
- this.os = os;
- }
-
- public String getPayload() {
- return new String(baous.toString());
- }
-
- @Override
- public void write(byte[] b, int off, int len) {
- try {
- baous.write(b, off, len);
- os.write(b, off, len);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public
- void write(byte[] b) {
- try {
- baous.write(b);
- os.write(b);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void write(int ch) throws IOException {
- baous.write(ch);
- os.write(ch);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.chemistry.opencmis.server.support.filter;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Scanner;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LoggingFilter implements Filter {
+
+ private static final Logger log = LoggerFactory.getLogger(LoggingFilter.class);
+ private static int REQUEST_NO = 0;
+ private static final SimpleDateFormat FORMAT = new SimpleDateFormat("EEE MMM dd hh:mm:ss a z yyyy", Locale.US);
+ private String logDir;
+ private boolean prettyPrint = true;
+ private boolean logHeaders = true;
+ private int indent = -1;
+
+ public void init(FilterConfig cfg) throws ServletException {
+
+ String val;
+ logDir = cfg.getInitParameter("LogDir");
+ if (null == logDir || logDir.length() == 0)
+ logDir = System.getProperty("java.io.tmpdir");
+ if (null == logDir|| logDir.length() == 0)
+ logDir = "." + File.separator;
+
+ if (!logDir.endsWith(File.separator))
+ logDir += File.separator;
+
+ val = cfg.getInitParameter("Indent");
+ if (null != val)
+ indent = Integer.parseInt(val);
+ if (indent < 0)
+ indent = 4;
+
+ val = cfg.getInitParameter("PrettyPrint");
+ if (null != val)
+ prettyPrint = Boolean.parseBoolean(val);
+
+ val = cfg.getInitParameter("LogHeaders");
+ if (null != val)
+ logHeaders = Boolean.parseBoolean(val);
+ }
+
+ public void destroy() {
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException,
+ ServletException {
+ log.debug("Logging filter doFilter");
+
+ if (resp instanceof HttpServletResponse && req instanceof HttpServletRequest) {
+ LoggingRequestWrapper logReq = new LoggingRequestWrapper((HttpServletRequest)req);
+ LoggingResponseWrapper logResponse = new LoggingResponseWrapper((HttpServletResponse)resp);
+
+ chain.doFilter(logReq, logResponse);
+
+ int reqNo = getNextRequestNumber();
+ String requestFileName = getRequestFileName(reqNo);
+ String cType = logReq.getContentType();
+ String xmlRequest = logReq.getPayload();
+ StringBuffer sb = new StringBuffer();
+
+ if (logHeaders)
+ logHeaders(logReq, sb);
+
+ if (xmlRequest == null || xmlRequest.length() == 0)
+ xmlRequest = "";
+
+ if (prettyPrint && cType != null) {
+ if (cType.startsWith("multipart")) {
+ xmlRequest = processMultipart(cType, xmlRequest);
+ } else if (cType.contains("xml")) {
+ xmlRequest = prettyPrintXml(xmlRequest, indent);
+ }
+ }
+
+ xmlRequest = sb.toString() + xmlRequest;
+ log.debug("Found request: " + requestFileName + ": " + xmlRequest);
+ writeTextToFile(requestFileName, xmlRequest);
+
+
+ sb = new StringBuffer();
+ cType = logResponse.getContentType();
+ String xmlResponse = logResponse.getPayload();
+ String responseFileName = getResponseFileName(reqNo);
+
+ if (logHeaders) {
+ logHeaders(logResponse, req.getProtocol(), sb);
+ }
+
+ if (xmlResponse == null || xmlResponse.length() == 0)
+ xmlResponse = "";
+
+ if (prettyPrint && cType != null) {
+ if (cType.startsWith("multipart")) {
+ xmlResponse = processMultipart(cType, xmlResponse);
+ } else if (cType.contains("xml")) {
+ xmlResponse = prettyPrintXml(xmlResponse, indent);
+ } else if (cType.contains("json")) {
+ xmlResponse = prettyPrintJson(xmlResponse, indent);
+ }
+ }
+
+ xmlResponse = sb.toString() + xmlResponse;
+ log.debug("Found response: " + responseFileName + ": " + xmlResponse);
+ writeTextToFile(responseFileName, xmlResponse);
+ } else {
+ chain.doFilter(req, resp);
+ }
+ }
+
+ private void writeTextToFile(String filename, String content) {
+ PrintWriter pw = null;
+ FileWriter fw = null;
+ try {
+ fw = new FileWriter(filename);
+ pw = new PrintWriter(fw);
+
+ Scanner scanner = new Scanner(content);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ pw.println(line);
+ }
+
+ pw.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (pw != null)
+ pw.close();
+ if (fw != null)
+ try {
+ fw.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static String prettyPrintXml(String input, int indent) {
+ try {
+ Source xmlInput = new StreamSource(new StringReader(input));
+ StringWriter stringWriter = new StringWriter();
+ StreamResult xmlOutput = new StreamResult(stringWriter);
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ transformerFactory.setAttribute("indent-number", indent);
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.transform(xmlInput, xmlOutput);
+ return xmlOutput.getWriter().toString();
+ } catch (Exception e) {
+ throw new RuntimeException(e); // simple exception handling, please review it
+ }
+ }
+
+ private static String prettyPrintJson(String input, int indent) {
+ JsonPrettyPrinter pp = new JsonPrettyPrinter(indent);
+ return pp.prettyPrint(input);
+ }
+
+ private String processMultipart(String cType, String messageBody) throws IOException {
+ int beginIndex = cType.indexOf("boundary=\"") + 10;
+ int endIndex = cType.indexOf("\"", beginIndex);
+ if (endIndex < 0)
+ endIndex = cType.length();
+ String boundary = "--" + cType.substring(beginIndex, endIndex);
+ log.debug("Boundary = " + boundary);
+ BufferedReader in = new BufferedReader(new StringReader(messageBody));
+ StringBuffer out = new StringBuffer();
+ String line;
+ ByteArrayOutputStream xmlBodyBuffer = new ByteArrayOutputStream();
+ boolean boundaryFound;
+
+ boolean inXmlOrJsonBody = false;
+ boolean inXmlOrJsonPart = false;
+ boolean isXml;
+ while ((line = in.readLine()) != null) {
+ if (inXmlOrJsonPart) {
+ if (line.startsWith("<?xml") || line.startsWith("{")) {
+ inXmlOrJsonBody = true;
+ isXml = line.startsWith("<?xml");
+ xmlBodyBuffer.write(line.getBytes(), 0, line.length());
+ while (inXmlOrJsonBody) {
+ line = in.readLine();
+ boundaryFound = line.startsWith(boundary);
+ if (boundaryFound) {
+ log.debug("Leaving XML body: " + line);
+ inXmlOrJsonBody = false;
+ inXmlOrJsonPart = false;
+ if (isXml)
+ out.append(prettyPrintXml(xmlBodyBuffer.toString(), indent));
+ else
+ out.append(prettyPrintJson(xmlBodyBuffer.toString(), indent));
+ out.append(line).append("\n");
+ } else
+ xmlBodyBuffer.write(line.getBytes(), 0, line.length());
+ }
+ } else {
+ log.debug("in XML part is: " + line);
+ out.append(line).append("\n");
+ }
+
+ } else {
+ log.debug("not in XML part: " + line);
+ out.append(line).append("\n");
+ boundaryFound = line.startsWith(boundary);
+ if (boundaryFound) {
+ log.debug("Boundardy found!");
+ inXmlOrJsonPart = true;
+ }
+ }
+ }
+ in.close();
+ log.debug("End parsing multipart.");
+
+ return out.toString();
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void logHeaders(LoggingRequestWrapper req, StringBuffer sb) {
+ sb.append(req.getMethod());
+ sb.append(" ");
+ sb.append(req.getRequestURI());
+ String queryString = req.getQueryString();
+ if (null != queryString && queryString.length() > 0) {
+ sb.append("?");
+ sb.append(queryString);
+ }
+ sb.append(" ");
+ sb.append(req.getProtocol());
+ sb.append("\n");
+ Enumeration headerNames = req.getHeaderNames();
+ while (headerNames.hasMoreElements()) {
+ String headerName = headerNames.nextElement().toString();
+ headerName = headerName.substring(0, 1).toUpperCase() + headerName.substring(1);
+ sb.append(headerName + ": ");
+ sb.append(req.getHeader(headerName));
+ sb.append("\n");
+ }
+ sb.append("\n");
+ }
+
+ private void logHeaders(LoggingResponseWrapper resp, String protocol, StringBuffer sb) {
+ sb.append(protocol);
+ sb.append(" ");
+ sb.append(String.valueOf(resp.getStatus()));
+ sb.append("\n");
+ Map<String, String> headers = resp.getHeaders();
+ for ( Map.Entry<String, String> header: headers.entrySet()) {
+ sb.append(header.getKey());
+ sb.append(": ");
+ sb.append(header.getValue());
+ sb.append("\n");
+ }
+ sb.append("\n");
+ }
+
+ private String getRequestFileName(int no) {
+ return logDir + String.format("%05d-request.log", no);
+ }
+
+ private String getResponseFileName(int no) {
+ return logDir + String.format("%05d-response.log", no);
+ }
+
+ private static synchronized int getNextRequestNumber() {
+ return REQUEST_NO++;
+ }
+
+ private class LoggingRequestWrapper extends HttpServletRequestWrapper {
+
+ private LoggingInputStream is;
+
+ public LoggingRequestWrapper(HttpServletRequest request) throws IOException {
+ super(request);
+ }
+
+ @Override
+ public ServletInputStream getInputStream() throws IOException {
+ this.is = new LoggingInputStream(super.getInputStream());
+ return is;
+ }
+
+ public String getPayload() {
+ return null == is ? "" : is.getPayload();
+ }
+ }
+
+ private class LoggingInputStream extends ServletInputStream {
+
+ private ByteArrayOutputStream baous = new ByteArrayOutputStream();
+ private ServletInputStream is;
+
+ public LoggingInputStream(ServletInputStream is) {
+ super();
+ this.is = is;
+ }
+
+ // Since we are not sure which method is used just overwrite all 4 of them:
+ @Override
+ public int read() throws IOException {
+ int ch = is.read();
+ if (ch != -1) {
+ baous.write(ch);
+ }
+ return ch;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ int ch = is.read(b);
+ if (ch != -1) {
+ baous.write(b, 0, ch);
+ }
+ return ch;
+ }
+
+ @Override
+ public int read(byte[] b, int o, int l) throws IOException {
+ int ch = is.read(b, o, l);
+ if (ch != -1) {
+ baous.write(b, o, ch);
+ }
+ return ch;
+ }
+
+ @Override
+ public int readLine(byte[] b, int o, int l) throws IOException {
+ int ch = is.readLine(b, o, l);
+ if (ch != -1) {
+ baous.write(b, o, ch);
+ }
+ return ch;
+ }
+
+ public String getPayload() {
+ return baous.toString();
+ }
+ }
+
+ private class LoggingResponseWrapper extends HttpServletResponseWrapper {
+
+ private LoggingOutputStream os;
+ private PrintWriter writer;
+ private int statusCode;
+ private Map<String, String> headers = new HashMap<String, String>();
+ String encoding;
+
+ public LoggingResponseWrapper(HttpServletResponse response) throws IOException {
+ super(response);
+ this.os = new LoggingOutputStream(response.getOutputStream());
+ }
+
+ @Override
+ public PrintWriter getWriter() {
+ try {
+ if (null == writer)
+ writer = new PrintWriter(this.getOutputStream());
+ return writer;
+ } catch (IOException e) {
+ log.error("Failed to get PrintWriter in LoggingFilter: "+ e);
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ public ServletOutputStream getOutputStream() throws IOException {
+ return os;
+ }
+
+ public String getPayload() {
+ return os.getPayload();
+ }
+
+ @Override
+ public void addCookie(Cookie cookie) {
+ super.addCookie(cookie);
+ String value;
+ if (headers.containsKey("Cookie")) {
+ value = headers.get("Cookie") + "; " + cookie.toString();
+ } else
+ value = cookie.toString();
+ headers.put("Cookie", value);
+ }
+
+ @Override
+ public void setContentType(String type) {
+ super.setContentType(type);
+ if (headers.containsKey("Content-Type")) {
+ String cType = headers.get("Content-Type");
+ int pos = cType.indexOf(";charset=");
+ if (pos < 0 && encoding != null)
+ type = cType + ";charset=" + encoding;
+ else if (pos >= 0)
+ encoding = null;
+ }
+ headers.put("Content-Type", type);
+ }
+
+ @Override
+ public void setCharacterEncoding(java.lang.String charset) {
+ super.setCharacterEncoding(charset);
+ encoding = charset;
+ if (headers.containsKey("Content-Type")) {
+ String cType = headers.get("Content-Type");
+ int pos = cType.indexOf(";charset=");
+ if (pos >=0)
+ cType = cType.substring(0, pos) + ";charset=" + encoding;
+ else
+ cType = cType + ";charset=" + encoding;
+ headers.put("Content-Type", cType);
+ }
+ }
+
+ @Override
+ public void setContentLength(int len) {
+ super.setContentLength(len);
+ headers.put("Content-Length", String.valueOf(len));
+ }
+
+ private String getDateString(long date) {
+ return FORMAT.format(new Date(date));
+ }
+
+ @Override
+ public void setDateHeader(String name, long date) {
+ super.setDateHeader(name, date);
+ headers.put(name, String.valueOf(getDateString(date)));
+ }
+
+ @Override
+ public void addDateHeader(String name, long date) {
+ super.addDateHeader(name, date);
+ if (headers.containsKey(name)) {
+ headers.put(name, headers.get(name) + "; " + getDateString(date));
+ } else {
+ headers.put(name, String.valueOf(getDateString(date)));
+ }
+ }
+
+ @Override
+ public void setHeader(String name, String value) {
+ super.setHeader(name, value);
+ headers.put(name, String.valueOf(value));
+ }
+
+ @Override
+ public void addHeader(String name, String value) {
+ super.addHeader(name, value);
+ if (headers.containsKey(name)) {
+ headers.put(name, headers.get(name) + "; " + value);
+ } else {
+ headers.put(name, String.valueOf(value));
+ }
+ }
+
+ @Override
+ public void setIntHeader(String name, int value) {
+ super.setIntHeader(name, value);
+ headers.put(name, String.valueOf(value));
+ }
+
+ @Override
+ public void addIntHeader(String name, int value) {
+ super.addIntHeader(name, value);
+ if (headers.containsKey(name)) {
+ headers.put(name, headers.get(name) + "; " + String.valueOf(value));
+ } else {
+ headers.put(name, String.valueOf(value));
+ }
+ }
+
+ @Override
+ public void sendError(int sc) throws IOException {
+ statusCode = sc;
+ super.sendError(sc);
+ }
+
+ @Override
+ public void sendError(int sc, String msg) throws IOException {
+ statusCode = sc;
+ super.sendError(sc, msg);
+ }
+
+ @Override
+ public void sendRedirect(String location) throws IOException {
+ statusCode = 302;
+ super.sendRedirect(location);
+ }
+
+ @Override
+ public void setStatus(int sc) {
+ statusCode = sc;
+ super.setStatus(sc);
+ }
+
+ public int getStatus() {
+ return statusCode;
+ }
+
+ public Map<String, String> getHeaders() {
+ return headers;
+ }
+ }
+
+ private class LoggingOutputStream extends ServletOutputStream {
+ private ByteArrayOutputStream baous = new ByteArrayOutputStream();
+ private ServletOutputStream os;
+
+ public LoggingOutputStream(ServletOutputStream os) {
+ super();
+ this.os = os;
+ }
+
+ public String getPayload() {
+ return new String(baous.toString());
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) {
+ try {
+ baous.write(b, off, len);
+ os.write(b, off, len);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public
+ void write(byte[] b) {
+ try {
+ baous.write(b);
+ os.write(b);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void write(int ch) throws IOException {
+ baous.write(ch);
+ os.write(ch);
+ }
+ }
+}
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java Sat Feb 25 13:43:31 2012
@@ -31,8 +31,8 @@ import org.antlr.runtime.tree.Tree;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.server.support.TypeManager;
import org.apache.chemistry.opencmis.server.support.TypeValidator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -44,7 +44,7 @@ import org.apache.commons.logging.LogFac
*/
public class QueryObject {
- private static final Log LOG = LogFactory.getLog(QueryObject.class);
+ private static final Logger LOG = LoggerFactory.getLogger(QueryObject.class);
// For error handling see:
// http://www.antlr.org/pipermail/antlr-interest/2008-April/027600.html
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java Sat Feb 25 13:43:31 2012
@@ -31,8 +31,8 @@ import org.antlr.runtime.Lexer;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.stringtemplate.StringTemplate;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This class is clone of org.antlr.gunit.gUnitBase class adapted to Java style
@@ -42,7 +42,7 @@ import org.apache.commons.logging.LogFac
*/
public class AbstractParserTest{
- private static final Log log = LogFactory.getLog(AbstractParserTest.class);
+ private static final Logger log = LoggerFactory.getLogger(AbstractParserTest.class);
protected String superGrammarName;
Class<?> lexer;
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/StringUtilTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/StringUtilTest.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/StringUtilTest.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/StringUtilTest.java Sat Feb 25 13:43:31 2012
@@ -18,7 +18,8 @@
*/
package org.apache.chemistry.opencmis.server.support.query;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java Sat Feb 25 13:43:31 2012
@@ -18,15 +18,15 @@
*/
package org.apache.chemistry.opencmis.server.support.query;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class TestParserExt extends AbstractParserTest {
- private static final Log log = LogFactory.getLog(TestParserStrict.class);
+ private static final Logger log = LoggerFactory.getLogger(TestParserStrict.class);
@Before
public void setUp() throws Exception {
Modified: chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java?rev=1293600&r1=1293599&r2=1293600&view=diff
==============================================================================
--- chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java (original)
+++ chemistry/opencmis/branches/android/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java Sat Feb 25 13:43:31 2012
@@ -18,11 +18,11 @@
*/
package org.apache.chemistry.opencmis.server.support.query;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Jens
@@ -30,7 +30,7 @@ import org.junit.Test;
*/
public class TestParserStrict extends AbstractParserTest{
- private static final Log log = LogFactory.getLog(TestParserStrict.class);
+ private static final Logger log = LoggerFactory.getLogger(TestParserStrict.class);
@Before
public void setUp() {