/** * Constructor. * * @param resourceClass * The resource/servlet class which serves as the base location of the location below. * @param path * The mapped URI path. * <br>Leading and trailing slashes are trimmed. * @param location * The location relative to the resource class. * <br>Leading and trailing slashes are trimmed. * @param responseHeaders * The response headers. * Can be <jk>null</jk>. */ public StaticFileMapping(Class<?> resourceClass, String path, String location, Map<String,Object> responseHeaders) { this.resourceClass = resourceClass; this.path = StringUtils.trimSlashes(path); this.location = StringUtils.trimSlashes(location); this.responseHeaders = immutableMap(responseHeaders); }
/** * Constructor. * * @param resourceClass * The resource/servlet class which serves as the base location of the location below. * @param path * The mapped URI path. * <br>Leading and trailing slashes are trimmed. * @param location * The location relative to the resource class. * <br>Leading and trailing slashes are trimmed. * @param responseHeaders * The response headers. * Can be <jk>null</jk>. */ public StaticFileMapping(Class<?> resourceClass, String path, String location, Map<String,Object> responseHeaders) { this.resourceClass = resourceClass; this.path = StringUtils.trimSlashes(path); this.location = StringUtils.trimSlashes(location); this.responseHeaders = immutableMap(responseHeaders); }
/** * Constructor. * * @param resourceClass * The resource/servlet class which serves as the base location of the location below. * @param path * The mapped URI path. * <br>Leading and trailing slashes are trimmed. * @param location * The location relative to the resource class. * <br>Leading and trailing slashes are trimmed. * @param responseHeaders * The response headers. * Can be <jk>null</jk>. */ public StaticFileMapping(Class<?> resourceClass, String path, String location, Map<String,Object> responseHeaders) { this.resourceClass = resourceClass; this.path = StringUtils.trimSlashes(path); this.location = StringUtils.trimSlashes(location); this.responseHeaders = immutableMap(responseHeaders); }
/** * Constructor. * * @param restUrl The absolute URL of the REST interface backing the interface proxy. * @param m The Java method. */ public RemoteInterfaceMethod(final String restUrl, Method m) { this.method = m; this.path = m.getName() + '/' + HttpUtils.getMethodArgsSignature(m, true); this.url = trimSlashes(restUrl) + '/' + urlEncode(path); }
/** * Constructor. * * @param restUrl The absolute URL of the REST interface backing the interface proxy. * @param m The Java method. */ public RemoteInterfaceMethod(final String restUrl, Method m) { this.method = m; this.path = m.getName() + '/' + HttpUtils.getMethodArgsSignature(m, true); this.url = trimSlashes(restUrl) + '/' + urlEncode(path); }
/** * Constructor. * * @param restUrl The absolute URL of the REST interface backing the interface proxy. * @param m The Java method. */ public RemoteInterfaceMethod(final String restUrl, Method m) { this.method = m; this.path = m.getName() + '/' + HttpUtils.getMethodArgsSignature(m, true); this.url = trimSlashes(restUrl) + '/' + urlEncode(path); }
/** * Constructor. * * <p> * Leading and trailing slashes are trimmed of all parameters. * * <p> * Any parameter can be <jk>null</jk>. Blanks and nulls are equivalent. * * @param authority * The authority portion of URL (e.g. <js>"http://hostname:port"</js>) * @param contextRoot * The context root of the application (e.g. <js>"/context-root"</js>, or <js>"context-root"</js>) * @param servletPath * The servlet path (e.g. <js>"/servlet-path"</js>, or <js>"servlet-path"</js>) * @param pathInfo * The path info (e.g. <js>"/path-info"</js>, or <js>"path-info"</js>) */ @BeanConstructor(properties="authority,contextRoot,servletPath,pathInfo") public UriContext(String authority, String contextRoot, String servletPath, String pathInfo) { this.authority = nullIfEmpty(trimSlashes(authority)); this.contextRoot = nullIfEmpty(trimSlashes(contextRoot)); this.servletPath = nullIfEmpty(trimSlashes(servletPath)); this.pathInfo = nullIfEmpty(trimSlashes(pathInfo)); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * Constructor. * * <p> * Leading and trailing slashes are trimmed of all parameters. * * <p> * Any parameter can be <jk>null</jk>. Blanks and nulls are equivalent. * * @param authority * The authority portion of URL (e.g. <js>"http://hostname:port"</js>) * @param contextRoot * The context root of the application (e.g. <js>"/context-root"</js>, or <js>"context-root"</js>) * @param servletPath * The servlet path (e.g. <js>"/servlet-path"</js>, or <js>"servlet-path"</js>) * @param pathInfo * The path info (e.g. <js>"/path-info"</js>, or <js>"path-info"</js>) */ @BeanConstructor(properties="authority,contextRoot,servletPath,pathInfo") public UriContext(String authority, String contextRoot, String servletPath, String pathInfo) { this.authority = nullIfEmpty(trimSlashes(authority)); this.contextRoot = nullIfEmpty(trimSlashes(contextRoot)); this.servletPath = nullIfEmpty(trimSlashes(servletPath)); this.pathInfo = nullIfEmpty(trimSlashes(pathInfo)); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * Constructor. * * <p> * Leading and trailing slashes are trimmed of all parameters. * * <p> * Any parameter can be <jk>null</jk>. Blanks and nulls are equivalent. * * @param authority * The authority portion of URL (e.g. <js>"http://hostname:port"</js>) * @param contextRoot * The context root of the application (e.g. <js>"/context-root"</js>, or <js>"context-root"</js>) * @param servletPath * The servlet path (e.g. <js>"/servlet-path"</js>, or <js>"servlet-path"</js>) * @param pathInfo * The path info (e.g. <js>"/path-info"</js>, or <js>"path-info"</js>) */ @BeanConstructor(properties="authority,contextRoot,servletPath,pathInfo") public UriContext(String authority, String contextRoot, String servletPath, String pathInfo) { this.authority = nullIfEmpty(trimSlashes(authority)); this.contextRoot = nullIfEmpty(trimSlashes(contextRoot)); this.servletPath = nullIfEmpty(trimSlashes(servletPath)); this.pathInfo = nullIfEmpty(trimSlashes(pathInfo)); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * Returns the path defined on this servlet if it's defined via {@link RestResource#path()}. * * @return The path defined on this servlet, or an empty string if not specified. */ public synchronized String getPath() { if (context != null) return context.getPath(); for (RestResource rr : ClassUtils.getAnnotations(RestResource.class, this.getClass())) if (! rr.path().isEmpty()) return trimSlashes(rr.path()); return ""; }
/** * Returns the path defined on this servlet if it's defined via {@link RestResource#path()}. * * @return The path defined on this servlet, or an empty string if not specified. */ public synchronized String getPath() { if (context != null) return context.getPath(); for (RestResource rr : ClassUtils.getAnnotations(RestResource.class, this.getClass())) if (! rr.path().isEmpty()) return trimSlashes(rr.path()); return ""; }
/** * Returns the path defined on this servlet if it's defined via {@link RestResource#path()}. * * @return The path defined on this servlet, or an empty string if not specified. */ public synchronized String getPath() { if (context != null) return context.getPath(); for (RestResource rr : ClassUtils.getAnnotations(RestResource.class, this.getClass())) if (! rr.path().isEmpty()) return trimSlashes(rr.path()); return ""; }
/** * String constructor. * * <p> * Input string is a JSON object with the following format: * <js>{authority:'xxx',contextRoot:'xxx',servletPath:'xxx',pathInfo:'xxx'}</js> * * @param s * The input string. * <br>Example: <js>{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}</js> * @throws ParseException * If input string is not a valid JSON object. */ public UriContext(String s) throws ParseException { ObjectMap m = new ObjectMap(s); this.authority = nullIfEmpty(trimSlashes(m.getString("authority"))); this.contextRoot = nullIfEmpty(trimSlashes(m.getString("contextRoot"))); this.servletPath = nullIfEmpty(trimSlashes(m.getString("servletPath"))); this.pathInfo = nullIfEmpty(trimSlashes(m.getString("pathInfo"))); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * String constructor. * * <p> * Input string is a JSON object with the following format: * <js>{authority:'xxx',contextRoot:'xxx',servletPath:'xxx',pathInfo:'xxx'}</js> * * @param s * The input string. * <br>Example: <js>{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}</js> * @throws ParseException * If input string is not a valid JSON object. */ public UriContext(String s) throws ParseException { ObjectMap m = new ObjectMap(s); this.authority = nullIfEmpty(trimSlashes(m.getString("authority"))); this.contextRoot = nullIfEmpty(trimSlashes(m.getString("contextRoot"))); this.servletPath = nullIfEmpty(trimSlashes(m.getString("servletPath"))); this.pathInfo = nullIfEmpty(trimSlashes(m.getString("pathInfo"))); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * String constructor. * * <p> * Input string is a JSON object with the following format: * <js>{authority:'xxx',contextRoot:'xxx',servletPath:'xxx',pathInfo:'xxx'}</js> * * @param s * The input string. * <br>Example: <js>{authority:'http://localhost:10000',contextRoot:'/myContext',servletPath:'/myServlet',pathInfo:'/foo'}</js> * @throws ParseException * If input string is not a valid JSON object. */ public UriContext(String s) throws ParseException { ObjectMap m = new ObjectMap(s); this.authority = nullIfEmpty(trimSlashes(m.getString("authority"))); this.contextRoot = nullIfEmpty(trimSlashes(m.getString("contextRoot"))); this.servletPath = nullIfEmpty(trimSlashes(m.getString("servletPath"))); this.pathInfo = nullIfEmpty(trimSlashes(m.getString("pathInfo"))); this.parentPath = this.pathInfo == null || this.pathInfo.indexOf('/') == -1 ? null : this.pathInfo.substring(0, this.pathInfo.lastIndexOf('/')); }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
@Test public void testTrimSlashes() throws Exception { assertNull(trimSlashes(null)); assertEquals("", trimSlashes("")); assertEquals("", trimSlashes("/")); assertEquals("", trimSlashes("//")); assertEquals("foo/bar", trimSlashes("foo/bar")); assertEquals("foo/bar", trimSlashes("foo/bar//")); assertEquals("foo/bar", trimSlashes("/foo/bar//")); assertEquals("foo/bar", trimSlashes("//foo/bar//")); }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
/** * Constructor. * * @param c The interface class annotated with a {@link RemoteResource @RemoteResource} annotation (optional). */ public RemoteResourceMeta(Class<?> c) { String path = ""; for (RemoteResource r : getAnnotationsParentFirst(RemoteResource.class, c)) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteMethodMeta> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteMethodMeta(path, m, false, "GET")); this.methods = unmodifiableMap(methods); this.path = path; }
/** * Constructor. * * @param c * The interface class annotated with a {@link RemoteInterface @RemoteInterface} annotation. * <br>Note that the annotations are optional. * @param uri * The absolute URL of the remote REST interface that implements this proxy interface. * <br>This is only used on the client side. */ public RemoteInterfaceMeta(Class<?> c, String uri) { this.c = c; String path = ""; List<RemoteInterface> rr = getAnnotationsParentFirst(RemoteInterface.class, c); for (RemoteInterface r : rr) if (! r.path().isEmpty()) path = trimSlashes(r.path()); Map<Method,RemoteInterfaceMethod> methods = new LinkedHashMap<>(); for (Method m : c.getMethods()) if (isPublic(m)) methods.put(m, new RemoteInterfaceMethod(uri, m)); Map<String,RemoteInterfaceMethod> methodsByPath = new LinkedHashMap<>(); for (RemoteInterfaceMethod rmm : methods.values()) methodsByPath.put(rmm.getPath(), rmm); this.methods = unmodifiableMap(methods); this.methodsByPath = unmodifiableMap(methodsByPath); this.path = path; }