Author: rmannibucau
Date: Tue Sep 11 06:34:54 2012
New Revision: 1383253
URL: http://svn.apache.org/viewvc?rev=1383253&view=rev
Log:
fixing the way rest urls are built
Modified:
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
Modified:
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java?rev=1383253&r1=1383252&r2=1383253&view=diff
==============================================================================
---
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
(original)
+++
openejb/trunk/openejb/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
Tue Sep 11 06:34:54 2012
@@ -56,6 +56,7 @@ import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -211,10 +212,6 @@ public abstract class RESTService implem
restEjbs.clear();
}
- private static boolean isManagedBean(final BeanContext ctx) {
- return BeanType.MANAGED.equals(ctx.getComponentType());
- }
-
private boolean hasEjbAndIsNotAManagedBean(final Map<String,
EJBRestServiceInfo> restEjbs, final String clazz) {
return restEjbs.containsKey(clazz) &&
!BeanType.MANAGED.equals(restEjbs.get(clazz).context.getComponentType());
}
@@ -364,16 +361,30 @@ public abstract class RESTService implem
return address.substring(0, address.lastIndexOf("/"));
}
- String webCtx = context; // context can get the app path too
+ // context can get the app path too
+ // so keep only web context without /
+ String webCtx = context;
+ if (webCtx.startsWith("/")) {
+ webCtx = webCtx.substring(1);
+ }
if (webCtx.contains("/")) {
webCtx = webCtx.substring(0, webCtx.indexOf("/"));
}
- int idx = address.indexOf(webCtx);
- String base = address.substring(0, idx);
- if (!base.endsWith("/") && !webCtx.startsWith("/")) {
- base = base + '/';
+
+ // get root path ending with /
+ String base;
+ try {
+ final URL url = new URL(address);
+ base = url.getProtocol() + "://" + url.getHost() + ":" +
url.getPort() + "/";
+ } catch (MalformedURLException e) {
+ int idx = address.indexOf(webCtx);
+ base = address.substring(0, idx);
+ if (!base.endsWith("/") && !webCtx.startsWith("/")) {
+ base = base + '/';
+ }
}
- return base + context;
+
+ return base + webCtx;
}
private String getAddress(String context, Class<?> clazz) {