Author: areshetnyak
Date: 2011-04-07 10:59:04 -0400 (Thu, 07 Apr 2011)
New Revision: 4218
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/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java
Log:
JCR-1563 : Th parameter "backup-set-path" was used QueryPqram in
HTTPBackupAgent.
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-07
14:58:38 UTC (rev 4217)
+++
jcr/trunk/exo.jcr.component.ext/src/main/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgent.java 2011-04-07
14:59:04 UTC (rev 4218)
@@ -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;
@@ -840,14 +842,31 @@
@RolesAllowed("administrators")
@Path("/restore/backup-set/{repo}/{remove-Existing}")
public Response restoreBackupSet(WorkspaceEntry wEntry, @PathParam("repo")
String repository,
- @QueryParam("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));
@@ -1137,13 +1156,28 @@
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("administrators")
@Path("/restore/backup-set/{remove-Existing}")
- public Response restoreFromBackupSet(@QueryParam("backup-set-path") String
backupSetPath,
+ 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;
@@ -1614,15 +1648,32 @@
@RolesAllowed("administrators")
@Path("/restore-repository/backup-set/{remove-Existing}")
public Response restoreRepositoryBackupSet(RepositoryEntry rEntry,
- @QueryParam("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-07
14:58:38 UTC (rev 4217)
+++
jcr/trunk/exo.jcr.component.ext/src/test/java/org/exoplatform/services/jcr/ext/backup/server/HTTPBackupAgentTest.java 2011-04-07
14:59:04 UTC (rev 4218)
@@ -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;
}
}
@@ -1553,7 +1554,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -1655,7 +1656,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -1758,7 +1759,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -2512,7 +2513,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -2659,7 +2660,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -2806,7 +2807,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}
@@ -2907,7 +2908,7 @@
{
if (bcl.getBackupId().equals(id))
{
- backupSetPath = bcl.getBackupConfig().getBackupDir().getCanonicalPath();
+ backupSetPath =
URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(),
"UTF-8");
break;
}
}