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:com.exedio.cope.live.Anchor.java

Anchor(final boolean draftsEnabled, final HttpServletRequest request, final String username,
        final Session session, final String sessionName) {
    this.defaultTarget = draftsEnabled ? TargetNewDraft.INSTANCE : TargetLive.INSTANCE;
    this.draftsEnabled = draftsEnabled;

    this.borderDisableButtonURL = LiveServlet.borderDisable.getURL(request);
    this.borderEnableButtonURL = LiveServlet.borderEnable.getURL(request);
    this.hideButtonURL = LiveServlet.hide.getURL(request);
    this.closeButtonURL = LiveServlet.close.getURL(request);
    this.errorButtonURL = LiveServlet.error.getURL(request);
    this.servletPath = request.getContextPath() + request.getServletPath() + '/'; // TODO remove trailing slash

    this.username = username;
    this.session = session;
    this.sessionName = sessionName;
    this.target = defaultTarget;
    assert defaultTarget != null;
    assert username != null;
    assert session != null;
}

From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Builds a URL to redirect the supplied request to HTTPS. Used to redirect
 * the current request to HTTPS, before doing a forward to the login page.
 *
 * @param request/*from ww w.j a  v  a  2 s .c o  m*/
 * @return
 * @throws java.io.IOException
 * @throws javax.servlet.ServletException
 */
protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request)
        throws IOException, ServletException {

    int serverPort = portResolver.getServerPort(request);
    Integer httpsPort = portMapper.lookupHttpsPort(serverPort);

    if (httpsPort != null) {
        RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
        urlBuilder.setScheme("https");
        urlBuilder.setServerName(request.getServerName());
        urlBuilder.setPort(httpsPort);
        urlBuilder.setContextPath(request.getContextPath());
        urlBuilder.setServletPath(request.getServletPath());
        urlBuilder.setPathInfo(request.getPathInfo());
        urlBuilder.setQuery(request.getQueryString());

        return urlBuilder.getUrl();
    }

    // Fall through to server-side forward with warning message
    logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);

    return null;
}

From source file:com.senseidb.servlet.AbstractSenseiClientServlet.java

private void handleJMXRequest(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    InputStream is = null;//from w ww.j av  a2s.com
    OutputStream os = null;
    try {
        String myPath = req.getRequestURI().substring(req.getServletPath().length() + 11);
        URL adminUrl = null;
        if (myPath.indexOf('/') > 0) {
            adminUrl = new URL(
                    new StringBuilder(URLDecoder.decode(myPath.substring(0, myPath.indexOf('/')), "UTF-8"))
                            .append("/admin/jmx").append(myPath.substring(myPath.indexOf('/'))).toString());
        } else {
            adminUrl = new URL(
                    new StringBuilder(URLDecoder.decode(myPath, "UTF-8")).append("/admin/jmx").toString());
        }

        URLConnection conn = adminUrl.openConnection();

        byte[] buffer = new byte[8192]; // 8k
        int len = 0;

        InputStream ris = req.getInputStream();

        while ((len = ris.read(buffer)) > 0) {
            if (!conn.getDoOutput()) {
                conn.setDoOutput(true);
                os = conn.getOutputStream();
            }
            os.write(buffer, 0, len);
        }
        if (os != null)
            os.flush();

        is = conn.getInputStream();
        OutputStream ros = resp.getOutputStream();

        while ((len = is.read(buffer)) > 0) {
            ros.write(buffer, 0, len);
        }
        ros.flush();
    } catch (Exception e) {
        throw new ServletException(e.getMessage(), e);
    } finally {
        if (is != null)
            is.close();
        if (os != null)
            os.close();
    }
}

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

/**
 * Creates a new Entity//from w  w w.ja  v  a2s .com
 *
 * @return a reply...
 * @throws McBasicRestException
 */
protected ResponseEntity<T> createEntity(HttpServletRequest request, String orgMrn, T input)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        // Check that the entity being created belongs to the organization
        if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn)
                .equals(MrnUtil.getOrgShortNameFromEntityMrn(input.getMrn()))) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS,
                    request.getServletPath());
        }
        input.setIdOrganization(org.getId());
        try {
            T newEntity = this.entityService.save(input);
            return new ResponseEntity<>(newEntity, HttpStatus.OK);
        } catch (DataIntegrityViolationException e) {
            throw new McBasicRestException(HttpStatus.CONFLICT, e.getRootCause().getMessage(),
                    request.getServletPath());
        }
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

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

/**
 * Creates or updates a logo for an organization
 * @param request request to get servletPath
 * @param orgMrn resource location for organization
 * @param logo the log encoded as a MultipartFile
 * @throws McBasicRestException/*from   w w w.j  ava 2  s .c o  m*/
 */
@RequestMapping(value = "/api/org/{orgMrn}/logo", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> createLogoPost(HttpServletRequest request, @PathVariable String orgMrn,
        @RequestParam("logo") MultipartFile logo) throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        try {
            this.updateLogo(org, logo.getInputStream());
            organizationService.save(org);
            return new ResponseEntity<>(HttpStatus.CREATED);
        } catch (IOException e) {
            log.error("Unable to create logo", e);
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_IMAGE,
                    request.getServletPath());
        }
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:com.buaa.cfs.conf.ReconfigurationServlet.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    LOG.info("POST");
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    Reconfigurable reconf = getReconfigurable(req);
    String nodeName = reconf.getClass().getCanonicalName();

    printHeader(out, nodeName);//from   w  w  w . j av a  2  s .  com

    try {
        applyChanges(out, reconf, req);
    } catch (ReconfigurationException e) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, StringUtils.stringifyException(e));
        return;
    }

    out.println("<p><a href=\"" + req.getServletPath() + "\">back</a></p>");
    printFooter(out);
}

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

