# HG changeset patch # User casties # Date 1423586756 -3600 # Node ID fcb6fe10e08c10a5ebe08995216efd1477441d7e # Parent cf44d9e1a4a788c545827f19e13ee30d4a9f764e added config option for webapp URL prefix. diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java Sun Feb 08 18:09:00 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorRestlet.java Tue Feb 10 17:45:56 2015 +0100 @@ -29,6 +29,8 @@ import org.restlet.engine.application.CorsFilter; import org.restlet.routing.Router; +import de.mpiwg.itgroup.annotations.restlet.utils.UrlPrefixFilter; + /** * @author casties * @@ -45,6 +47,7 @@ @Override public Restlet createInboundRoot() { + Restlet root = null; Router router = new Router(getContext()); router.attach("/annotations", AnnotatorAnnotations.class); @@ -58,18 +61,27 @@ router.attach("/resources/{id}", AnnotatorResources.class); router.attach("/resources/{id}/annotations", AnnotatorAnnotationsByResources.class); router.attach("/", AnnotatorInfo.class); - //return router; + root = router; // this.authenticator = createAuthenticator(); // authenticator.setNext(router); - // return authenticator; + + if (this.webappUriPrefix != null) { + // add prefix path to url + UrlPrefixFilter prefixFilter = new UrlPrefixFilter(); + prefixFilter.setPrefix(this.webappUriPrefix);; + prefixFilter.setNext(root); + root = prefixFilter; + } // handle Cross-Origin-Resource-Security headers CorsFilter corsFilter = new CorsFilter(getContext(), router); corsFilter.setAllowedOrigins(new HashSet(Arrays.asList("*"))); corsFilter.setAllowedCredentials(true); - corsFilter.setNext(router); - return corsFilter; + corsFilter.setNext(root); + root = corsFilter; + + return root; } diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Sun Feb 08 18:09:00 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Tue Feb 10 17:45:56 2015 +0100 @@ -114,6 +114,12 @@ public static final String AUTHORIZATION_MODE_KEY = "annotationmanager.authorization"; /** + * prefix for webapp URLs (if needed by proxying). + */ + protected String webappUriPrefix = null; + public static final String WEBAPP_PREFIX = "annotationmanager.webapp.prefix"; + + /** * prefix to create uris for tags in store. */ public static String TAGS_URI_PREFIX = ""; @@ -171,6 +177,7 @@ */ graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath); ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null); + webappUriPrefix = serverConfig.getProperty(WEBAPP_PREFIX, null); /* * uri prefixes */ diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java Sun Feb 08 18:09:00 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsResource.java Tue Feb 10 17:45:56 2015 +0100 @@ -48,7 +48,7 @@ */ public class AnnotationsResource extends ServerResource { - public static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.restlet.annotations_ui.AnnotationsResource"); + public static Logger logger = Logger.getLogger(AnnotationsResource.class.getCanonicalName()); private AnnotationStore store; diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java Sun Feb 08 18:09:00 2015 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/annotations_ui/AnnotationsUiRestlet.java Tue Feb 10 17:45:56 2015 +0100 @@ -34,6 +34,7 @@ import org.restlet.security.MapVerifier; import de.mpiwg.itgroup.annotations.restlet.BaseRestlet; +import de.mpiwg.itgroup.annotations.restlet.utils.UrlPrefixFilter; /** * @author casties @@ -53,9 +54,9 @@ @Override public Restlet createInboundRoot() { // this.authenticator = createAuthenticator(); - + Restlet root = null; + Router router = new Router(getContext()); - router.attach("/groups", GroupsResource.class); router.attach("/groups/", GroupsResource.class); router.attach("/groups/{id}", GroupResource.class); @@ -69,8 +70,16 @@ router.attach("/annotations/", AnnotationsResource.class); router.attach("/annotations/{id}", AnnotationResource.class); router.attach("/annotations/{id}/", AnnotationResource.class); - router.attach("/", InfoResource.class); + root = router; + + if (this.webappUriPrefix != null) { + // add prefix path to url + UrlPrefixFilter prefixFilter = new UrlPrefixFilter(); + prefixFilter.setPrefix(this.webappUriPrefix);; + prefixFilter.setNext(root); + root = prefixFilter; + } // use simple password verifier MapVerifier verifier = new MapVerifier(); @@ -86,8 +95,10 @@ ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial"); guard.setVerifier(verifier); // put everything through guard - guard.setNext(router); - return guard; + guard.setNext(root); + root = guard; + + return root; } @Override diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/UrlPrefixFilter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/utils/UrlPrefixFilter.java Tue Feb 10 17:45:56 2015 +0100 @@ -0,0 +1,67 @@ +package de.mpiwg.itgroup.annotations.restlet.utils; + +/* + * #%L + * AnnotationManager + * %% + * Copyright (C) 2012 - 2015 MPIWG Berlin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * . + * #L% + */ + +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.data.Reference; +import org.restlet.routing.Filter; + +/** + * Filter that adds a prefix path to all internally generated URLs. + * + * @author casties + * + */ +public class UrlPrefixFilter extends Filter { + + private String prefix = null; + + /** + * Set the prefix to add. + * + * @param prefix + */ + public void setPrefix(String prefix) { + if (!prefix.startsWith("/")) { + prefix = "/" + prefix; + } + this.prefix = prefix; + } + + @Override + protected int beforeHandle(Request request, Response response) { + // get ref to change + Reference ref = request.getResourceRef(); + String path = ref.getPath(); + // add prefix to path + ref.setPath(prefix + path); + // change baseRef as well + Reference baseRef = ref.getBaseRef(); + String basePath = baseRef.getPath(); + // add prefix to base ref path + baseRef.setPath(prefix + basePath); + return super.beforeHandle(request, response); + } + +} diff -r cf44d9e1a4a7 -r fcb6fe10e08c src/main/webapp/WEB-INF/serverconfig.property.template --- a/src/main/webapp/WEB-INF/serverconfig.property.template Sun Feb 08 18:09:00 2015 +0100 +++ b/src/main/webapp/WEB-INF/serverconfig.property.template Tue Feb 10 17:45:56 2015 +0100 @@ -9,3 +9,4 @@ annotationmanager.uris.persons = http://entities.mpiwg-berlin.mpg.de/persons/ annotationmanager.uris.groups = http://entities.mpiwg-berlin.mpg.de/groups/ annotationmanager.uris.annotations = http://entities.mpiwg-berlin.mpg.de/annotations/ +#annotationmanager.webapp.prefix = /annotations