Example usage for javax.servlet.http HttpServletRequest getQueryString

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

Introduction

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

Prototype

public String getQueryString();

Source Link

Document

Returns the query string that is contained in the request URL after the path.

Usage

From source file:com.yiji.openapi.sdk.util.Servlets.java

public static String getQueryString(HttpServletRequest request) {
    return getRequestPath(request) + "?" + request.getQueryString();
}

From source file:org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticationFilter.java

@VisibleForTesting
static String getDoAs(HttpServletRequest request) {
    List<NameValuePair> list = URLEncodedUtils.parse(request.getQueryString(), UTF8_CHARSET);
    if (list != null) {
        for (NameValuePair nv : list) {
            if (DelegationTokenAuthenticatedURL.DO_AS.equalsIgnoreCase(nv.getName())) {
                return nv.getValue();
            }//from   www  .  j  av  a  2 s.  c om
        }
    }
    return null;
}

From source file:info.magnolia.module.servletsanity.support.ServletAssert.java

private static void testQueryString(String level, HttpServletRequest request, String expected)
        throws IOException {
    if (!StringUtils.equals(request.getQueryString(), expected)) {
        append(level + " QueryString is [" + request.getQueryString() + "] expected it to be [" + expected
                + "]");
    } else {//from w  w  w. j a v  a  2s.c  om
        append("PASSED QueryString is correct");
    }
}

From source file:com.liusoft.dlog4j.util.RequestUtils.java

/**
 * ?URL//from  ww w .  j a va2s. c om
 * @param req
 * @return
 */
public static String getRequestURL(HttpServletRequest req) {
    StringBuffer url = new StringBuffer(req.getRequestURI());
    String param = req.getQueryString();
    if (param != null) {
        url.append('?');
        url.append(param);
    }
    String path = url.toString();
    return path.substring(req.getContextPath().length());
}

From source file:eu.europeana.core.util.web.ClickStreamLoggerImpl.java

private static String getRequestUrl(HttpServletRequest request) {
    String base = ControllerUtil.getFullServletUrl(request);
    String queryStringParameters = request.getQueryString();
    Map postParameters = request.getParameterMap();
    StringBuilder out = new StringBuilder();
    out.append(base);/*  ww  w  . j a  v  a 2 s  . c  o  m*/
    String queryString;
    if (queryStringParameters != null) {
        out.append("?").append(queryStringParameters);
        queryString = out.toString();
    } else if (postParameters.size() > 0) {
        out.append("?");
        for (Object entryKey : postParameters.entrySet()) {
            Map.Entry entry = (Map.Entry) entryKey;
            String key = entry.getKey().toString();
            String[] values = (String[]) entry.getValue();
            for (String value : values) {
                out.append(key).append("=").append(value).append("&");
            }
        }
        queryString = out.toString().substring(0, out.toString().length() - 1);
    } else {
        queryString = out.toString();
    }
    return queryString;
}

From source file:io.apiman.test.common.mock.EchoServlet.java

/**
 * Create an echo response from the inbound information in the http server
 * request.//from  w ww  . j  a  v  a2 s .  com
 * @param request the request
 * @param withBody if request is with body
 * @return a new echo response
 */
public static EchoResponse response(HttpServletRequest request, boolean withBody) {
    EchoResponse response = new EchoResponse();
    response.setMethod(request.getMethod());
    if (request.getQueryString() != null) {
        String[] normalisedQueryString = request.getQueryString().split("&");
        Arrays.sort(normalisedQueryString);
        response.setResource(
                request.getRequestURI() + "?" + SimpleStringUtils.join("&", normalisedQueryString));
    } else {
        response.setResource(request.getRequestURI());
    }
    response.setUri(request.getRequestURI());
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String name = headerNames.nextElement();
        String value = request.getHeader(name);
        response.getHeaders().put(name, value);
    }
    if (withBody) {
        long totalBytes = 0;
        InputStream is = null;
        try {
            is = request.getInputStream();
            MessageDigest sha1 = MessageDigest.getInstance("SHA1");
            byte[] data = new byte[1024];
            int read;
            while ((read = is.read(data)) != -1) {
                sha1.update(data, 0, read);
                totalBytes += read;
            }
            ;

            byte[] hashBytes = sha1.digest();
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < hashBytes.length; i++) {
                sb.append(Integer.toString((hashBytes[i] & 0xff) + 0x100, 16).substring(1));
            }
            String fileHash = sb.toString();

            response.setBodyLength(totalBytes);
            response.setBodySha1(fileHash);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    return response;
}

From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java

/**
 * Constructs a URI for request and calls changeProtocolAndPort(String, int, URI).
 * //from   w w w  .j  a v  a2  s.  c om
 * @param protocol the new protocol (scheme) in the resulting URI.
 * @param port the new port in the resulting URI, or the default port if -1 is provided.
 * @param request the request to use as the URI template.
 * @return a new URI object with the updated protocol and port.
 * @throws URISyntaxException 
  */
public static URI changeProtocolAndPort(String protocol, int port, HttpServletRequest request)
        throws URISyntaxException {
    return changeProtocolAndPort(protocol, port,
            URI.create(request.getRequestURL().append(
                    (StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString()))
                    .toString()));
}

From source file:com.ai.smart.common.helper.util.RequestUtils.java

public static Map<String, Object> getQueryParams(HttpServletRequest request) {
    Map<String, String[]> map;
    if (request.getMethod().equalsIgnoreCase(POST)) {
        map = request.getParameterMap();
    } else {// ww w. ja v  a  2 s  . c om
        String s = request.getQueryString();
        if (StringUtils.isBlank(s)) {
            return new HashMap<String, Object>();
        }
        try {
            s = URLDecoder.decode(s, UTF8);
        } catch (UnsupportedEncodingException e) {
            log.error("encoding " + UTF8 + " not support?", e);
        }
        map = parseQueryString(s);
    }

    Map<String, Object> params = new HashMap<String, Object>(map.size());
    int len;
    for (Map.Entry<String, String[]> entry : map.entrySet()) {
        len = entry.getValue().length;
        if (len == 1) {
            params.put(entry.getKey(), entry.getValue()[0]);
        } else if (len > 1) {
            params.put(entry.getKey(), entry.getValue());
        }
    }
    return params;
}

From source file:edu.harvard.i2b2.fhirserver.ws.I2b2Helper.java

static Bundle parsePatientIdToFetchPDO(HttpServletRequest request, HttpSession session, String resourceName,
        PatientBundleService service) throws XQueryUtilException, JAXBException, IOException,
        AuthenticationFailure, FhirServerException, InterruptedException {
    String patientId = I2b2Helper.extractPatientId(request.getQueryString());
    if (patientId == null)
        patientId = I2b2Helper.extractPatientId2(request.getRequestURL().toString(), resourceName);
    logger.info("PatientId:" + patientId);
    if (patientId != null) {
        // filter.put("Patient", "Patient/" + patientId);
        return I2b2Helper.getPdo(session, patientId, service);
    } else {/*from w w  w  .  j a  v  a 2 s.c om*/
        if (resourceName.equals("Patient"))
            return I2b2Helper.initAllPatients(session);

    }
    return null;
}

From source file:eu.fusepool.p3.proxy.ProxyHandler.java

private static String getFullRequestUrl(HttpServletRequest request) {
    StringBuffer requestURL = request.getRequestURL();
    if (request.getQueryString() != null) {
        requestURL.append("?").append(request.getQueryString());
    }//from w  w w. jav  a 2s.  co  m
    return requestURL.toString();
}