/** * Returns the base url of a request. */ public static String getBaseURL( Request request ) { Reference ref = request.getResourceRef(); HttpServletRequest servletRequest = getServletRequest(request); if ( servletRequest != null ) { String baseURL = ref.getIdentifier(); return baseURL.substring(0, baseURL.length()-servletRequest.getPathInfo().length()); } else { return ref.getParentRef().getIdentifier(); } }
private void doGet(Request request, Response response) { Reference resourceRef = request.getResourceRef(); String baseUrl = resourceRef.toString(); if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } Representation result = new StringRepresentation( "<html><body>\n" + "<a id=\"logo\" href=\"" + resourceRef.getParentRef() + "\">" + "<img src=\"" + baseUrl + "/web/geowebcache_logo.png\" alt=\"\" height=\"100\" width=\"353\" border=\"0\"/></a>\n" + "<h3>Resources available from here:</h3>" + "<ul>" + "<li><h4><a href=\"" + baseUrl + "/layers/\">layers</a></h4>" + "Lets you see the configured layers. You can also view a specific layer " + " by appending the name of the layer to the URL, DELETE an existing layer " + " or POST a new one. Note that the latter operations only make sense when GeoWebCache" + " has been configured through geowebcache.xml. You can POST either XML or JSON." + "</li>\n" + "<li><h4>seed</h4>" + "" + "</li>\n" + "</ul>" + "</body></html>", MediaType.TEXT_HTML); response.setEntity(result); } }
@Override public Reference getContextRoot(Request request) { Reference result = null; if (globalRestApiSettings.isEnabled() && globalRestApiSettings.isForceBaseUrl() && StringUtils.isNotEmpty(globalRestApiSettings.getBaseUrl())) { result = new Reference(globalRestApiSettings.getBaseUrl()); } else { // TODO: NEXUS-6045 hack, Restlet app root is now "/service/local", so going up 2 levels! result = request.getRootRef().getParentRef().getParentRef(); } // fix for when restlet is at webapp root if (StringUtils.isEmpty(result.getPath())) { result.setPath("/"); } return result; }
/** * GET outputs an existing layer * * @param req * @param resp * @throws RestletException * @throws */ protected void doGet(Request req, Response resp) throws RestletException { String layerName = (String) req.getAttributes().get("layer"); final String formatExtension = (String) req.getAttributes().get("extension"); Representation representation; if (layerName == null) { String restRoot = req.getResourceRef().getParentRef().toString(); if (restRoot.endsWith("/")) { restRoot = restRoot.substring(0, restRoot.length() - 1); } representation = listLayers(formatExtension, restRoot); } else { try { layerName = URLDecoder.decode(layerName, "UTF-8"); } catch (UnsupportedEncodingException uee) { } representation = doGetInternal(layerName, formatExtension); } resp.setEntity(representation); }
/** * Returns a representation of the list in "text/html" format. * * @return A representation of the list in "text/html" format. */ public Representation getWebRepresentation() { // Create a simple HTML list final StringBuilder sb = new StringBuilder(); sb.append("<html><body style=\"font-family: sans-serif;\">\n"); if (getIdentifier() != null) { sb.append("<h2>Listing of \"" + getIdentifier().getPath() + "\"</h2>\n"); final Reference parentRef = getIdentifier().getParentRef(); if (!parentRef.equals(getIdentifier())) { sb.append("<a href=\"" + parentRef + "\">..</a><br>\n"); } } else { sb.append("<h2>List of references</h2>\n"); } for (final Reference ref : this) { sb.append("<a href=\"" + ref.toString() + "\">" + ref.getRelativeRef(getIdentifier()) + "</a><br>\n"); } sb.append("</body></html>\n"); return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML); }
/** * Returns a representation of the list in "text/html" format. * * @return A representation of the list in "text/html" format. */ public Representation getWebRepresentation() { // Create a simple HTML list final StringBuilder sb = new StringBuilder(); sb.append("<html><body>\n"); if (getIdentifier() != null) { sb.append("<h2>Listing of \"" + getIdentifier().getPath() + "\"</h2>\n"); final Reference parentRef = getIdentifier().getParentRef(); if (!parentRef.equals(getIdentifier())) { sb.append("<a href=\"" + parentRef + "\">..</a><br>\n"); } } else { sb.append("<h2>List of references</h2>\n"); } for (final Reference ref : this) { sb.append("<a href=\"" + ref.toString() + "\">" + ref.getRelativeRef(getIdentifier()) + "</a><br>\n"); } sb.append("</body></html>\n"); return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML); }
/** * Returns a representation of the list in "text/html" format. * * @return A representation of the list in "text/html" format. */ public Representation getWebRepresentation() { // Create a simple HTML list final StringBuilder sb = new StringBuilder(); sb.append("<html><body style=\"font-family: sans-serif;\">\n"); if (getIdentifier() != null) { sb.append("<h2>Listing of \"" + getIdentifier().getPath() + "\"</h2>\n"); final Reference parentRef = getIdentifier().getParentRef(); if (!parentRef.equals(getIdentifier())) { sb.append("<a href=\"" + parentRef + "\">..</a><br>\n"); } } else { sb.append("<h2>List of references</h2>\n"); } for (final Reference ref : this) { sb.append("<a href=\"" + ref.toString() + "\">" + ref.getRelativeRef(getIdentifier()) + "</a><br>\n"); } sb.append("</body></html>\n"); return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML); }
baseURL = Request.getCurrent().getRootRef().getParentRef().getParentRef().toString();
private String getResourceUri(Request req, ContentListResource resource, StorageItem child) { // NEXUS-4244: simply force both baseURLs, coming from nexus.xml and extracted from current request // to end with slash ("/"). Reference root = getContextRoot(req); if (StringUtils.isBlank(root.getPath()) || !root.getPath().endsWith("/")) { root.setPath(StringUtils.defaultString(root.getPath(), "") + "/"); } Reference requestRoot = req.getRootRef().getParentRef().getParentRef(); if (StringUtils.isBlank(requestRoot.getPath()) || !requestRoot.getPath().endsWith("/")) { requestRoot.setPath(StringUtils.defaultString(requestRoot.getPath(), "") + "/"); } final Reference ref = req.getResourceRef().getTargetRef(); String uri = ref.toString(); if (ref.getQuery() != null) { uri = uri.substring(0, uri.length() - ref.getQuery().length() - 1); } if (!uri.endsWith("/")) { uri += "/"; } uri += child.getName(); if (!resource.isLeaf()) { uri += "/"; } if (root == requestRoot || root.equals(requestRoot)) { return uri; } else { return uri.replace(requestRoot.toString(), root.toString()); } }
String baseURL = request.getRootRef().getParentRef().toString(); String rootPath = request.getRootRef().toString().substring(baseURL.length()); String pagePath = request.getResourceRef().toString().substring(baseURL.length());
/** * Remove this resource. */ @Delete public void removeContact() throws ResourceException { getObjectsFacade().deleteContact(this.user, this.contact); getResponse().redirectSeeOther( getRequest().getResourceRef().getParentRef()); }
/** * Remove this resource. */ @Delete public void removeUser() throws ResourceException { getObjectsFacade().deleteUser(this.user); getResponse().redirectSeeOther( getRequest().getResourceRef().getParentRef()); }
/** * Returns the parent resource. The parent resource is defined in the sense * of hierarchical URIs. If the resource URI is not hierarchical, then an * exception is thrown. * * @return The parent resource. */ public ClientResource getParent() throws ResourceException { ClientResource result = null; if (getReference().isHierarchical()) { result = new ClientResource(this); result.setReference(getReference().getParentRef()); } else { doError(Status.CLIENT_ERROR_BAD_REQUEST, "The resource URI is not hierarchical."); } return result; }
/** * Sets up a new authorization session. * * @param redirectUri * The redirection URI. */ protected static AuthSession setupAuthSession(RedirectionURI redirectUri) { getLogger().fine("Base ref = " + getReference().getParentRef()); AuthSession session = AuthSession.newAuthSession(); session.setRedirectionURI(redirectUri); CookieSetting cs = new CookieSetting(ClientCookieID, session.getId()); // TODO create a secure mode setting, update all cookies // cs.setAccessRestricted(true); // cs.setSecure(true); getResourceCookieSettings().add(cs); getLogger().fine("Setting cookie in SetupSession - " + session.getId()); getResourceContext().getAttributes().put(session.getId(), session); return session; }
/** * Sets up a new authorization session. * * @param redirectUri * The redirection URI. */ protected AuthSession setupAuthSession(RedirectionURI redirectUri) { getLogger().fine("Base ref = " + getReference().getParentRef()); AuthSession session = AuthSession.newAuthSession(); session.setRedirectionURI(redirectUri); CookieSetting cs = new CookieSetting(ClientCookieID, session.getId()); // TODO create a secure mode setting, update all cookies // cs.setAccessRestricted(true); // cs.setSecure(true); getCookieSettings().add(cs); getLogger().fine("Setting cookie in SetupSession - " + session.getId()); getContext().getAttributes().put(session.getId(), session); return session; }
resource.setRepositories(getRepositoryRouteMemberRepositoryList(request.getResourceRef().getParentRef(), route.getMappedRepositories(), request, route.getId()));
resource.setRepositories( getRepositoryRouteMemberRepositoryList( request.getResourceRef().getParentRef(), route.getMappedRepositories(), request, route.getId() ) );