+restUrl=http://localhost:8080/gss/rest/
+
version=1.0.0-beta
fileRepositoryPath=/tmp/gss-root
public class FileHeaderDTO implements Serializable {
/**
- * The preamble of every REST API URI.
- */
- public static final String PATH_GSS = "http://gss.grnet.gr/gss/rest/";
-
- /**
* The path for the resource manipulation subsystem.
*/
public static final String PATH_FILES = "/files";
/**
- * Retrieve the URI for this resource. This unique identifier can
- * be used to refer to the resource from various GSS clients.
+ * Retrieve the URI for this resource, relative to the REST API root URI.
+ * This unique identifier can be used to refer to the resource from
+ * various GSS clients.
*
* @return the URI
*/
public String getURI() {
- return PATH_GSS + owner.getUsername() + PATH_FILES + getPath();
+ return owner.getUsername() + PATH_FILES + getPath();
}
}
/**
- * Retrieve the URI for this resource. This unique identifier can
- * be used to refer to the resource from various GSS clients.
+ * Retrieve the URI for this resource, relative to the REST API root URI.
+ * This unique identifier can be used to refer to the resource from
+ * various GSS clients.
*
* @return the URI
*/
public String getURI() {
- return FileHeaderDTO.PATH_GSS + owner.getUsername() + FileHeaderDTO.PATH_FILES + getPath();
+ return owner.getUsername() + FileHeaderDTO.PATH_FILES + getPath();
}
}
put("deleted", folder.isDeleted());
if (folder.getParent() != null) {
JSONObject j = new JSONObject();
- j.put("uri", folder.getParent().getURI());
+ j.put("uri", getApiRoot() + folder.getParent().getURI());
j.put("name", folder.getParent().getName());
json.put("parent", j);
}
put("readForAll", file.isReadForAll()).
put("tags", file.getTags()).
put("path",URLEncoder.encode(file.getFolder().getPath(),"UTF-8")).
- put("uri", file.getURI()).
+ put("uri", getApiRoot() + file.getURI()).
put("deleted", file.isDeleted());
JSONObject j = new JSONObject();
- j.put("uri", file.getFolder().getURI()).
+ j.put("uri", getApiRoot() + file.getFolder().getURI()).
put("name", URLEncoder.encode(file.getFolder().getName(),"UTF-8"));
json.put("folder", j);
if (oldBody != null)
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
import gr.ebs.gss.client.exceptions.RpcException;
+import gr.ebs.gss.server.configuration.GSSConfigurationFactory;
import gr.ebs.gss.server.domain.User;
import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
import gr.ebs.gss.server.webdav.Webdav;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.configuration.BaseConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DataConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
private static Log logger = LogFactory.getLog(RequestHandler.class);
/**
+ * Gss configuration
+ */
+ private static DataConfiguration conf = null;
+
+ static {
+ try {
+ conf = GSSConfigurationFactory.getConfiguration();
+ }
+ catch (ConfigurationException e) {
+ // Use empty configuration, so we get no NPE but default values
+ conf = new DataConfiguration(new BaseConfiguration());
+ logger.error("Error in ExternalAPI initialization! GSS is running with default values!", e);
+ }
+ }
+
+ /**
* Create a mapping between paths and allowed HTTP methods for fast lookup.
*/
private final Map<String, String> methodsAllowed = new HashMap<String, String>(7);
methodsAllowed.put(PATH_TRASH, METHOD_GET + ", " + METHOD_DELETE);
}
+ /**
+ * Return the root of every API request URL.
+ */
+ protected String getApiRoot() {
+ return conf.getString("restUrl", "http://localhost:8080/gss/rest/");
+ }
+
@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
String method = request.getMethod();
put("size", f.getFileSize()).
put("path", f.getFolder().getPath()).
put("creationDate", f.getAuditInfo().getCreationDate().getTime()).
- put("uri", f.getURI());
+ put("uri", getApiRoot() + f.getURI());
JSONObject jf = new JSONObject();
- jf.put("uri", f.getFolder().getURI()).
+ jf.put("uri", getApiRoot() + f.getFolder().getURI()).
put("name", URLEncoder.encode(f.getFolder().getName(),"UTF-8"));
j.put("folder", jf);
json.put(j);
j.put("name", f.getName()).
put("uri", parentUrl + f.getPath());
if (f.getParent() != null)
- j.put("parent", f.getParent().getURI());
+ j.put("parent", getApiRoot() + f.getParent().getURI());
subfolders.add(j);
}
json.put("folders", subfolders);
put("creationDate", f.getAuditInfo().getCreationDate().getTime()).
put("uri", parentUrl + f.getPath());
JSONObject jf = new JSONObject();
- jf.put("uri", f.getFolder().getURI()).
+ jf.put("uri", getApiRoot() + f.getFolder().getURI()).
put("name", URLEncoder.encode(f.getFolder().getName(),"UTF-8"));
j.put("folder", jf);
files.add(j);
j.put("name", f.getName()).
put("uri", parentUrl + f.getPath());
if (f.getParent() != null)
- j.put("parent", f.getParent().getURI());
+ j.put("parent", getApiRoot() + f.getParent().getURI());
trashFolders.add(j);
}
json.put("folders", trashFolders);
put("creationDate", f.getAuditInfo().getCreationDate().getTime()).
put("uri", parentUrl + f.getPath());
JSONObject p = new JSONObject();
- p.put("uri", f.getFolder().getURI()).
+ p.put("uri", getApiRoot() + f.getFolder().getURI()).
put("name", URLEncoder.encode(f.getFolder().getName(),"UTF-8"));
j.put("folder", p);
trashFiles.add(j);