/**
 * Returns info about the entity identified by the given ID
 *
 * @return a reply...//from   ww w  .  j a v a2s  .c o m
 * @throws McBasicRestException
 */
protected ResponseEntity<T> getEntity(HttpServletRequest request, String orgMrn, String entityMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        // Check that the entity being queried belongs to the organization
        if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn)
                .equals(MrnUtil.getOrgShortNameFromEntityMrn(entityMrn))) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS,
                    request.getServletPath());
        }
        T entity = this.entityService.getByMrn(entityMrn);
        if (entity == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND,
                    request.getServletPath());
        }
        if (entity.getIdOrganization().compareTo(org.getId()) == 0) {
            return new ResponseEntity<>(entity, HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (logger.isMdwDebugEnabled()) {
        logger.mdwDebug("SOAP Listener GET Request:\n" + request.getRequestURI()
                + (request.getQueryString() == null ? "" : ("?" + request.getQueryString())));
    }//  ww  w .j a  v  a2  s  .c o m

    if (request.getServletPath().endsWith(RPC_SERVICE_PATH) || RPC_SERVICE_PATH.equals(request.getPathInfo())) {
        Asset rpcWsdlAsset = AssetCache.getAsset(Package.MDW + "/MdwRpcWebService.wsdl", Asset.WSDL);
        response.setContentType("text/xml");
        response.getWriter().print(substituteRuntimeWsdl(rpcWsdlAsset.getStringContent()));
    } else if (request.getPathInfo() == null || request.getPathInfo().equalsIgnoreCase("mdw.wsdl")) {
        // forward to general wsdl
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/mdw.wsdl");
        requestDispatcher.forward(request, response);
    } else if (request.getPathInfo().toUpperCase().endsWith(Asset.WSDL)) {
        String wsdlAsset = request.getPathInfo().substring(1);
        Asset asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        if (asset == null) {
            // try trimming file extension
            wsdlAsset = wsdlAsset.substring(0, wsdlAsset.length() - 5);
            asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        }
        if (asset == null) {
            // try with lowercase extension
            wsdlAsset = wsdlAsset + ".wsdl";
            asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        }
        if (asset == null) {
            String message = "No WSDL resource found: " + request.getPathInfo().substring(1);
            logger.severe(message);
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.getWriter().print(message);
        } else {
            response.setContentType("text/xml");
            response.getWriter().print(substituteRuntimeWsdl(asset.getStringContent()));
        }
    } else {
        ServletException ex = new ServletException(
                "HTTP GET not supported for URL: " + request.getRequestURL());
        logger.severeException(ex.getMessage(), ex);
        throw ex;
    }
}

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

/**
 * Deletes a Device/*from   w w w  .j a  va  2  s  .  co m*/
 *
 * @return a reply...
 * @throws McBasicRestException
 */
protected ResponseEntity<?> deleteEntity(HttpServletRequest request, String orgMrn, String entityMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        // Check that the entity being deleted belongs to the organization
        if (!MrnUtil.getOrgShortNameFromOrgMrn(orgMrn)
                .equals(MrnUtil.getOrgShortNameFromEntityMrn(entityMrn))) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.MISSING_RIGHTS,
                    request.getServletPath());
        }
        T entity = this.entityService.getByMrn(entityMrn);
        if (entity == null) {
            throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ENTITY_NOT_FOUND,
                    request.getServletPath());
        }
        if (entity.getIdOrganization().compareTo(org.getId()) == 0) {
            this.entityService.delete(entity.getId());
            return new ResponseEntity<>(HttpStatus.OK);
        }
        throw new McBasicRestException(HttpStatus.FORBIDDEN, MCIdRegConstants.MISSING_RIGHTS,
                request.getServletPath());
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java

/**
 * Builds a URL to redirect the supplied request to HTTPS. Used to redirect the current request
 * to HTTPS, before doing a forward to the login page.
 *//*from w w w  .j a v a2s .c  om*/
protected String buildHttpsRedirectUrlForRequest(HttpServletRequest request)
        throws IOException, ServletException {

    int serverPort = portResolver.getServerPort(request);
    Integer httpsPort = portMapper.lookupHttpsPort(Integer.valueOf(serverPort));

    if (httpsPort != null) {
        RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder();
        urlBuilder.setScheme("https");
        urlBuilder.setServerName(request.getServerName());
        urlBuilder.setPort(httpsPort.intValue());
        urlBuilder.setContextPath(request.getContextPath());
        urlBuilder.setServletPath(request.getServletPath());
        urlBuilder.setPathInfo(request.getPathInfo());
        urlBuilder.setQuery(request.getQueryString());

        return urlBuilder.getUrl();
    }

    // Fall through to server-side forward with warning message
    logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort);

    return null;
}