You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/09/18 22:45:40 UTC
svn commit: r1387352 - in
/chemistry/playground/chemistry-opencmis-proxybridge: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/chemistry/
src/main/java/org/apache/chemistry/opencmis/ src/main/java...
Author: jens
Date: Tue Sep 18 20:45:39 2012
New Revision: 1387352
URL: http://svn.apache.org/viewvc?rev=1387352&view=rev
Log:
proxybridge: add some very experimental code to playground
Added:
chemistry/playground/chemistry-opencmis-proxybridge/
chemistry/playground/chemistry-opencmis-proxybridge/pom.xml
chemistry/playground/chemistry-opencmis-proxybridge/readme.txt
chemistry/playground/chemistry-opencmis-proxybridge/src/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/Configurator.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ImageScaler.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyBridgeServlet.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyConstants.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyServlet.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/RenditionCmisService.java
chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/log4j.properties
chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/repository.properties
chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/
chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/web.xml
chemistry/playground/chemistry-opencmis-proxybridge/src/test/
chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/
chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/RenditionCreationCmisService.java
Added: chemistry/playground/chemistry-opencmis-proxybridge/pom.xml
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/pom.xml?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/pom.xml (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/pom.xml Tue Sep 18 20:45:39 2012
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+ <!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.chemistry.opencmis</groupId>
+ <artifactId>chemistry-opencmis</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>chemistry-opencmis-proxybridge</artifactId>
+ <name>OpenCMIS Proxy Bridge</name>
+ <packaging>war</packaging>
+
+ <properties>
+ <parentBasedir>../..</parentBasedir>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ <manifestEntries>
+ <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
+ <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.9</version>
+ <configuration>
+ <wtpversion>2.0</wtpversion>
+ <wtpContextName>inmemory</wtpContextName>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>chemistry-opencmis-bridge</artifactId>
+ <version>${project.version}</version>
+ <classifier>classes</classifier>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>chemistry-opencmis-server-bindings</artifactId>
+ <version>${project.version}</version>
+ <classifier>classes</classifier>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>chemistry-opencmis-client-bindings</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>chemistry-opencmis-commons-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.chemistry.opencmis</groupId>
+ <artifactId>chemistry-opencmis-commons-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: chemistry/playground/chemistry-opencmis-proxybridge/readme.txt
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/readme.txt?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/readme.txt (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/readme.txt Tue Sep 18 20:45:39 2012
@@ -0,0 +1,5 @@
+readme.txt:
+===========
+
+Warning: This experimental code is in half-baken state. Please do not use!!!
+
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/Configurator.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/Configurator.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/Configurator.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/Configurator.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,159 @@
+/*
+ * 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.proxybridge;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class Configurator {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Configurator.class.getName());
+
+
+ private static final String PROPERTY_PREFIX = "proxybridge.";
+ private static final String PROPERTY_FORWARD_PREFIX_HTTP = PROPERTY_PREFIX + "addHeaderHttp";
+ private static final String PROPERTY_FORWARD_PREFIX_HTTPS = PROPERTY_PREFIX + "addHeaderHttps";
+ private static final String PROPERTY_METHOD_PREFIX = PROPERTY_PREFIX + "method.";
+
+ private static final String[] methods = { ProxyConstants.APPLY_ACL, ProxyConstants.REMOVE_POLICY, ProxyConstants.APPLY_POLICY,
+ ProxyConstants.CHECK_IN, ProxyConstants.CANCEL_CHECK_OUT, ProxyConstants.CHECK_OUT, ProxyConstants.REMOVE_OBJECT_FROM_FOLDER,
+ ProxyConstants.ADD_OBJECT_TO_FOLDER, ProxyConstants.MOVE_OBJECT, ProxyConstants.DELETE_TREE, ProxyConstants.DELETE_OBJECT,
+ ProxyConstants.DELETE_CONTENT_STREAM, ProxyConstants.SET_CONTENT_STREAM, ProxyConstants.UPDATE_PROPERTIES,
+ ProxyConstants.CREATE_FOLDER, ProxyConstants.GET_ACL, ProxyConstants.GET_APPLIED_POLICIES,
+ ProxyConstants.GET_OBJECT_RELATIONSHIPS, ProxyConstants.GET_ALL_VERSIONS, ProxyConstants.GET_OBJECT_PARENTS,
+ ProxyConstants.GET_FOLDER_PARENT, ProxyConstants.GET_FOLDER_TREE, ProxyConstants.GET_DESCENDANTS, ProxyConstants.GET_CHILDREN,
+ ProxyConstants.GET_CONTENT_STREAM, ProxyConstants.GET_RENDITIONS, ProxyConstants.GET_ALLOWABLE_ACTIONS,
+ ProxyConstants.GET_PROPERTIES, ProxyConstants.GET_OBJECT, ProxyConstants.CREATE_RELATIONSHIP, ProxyConstants.CREATE_POLICY,
+ ProxyConstants.CREATE_DOCUMENT_FROM_SOURCE, ProxyConstants.CREATE_DOCUMENT, ProxyConstants.GET_CONTENT_CHANGES,
+ ProxyConstants.GET_CHECKED_OUT_DOCS, ProxyConstants.QUERY, ProxyConstants.GET_TYPE_DEFINITION,
+ ProxyConstants.GET_TYPE_DESCENDANTS, ProxyConstants.GET_TYPE_CHILDREN, ProxyConstants.GET_LAST_RESULT,
+ ProxyConstants.GET_REPOSITORY_INFO, ProxyConstants.GET_REPOSITORIES };
+
+ private Map<String, Boolean> methodMap = new HashMap<String, Boolean>();
+
+ private String forwardUrl;
+ private boolean addHeaderHttp;
+ private boolean addHeaderHttps;
+ private boolean hasMethodOverrides = false;
+
+ public Configurator() {
+ init();
+ }
+
+ public String getForwardUrl() {
+ return forwardUrl;
+ }
+
+ public boolean addForwardRequestHttp() {
+ return addHeaderHttp;
+ }
+
+ public boolean addForwardRequestHttps() {
+ return addHeaderHttps;
+ }
+
+ public boolean hasMethodOverrides() {
+ return hasMethodOverrides;
+ }
+
+ public final Map<String, Boolean> getMethodMap() {
+ return methodMap;
+ }
+
+ protected void init() {
+
+ String name = "/repository.properties";
+ Properties properties = new Properties();
+ InputStream in = null;
+
+ try {
+ in = this.getClass().getResourceAsStream (name);
+ if (in != null)
+ {
+ properties.load (in);
+ readConfiguration(name, properties);
+ }
+ } catch (Exception e) {
+ LOG.error("Configuration error cannot read properties from " + name, e);
+ e.printStackTrace();
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ LOG.error("Error when closing resource stream", e);
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected void readConfiguration(String name, Properties properties) {
+ // read URL and binding
+ String binding = properties.getProperty("forwarding.binding.org.apache.chemistry.opencmis.binding.spi.type");
+ if (!binding.equals("browser")) {
+ LOG.error("Configuration error: ProxyBridge only supports browser binding, binding is " + binding);
+ return;
+ }
+ forwardUrl = properties.getProperty("forwarding.binding.org.apache.chemistry.opencmis.binding.browser.url");
+ if (null == forwardUrl) {
+ LOG.error("Configuration error: ProxyBridge no URL for target server found in " + name + ". Check configuration.") ;
+ return;
+ }
+ LOG.debug("ProxyBridge configuration, fowarding to " + forwardUrl);
+
+ // read configuration for adding forward headers
+ String propVal = properties.getProperty(PROPERTY_FORWARD_PREFIX_HTTP);
+ if (LOG.isDebugEnabled())
+ LOG.debug("configuration found for key " + PROPERTY_FORWARD_PREFIX_HTTP
+ + " set to value " + Boolean.valueOf(propVal));
+ addHeaderHttp = Boolean.valueOf(propVal);
+ propVal = properties.getProperty(PROPERTY_FORWARD_PREFIX_HTTPS);
+ if (LOG.isDebugEnabled())
+ LOG.debug("configuration found for key " + PROPERTY_FORWARD_PREFIX_HTTPS
+ + " set to value " + Boolean.valueOf(propVal));
+ addHeaderHttps = Boolean.valueOf(propVal);
+
+ // read method overrides
+ for (String method : methods) {
+ propVal = properties.getProperty(PROPERTY_METHOD_PREFIX + method);
+ boolean val = Boolean.valueOf(propVal);
+ if (null != propVal) {
+ if (LOG.isDebugEnabled())
+ LOG.debug("configuration from key " + PROPERTY_METHOD_PREFIX + method + " to value "
+ + val);
+ methodMap.put(method, val);
+ if (val)
+ hasMethodOverrides = true;
+ } else {
+ if (LOG.isDebugEnabled())
+ LOG.debug("no configuration found for key " + PROPERTY_METHOD_PREFIX + method
+ + " set to default value false.");
+ methodMap.put(method, false);
+ }
+ }
+
+ }
+
+
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ImageScaler.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ImageScaler.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ImageScaler.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ImageScaler.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,76 @@
+/*
+ * 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.proxybridge;
+
+import java.awt.AlphaComposite;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.imageio.ImageIO;
+
+public class ImageScaler {
+
+
+ public byte[] scaleImage(InputStream stream, int width, int height) throws IOException {
+
+ BufferedImage originalImage = ImageIO.read(stream);
+
+ BufferedImage resizedImage = new BufferedImage(width, height, originalImage.getType());
+ // ColorSpace.TYPE_RGB);
+ Graphics2D g = resizedImage.createGraphics();
+
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ g.drawImage(originalImage, 0, 0, width, height, null);
+ g.dispose();
+ g.setComposite(AlphaComposite.Src);
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ boolean ok = ImageIO.write(resizedImage, "JPG", os);
+ if (ok)
+ return os.toByteArray();
+ else
+ return null;
+ }
+
+ public void writeImage(BufferedImage image) throws IOException {
+ ImageIO.write(image, "JPG", new File("thumbnail.jpg"));
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ boolean ok = ImageIO.write(image, "JPG", os);
+ if (!ok)
+ System.out.println("Wrting thumbnail failed.");
+ else
+ System.out.println("Wrting thumbnail succeeded.");
+ byte[] bytes = os.toByteArray();
+ System.out.println("Thumbnail has size: " + bytes.length + " Bytes.");
+ }
+
+ private BufferedImage readImage(String fileName) throws IOException {
+ BufferedImage image = ImageIO.read(new File(fileName));
+ return image;
+ }
+
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyBridgeServlet.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyBridgeServlet.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyBridgeServlet.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyBridgeServlet.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,344 @@
+package org.apache.chemistry.opencmis.proxybridge;
+
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_ADD_OBJECT_TO_FOLDER;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_APPLY_ACL;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_APPLY_POLICY;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CANCEL_CHECK_OUT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CHECK_IN;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CHECK_OUT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CREATE_DOCUMENT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CREATE_DOCUMENT_FROM_SOURCE;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CREATE_FOLDER;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CREATE_POLICY;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_CREATE_RELATIONSHIP;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_DELETE;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_DELETE_CONTENT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_DELETE_TREE;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_MOVE;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_QUERY;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_REMOVE_OBJECT_FROM_FOLDER;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_REMOVE_POLICY;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_SET_CONTENT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.CMISACTION_UPDATE_PROPERTIES;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_ACL;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_ALLOWABLEACTIONS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_CHECKEDOUT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_CHILDREN;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_CONTENT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_CONTENT_CHANGES;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_DESCENDANTS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_FOLDER_TREE;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_LAST_RESULT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_OBJECT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_PARENT;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_PARENTS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_POLICIES;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_PROPERTIES;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_QUERY;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_RELATIONSHIPS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_RENDITIONS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_REPOSITORY_INFO;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_TYPE_CHILDREN;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_TYPE_DEFINITION;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_TYPE_DESCENDANTS;
+import static org.apache.chemistry.opencmis.commons.impl.Constants.SELECTOR_VERSIONS;
+
+
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.APPLY_ACL;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.REMOVE_POLICY;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.APPLY_POLICY;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CHECK_IN;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CANCEL_CHECK_OUT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CHECK_OUT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.REMOVE_OBJECT_FROM_FOLDER;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.ADD_OBJECT_TO_FOLDER;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.MOVE_OBJECT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.DELETE_TREE;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.DELETE_OBJECT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.DELETE_CONTENT_STREAM;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.SET_CONTENT_STREAM;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.UPDATE_PROPERTIES;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CREATE_FOLDER;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_ACL;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_APPLIED_POLICIES;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_OBJECT_RELATIONSHIPS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_ALL_VERSIONS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_OBJECT_PARENTS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_FOLDER_PARENT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_FOLDER_TREE;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_DESCENDANTS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_CHILDREN;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_CONTENT_STREAM;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_RENDITIONS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_ALLOWABLE_ACTIONS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_PROPERTIES;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_OBJECT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CREATE_RELATIONSHIP;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CREATE_POLICY;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CREATE_DOCUMENT_FROM_SOURCE;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.CREATE_DOCUMENT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_CONTENT_CHANGES;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_CHECKED_OUT_DOCS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.QUERY;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_TYPE_DEFINITION;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_TYPE_DESCENDANTS;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_TYPE_CHILDREN;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_LAST_RESULT;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_REPOSITORY_INFO;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.GET_REPOSITORIES;
+
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.METHOD_GET;
+import static org.apache.chemistry.opencmis.proxybridge.ProxyConstants.METHOD_POST;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.chemistry.opencmis.commons.impl.Constants;
+import org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils;
+import org.apache.chemistry.opencmis.server.shared.HttpUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Servlet implementation class ProxyBridgeServlet
+ */
+public class ProxyBridgeServlet extends ProxyServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyBridgeServlet.class.getName());
+
+ private Map<String, Boolean> methodMap;
+ private Map<String, String> urlMap = new HashMap<String, String>();
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ initUrlMap();
+
+ methodMap = cfg.getMethodMap();
+
+ forwardUrlPrefix = cfg.getForwardUrl();
+ if (null == forwardUrlPrefix) {
+ String msg = "Configuration error, no URL of target CMIS server configured.";
+ LOG.error(msg);
+ throw new ServletException(msg);
+ }
+ }
+
+ private void initUrlMap() {
+ urlMap.put(getKey(SELECTOR_REPOSITORY_INFO, METHOD_GET), GET_REPOSITORY_INFO);
+ urlMap.put(getKey(SELECTOR_LAST_RESULT, METHOD_GET), GET_LAST_RESULT);
+ urlMap.put(getKey(SELECTOR_TYPE_CHILDREN, METHOD_GET), GET_TYPE_CHILDREN);
+ urlMap.put(getKey(SELECTOR_TYPE_DESCENDANTS, METHOD_GET), GET_TYPE_DESCENDANTS);
+ urlMap.put(getKey(SELECTOR_TYPE_DEFINITION, METHOD_GET), GET_TYPE_DEFINITION);
+ urlMap.put(getKey(SELECTOR_QUERY, METHOD_GET), QUERY);
+ urlMap.put(getKey(SELECTOR_CHECKEDOUT, METHOD_GET), GET_CHECKED_OUT_DOCS);
+ urlMap.put(getKey(SELECTOR_CONTENT_CHANGES, METHOD_GET), GET_CONTENT_CHANGES);
+
+ urlMap.put(getKey(CMISACTION_QUERY, METHOD_POST), QUERY);
+ urlMap.put(getKey(CMISACTION_CREATE_DOCUMENT, METHOD_POST), CREATE_DOCUMENT);
+ urlMap.put(getKey(CMISACTION_CREATE_DOCUMENT_FROM_SOURCE, METHOD_POST), CREATE_DOCUMENT_FROM_SOURCE);
+ urlMap.put(getKey(CMISACTION_CREATE_POLICY, METHOD_POST), CREATE_POLICY);
+ urlMap.put(getKey(CMISACTION_CREATE_RELATIONSHIP, METHOD_POST), CREATE_RELATIONSHIP);
+
+ urlMap.put(getKey(SELECTOR_OBJECT, METHOD_GET), GET_OBJECT);
+ urlMap.put(getKey(SELECTOR_PROPERTIES, METHOD_GET), GET_PROPERTIES);
+ urlMap.put(getKey(SELECTOR_ALLOWABLEACTIONS, METHOD_GET), GET_ALLOWABLE_ACTIONS);
+ urlMap.put(getKey(SELECTOR_RENDITIONS, METHOD_GET), GET_RENDITIONS);
+ urlMap.put(getKey(SELECTOR_CONTENT, METHOD_GET), GET_CONTENT_STREAM);
+ urlMap.put(getKey(SELECTOR_CHILDREN, METHOD_GET), GET_CHILDREN);
+ urlMap.put(getKey(SELECTOR_DESCENDANTS, METHOD_GET), GET_DESCENDANTS);
+ urlMap.put(getKey(SELECTOR_FOLDER_TREE, METHOD_GET), GET_FOLDER_TREE);
+ urlMap.put(getKey(SELECTOR_PARENT, METHOD_GET), GET_FOLDER_PARENT);
+ urlMap.put(getKey(SELECTOR_PARENTS, METHOD_GET), GET_OBJECT_PARENTS);
+ urlMap.put(getKey(SELECTOR_VERSIONS, METHOD_GET), GET_ALL_VERSIONS);
+ urlMap.put(getKey(SELECTOR_RELATIONSHIPS, METHOD_GET), GET_OBJECT_RELATIONSHIPS);
+ urlMap.put(getKey(SELECTOR_CHECKEDOUT, METHOD_GET), GET_CHECKED_OUT_DOCS);
+ urlMap.put(getKey(SELECTOR_POLICIES, METHOD_GET), GET_APPLIED_POLICIES);
+ urlMap.put(getKey(SELECTOR_ACL, METHOD_GET), GET_ACL);
+
+ urlMap.put(getKey(CMISACTION_CREATE_DOCUMENT, METHOD_POST), CREATE_DOCUMENT);
+ urlMap.put(getKey(CMISACTION_CREATE_DOCUMENT_FROM_SOURCE, METHOD_POST), CREATE_DOCUMENT_FROM_SOURCE);
+ urlMap.put(getKey(CMISACTION_CREATE_FOLDER, METHOD_POST), CREATE_FOLDER);
+ urlMap.put(getKey(CMISACTION_CREATE_POLICY, METHOD_POST), CREATE_POLICY);
+ urlMap.put(getKey(CMISACTION_UPDATE_PROPERTIES, METHOD_POST), UPDATE_PROPERTIES);
+ urlMap.put(getKey(CMISACTION_SET_CONTENT, METHOD_POST), SET_CONTENT_STREAM);
+ urlMap.put(getKey(CMISACTION_DELETE_CONTENT, METHOD_POST), DELETE_CONTENT_STREAM);
+ urlMap.put(getKey(CMISACTION_DELETE, METHOD_POST), DELETE_OBJECT);
+ urlMap.put(getKey(CMISACTION_DELETE_TREE, METHOD_POST), DELETE_TREE);
+ urlMap.put(getKey(CMISACTION_MOVE, METHOD_POST), MOVE_OBJECT);
+ urlMap.put(getKey(CMISACTION_ADD_OBJECT_TO_FOLDER, METHOD_POST), ADD_OBJECT_TO_FOLDER);
+ urlMap.put(getKey(CMISACTION_REMOVE_OBJECT_FROM_FOLDER, METHOD_POST), REMOVE_OBJECT_FROM_FOLDER);
+ urlMap.put(getKey(CMISACTION_CHECK_OUT, METHOD_POST), CHECK_OUT);
+ urlMap.put(getKey(CMISACTION_CANCEL_CHECK_OUT, METHOD_POST), CANCEL_CHECK_OUT);
+ urlMap.put(getKey(CMISACTION_CHECK_IN, METHOD_POST), CHECK_IN);
+ urlMap.put(getKey(CMISACTION_APPLY_POLICY, METHOD_POST), APPLY_POLICY);
+ urlMap.put(getKey(CMISACTION_REMOVE_POLICY, METHOD_POST), REMOVE_POLICY);
+ urlMap.put(getKey(CMISACTION_APPLY_ACL, METHOD_POST), APPLY_ACL);
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+
+ String queryString = req.getQueryString();
+ String url = req.getRequestURL().toString() + (null == queryString ? "" : "?" + queryString);
+
+ boolean filterRequest = sendRequestToBridge(url, req);
+ if (filterRequest) {
+ filterRequest(req, resp);
+ } else {
+ super.forwardRequest(req, resp);
+ }
+ }
+
+ /**
+ * @see HttpServlet#HttpServlet()
+ */
+ public ProxyBridgeServlet() {
+ super();
+ }
+
+ private void filterRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String path = getLocalForwardUrl("/browserbridge", request);
+ LOG.debug("filterRequest, forwarding to " + path);
+ RequestDispatcher requestDispatcher = config.getServletContext().getRequestDispatcher(path);
+ if (null == requestDispatcher) {
+ LOG.error("Could not find request disatcher for path " + path);
+ } else {
+ try {
+ requestDispatcher.forward(request, response);
+ } catch (Exception e) {
+ LOG.error("Exception in filtered call", e);
+ throw new ServletException(e);
+ }
+ }
+ }
+
+
+ public boolean sendRequestToBridge(String url, HttpServletRequest request) {
+
+ BrowserBindingUtils.CallUrl callUrl = null;
+
+ // analyze the path
+ String[] pathFragments = HttpUtils.splitPath(request);
+
+ if (pathFragments.length < 1) {
+ return methodMap.get(GET_REPOSITORIES);
+ }
+
+ // select dispatcher
+
+ if (pathFragments.length == 1) {
+ callUrl = BrowserBindingUtils.CallUrl.REPOSITORY;
+ } else if (BrowserBindingUtils.ROOT_PATH_FRAGMENT.equals(pathFragments[1])) {
+ callUrl = BrowserBindingUtils.CallUrl.ROOT;
+ }
+
+ if (callUrl == null) {
+ throw new CmisNotSupportedException("Unknown operation");
+ }
+
+ String method = request.getMethod();
+ // String repositoryId = pathFragments[0];
+ Boolean doFilter = false;
+ String cmisMethod;
+
+ if (METHOD_GET.equals(method)) {
+ String selector = HttpUtils.getStringParameter(request, Constants.PARAM_SELECTOR);
+
+ // dispatch
+ if (callUrl == BrowserBindingUtils.CallUrl.REPOSITORY) {
+ if (selector == null) {
+ selector = "";
+ }
+
+ cmisMethod = urlMap.get(getKey(selector, method));
+ if (null == cmisMethod)
+ LOG.warn("Could not find CMIS method for GET request for selector " + selector);
+
+ } else if (callUrl == BrowserBindingUtils.CallUrl.ROOT) {
+ // set default method if necessary
+ if (selector == null) {
+ LOG.warn("The filter bridge does not allow to omit the selector parameter, please set " +
+ "selector parameter, defaulting to 'object'.");
+// try {
+// BaseTypeId basetype = BaseTypeId.fromValue((String) context.get(CONTEXT_BASETYPE_ID));
+// switch (basetype) {
+// case CMIS_DOCUMENT:
+// selector = SELECTOR_CONTENT;
+// break;
+// case CMIS_FOLDER:
+// selector = SELECTOR_CHILDREN;
+// break;
+// default:
+// selector = SELECTOR_OBJECT;
+// break;
+// }
+// } catch (Exception e) {
+// selector = SELECTOR_OBJECT;
+// }
+ }
+ }
+
+ cmisMethod = urlMap.get(getKey(selector, method));
+ if (null == cmisMethod)
+ LOG.warn("Could not find CMIS method for GET request for selector " + selector);
+
+ } else if (METHOD_POST.equals(method)) {
+ String cmisaction = HttpUtils.getStringParameter(request, Constants.CONTROL_CMISACTION);
+
+ if (cmisaction == null || cmisaction.length() == 0) {
+ LOG.warn("cmisaction parameter is null, defaulting to false");
+ return false;
+ }
+
+ cmisMethod = urlMap.get(getKey(cmisaction, method));
+ if (null == cmisMethod) {
+ LOG.warn("Could not find CMIS method for GET request for selector " + cmisaction);
+ }
+ } else {
+ LOG.error("Unsupported http method for browser binding, must be GET or POST: " + method);
+ cmisMethod = null;
+ }
+
+ if (null == cmisMethod) {
+ doFilter = false;
+ } else {
+ doFilter = methodMap.get(cmisMethod);
+ if (null == doFilter) {
+ LOG.warn("Could not find configuation for method " + cmisMethod + ", defaulting to false");
+ doFilter = false;
+ }
+ }
+
+ return doFilter;
+ }
+
+ /**
+ * Generates a map key from a resource and an HTTP method.
+ */
+ private String getKey(String resource, String httpMethod) {
+ String s = resource + "/" + httpMethod;
+ return s.toUpperCase();
+ }
+
+ protected String getLocalForwardUrl(String urlPrefix, HttpServletRequest request) {
+ String urlString = request.getRequestURL().toString();
+ String queryString = request.getQueryString();
+ int pos = urlString.indexOf("/browser") + 8;
+ String pathToForward = urlString.substring(pos);
+ String result = urlPrefix + pathToForward + (null == queryString ? "" : "?" + queryString);
+ LOG.debug("getLocalForwardUrl() forwarding to " + result);
+ return result;
+ }
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyConstants.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyConstants.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyConstants.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyConstants.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,68 @@
+/*
+ * 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.proxybridge;
+
+public class ProxyConstants {
+ public static final String APPLY_ACL = "applyACL";
+ public static final String REMOVE_POLICY = "removePolicy";
+ public static final String APPLY_POLICY = "applyPolicy";
+ public static final String CHECK_IN = "checkIn";
+ public static final String CANCEL_CHECK_OUT = "cancelCheckOut";
+ public static final String CHECK_OUT = "checkOut";
+ public static final String REMOVE_OBJECT_FROM_FOLDER = "removeObjectFromFolder";
+ public static final String ADD_OBJECT_TO_FOLDER = "addObjectToFolder";
+ public static final String MOVE_OBJECT = "moveObject";
+ public static final String DELETE_TREE = "deleteTree";
+ public static final String DELETE_OBJECT = "deleteObject";
+ public static final String DELETE_CONTENT_STREAM = "deleteContentStream";
+ public static final String SET_CONTENT_STREAM = "setContentStream";
+ public static final String UPDATE_PROPERTIES = "updateProperties";
+ public static final String CREATE_FOLDER = "createFolder";
+ public static final String GET_ACL = "getACL";
+ public static final String GET_APPLIED_POLICIES = "getAppliedPolicies";
+ public static final String GET_OBJECT_RELATIONSHIPS = "getObjectRelationships";
+ public static final String GET_ALL_VERSIONS = "getAllVersions";
+ public static final String GET_OBJECT_PARENTS = "getObjectParents";
+ public static final String GET_FOLDER_PARENT = "getFolderParent";
+ public static final String GET_FOLDER_TREE = "getFolderTree";
+ public static final String GET_DESCENDANTS = "getDescendants";
+ public static final String GET_CHILDREN = "getChildren";
+ public static final String GET_CONTENT_STREAM = "getContentStream";
+ public static final String GET_RENDITIONS = "getRenditions";
+ public static final String GET_ALLOWABLE_ACTIONS = "getAllowableActions";
+ public static final String GET_PROPERTIES = "getProperties";
+ public static final String GET_OBJECT = "getObject";
+ public static final String CREATE_RELATIONSHIP = "createRelationship";
+ public static final String CREATE_POLICY = "createPolicy";
+ public static final String CREATE_DOCUMENT_FROM_SOURCE = "createDocumentFromSource";
+ public static final String CREATE_DOCUMENT = "createDocument";
+ public static final String GET_CONTENT_CHANGES = "getContentChanges";
+ public static final String GET_CHECKED_OUT_DOCS = "getCheckedOutDocs";
+ public static final String QUERY = "query";
+ public static final String GET_TYPE_DEFINITION = "getTypeDefinition";
+ public static final String GET_TYPE_DESCENDANTS = "getTypeDescendants";
+ public static final String GET_TYPE_CHILDREN = "getTypeChildren";
+ public static final String GET_LAST_RESULT = "getLastResult";
+ public static final String GET_REPOSITORY_INFO = "getRepositoryInfo";
+ public static final String GET_REPOSITORIES = "getRepositories";
+
+ public static final String METHOD_GET = "GET";
+ public static final String METHOD_POST = "POST";
+
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyServlet.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyServlet.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyServlet.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/ProxyServlet.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,237 @@
+package org.apache.chemistry.opencmis.proxybridge;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Servlet implementation class ProxyServlet
+ */
+public class ProxyServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger LOG = LoggerFactory.getLogger(ProxyServlet.class.getName());
+
+ public static final String FORWARDED_HOST_HEADER = "X-Forwarded-Host";
+ public static final String FORWARDED_PROTO_HEADER = "X-Forwarded-Proto";
+ public static final String HTTPS_SCHEME = "https";
+ public static final String HTTP_SCHEME = "http";
+
+ protected String forwardUrlPrefix;
+ protected ServletConfig config;
+ protected Configurator cfg;
+
+ /**
+ * @see HttpServlet#HttpServlet()
+ */
+ public ProxyServlet() {
+ super();
+ }
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ this.config = config;
+ cfg = new Configurator();
+ forwardUrlPrefix = cfg.getForwardUrl();
+ if (null == forwardUrlPrefix) {
+ String msg = "Configuration error, no URL of target CMIS server configured.";
+ LOG.error(msg);
+ throw new ServletException(msg);
+ }
+ }
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+
+ forwardRequest(req, resp);
+ }
+
+ protected void forwardRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
+
+ InputStream clientRequestIS = null;
+ OutputStream clientResponseOS = null;
+ InputStream responseIS = null;
+ OutputStream responseOS = null;
+
+ HttpURLConnection con;
+
+ try{
+ int statusCode;
+ byte[] buf = new byte[65536];
+ int bytesRead;
+ String methodName;
+
+ String pathToForward = getForwardUrl(forwardUrlPrefix, request);
+
+ URL url = new URL(pathToForward);
+
+ methodName = request.getMethod();
+ LOG.debug("Forwarding to: " + methodName + " " + pathToForward);
+
+ con =(HttpURLConnection) url.openConnection();
+ con.setDoOutput(true);
+ con.setDoInput(true);
+ con.setUseCaches(true);
+ con.setInstanceFollowRedirects(false); // do not follow redirects delegate back to client
+
+ for( Enumeration<?> e = request.getHeaderNames() ; e.hasMoreElements();){
+ String headerName = e.nextElement().toString();
+ con.setRequestProperty(headerName, request.getHeader(headerName));
+ }
+
+ String proto = url.getProtocol();
+ if ((cfg.addForwardRequestHttp() && proto.equalsIgnoreCase("http")) ||
+ (cfg.addForwardRequestHttps() && proto.equalsIgnoreCase("https"))) {
+ int port = url.getPort();
+ if (port < 0)
+ port = url.getDefaultPort();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Add X-Forwarded-Host header: " + url.getHost() + ":" + port);
+ LOG.debug("Add X-Forwarded-Proto header: " + url.getProtocol());
+ }
+ con.setRequestProperty(FORWARDED_HOST_HEADER, url.getHost() + ":" + port);
+ con.setRequestProperty(FORWARDED_PROTO_HEADER, url.getProtocol());
+ }
+
+ clientRequestIS = request.getInputStream();
+
+ con.setRequestMethod(methodName);
+
+ while ((bytesRead = clientRequestIS.read(buf)) != -1) {
+ if (null == responseOS) {
+ con.setDoOutput(true);
+ responseOS = con.getOutputStream(); // call getOutputStream only if data are read
+ }
+ responseOS.write(buf, 0, bytesRead);
+ }
+
+ // if we could not read the body in a POST request, check if parameters already have been read
+ // and must be re-sent
+ if (methodName.equalsIgnoreCase(ProxyConstants.METHOD_POST) && null == responseOS) {
+ String postBody = processPostParametersFromBody(request);
+ if (null != postBody) {
+ responseOS = con.getOutputStream();
+ responseOS.write(postBody.toString().getBytes());
+ }
+ }
+
+ con.connect();
+
+ if (null != responseOS) {
+ responseOS.flush();
+ responseOS.close();
+ }
+ clientRequestIS.close();
+
+ // wait for response
+ statusCode = con.getResponseCode();
+ LOG.debug("Received response with status code: " + statusCode + ", content length is: " + con.getContentLength());
+ response.setStatus(statusCode);
+
+ if (statusCode > 400 && statusCode < 600) {
+ responseIS = con.getErrorStream();
+ } else {
+ responseIS = con.getInputStream();
+ }
+
+ Map<String, List<String>> headerFields = con.getHeaderFields();
+ for (Map.Entry<String, List<String>> entry: headerFields.entrySet()) {
+ if (entry.getKey()!=null)
+ response.setHeader(entry.getKey(), entry.getValue().get(0));
+ }
+
+ while ((bytesRead = responseIS.read(buf)) != -1) {
+ if (null == clientResponseOS) {
+ clientResponseOS = response.getOutputStream();
+ }
+ clientResponseOS.write(buf, 0, bytesRead);
+ }
+
+ if (null != clientResponseOS) {
+ clientResponseOS.flush();
+ clientResponseOS.close();
+ }
+
+ responseIS.close();
+
+ }catch(Exception e){
+ LOG.error("Error in proxying request." , e);
+ e.printStackTrace();
+ throw new ServletException(e);
+ }
+ finally{
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private String processPostParametersFromBody(HttpServletRequest request) throws UnsupportedEncodingException {
+
+ Map<String, String[]> parameters = (Map<String, String[]>) request.getParameterMap();
+ String queryString = request.getQueryString();
+ StringBuffer postBody = new StringBuffer();
+ boolean first=true;
+ for (Map.Entry<String, String[]> parameter : parameters.entrySet()) {
+ // if parameter is not in queryString append it to body
+ if (queryString == null || !queryString.contains(parameter.getKey())) {
+ if (!first)
+ postBody.append("&");
+ else
+ first = false;
+ String[] value = parameter.getValue();
+ if (value == null) {
+ postBody.append(parameter.getKey());
+ } else {
+ for (int i=0; i<value.length; i++) {
+ if (i>0)
+ postBody.append("&");
+ postBody.append(parameter.getKey());
+ postBody.append(("="));
+ postBody.append(URLEncoder.encode(value[i], "UTF-8"));
+ }
+ }
+ }
+ }
+ if (postBody.length() > 0) {
+ return postBody.toString();
+ } else
+ return null;
+ }
+
+ protected String getForwardUrl(String urlPrefix, HttpServletRequest request) {
+ urlPrefix = urlPrefix.substring(0, urlPrefix.lastIndexOf("/"));
+ String urlString = request.getRequestURL().toString();
+ String queryString = request.getQueryString();
+ String ctxPath = request.getContextPath();
+ String servletPath = request.getServletPath();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Forwarding URK prefix truncated to: "+ urlPrefix);
+ LOG.debug("Original request url: "+ urlString);
+ LOG.debug("Original query string: "+ queryString);
+ LOG.debug("servlet path: "+ servletPath);
+ LOG.debug("context path: "+ ctxPath);
+ }
+ int pos = urlString.indexOf(servletPath);
+ String pathToForward = urlString.substring(pos);
+ String result = urlPrefix + pathToForward + (null == queryString ? "" : "?" + queryString);
+ LOG.debug("getForwardUrl() forwarding to " + result);
+ return result;
+ }
+
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/RenditionCmisService.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/RenditionCmisService.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/RenditionCmisService.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/java/org/apache/chemistry/opencmis/proxybridge/RenditionCmisService.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,188 @@
+/*
+ * 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.proxybridge;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.bridge.client.SimpleCmisBindingFactory;
+import org.apache.chemistry.opencmis.bridge.httpsession.HttpSessionCmisService;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
+import org.apache.chemistry.opencmis.commons.data.RepositoryCapabilities;
+import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
+import org.apache.chemistry.opencmis.commons.enums.CapabilityRenditions;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.RenditionDataImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryCapabilitiesImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.RepositoryInfoImpl;
+import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
+import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
+
+public class RenditionCmisService extends HttpSessionCmisService {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private static final String RENDITION_SUFFIX = "-rendition";
+ private static final int IMG_WIDTH = 100;
+ private static final int IMG_HEIGHT = 100;
+ private static final String BINDING_PARAMETERS_PREFIX = "forwarding.binding.";
+ private static final String RENDITION_MIME_TYPE = "image/jpeg";
+
+ private Map<String, String> bindingParameters;
+ private BindingsObjectFactory objFactory;
+ CmisBinding binding;
+ ImageScaler scaler = new ImageScaler();
+
+ @Override
+ public CmisBinding createCmisBinding() {
+ binding = SimpleCmisBindingFactory.createCmisBinding(getCallContext(), bindingParameters);
+ objFactory = binding.getObjectFactory();
+ return binding;
+ }
+
+ @Override
+ public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
+
+ List<RepositoryInfo> repoInfos = binding.getRepositoryService().getRepositoryInfos(extension);
+ List<RepositoryInfo> repoInfosNew = new ArrayList<RepositoryInfo>();
+ RepositoryInfo repoInfoNew;
+
+ for (RepositoryInfo repoInfo : repoInfos) {
+ repoInfoNew = getRepositoryInfo(repoInfo.getId(), null);
+ repoInfosNew.add(repoInfoNew);
+ }
+ return repoInfosNew;
+ }
+
+ @Override
+ public void init(Map<String, String> parameters) {
+ super.init(parameters);
+
+ // gather binding parameters
+ bindingParameters = new HashMap<String, String>();
+
+ for (Map.Entry<String, String> p : parameters.entrySet()) {
+ if (p.getKey().startsWith(BINDING_PARAMETERS_PREFIX)) {
+ bindingParameters.put(p.getKey().substring(BINDING_PARAMETERS_PREFIX.length()), p.getValue());
+ }
+ }
+ }
+
+
+ @Override
+ public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension) {
+
+ RepositoryInfo repInfo = getCmisBinding().getRepositoryService().getRepositoryInfo(repositoryId, extension);
+
+ RepositoryInfoImpl newRepInfo = new RepositoryInfoImpl(repInfo);
+ newRepInfo.setDescription(repInfo.getDescription() + " (forwarded by the OpenCMIS ProxyBridge)");
+ RepositoryCapabilities capabilities = repInfo.getCapabilities();
+ RepositoryCapabilitiesImpl newCaps = new RepositoryCapabilitiesImpl();
+ newCaps.setAllVersionsSearchable(capabilities.isAllVersionsSearchableSupported());
+ newCaps.setCapabilityAcl(capabilities.getAclCapability());
+ newCaps.setCapabilityChanges(capabilities.getChangesCapability());
+ newCaps.setCapabilityContentStreamUpdates(capabilities.getContentStreamUpdatesCapability());
+ newCaps.setExtensions(capabilities.getExtensions());
+ newCaps.setCapabilityJoin(capabilities.getJoinCapability());
+ newCaps.setCapabilityQuery(capabilities.getQueryCapability());
+ newCaps.setCapabilityRendition(CapabilityRenditions.READ);
+ newCaps.setIsPwcSearchable(capabilities.isPwcSearchableSupported());
+ newCaps.setIsPwcUpdatable(capabilities.isPwcUpdatableSupported());
+ newCaps.setSupportsGetDescendants(capabilities.isGetDescendantsSupported());
+ newCaps.setSupportsGetFolderTree(capabilities.isGetFolderTreeSupported());
+ newCaps.setSupportsMultifiling(capabilities.isMultifilingSupported());
+ newCaps.setSupportsUnfiling(capabilities.isUnfilingSupported());
+ newCaps.setSupportsVersionSpecificFiling(capabilities.isUnfilingSupported());
+ newRepInfo.setCapabilities(newCaps);
+ return newRepInfo;
+ }
+
+ @Override
+ public List<RenditionData> getRenditions(String repositoryId, String objectId, String renditionFilter,
+ BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
+
+ String tokenizer = "[\\s;]";
+ String[] formats = renditionFilter.split(tokenizer);
+ boolean isImageRendition = testRenditionFilterForImage(formats);
+ if (isImageRendition) {
+ List<RenditionData> renditions = new ArrayList<RenditionData>(1);
+ RenditionDataImpl rendition = new RenditionDataImpl();
+ rendition.setBigHeight(BigInteger.valueOf(IMG_HEIGHT));
+ rendition.setBigWidth(BigInteger.valueOf(IMG_WIDTH));
+ rendition.setKind("cmis:thumbnail");
+ rendition.setMimeType(RENDITION_MIME_TYPE);
+ rendition.setRenditionDocumentId(objectId);
+ rendition.setStreamId(objectId + RENDITION_SUFFIX);
+ rendition.setBigLength(BigInteger.ZERO);
+ renditions.add(rendition);
+ return renditions;
+ } else {
+ return binding.getObjectService().getRenditions(repositoryId, objectId, renditionFilter, maxItems, skipCount, extension);
+ }
+ }
+
+ private boolean testRenditionFilterForImage(String[] formats) {
+ return arrayContainsString(formats, "*") || arrayContainsString(formats, "image/*")
+ || arrayContainsString(formats, "image/jpeg") ;
+ }
+
+ private boolean arrayContainsString(String[] arr, String val) {
+ for (String s : arr) {
+ if (val.equals(s))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public ContentStream getContentStream(String repositoryId, String objectId, String streamId, BigInteger offset,
+ BigInteger length, ExtensionsData extension) {
+ if (null != streamId && streamId.endsWith(RENDITION_SUFFIX))
+ return getRendition(repositoryId, streamId.substring(0, streamId.length() - RENDITION_SUFFIX.length()));
+ else
+ return binding.getObjectService().getContentStream(repositoryId, objectId, streamId, offset, length, extension);
+ }
+
+ private ContentStream getRendition(String repositoryId, String objectId) {
+ String streamId = null;
+ ContentStream mainContent = binding.getObjectService().getContentStream(repositoryId, streamId, streamId, null, null, null);
+ byte[] thumbnail;
+ try {
+ thumbnail = scaler.scaleImage(mainContent.getStream(), IMG_WIDTH, IMG_HEIGHT);
+ ContentStreamImpl cs = new ContentStreamImpl();
+ cs.setFileName("thumbnail.jog");
+ cs.setMimeType(RENDITION_MIME_TYPE);
+ cs.setStream(new ByteArrayInputStream(thumbnail));
+ return cs;
+ } catch (IOException e) {
+ throw new CmisRuntimeException("Failed to generate thumbnail", e);
+ }
+ }
+
+}
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/log4j.properties?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/log4j.properties (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/log4j.properties Tue Sep 18 20:45:39 2012
@@ -0,0 +1,37 @@
+# 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.
+
+# sample log4j.properties
+
+log4j.rootCategory=WARN, R, O
+
+# Stdout
+log4j.appender.O=org.apache.log4j.ConsoleAppender
+
+# File
+log4j.appender.R=org.apache.log4j.RollingFileAppender
+log4j.appender.R.File=target/logs/log4j.log
+
+# Control the maximum log file size
+log4j.appender.R.MaxFileSize=100KB
+
+# Archive log files (one backup file here)
+log4j.appender.R.MaxBackupIndex=1
+log4j.appender.R.layout=org.apache.log4j.PatternLayout
+log4j.appender.O.layout=org.apache.log4j.PatternLayout
+log4j.appender.R.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c: %m%n
+log4j.appender.O.layout.ConversionPattern=%d{ISO8601} %-5p [%t] %c: %m%n
+
+log4j.logger.org.apache.chemistry.opencmis.proxybridge=DEBUG
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/repository.properties
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/repository.properties?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/repository.properties (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/resources/repository.properties Tue Sep 18 20:45:39 2012
@@ -0,0 +1,121 @@
+# 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.
+
+
+###########################################################
+#
+# Bridge configuration
+#
+# Note: class MUST be set
+#
+###########################################################
+
+class=org.apache.chemistry.opencmis.bridge.httpsession.HttpSessionBridgeServiceFactory
+# bridge.tempDirectory=/tmp
+# bridge.memoryThreshold=4194304
+# bridge.maxContentSize=4294967296
+
+# cache.size=1000
+
+
+###########################################################
+#
+# Service configuration
+#
+# Note: service.class MUST be set
+#
+###########################################################
+
+# service.class=org.apache.chemistry.opencmis.bridge.httpsession.sample.SimpleForwardingCmisService
+service.class=org.apache.chemistry.opencmis.proxybridge.RenditionCmisService
+# service.defaultMaxItems=100000
+# service.defaultDepth=-1
+# service.defaultTypesMaxItems=1000
+# service.defaultTypesDepth=10
+
+
+###########################################################
+#
+# Sample configuration for the SimpleForwardingCmisService
+#
+# Note: user name and password are added on-the-fly
+#
+###########################################################
+
+forwarding.binding.org.apache.chemistry.opencmis.binding.spi.type=browser
+forwarding.binding.org.apache.chemistry.opencmis.binding.browser.url=http://localhost:8080/inmemory/browser
+forwarding.binding.org.apache.chemistry.opencmis.binding.compression=true
+forwarding.binding.org.apache.chemistry.opencmis.binding.cookies=true
+
+###########################################################
+#
+# Sample configuration ProxyBridgeServlet
+# Note: setting the following properties to true
+# will add X-Forwarded-Host and X-Forwarded-Proto
+# headers to all forwarded requests (using configured URL)
+###########################################################
+proxybridge.addHeaderHttp = true
+proxybridge.addHeaderHttps = true
+
+###########################################################
+#
+# Method overrides for ProxyBridgeServlet
+# Note: set to true passes the request to opencmis bridge
+# set to false directly sends it to target server
+#
+###########################################################
+proxybridge.method.applyACL = false
+proxybridge.method.removePolicy = false
+proxybridge.method.applyPolicy = false
+proxybridge.method.checkIn = false
+proxybridge.method.cancelCheckOut = false
+proxybridge.method.checkOut = false
+proxybridge.method.removeObjectFromFolder = false
+proxybridge.method.addObjectToFolder = false
+proxybridge.method.moveObject = false
+proxybridge.method.deleteTree = false
+proxybridge.method.deleteObject = false
+proxybridge.method.deleteContentStream = false
+proxybridge.method.setContentStream = false
+proxybridge.method.updateProperties = false
+proxybridge.method.createFolder = false
+proxybridge.method.getACL = false
+proxybridge.method.getAppliedPolicies = false
+proxybridge.method.getObjectRelationships = false
+proxybridge.method.getAllVersions = false
+proxybridge.method.getObjectParents = false
+proxybridge.method.getFolderParent = false
+proxybridge.method.getFolderTree = false
+proxybridge.method.getDescendants = false
+proxybridge.method.getChildren = false
+proxybridge.method.getContentStream = false
+proxybridge.method.getRenditions = true
+proxybridge.method.getAllowableActions = false
+proxybridge.method.getProperties = false
+proxybridge.method.getObject = false
+proxybridge.method.createRelationship = false
+proxybridge.method.createPolicy = false
+proxybridge.method.createDocumentFromSource = false
+proxybridge.method.createDocument = false
+proxybridge.method.getContentChanges = false
+proxybridge.method.getCheckedOutDocs = false
+proxybridge.method.query = false
+proxybridge.method.getTypeDefinition = false
+proxybridge.method.getTypeDescendants = false
+proxybridge.method.getTypeChildren = false
+proxybridge.method.getLastResult = false
+proxybridge.method.getRepositoryInfo = true
+proxybridge.method.getRepositories = true
+
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/web.xml?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/web.xml (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/main/webapp/WEB-INF/web.xml Tue Sep 18 20:45:39 2012
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<web-app version="2.4"
+ xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <display-name>OpenCMIS Proxy-Bridge</display-name>
+
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>proxybridge</servlet-name>
+ <servlet-class>org.apache.chemistry.opencmis.proxybridge.ProxyBridgeServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>proxybridge</servlet-name>
+ <url-pattern>/browser/*</url-pattern>
+ </servlet-mapping>
+<!-- -->
+ <servlet>
+ <servlet-name>cmisbrowser</servlet-name>
+ <servlet-class>org.apache.chemistry.opencmis.server.impl.browser.CmisBrowserBindingServlet</servlet-class>
+ <init-param>
+ <param-name>callContextHandler</param-name>
+ <param-value>org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler</param-value>
+ </init-param>
+
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+
+ <servlet>
+ <description>
+ </description>
+ <display-name>ProxyServlet</display-name>
+ <servlet-name>ProxyServlet</servlet-name>
+ <servlet-class>org.apache.chemistry.opencmis.proxybridge.ProxyBridgeServlet</servlet-class>
+ </servlet>
+
+ <context-param>
+ <param-name>org.apache.chemistry.opencmis.servicesfactory</param-name>
+ <param-value>org.apache.chemistry.opencmis.bridge.client.SimpleCmisBindingFactory</param-value>
+ </context-param>
+
+ <servlet-mapping>
+ <servlet-name>cmisbrowser</servlet-name>
+ <url-pattern>/browserbridge/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>ProxyServlet</servlet-name>
+ <url-pattern>/ProxyServlet</url-pattern>
+ </servlet-mapping>
+<!-- -->
+
+ <servlet>
+ <servlet-name>cmisws</servlet-name>
+ <servlet-class>org.apache.chemistry.opencmis.proxybridge.ProxyServlet</servlet-class>
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>cmisws</servlet-name>
+ <url-pattern>/services/*</url-pattern>
+ </servlet-mapping>
+
+
+ <servlet>
+ <servlet-name>cmisatom</servlet-name>
+ <servlet-class>org.apache.chemistry.opencmis.proxybridge.ProxyServlet</servlet-class>
+ <init-param>
+ <param-name>callContextHandler</param-name>
+ <param-value>org.apache.chemistry.opencmis.server.shared.BasicAuthCallContextHandler</param-value>
+ </init-param>
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>cmisatom</servlet-name>
+ <url-pattern>/atom/*</url-pattern>
+ </servlet-mapping>
+
+
+ <listener>
+ <listener-class>org.apache.chemistry.opencmis.server.impl.CmisRepositoryContextListener</listener-class>
+ </listener>
+
+
+ <session-config>
+ <session-timeout>60</session-timeout>
+ </session-config>
+</web-app>
Added: chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/RenditionCreationCmisService.java
URL: http://svn.apache.org/viewvc/chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/RenditionCreationCmisService.java?rev=1387352&view=auto
==============================================================================
--- chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/RenditionCreationCmisService.java (added)
+++ chemistry/playground/chemistry-opencmis-proxybridge/src/test/java/RenditionCreationCmisService.java Tue Sep 18 20:45:39 2012
@@ -0,0 +1,53 @@
+import java.math.BigInteger;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.chemistry.opencmis.bridge.client.SimpleCmisBindingFactory;
+import org.apache.chemistry.opencmis.bridge.httpsession.HttpSessionCmisService;
+import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
+import org.apache.chemistry.opencmis.commons.data.RenditionData;
+import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
+
+/*
+ * 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.
+ */
+
+public class RenditionCreationCmisService extends HttpSessionCmisService {
+
+ private Map<String, String> bindingParameters;
+
+ @Override
+ public void init(Map<String, String> parameters) {
+ super.init(parameters);
+ }
+
+ @Override
+ public CmisBinding createCmisBinding() {
+ return SimpleCmisBindingFactory.createCmisBinding(getCallContext(), bindingParameters);
+ }
+
+ @Override
+ public List<RenditionData> getRenditions(String repositoryId, String objectId, String renditionFilter,
+ BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
+ // TODO Auto-generated method stub
+ return super.getRenditions(repositoryId, objectId, renditionFilter, maxItems, skipCount, extension);
+ }
+
+
+}