Example usage for javax.servlet.http HttpServletRequest getRequestURL

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

Introduction

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

Prototype

public StringBuffer getRequestURL();

Source Link

Document

Reconstructs the URL the client used to make the request.

Usage

From source file:by.iharkaratkou.TestServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *//*from www.  j  a  va 2  s  . c  o  m*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String text = "some text Ihar";
    String url = request.getRequestURL().toString();
    System.out.println("url " + url);
    String[] urlParts = url.split("/");
    String id = urlParts[5];
    System.out.println("id " + id);
    String password = urlParts[6];
    System.out.println("password " + password);

    DBUtils dbu = new DBUtils();
    Integer isIDexist = 0;
    Integer isPasswordCorrect = 0;
    try {
        isIDexist = dbu.checkID(Integer.valueOf(id));
        if (isIDexist > 0) {
            isPasswordCorrect = dbu.checkPassword(Integer.valueOf(id), password);
        }
        //System.out.println("isIDexist " + isIDexist);
    } catch (NumberFormatException | ClassNotFoundException | SQLException e) {

        e.printStackTrace();
    }
    System.out.println("isIDexist " + isIDexist);
    System.out.println("isPasswordCorrect " + isPasswordCorrect);
    response.setContentType("text/plain"); // Set content type of the response so that jQuery knows what it can expect.
    response.setCharacterEncoding("UTF-8"); // You want world domination, huh?
    response.getWriter().write(isIDexist.toString() + isPasswordCorrect.toString()); // Write response body.
}

From source file:com.vmware.identity.SharedUtils.java

/**
 * Create mock request based on the url/*from  w w w  .  ja  v a 2  s.  c o  m*/
 *
 * @param string
 * @return
 * @throws MalformedURLException
 * @throws UnsupportedEncodingException
 */
public static HttpServletRequest buildMockRequestObjectFromUrl(String string)
        throws MalformedURLException, UnsupportedEncodingException {
    Cookie[] expectedCookies = new Cookie[] {};

    URL url = new URL(string);
    Map<String, String> queryMap = getQueryMap(url.getQuery());

    String samlRequestParameter = getParameterFromQueryMap(queryMap, Shared.SAML_REQUEST_PARAMETER);
    String relayStateParameter = getParameterFromQueryMap(queryMap, Shared.RELAY_STATE_PARAMETER);
    String sigAlgParameter = getParameterFromQueryMap(queryMap, Shared.SIGNATURE_ALGORITHM_PARAMETER);
    String signatureParameter = getParameterFromQueryMap(queryMap, Shared.SIGNATURE_PARAMETER);
    StringBuffer sbRequestUrl = new StringBuffer();
    sbRequestUrl.append(string.replace("?" + url.getQuery(), ""));

    // build mock request object
    HttpServletRequest request = createMock(HttpServletRequest.class);
    expect(request.getCookies()).andReturn(expectedCookies).anyTimes();
    expect(request.getParameter(Shared.SAML_REQUEST_PARAMETER)).andReturn(samlRequestParameter).anyTimes();
    expect(request.getParameter(Shared.RELAY_STATE_PARAMETER)).andReturn(relayStateParameter).anyTimes();
    expect(request.getParameter(Shared.SIGNATURE_ALGORITHM_PARAMETER)).andReturn(sigAlgParameter).anyTimes();
    expect(request.getParameter(Shared.SIGNATURE_PARAMETER)).andReturn(signatureParameter).anyTimes();
    expect(request.getRequestURL()).andReturn(sbRequestUrl).anyTimes();
    expect(request.getParameter(Shared.REQUEST_AUTH_PARAM)).andReturn(TestConstants.AUTHORIZATION).anyTimes();
    String queryString = Shared.SAML_REQUEST_PARAMETER + "=" + samlRequestParameter;
    if (relayStateParameter != null) {
        queryString = queryString + "&" + Shared.RELAY_STATE_PARAMETER + "=" + relayStateParameter;
    }
    if (sigAlgParameter != null) {
        queryString = queryString + "&" + Shared.SIGNATURE_ALGORITHM_PARAMETER + "=" + sigAlgParameter;
    }
    if (signatureParameter != null) {
        queryString = queryString + "&" + Shared.SIGNATURE_PARAMETER + "=" + signatureParameter;
    }
    expect(request.getQueryString()).andReturn(queryString).anyTimes();

    replay(request);
    return request;
}

From source file:ch.unifr.pai.twice.widgets.mpproxy.server.SimpleHttpUrlConnectionServletFilter.java

/**
 * @param request/*w  ww.  j a  v a  2  s. c  o  m*/
 * @return the full request string including GET-parameters
 */
private String getFullRequestString(HttpServletRequest request) {
    StringBuilder sb = new StringBuilder();
    sb.append(request.getRequestURL());
    if (request.getQueryString() != null) {
        sb.append("?");
        sb.append(request.getQueryString());
    }
    return sb.toString();
}

From source file:org.lareferencia.xoai.services.impl.xoai.LRRepositoryConfiguration.java

@Override
public String getBaseUrl() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();/*  w w w .j  a v  a  2  s . c  o m*/
    if (baseUrl == null) {
        baseUrl = request.getRequestURL().toString().replace(request.getPathInfo(), "");
    }
    return baseUrl + request.getPathInfo();
}

