Example usage for javax.servlet.http HttpServletRequest getServletPath

List of usage examples for javax.servlet.http HttpServletRequest getServletPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletPath.

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:cec.easyshop.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }/*  ww  w  .  j  a v  a 2  s. c  o m*/

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old + "/")) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old + "/", "/" + current + "/");
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.google.acre.servlet.ProxyPassServlet.java

private String getProxyURL(HttpServletRequest httpServletRequest) {
    // Set the protocol to HTTP
    String stringProxyURL = "http://" + this.metawebAPIHostAndPort;
    // Check if we are proxying to a path other that the document root
    if ("USE_SERVLET_PATH".equals(this.metawebAPIPath)) {
        //if proxy path is set to USE_SERVLET_PATH - use the servlet path
        stringProxyURL += httpServletRequest.getServletPath();
    } else {/*from   w  w  w . j  av a  2  s. c  om*/
        stringProxyURL += this.metawebAPIPath;
    }

    // Handle the path given to the servlet
    if (httpServletRequest.getPathInfo() != null)
        stringProxyURL += httpServletRequest.getPathInfo();

    // Handle the query string
    if (httpServletRequest.getQueryString() != null) {
        stringProxyURL += "?" + httpServletRequest.getQueryString();
    }
    return stringProxyURL;
}

From source file:net.maritimecloud.identityregistry.controllers.RoleController.java

/**
 * Returns a list of rolemappings for this organization
 *
 * @return a reply.../*  w ww .ja  va  2  s. c  o  m*/
 */
@RequestMapping(value = "/api/org/{orgMrn}/roles", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<List<Role>> getRoles(HttpServletRequest request, @PathVariable String orgMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        List<Role> roles = this.roleService.listFromOrg(org.getId());
        return new ResponseEntity<>(roles, HttpStatus.OK);
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:com.twinsoft.convertigo.engine.servlets.GenericServlet.java

protected void handleStaticData(HttpServletRequest request, HttpServletResponse response) {
    String resourceUri = request.getServletPath();
    Engine.logContext.debug("Serving static ressource: " + resourceUri);

    // TODO: enhance to support content types according to file extension
    if (resourceUri.endsWith(".xml") || resourceUri.endsWith(".cxml") || resourceUri.endsWith(".pxml"))
        response.setContentType(MimeType.TextXml.value());
    else//from   www.  j a  v a  2  s .  c o  m
        response.setContentType(MimeType.Html.value());

    try {
        InputStream is = getServletContext().getResourceAsStream(resourceUri);
        if (is == null) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND,
                    "Static resource " + resourceUri + " not found");
            return;
        }

        byte array[] = new byte[4096];

        OutputStream os = response.getOutputStream();
        while (is.available() != 0) {
            int nb = is.read(array);
            os.write(array, 0, nb);
        }
        os.flush();

    } catch (IOException e) {
        Engine.logContext.trace("Error serving static resource: " + resourceUri);
    }
}

From source file:azkaban.webapp.servlet.LoginAbstractAzkabanServlet.java

private boolean handleFileGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    if (webResourceDirectory == null) {
        return false;
    }//w  w  w .  j a v a 2s.  co  m

    // Check if it's a resource
    String prefix = req.getContextPath() + req.getServletPath();
    String path = req.getRequestURI().substring(prefix.length());
    int index = path.lastIndexOf('.');
    if (index == -1) {
        return false;
    }

    String extension = path.substring(index);
    if (contextType.containsKey(extension)) {
        File file = new File(webResourceDirectory, path);
        if (!file.exists() || !file.isFile()) {
            return false;
        }

        resp.setContentType(contextType.get(extension));

        OutputStream output = resp.getOutputStream();
        BufferedInputStream input = null;
        try {
            input = new BufferedInputStream(new FileInputStream(file));
            IOUtils.copy(input, output);
        } finally {
            if (input != null) {
                input.close();
            }
        }
        output.flush();
        return true;
    }

    return false;
}

From source file:org.jtwig.functions.SpringFunctions.java

@JtwigFunction(name = "render")
public String render(HttpServletRequest request, @Parameter String url,
        @Parameter Map<String, String> parameters) throws FunctionException {
    RenderHttpServletResponse responseWrapper = new RenderHttpServletResponse();
    RenderHttpServletRequest builder = new RenderHttpServletRequest(request).to(url).withMethod(GET);

    for (Map.Entry<String, String> entry : parameters.entrySet()) {
        builder.withGetParameter(entry.getKey(), entry.getValue());
    }/*from w ww  .j a va 2 s. c  om*/

    try {
        RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getServletPath());
        requestDispatcher.include(builder, responseWrapper);

        return responseWrapper.toString();
    } catch (ServletException | IOException e) {
        throw new FunctionException(e);
    }
}

From source file:org.reallysqs.server.views.QueueListView.java

@SuppressWarnings("unchecked")
@Override/*from  w  w  w  .  j  av  a  2s .  c  o m*/
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    response.setContentType("text/xml");

    Map<String, Queue> queues = (Map<String, Queue>) model.get("queues");

    Collection<Queue> queueList = queues.values();

    ServletOutputStream outputStream = response.getOutputStream();
    outputStream.print(prelude);

    for (Queue queue : queueList) {
        outputStream.print("<QueueUrl>");
        outputStream.print("http://" + request.getLocalName() + ":" + request.getLocalPort()
                + request.getContextPath() + request.getServletPath() + "/queues/" + queue.getName());
        outputStream.print("</QueueUrl>");
    }

    outputStream.print(epilogue);

}