exo-jcr SVN: r2726 - jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-30 09:23:12 -0400 (Wed, 30 Jun 2010)
New Revision: 2726
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
Log:
EXOJCR-817: max-buffer-size from configuration should be use in TransientValueData during import
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2010-06-30 12:18:49 UTC (rev 2725)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2010-06-30 13:23:12 UTC (rev 2726)
@@ -53,7 +53,9 @@
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.ConversationState;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -421,14 +423,23 @@
{
try
{
+ InputStream vStream = new ByteArrayInputStream(Base64.decode(propertiesMap.get(propName)));
+ TransientValueData binaryValue =
+ new TransientValueData(0, vStream, valueFactory.getFileCleaner(), valueFactory.getMaxBufferSize(), null,
+ true);
+ binaryValue.getAsStream().close();
+
newProperty =
- TransientPropertyData.createPropertyData(getParent(), propName, PropertyType.BINARY, false,
- new TransientValueData(0, Base64.decode(propertiesMap.get(propName))));
+ TransientPropertyData.createPropertyData(getParent(), propName, PropertyType.BINARY, false, binaryValue);
}
catch (DecodingException e)
{
throw new RepositoryException(e);
}
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
return newProperty;
}
13 years, 10 months
exo-jcr SVN: r2725 - jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-30 08:18:49 -0400 (Wed, 30 Jun 2010)
New Revision: 2725
Modified:
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
Log:
EXOJCR-482 : cleanup
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-30 11:45:08 UTC (rev 2724)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/script/groovy/GroovyScript2RestLoaderTest.java 2010-06-30 12:18:49 UTC (rev 2725)
@@ -55,9 +55,6 @@
private ResourceBinder binder;
- @Deprecated
- private RequestHandler handler;
-
private ThreadLocalSessionProviderService sesProv;
private Node scriptFile;
@@ -83,7 +80,7 @@
sesProv.setSessionProvider(null, new SessionProvider(new ConversationState(new Identity("root"))));
binder = (ResourceBinder)container.getComponentInstanceOfType(ResourceBinder.class);
resourceNumber = binder.getSize();
- handler = (RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
+ RequestHandler handler = (RequestHandler)container.getComponentInstanceOfType(RequestHandler.class);
testRoot = root.addNode("testRoot", "nt:unstructured");
scriptFile = testRoot.addNode("script", "nt:file");
13 years, 10 months
exo-jcr SVN: r2724 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing.
by do-not-reply@jboss.org
Author: tolusha
Date: 2010-06-30 07:45:08 -0400 (Wed, 30 Jun 2010)
New Revision: 2724
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
Log:
EXOJCR-817: max-buffer-size from configuration should be use in TransientValueData during import
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2010-06-30 08:11:08 UTC (rev 2723)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/DocumentViewImporter.java 2010-06-30 11:45:08 UTC (rev 2724)
@@ -53,7 +53,9 @@
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.ConversationState;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -421,14 +423,23 @@
{
try
{
+ InputStream vStream = new ByteArrayInputStream(Base64.decode(propertiesMap.get(propName)));
+ TransientValueData binaryValue =
+ new TransientValueData(0, vStream, valueFactory.getFileCleaner(), valueFactory.getMaxBufferSize(), null,
+ true);
+ binaryValue.getAsStream().close();
+
newProperty =
- TransientPropertyData.createPropertyData(getParent(), propName, PropertyType.BINARY, false,
- new TransientValueData(0, Base64.decode(propertiesMap.get(propName))));
+ TransientPropertyData.createPropertyData(getParent(), propName, PropertyType.BINARY, false, binaryValue);
}
catch (DecodingException e)
{
throw new RepositoryException(e);
}
+ catch (IOException e)
+ {
+ throw new RepositoryException(e);
+ }
return newProperty;
}
13 years, 10 months
exo-jcr SVN: r2723 - core/branches/2.3.x/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-30 04:11:08 -0400 (Wed, 30 Jun 2010)
New Revision: 2723
Modified:
core/branches/2.3.x/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java
Log:
EXOJCR-772 cause added to thrown LoginException
Modified: core/branches/2.3.x/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java
===================================================================
--- core/branches/2.3.x/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java 2010-06-30 08:07:27 UTC (rev 2722)
+++ core/branches/2.3.x/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java 2010-06-30 08:11:08 UTC (rev 2723)
@@ -77,7 +77,9 @@
}
catch (final Throwable e)
{
- throw new LoginException(e.getMessage());
+ LoginException le = new LoginException(e.getMessage());
+ le.initCause(e);
+ throw le;
}
}
13 years, 10 months
exo-jcr SVN: r2722 - in jcr/trunk/exo.jcr.component.core/src: test/java/org/exoplatform/services/jcr/api/observation and 2 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2010-06-30 04:07:27 -0400 (Wed, 30 Jun 2010)
New Revision: 2722
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/observation/TestSessionsObservation.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestAccess.java
Log:
EXOJCR-768: Fixing some tests that were using a session after logout. And added log.warn(...) in ItemImpl.checkValid() if session is logged out.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-30 08:06:30 UTC (rev 2721)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/ItemImpl.java 2010-06-30 08:07:27 UTC (rev 2722)
@@ -153,8 +153,18 @@
*/
protected boolean checkValid() throws InvalidItemStateException
{
+ if (!session.isLive())
+ {
+ log
+ .warn(
+ "This kind of operation is forbidden after a session.logout(), please note that an exception will be raised in the next jcr version.",
+ new Exception());
+ }
+
if (data == null)
+ {
throw new InvalidItemStateException("Invalid item state. Item was removed or discarded.");
+ }
session.updateLastAccessTime();
return true;
@@ -221,7 +231,9 @@
checkValid();
if (isRoot())
+ {
throw new ItemNotFoundException("Root node does not have a parent");
+ }
return parent(true);
}
@@ -251,10 +263,14 @@
if (isValid())
{
if (otherItem == null)
+ {
return false;
+ }
if (!this.getClass().equals(otherItem.getClass()))
+ {
return false;
+ }
try
{
@@ -454,7 +470,9 @@
identifier = prevProp.getInternalIdentifier();
version = prevProp.getData().getPersistedVersion();
if (propertyValues == null)
+ {
state = ItemState.DELETED;
+ }
else
{
state = ItemState.UPDATED;
@@ -551,7 +569,9 @@
else
{
if (log.isDebugEnabled())
+ {
log.debug("Set null value (" + getPath() + ", multivalued: " + multiValue + ")");
+ }
}
}
}
@@ -642,10 +662,14 @@
// mix:referenceable
if (changedItem.isDeleted())
+ {
refNodes.add(refNode); // add to refs (delete - alway is first)
+ }
else if (changedItem.isAdded() || changedItem.isRenamed())
+ {
refNodes.remove(refNode); // remove from refs (add - always at the
- // end)
+ // end)
+ }
}
}
}
@@ -659,7 +683,9 @@
// if ref property is deleted in this session
ItemState refState = dataManager.getChangesLog().getItemState(refProp.getIdentifier());
if (refState != null && refState.isDeleted())
+ {
continue;
+ }
NodeData refParent = (NodeData)dataManager.getItemData(refProp.getParentIdentifier());
AccessControlList acl = refParent.getACL();
@@ -803,7 +829,9 @@
public JCRPath getLocation() throws RepositoryException
{
if (this.location == null)
+ {
this.location = session.getLocationFactory().createJCRPath(qpath);
+ }
return this.location;
}
@@ -869,7 +897,9 @@
ItemImpl otherItem = (ItemImpl)obj;
if (!otherItem.isValid() || !this.isValid())
+ {
return false;
+ }
try
{
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/observation/TestSessionsObservation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/observation/TestSessionsObservation.java 2010-06-30 08:06:30 UTC (rev 2721)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/observation/TestSessionsObservation.java 2010-06-30 08:07:27 UTC (rev 2722)
@@ -59,6 +59,9 @@
testRootWs.remove();
session.save();
+ sessionWs1 = (SessionImpl)repository.login(credentials, "ws1");
+ testRootWs1 = sessionWs1.getRootNode().getNode("observationTest");
+
testRootWs1.remove();
sessionWs1.save();
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java 2010-06-30 08:06:30 UTC (rev 2721)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/reading/TestSession.java 2010-06-30 08:07:27 UTC (rev 2722)
@@ -20,6 +20,7 @@
import org.exoplatform.services.jcr.JcrAPIBaseTest;
import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.core.SessionImpl;
import java.util.Calendar;
@@ -86,7 +87,8 @@
public void testLogout() throws Exception
{
- session.logout();
+ Session localSession = repository.login(credentials, "ws");
+ localSession.logout();
}
public void testGetRootNode() throws RepositoryException
@@ -150,7 +152,9 @@
{
// folder.refresh(false);
if (log.isDebugEnabled())
+ {
log.debug("SDM before remove: " + session.getTransientNodesManager().dump());
+ }
folder.remove();
session.save();
}
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestAccess.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestAccess.java 2010-06-30 08:06:30 UTC (rev 2721)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/access/TestAccess.java 2010-06-30 08:07:27 UTC (rev 2722)
@@ -67,7 +67,9 @@
session.save();
}
else
+ {
accessTestRoot = (ExtendedNode)session.getRootNode().getNode("accessTestRoot");
+ }
}
@Override
@@ -78,6 +80,7 @@
super.tearDown();
}
+ @Override
public String getRepositoryName()
{
return "db1";
@@ -178,7 +181,9 @@
session.save();
if (log.isDebugEnabled())
+ {
log.debug("NODE PERM 1 >>> " + node.getACL().dump());
+ }
// change permission
HashMap<String, String[]> perm = new HashMap<String, String[]>();
perm.put("john", new String[]{PermissionType.ADD_NODE, PermissionType.READ});
@@ -187,22 +192,30 @@
// showPermissions("accessTestRoot/testIfPermissionSaved");
if (log.isDebugEnabled())
+ {
log.debug("NODE PERM 1 >>> " + node.getACL().dump());
+ }
session.save();
if (log.isDebugEnabled())
+ {
log.debug("NODE PERM 2 >>> " + node.getACL().dump());
+ }
// get node in new session
NodeImpl testNode =
(NodeImpl)repository.getSystemSession().getRootNode().getNode("accessTestRoot/testIfPermissionSaved");
if (log.isDebugEnabled())
+ {
log.debug("NODE PERM 4 >>> " + node.getACL().dump());
+ }
if (log.isDebugEnabled())
+ {
log.debug("TEST PERM >>> " + testNode.getACL().dump());
+ }
showPermissions("accessTestRoot/testIfPermissionSaved");
@@ -784,8 +797,8 @@
(ExtendedNode)session2.getRootNode().getNode("accessTestRoot/testRemoveExoOwnable/subroot");
assertEquals("john", subRoot2.getProperty("exo:owner").getString());
assertEquals("john", subRoot2.getACL().getOwner());
- Node testNode2 = subRoot1.getNode("node");
- testNode.remove();
+ Node testNode2 = subRoot2.getNode("node");
+ testNode2.remove();
session2.save();
@@ -1087,7 +1100,9 @@
NodeImpl node = (NodeImpl)this.repository.getSystemSession().getRootNode().getNode(path);
AccessControlList acl = node.getACL();
if (log.isDebugEnabled())
+ {
log.debug("DUMP: " + acl.dump());
+ }
}
13 years, 10 months
exo-jcr SVN: r2721 - core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas.
by do-not-reply@jboss.org
Author: dkatayev
Date: 2010-06-30 04:06:30 -0400 (Wed, 30 Jun 2010)
New Revision: 2721
Modified:
core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java
Log:
EXOJCR-772 cause added to thrown LoginException
Modified: core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java
===================================================================
--- core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java 2010-06-29 16:09:50 UTC (rev 2720)
+++ core/trunk/exo.core.component.security.core/src/main/java/org/exoplatform/services/security/jaas/SharedStateLoginModule.java 2010-06-30 08:06:30 UTC (rev 2721)
@@ -77,7 +77,9 @@
}
catch (final Throwable e)
{
- throw new LoginException(e.getMessage());
+ LoginException le = new LoginException(e.getMessage());
+ le.initCause(e);
+ throw le;
}
}
13 years, 10 months
exo-jcr SVN: r2720 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-29 12:09:50 -0400 (Tue, 29 Jun 2010)
New Revision: 2720
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-800
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 16:09:22 UTC (rev 2719)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 16:09:50 UTC (rev 2720)
@@ -207,7 +207,7 @@
resp = conn.Post(url.getFile(), stream, headerPairs);
byte[] buf = new byte[1024];
int r = -1;
- while ((r = entity.read()) != -1)
+ while ((r = entity.read(buf)) != -1)
{
stream.write(buf, 0, r);
}
@@ -282,7 +282,7 @@
resp = conn.Put(url.getFile(), stream, headerPairs);
byte[] buf = new byte[1024];
int r = -1;
- while ((r = entity.read()) != -1)
+ while ((r = entity.read(buf)) != -1)
{
stream.write(buf, 0, r);
}
13 years, 10 months
exo-jcr SVN: r2719 - ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-29 12:09:22 -0400 (Tue, 29 Jun 2010)
New Revision: 2719
Modified:
ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-800
Modified: ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 15:19:13 UTC (rev 2718)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 16:09:22 UTC (rev 2719)
@@ -207,7 +207,7 @@
resp = conn.Post(url.getFile(), stream, headerPairs);
byte[] buf = new byte[1024];
int r = -1;
- while ((r = entity.read()) != -1)
+ while ((r = entity.read(buf)) != -1)
{
stream.write(buf, 0, r);
}
@@ -282,7 +282,7 @@
resp = conn.Put(url.getFile(), stream, headerPairs);
byte[] buf = new byte[1024];
int r = -1;
- while ((r = entity.read()) != -1)
+ while ((r = entity.read(buf)) != -1)
{
stream.write(buf, 0, r);
}
13 years, 10 months
exo-jcr SVN: r2718 - ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-29 11:19:13 -0400 (Tue, 29 Jun 2010)
New Revision: 2718
Removed:
ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
Modified:
ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-800
Deleted: ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-29 15:12:54 UTC (rev 2717)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-29 15:19:13 UTC (rev 2718)
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.rest.ext.proxy;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.HttpHeaders;
-
-import org.exoplatform.common.http.client.Codecs;
-import org.exoplatform.common.http.client.HTTPConnection;
-import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.common.http.client.ModuleException;
-import org.exoplatform.common.http.client.NVPair;
-import org.exoplatform.common.http.client.ParseException;
-import org.exoplatform.common.http.client.ProtocolNotSuppException;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-/**
- * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
- * @version $Id$
- */
-public class BaseConnector extends Connector
-{
-
- /** The connection. */
- private HTTPConnection conn;
-
- /** The HTTPResponse. */
- HTTPResponse resp = null;
-
- /** The form_data array. */
- NVPair[] form_data;
-
- /** The headers array. */
- NVPair[] headers;
-
- /** Logger. */
- private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.ext.BaseConnector");
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
- prepareFormParams(url_obj);
- conn.setAllowUserInteraction(false);
- resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
-
- byte[] body = new byte[httpRequest.getContentLength()];
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
-
- byte[] body = new byte[httpRequest.getContentLength()];
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Put(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
- resp = conn.Delete(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * Prepares request headers.
- *
- * @param httpRequest the http request
- */
- private void prepareRequestHeaders(HttpServletRequest httpRequest)
- {
- ArrayList<NVPair> hds = new ArrayList<NVPair>();
- for (Enumeration<String> en = httpRequest.getHeaderNames(); en.hasMoreElements();)
- {
- NVPair pair = null;
- String headerName = (String)en.nextElement();
- if (!headerName.equalsIgnoreCase(HttpHeaders.HOST)) { //Do not need to send host
- for (Enumeration<String> en2 = httpRequest.getHeaders(headerName); en2.hasMoreElements();)
- {
- pair = new NVPair(headerName, en2.nextElement());
- }
- hds.add(pair);
- this.headers = new NVPair[hds.size()];
- this.headers = hds.toArray(headers);
- }
- }
- }
-
- /**
- * Prepares form params.
- *
- * @param url the url
- */
- private void prepareFormParams(URL url)
- {
- String query = url.getQuery();
- if (query != null)
- {
- try
- {
- this.form_data = Codecs.query2nv(query);
- }
- catch (ParseException e)
- {
- LOG.error(e.getMessage());
- }
- }
- }
-}
Deleted: ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-06-29 15:12:54 UTC (rev 2717)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-06-29 15:19:13 UTC (rev 2718)
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.rest.ext.proxy;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.common.http.client.ModuleException;
-import org.exoplatform.common.http.client.ParseException;
-import org.exoplatform.common.http.client.ProtocolNotSuppException;
-
-/**
- * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
- * @version $Id$
- */
-public abstract class Connector
-{
-
- /** The connect timeout. */
- protected static final int DEFAULT_CONNECT_TIMEOUT_MS = 5000;
-
-
- /**
- * Do GET proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
- /**
- * Do POST proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-
- /**
- * Do PUT proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-
- /**
- * Do DELETE proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-}
Modified: ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 15:12:54 UTC (rev 2717)
+++ ws/branches/2.1.x/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 15:19:13 UTC (rev 2718)
@@ -78,8 +78,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -89,11 +89,16 @@
HTTPResponse resp = conn.Delete(url.getFile(), headerPairs);
if (resp.getStatusCode() >= 300)
{
- LOG.warn("DELETE Received : " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("DELETE Received : " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("DELETE. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("DELETE. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -129,8 +134,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -140,11 +145,16 @@
HTTPResponse resp = conn.Get(url.getFile(), (NVPair[])null, headerPairs);
if (resp.getStatusCode() >= 300)
{
- LOG.warn("GET Received: " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("GET Received: " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("GET. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("GET. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -182,8 +192,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -210,11 +220,16 @@
if (resp.getStatusCode() >= 300)
{
- LOG.warn("POST Received: " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("POST Received: " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("POST. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("POST. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -252,8 +267,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -280,11 +295,16 @@
if (resp.getStatusCode() >= 300)
{
- LOG.warn("PUT Received : " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("PUT Received : " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("PUT. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("PUT Received : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -371,12 +391,12 @@
return credentials;
}
- private NVPair[] toNVPair(MultivaluedMap<String, String> map, Set<String> skip)
+ private NVPair[] toNVPair(MultivaluedMap<String, String> map, Set<CaseInsensitiveStringWrapper> skip)
{
List<NVPair> hds = new ArrayList<NVPair>();
for (Entry<String, List<String>> e : map.entrySet())
{
- if (!skip.contains(e.getKey()))
+ if (!skip.contains(new CaseInsensitiveStringWrapper(e.getKey())))
{
for (String v : e.getValue())
{
@@ -386,4 +406,50 @@
}
return hds.toArray(new NVPair[hds.size()]);
}
+
+ private class CaseInsensitiveStringWrapper
+ {
+
+ private final String string;
+
+ private final String caselessString;
+
+ CaseInsensitiveStringWrapper(String string)
+ {
+ this.string = string;
+ if (string != null)
+ {
+ this.caselessString = string.toLowerCase();
+ }
+ else
+ {
+ this.caselessString = null;
+ }
+ }
+
+ public String toString()
+ {
+ return string == null ? "null" : string;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ return false;
+ if (obj.getClass() != getClass())
+ return false;
+ CaseInsensitiveStringWrapper other = (CaseInsensitiveStringWrapper)obj;
+ return (caselessString == null && other.caselessString == null)
+ || (caselessString != null && caselessString.equals(other.caselessString));
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return caselessString == null ? 0 : caselessString.hashCode();
+ }
+
+ }
+
}
13 years, 10 months
exo-jcr SVN: r2717 - ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy.
by do-not-reply@jboss.org
Author: aparfonov
Date: 2010-06-29 11:12:54 -0400 (Tue, 29 Jun 2010)
New Revision: 2717
Removed:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
Modified:
ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
Log:
EXOJCR-800
Deleted: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-29 14:58:20 UTC (rev 2716)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/BaseConnector.java 2010-06-29 15:12:54 UTC (rev 2717)
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.rest.ext.proxy;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.HttpHeaders;
-
-import org.exoplatform.common.http.client.Codecs;
-import org.exoplatform.common.http.client.HTTPConnection;
-import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.common.http.client.ModuleException;
-import org.exoplatform.common.http.client.NVPair;
-import org.exoplatform.common.http.client.ParseException;
-import org.exoplatform.common.http.client.ProtocolNotSuppException;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-/**
- * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
- * @version $Id$
- */
-public class BaseConnector extends Connector
-{
-
- /** The connection. */
- private HTTPConnection conn;
-
- /** The HTTPResponse. */
- HTTPResponse resp = null;
-
- /** The form_data array. */
- NVPair[] form_data;
-
- /** The headers array. */
- NVPair[] headers;
-
- /** Logger. */
- private static final Log LOG = ExoLogger.getLogger("exo.ws.rest.ext.BaseConnector");
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- prepareRequestHeaders(httpRequest);
- prepareFormParams(url_obj);
- conn.setAllowUserInteraction(false);
- resp = conn.Get(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), form_data, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
-
- byte[] body = new byte[httpRequest.getContentLength()];
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Post(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
-
- byte[] body = new byte[httpRequest.getContentLength()];
- new DataInputStream(httpRequest.getInputStream()).readFully(body);
- resp = conn.Put(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), body, headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException,
- ProtocolNotSuppException, IOException, ModuleException, ParseException
- {
- URL url_obj = null;
- url_obj = new URL(url);
-
- conn = new HTTPConnection(url_obj);
- conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- conn.setAllowUserInteraction(false);
- prepareRequestHeaders(httpRequest);
- resp = conn.Delete(url_obj.getProtocol() + "://" + url_obj.getAuthority() + url_obj.getPath(), headers);
- if (resp.getStatusCode() >= 300)
- {
- LOG.error("Received Error: " + resp.getReasonLine());
- LOG.error(new String(resp.getData()));
- }
- return resp;
- }
-
- /**
- * Prepares request headers.
- *
- * @param httpRequest the http request
- */
- private void prepareRequestHeaders(HttpServletRequest httpRequest)
- {
- ArrayList<NVPair> hds = new ArrayList<NVPair>();
- for (Enumeration<String> en = httpRequest.getHeaderNames(); en.hasMoreElements();)
- {
- NVPair pair = null;
- String headerName = (String)en.nextElement();
- if (!headerName.equalsIgnoreCase(HttpHeaders.HOST)) { //Do not need to send host
- for (Enumeration<String> en2 = httpRequest.getHeaders(headerName); en2.hasMoreElements();)
- {
- pair = new NVPair(headerName, en2.nextElement());
- }
- hds.add(pair);
- this.headers = new NVPair[hds.size()];
- this.headers = hds.toArray(headers);
- }
- }
- }
-
- /**
- * Prepares form params.
- *
- * @param url the url
- */
- private void prepareFormParams(URL url)
- {
- String query = url.getQuery();
- if (query != null)
- {
- try
- {
- this.form_data = Codecs.query2nv(query);
- }
- catch (ParseException e)
- {
- LOG.error(e.getMessage());
- }
- }
- }
-}
Deleted: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-06-29 14:58:20 UTC (rev 2716)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/Connector.java 2010-06-29 15:12:54 UTC (rev 2717)
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.rest.ext.proxy;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.exoplatform.common.http.client.HTTPResponse;
-import org.exoplatform.common.http.client.ModuleException;
-import org.exoplatform.common.http.client.ParseException;
-import org.exoplatform.common.http.client.ProtocolNotSuppException;
-
-/**
- * @author <a href="mailto:max.shaposhnik@exoplatform.com">Max Shaposhnik</a>
- * @version $Id$
- */
-public abstract class Connector
-{
-
- /** The connect timeout. */
- protected static final int DEFAULT_CONNECT_TIMEOUT_MS = 5000;
-
-
- /**
- * Do GET proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse fetchGet(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
- /**
- * Do POST proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse fetchPost(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-
- /**
- * Do PUT proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse doPut(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-
- /**
- * Do DELETE proxy request.
- *
- * @param httpRequest the HttpServletRequest
- * @param url the url to request
- * @return response HTTPResponse
- */
- abstract HTTPResponse doDelete(HttpServletRequest httpRequest, String url) throws MalformedURLException, ProtocolNotSuppException,
- IOException, ModuleException,ParseException;
-
-}
Modified: ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 14:58:20 UTC (rev 2716)
+++ ws/trunk/exo.ws.rest.ext/src/main/java/org/exoplatform/services/rest/ext/proxy/ProxyService.java 2010-06-29 15:12:54 UTC (rev 2717)
@@ -78,8 +78,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -89,11 +89,16 @@
HTTPResponse resp = conn.Delete(url.getFile(), headerPairs);
if (resp.getStatusCode() >= 300)
{
- LOG.warn("DELETE Received : " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("DELETE Received : " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("DELETE. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("DELETE. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -129,8 +134,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -140,11 +145,16 @@
HTTPResponse resp = conn.Get(url.getFile(), (NVPair[])null, headerPairs);
if (resp.getStatusCode() >= 300)
{
- LOG.warn("GET Received: " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("GET Received: " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("GET. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("GET. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -182,8 +192,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -210,11 +220,16 @@
if (resp.getStatusCode() >= 300)
{
- LOG.warn("POST Received: " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("POST Received: " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("POST. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("POST. Text : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -252,8 +267,8 @@
URL url = new URL(urlParam);
HTTPConnection conn = new HTTPConnection(url);
conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
- NVPair[] headerPairs =
- toNVPair(headers.getRequestHeaders(), Collections.singleton(HttpHeaders.HOST.toLowerCase()));
+ NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
+ Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
conn.setAllowUserInteraction(false);
NVPair credentials = getCredentials(url);
if (credentials != null)
@@ -280,11 +295,16 @@
if (resp.getStatusCode() >= 300)
{
- LOG.warn("PUT Received : " + resp.getReasonLine());
- byte[] data = resp.getData();
- if (data != null)
+ if (LOG.isDebugEnabled())
{
- LOG.warn("PUT Received : " + new String(data));
+ // Do not read data if debug is off.
+ // Client may get empty response, may not read stream twice.
+ LOG.debug("PUT. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
+ byte[] data = resp.getData();
+ if (data != null)
+ {
+ LOG.debug("PUT Received : " + new String(data));
+ }
}
}
return createResponse(resp);
@@ -371,12 +391,12 @@
return credentials;
}
- private NVPair[] toNVPair(MultivaluedMap<String, String> map, Set<String> skip)
+ private NVPair[] toNVPair(MultivaluedMap<String, String> map, Set<CaseInsensitiveStringWrapper> skip)
{
List<NVPair> hds = new ArrayList<NVPair>();
for (Entry<String, List<String>> e : map.entrySet())
{
- if (!skip.contains(e.getKey()))
+ if (!skip.contains(new CaseInsensitiveStringWrapper(e.getKey())))
{
for (String v : e.getValue())
{
@@ -386,4 +406,50 @@
}
return hds.toArray(new NVPair[hds.size()]);
}
+
+ private class CaseInsensitiveStringWrapper
+ {
+
+ private final String string;
+
+ private final String caselessString;
+
+ CaseInsensitiveStringWrapper(String string)
+ {
+ this.string = string;
+ if (string != null)
+ {
+ this.caselessString = string.toLowerCase();
+ }
+ else
+ {
+ this.caselessString = null;
+ }
+ }
+
+ public String toString()
+ {
+ return string == null ? "null" : string;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null)
+ return false;
+ if (obj.getClass() != getClass())
+ return false;
+ CaseInsensitiveStringWrapper other = (CaseInsensitiveStringWrapper)obj;
+ return (caselessString == null && other.caselessString == null)
+ || (caselessString != null && caselessString.equals(other.caselessString));
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return caselessString == null ? 0 : caselessString.hashCode();
+ }
+
+ }
+
}
13 years, 10 months