[Registry-dev] svn commit r16450 - in trunk/registry/modules/core/src/main/java/org/wso2/registry: app config servlet

svn at wso2.org svn at wso2.org
Thu May 1 20:37:45 PDT 2008


Author: glen
Date: Thu May  1 20:37:42 2008
New Revision: 16450

Log:

APP improvements to get the right URIs in links and headers.


Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryAdapter.java	Thu May  1 20:37:42 2008
@@ -25,7 +25,6 @@
 import org.wso2.registry.exceptions.ResourceNotFoundException;
 import org.wso2.registry.jdbc.realm.RegistryRealm;
 import org.wso2.registry.jdbc.EmbeddedRegistry;
-import org.wso2.registry.secure.SecureRegistry;
 
 import javax.activation.MimeType;
 import javax.xml.namespace.QName;
@@ -160,17 +159,18 @@
         }
 
         EmptyResponseContext response = new EmptyResponseContext(200);
-        response.setLocation(getAtomURI(path));
+        response.setLocation(getAtomURI(path, request));
         return response; // TODO - fix return value
     }
 
-    String getAtomURI(String path) {
-        // TODO - We have to get this from the request somehow?
-        return getAbsoluteBase() + "/atom" + path;
+    String getAtomURI(String path, RequestContext context) {
+        return getAbsoluteBase(context) + RegistryResolver.ATOM + path;
     }
 
-    private String getAbsoluteBase() {
-        return "http://localhost:8081" + resolver.getBaseURI();
+    private String getAbsoluteBase(RequestContext context) {
+        String uri = context.getBaseUri().trailingSlash().toString();
+        uri = uri.substring(0, uri.length() - 1);  // remove trailing slash
+        return uri;
     }
 
     private ResponseContext processAspectRequest(RequestContext request, String path) {
@@ -265,7 +265,7 @@
                     }
                     String commentPath = secureRegistry.addComment(path, comment);
                     EmptyResponseContext responseContext = new EmptyResponseContext(200);
-                    responseContext.setLocation(getAtomURI(commentPath));
+                    responseContext.setLocation(getAtomURI(commentPath, request));
                     return responseContext;
                 } else if (method.equals("PUT")) {
                     Entry entry = (Entry)request.getDocument().getRoot();
@@ -398,7 +398,7 @@
             return new StringResponseContext(e, 500);
         }
         ResponseContext rc = new EmptyResponseContext(200);
-        rc.setLocation(getAtomURI(location));
+        rc.setLocation(getAtomURI(location, request));
         return rc;
     }
 
@@ -1267,15 +1267,15 @@
     }
 
     public String getMediaName(Resource entry) throws ResponseContextException {
-        String path = entry.getPath(); //TODO : fix
-        return path.substring(1);
+        return entry.getPath();
     }
 
     protected String addMediaContent(IRI feedIri,
                                      Entry entry,
                                      Resource entryObj,
                                      RequestContext request) throws ResponseContextException {
-        IRI mediaIri = new IRI(getAbsoluteBase() + RegistryResolver.RESOURCE + getMediaName(entryObj));
+        IRI mediaIri = new IRI(getAbsoluteBase(request) +
+                               RegistryResolver.RESOURCE + getMediaName(entryObj));
         String mediaLink = mediaIri.toString();
         entry.setContent(mediaIri, getContentType(entryObj));
         entry.addLink(mediaLink, "edit-media");

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RegistryResolver.java	Thu May  1 20:37:42 2008
@@ -35,7 +35,7 @@
 public class RegistryResolver implements Resolver<Target> {
     private Log log = LogFactory.getLog(RegistryResolver.class);
 
-    public static final String RESOURCE = "/resource/";
+    public static final String RESOURCE = "/resource";
     public static final String ATOM = "/atom";
 
     public static final TargetType TAGS_TYPE = TargetType.get("tags", true);
@@ -57,11 +57,11 @@
     public static final TargetType COLLECTION_CUSTOM_TYPE = TargetType.get("col-custom", true);
 
     private Registry registry;
-    private String baseURI;
+    private String basePath;
 
-    public RegistryResolver(Registry registry, String baseURI) {
+    public RegistryResolver(Registry registry, String basePath) {
         this.registry = registry;
-        this.baseURI = baseURI;
+        this.basePath = basePath;
     }
 
     static Map<String, TargetType> types;
@@ -89,7 +89,7 @@
             return null;
         }
         // URI will start with the baseURI, which we need to strip off.
-        uri = uri.substring(baseURI.length());
+        uri = uri.substring(basePath.length());
         context.setAttribute("pathInfo", uri);
         String [] parts = splitPath(uri);
         boolean hasColon = false;
@@ -166,7 +166,7 @@
 
         boolean isMedia = false;
         if (uri.startsWith(RESOURCE)) {
-            uri = uri.substring(RESOURCE.length() - 1);
+            uri = uri.substring(RESOURCE.length());
             isMedia = true;
         } else if (uri.startsWith(ATOM)) {
             uri = uri.substring(ATOM.length());
@@ -237,7 +237,7 @@
         return path.split("\\" + RegistryConstants.URL_SEPARATOR);
     }
 
-    public String getBaseURI() {
-        return baseURI;
+    public String getBasePath() {
+        return basePath;
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java	Thu May  1 20:37:42 2008
@@ -186,7 +186,7 @@
         queryProcessors.add(queryProcessorConfiguration);
     }
 
-    private String getBasePath() {
+    public String getBasePath() {
         String basePath = null;
         if (urlSupplier != null) {
             basePath = urlSupplier.getURL();

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	Thu May  1 20:37:42 2008
@@ -80,6 +80,7 @@
                             return config.getServletContext().getRealPath("/WEB-INF");
                         }
                     });
+            RegistryContext.setRegistryContext(registryContext);
             if (configPath != null) {
                 RegistryConfigurationProcessor.populateRegistryConfig(configPath, registryContext);
             } else {



More information about the Registry-dev mailing list