[exo-jcr-commits] exo-jcr SVN: r4223 - in jcr/trunk: exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Apr 11 05:54:46 EDT 2011
Author: areshetnyak
Date: 2011-04-11 05:54:46 -0400 (Mon, 11 Apr 2011)
New Revision: 4223
Modified:
jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
Log:
EXOJCR-1300 : Changes for QueryParam was commited.
Modified: jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java
===================================================================
--- jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2011-04-11 09:51:54 UTC (rev 4222)
+++ jcr/trunk/applications/exo.jcr.applications.backupconsole/src/main/java/org/exoplatform/jcr/backupconsole/BackupClientImpl.java 2011-04-11 09:54:46 UTC (rev 4223)
@@ -52,6 +52,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import javax.ws.rs.core.Response;
@@ -469,6 +470,13 @@
BackupAgentResponse response = null;
String sURL = null;
+ String backupSetPathEncoded = null;
+
+ if (backupSetPath != null)
+ {
+ backupSetPathEncoded = URLEncoder.encode(backupSetPath, "UTF-8");
+ }
+
if (workspaceName != null)
{
if (config != null)
@@ -484,7 +492,8 @@
sURL =
path + HTTPBackupAgent.Constants.BASE_URL
+ HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/"
- + repositoryName + "/" + backupSetPath + "/" + removeExists;
+ + repositoryName
+ + "/" + removeExists + "?backup-set-path=" + backupSetPathEncoded;
}
WorkspaceEntry wEntry = null;
@@ -529,8 +538,7 @@
sURL =
path + HTTPBackupAgent.Constants.BASE_URL
+ HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY_BACKUP_SET + "/"
- + backupSetPath + "/"
- + removeExists;
+ + removeExists + "?backup-set-path=" + backupSetPathEncoded;
}
RepositoryEntry wEntry = null;
@@ -613,8 +621,8 @@
{
sURL =
path + HTTPBackupAgent.Constants.BASE_URL
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
- + removeExists;
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + removeExists
+ + "?backup-set-path=" + backupSetPathEncoded;
}
response = transport.executeGET(sURL);
Modified: jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2011-04-11 09:51:54 UTC (rev 4222)
+++ jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2011-04-11 09:54:46 UTC (rev 4223)
@@ -56,6 +56,8 @@
import java.io.File;
import java.io.FilenameFilter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
@@ -70,6 +72,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -837,16 +840,33 @@
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
- @Path("/restore/backup-set/{repo}/{backup-set-path:.*}/{remove-Existing}")
+ @Path("/restore/backup-set/{repo}/{remove-Existing}")
public Response restoreBackupSet(WorkspaceEntry wEntry, @PathParam("repo") String repository,
- @PathParam("backup-set-path") String backupSetPath, @PathParam("remove-Existing") Boolean removeExisting)
+ @QueryParam("backup-set-path") String backupSetPathEncoded, @PathParam("remove-Existing") Boolean removeExisting)
{
String failMessage;
Response.Status status;
Throwable exception;
+ String backupSetPath = null;
+
try
{
+ backupSetPath = URLDecoder.decode(backupSetPathEncoded, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.error("Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
+ + "' from backup set '" + backupSetPath + "'", e);
+
+ return Response.status(Response.Status.BAD_REQUEST).entity(
+ "Can not start restore the workspace '" + "/" + repository + "/" + wEntry.getName()
+ + "' from backup set '" + backupSetPath + "' : " + e.getMessage())
+ .type(MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
+ try
+ {
validateOneRestoreInstants(repository, wEntry.getName());
File backupSetDir = (new File(backupSetPath));
@@ -1135,14 +1155,29 @@
@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
- @Path("/restore/backup-set/{backup-set-path:.*}/{remove-Existing}")
- public Response restoreFromBackupSet(@PathParam("backup-set-path") String backupSetPath,
+ @Path("/restore/backup-set/{remove-Existing}")
+ public Response restoreFromBackupSet(@QueryParam("backup-set-path") String backupSetPathEncoded,
@PathParam("remove-Existing") Boolean removeExisting)
{
String failMessage = null;
Response.Status status = null;
Throwable exception = null;
+
+ String backupSetPath = null;
+ try
+ {
+ backupSetPath = URLDecoder.decode(backupSetPathEncoded, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.error("Can not start restore from backup set '" + backupSetPathEncoded + "'", e);
+
+ return Response.status(Response.Status.BAD_REQUEST).entity(
+ "Can not start restore from backup set '" + backupSetPathEncoded + "' : " + e.getMessage()).type(
+ MediaType.TEXT_PLAIN).cacheControl(noCache).build();
+ }
+
File backupSetDir = (new File(backupSetPath));
File backuplog = null;
@@ -1611,17 +1646,34 @@
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
- @Path("/restore-repository/backup-set/{backup-set-path:.*}/{remove-Existing}")
+ @Path("/restore-repository/backup-set/{remove-Existing}")
public Response restoreRepositoryBackupSet(RepositoryEntry rEntry,
- @PathParam("backup-set-path") String backupSetPath,
+ @QueryParam("backup-set-path") String backupSetPathEncoded,
@PathParam("remove-Existing") Boolean removeExisting)
{
String failMessage;
Response.Status status;
Throwable exception;
+ String backupSetPath = null;
+
try
{
+ backupSetPath = URLDecoder.decode(backupSetPathEncoded, "UTF-8");
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ log.error("Can not start restore the repository '" + "/" + rEntry.getName() + "' from backup set '"
+ + backupSetPath + "'", e);
+
+ return Response.status(Response.Status.BAD_REQUEST).entity(
+ "Can not start restore the repository '" + "/" + rEntry.getName() + "' from backup set '"
+ + backupSetPath + "' : " + e.getMessage()).type(MediaType.TEXT_PLAIN).cacheControl(noCache)
+ .build();
+ }
+
+ try
+ {
validateOneRepositoryRestoreInstants(rEntry.getName());
File backupSetDir = (new File(backupSetPath));
Modified: jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2011-04-11 09:51:54 UTC (rev 4222)
+++ jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2011-04-11 09:54:46 UTC (rev 4223)
@@ -68,6 +68,7 @@
import java.io.File;
import java.io.InputStream;
import java.net.URI;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -1425,7 +1426,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -1472,8 +1473,9 @@
headers.putSingle("Content-Type", "application/json; charset=UTF-8");
ContainerRequestUserRole creq =
new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "db6" + "/" + backupSetPath + "/"
- + "true"), new URI(""), new ByteArrayInputStream(json.toString().getBytes("UTF-8")),
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "db6" + "/" + "true"
+ + "?backup-set-path=" + backupSetPath), new URI(""), new ByteArrayInputStream(json
+ .toString().getBytes("UTF-8")),
new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
@@ -1552,7 +1554,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -1575,8 +1577,8 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
ContainerRequestUserRole creq =
new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
- + "true"), new URI(""), null, new InputHeadersMap(headers));
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "true"
+ + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
@@ -1654,7 +1656,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -1678,8 +1680,8 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
ContainerRequestUserRole creq =
new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
- + "false"), new URI(""), null, new InputHeadersMap(headers));
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "false"
+ + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
@@ -1757,7 +1759,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -1807,7 +1809,7 @@
ContainerRequestUserRole creq =
new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
+ HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "db6" + "/"
- + backupSetPath + "/" + "false"), new URI(""), new ByteArrayInputStream(json.toString()
+ + "false" + "?backup-set-path=" + backupSetPath), new URI(""), new ByteArrayInputStream(json.toString()
.getBytes("UTF-8")), new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
@@ -2511,7 +2513,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -2579,8 +2581,7 @@
ContainerRequestUserRole creq =
new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
+ HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY_BACKUP_SET + "/"
- + backupSetPath + "/"
- + "true"),
+ + "true" + "?backup-set-path=" + backupSetPath),
new URI(""), new ByteArrayInputStream(json.toString().getBytes("UTF-8")),
new InputHeadersMap(headers));
@@ -2659,7 +2660,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -2728,7 +2729,7 @@
ContainerRequestUserRole creq =
new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
+ HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY_BACKUP_SET + "/"
- + backupSetPath + "/" + "false"), new URI(""), new ByteArrayInputStream(json.toString()
+ + "false" + "?backup-set-path=" + backupSetPath), new URI(""), new ByteArrayInputStream(json.toString()
.getBytes("UTF-8")), new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
@@ -2806,7 +2807,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -2829,8 +2830,8 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
ContainerRequestUserRole creq =
new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
- + "true"), new URI(""), null, new InputHeadersMap(headers));
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "true"
+ + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
@@ -2907,7 +2908,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
break;
}
}
@@ -2931,8 +2932,8 @@
MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
ContainerRequestUserRole creq =
new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
- + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + backupSetPath + "/"
- + "false"), new URI(""), null, new InputHeadersMap(headers));
+ + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "false"
+ + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));
ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
ContainerResponse cres = new ContainerResponse(responseWriter);
More information about the exo-jcr-commits
mailing list