From source file:com.artivisi.belajar.restful.ui.controller.ApplicationConfigController.java

@RequestMapping(value = "/config", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)/*from ww  w. j av a2  s. c o m*/
public void create(@RequestBody @Valid ApplicationConfig config, HttpServletRequest request,
        HttpServletResponse response) {
    belajarRestfulService.save(config);
    String requestUrl = request.getRequestURL().toString();
    URI uri = new UriTemplate("{requestUrl}/{id}").expand(requestUrl, config.getId());
    response.setHeader("Location", uri.toASCIIString());
}

From source file:com.mir00r.interceptor.MaintenanceInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    //  super.afterCompletion(request, response, handler, ex); //To change body of generated methods, choose Tools | Templates.

    System.out.println("Request URL :: " + request.getRequestURL().toString() + "End Time = "
            + System.currentTimeMillis());
}

From source file:com.haulmont.restapi.controllers.EntitiesController.java

@PostMapping("/{entityName}")
public ResponseEntity<String> createEntity(@RequestBody String entityJson, @PathVariable String entityName,
        @RequestParam(required = false) String modelVersion, HttpServletRequest request) {
    CreatedEntityInfo entityInfo = entitiesControllerManager.createEntity(entityJson, entityName, modelVersion);

    UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString())
            .path("/{id}").buildAndExpand(entityInfo.getId().toString());

    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(uriComponents.toUri());
    return new ResponseEntity<>(entityInfo.getJson(), httpHeaders, HttpStatus.CREATED);
}

From source file:com.alfaariss.oa.profile.aselect.binding.protocol.cgi.CGIRequest.java

/**
 * Creates the CGI request object.//from w  w w .j a  v a2  s.com
 * 
 * Reads the request parameters and puts them in a <code>Hashtable</code>
 * @param oRequest the servlet request 
 * @throws BindingException if the request object can't be created
 */
public CGIRequest(HttpServletRequest oRequest) throws BindingException {
    try {
        _logger = LogFactory.getLog(CGIRequest.class);
        _htRequest = new Hashtable<String, Object>();
        _sRequestedURL = oRequest.getRequestURL().toString();

        if (_logger.isDebugEnabled()) {
            String sQueryString = oRequest.getQueryString();
            if (sQueryString == null)
                sQueryString = "";
            _logger.debug("QueryString: " + sQueryString);
        }

        Hashtable<String, Vector<String>> htVectorItems = new Hashtable<String, Vector<String>>();
        Enumeration enumNames = oRequest.getParameterNames();
        while (enumNames.hasMoreElements()) {
            String sName = (String) enumNames.nextElement();
            String sValue = oRequest.getParameter(sName);
            if (sName.endsWith(CGIBinding.ENCODED_BRACES)
                    || sName.endsWith(CGIBinding.ENCODED_BRACES.toLowerCase()) || sName.endsWith("[]")) {
                Vector<String> vValues = htVectorItems.get(sName);
                if (vValues == null)
                    vValues = new Vector<String>();
                vValues.add(sValue);
                htVectorItems.put(sName, vValues);
            } else
                _htRequest.put(sName, sValue);
        }

        _htRequest.putAll(htVectorItems);
    } catch (Exception e) {
        _logger.fatal("Internal error during CGI Request creation", e);
        throw new BindingException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:com.npower.dl.OMADownloadServlet.java

public void doDownloadDescriptor(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String requestUrl = request.getRequestURL().toString();
    String requestUri = request.getRequestURI();
    log.info("Download Service: Download Descriptor: url: " + requestUrl);
    log.info("Download Service: Download Descriptor: uri: " + requestUri);

    String downloadID = DownloadFactory.parserDownloadID(requestUri);

    log.info("Download Service: Request download ID: " + downloadID);

    DownloadFactory ddFactory = DownloadFactory.newInstance();
    DownloadDescriptor descriptor = ddFactory.getDownloadDescriptor(downloadID);

    try {/*from ww w . j ava 2 s . co  m*/
        String serverURL = DownloadFactory.getServerURL(requestUrl);
        String baseURL = serverURL + request.getContextPath() + "/dl";

        //String baseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
        //                + request.getContextPath() + "/dl";

        descriptor.setDownloadURI(baseURL + "/" + DownloadFactory.OPERATION_DOWNLOAD);
        descriptor.setInstallNotifyURI(baseURL + "/" + DownloadFactory.OPERARION_INSTALL_NOTIFICATION);

        String content = descriptor.getContent();
        response.setContentType(descriptor.getContentType());
        response.setContentLength(content.length());

        OutputStream out = response.getOutputStream();
        out.write(content.getBytes("UTF-8"));
        out.flush();
        out.close();

        log.debug("Download Descriptor Content: " + content);
    } catch (Exception ex) {
        throw new ServletException(ex);
    } finally {
    }
}

From source file:io.onedecision.engine.decisions.web.DecisionUIModelController.java

@RequestMapping(value = "/", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)//from  w ww  . j  ava2s  . c  o  m
public @ResponseBody DecisionModel createModelForTenant(@PathVariable("tenantId") String tenantId,
        @RequestBody DecisionModel model, HttpServletRequest request, HttpServletResponse response) {
    DecisionModel dm = createModelForTenant(model, tenantId);
    response.setHeader("Location", String.format("%1$s%2$d", request.getRequestURL(), dm.getId()));
    return dm;
}