Example usage for java.net URLDecoder decode

List of usage examples for java.net URLDecoder decode

Introduction

In this page you can find the example usage for java.net URLDecoder decode.

Prototype

public static String decode(String s, Charset charset) 

Source Link

Document

Decodes an application/x-www-form-urlencoded string using a specific java.nio.charset.Charset Charset .

Usage

From source file:net.devmond.shell.handler.DecodeCommandHandler.java

@Override
protected Result executeInternal(CommandInput input) throws Exception {
    Charset charset = getConfiguredCharset(input.getValueForOption(CHARSET_FLAG));

    String encoding = input.nextArgument().toLowerCase();
    String arg = input.nextArgument();

    if (URL_ENCODING.equals(encoding))
        return textResult(URLDecoder.decode(arg, charset.toString()));

    if (BASE64_ENCODING.equals(encoding))
        return textResult(new String(decodeBase64(arg.getBytes(charset)), charset));

    if (HTML_ENCODING.equals(encoding))
        throw new UnsupportedOperationException();

    throw new InvalidCommandException(getHelpText());
}

From source file:com.epam.training.storefront.controllers.pages.OrganizationsController.java

@RequestMapping(value = "/organizations/{organizationName}", method = RequestMethod.GET)
public String showOrganizationDetails(@PathVariable String organizationName, final Model model)
        throws UnsupportedEncodingException {
    organizationName = URLDecoder.decode(organizationName, "UTF-8");
    final OrganizationData organization = organizationFacade.getOrganization(organizationName,
            "organizationDetailsFormat");
    organization.setName(organization.getName());
    model.addAttribute("organization", organization);
    return ORGANIZATION_DETAILS;
}

From source file:net.kaczmarzyk.blog.thdbview.TemplateController.java

@RequestMapping(value = "/templates", method = RequestMethod.POST)
@ResponseBody/*  ww w .  j  a  va 2s  .co  m*/
public void addTemplate(@RequestBody String templateContent) throws UnsupportedEncodingException {
    templateRepo.save(new Template(URLDecoder.decode(templateContent, "UTF-8")));
}

From source file:com.evolveum.midpoint.report.impl.ReportNodeUtils.java

public static InputStream executeOperation(String host, String fileName, String intraClusterHttpUrlPattern,
        String operation) throws CommunicationException, SecurityViolationException, ObjectNotFoundException,
        ConfigurationException, IOException {
    fileName = fileName.replaceAll("\\s", SPACE);
    InputStream inputStream = null;
    InputStream entityContent = null;
    LOGGER.trace("About to initiate connection with {}", host);
    try {//from  w  w  w.  ja va 2 s  .  co m
        if (StringUtils.isNotEmpty(intraClusterHttpUrlPattern)) {
            LOGGER.trace("The cluster uri pattern: {} ", intraClusterHttpUrlPattern);
            URI requestUri = buildURI(intraClusterHttpUrlPattern, host, fileName);
            fileName = URLDecoder.decode(fileName, ReportTypeUtil.URLENCODING);

            LOGGER.debug("Sending request to the following uri: {} ", requestUri);
            HttpRequestBase httpRequest = buildHttpRequest(operation);
            httpRequest.setURI(requestUri);
            httpRequest.setHeader("User-Agent", ReportTypeUtil.HEADER_USERAGENT);
            HttpClient client = HttpClientBuilder.create().build();
            try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpRequest)) {
                HttpEntity entity = response.getEntity();
                Integer statusCode = response.getStatusLine().getStatusCode();

                if (statusCode == HttpStatus.SC_OK) {
                    LOGGER.debug("Response OK, the file successfully returned by the cluster peer. ");
                    if (entity != null) {
                        entityContent = entity.getContent();
                        ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                        byte[] buffer = new byte[1024];
                        int len;
                        while ((len = entityContent.read(buffer)) > -1) {
                            arrayOutputStream.write(buffer, 0, len);
                        }
                        arrayOutputStream.flush();
                        inputStream = new ByteArrayInputStream(arrayOutputStream.toByteArray());
                    }
                } else if (statusCode == HttpStatus.SC_NO_CONTENT) {
                    if (HttpDelete.METHOD_NAME.equals(operation)) {
                        LOGGER.info("Deletion of the file {} was successful.", fileName);
                    }
                } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
                    LOGGER.error("The access to the report with the name {} is forbidden.", fileName);
                    String error = "The access to the report " + fileName + " is forbidden.";
                    throw new SecurityViolationException(error);
                } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
                    String error = "The report file " + fileName
                            + " was not found on the originating nodes filesystem.";
                    throw new ObjectNotFoundException(error);
                }
            } catch (ClientProtocolException e) {
                String error = "An exception with the communication protocol has occurred during a query to the cluster peer. "
                        + e.getLocalizedMessage();
                throw new CommunicationException(error);
            }
        } else {
            LOGGER.error(
                    "Cluster pattern parameters is empty, please refer to the documentation and set up the parameter value accordingly");
            throw new ConfigurationException(
                    "Cluster pattern parameters is empty, please refer to the documentation and set up the parameter value accordingly");
        }
    } catch (URISyntaxException e1) {
        throw new CommunicationException("Invalid uri syntax: " + e1.getLocalizedMessage());
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Unhandled exception when listing nodes");
        LoggingUtils.logUnexpectedException(LOGGER, "Unhandled exception when listing nodes", e);
    } finally {
        IOUtils.closeQuietly(entityContent);
    }

    return inputStream;
}

From source file:com.miyue.util.EncoderUtil.java

/**
 * URL ?, EncodeUTF-8. //from   ww  w .j a  va  2s .  com
 */
public static String URLDecode(String input) {
    try {
        return URLDecoder.decode(input, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported Encoding Exception", e);
    }
}

From source file:lv.semti.morphology.webservice.VerbResource.java

public String parsequery(Boolean verb) {
     String query = (String) getRequest().getAttributes().get("query");
     try {//from  ww w .ja v a 2 s.co m
         query = URLDecoder.decode(query, "UTF8");
     } catch (UnsupportedEncodingException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }

     MorphoServer.analyzer.defaultSettings();

     LinkedList<Word> tokens = Splitting.tokenize(MorphoServer.analyzer, query);
     String debug = "";
     for (Word token : tokens) {
         if (token.isRecognized())
             debug += token.wordforms.get(0).getDescription();
         else
             debug += token.getToken();
         debug += "\n";
     }
     debug += String.valueOf(tokens.size());

     String tag = "";
     if (tokens.size() == 1)
         tag = tagWord(tokens.get(0), verb);
     else
         tag = tagChunk(tokens); // Heiristikas vair?kv?rdu situ?cijas risin?anai

     if (tag == "")
         return debug;
     else
         return tag;
 }

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 {/*from   w w w.  j  av a2s  .c  o m*/
        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:com.cmri.bpt.common.util.EncodeUtil.java

/**
 * URL ?, EncodeUTF-8.// w  w  w. j a v  a 2 s  .co m
 */
public static String urlDecode(String part) {

    try {
        return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw ExceptionUtil.asUnChecked(e);
    }
}

From source file:com.swdouglass.joid.server.UserUrlFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    String s = request.getServletPath();
    s = URLDecoder.decode(s, "utf-8");
    log.debug("servletpath: " + s);
    String[] sections = s.split("/");
    log.debug("sections.length: " + sections.length);
    String contextPath = request.getContextPath();
    if (sections.length >= 2) {
        for (int i = 0; i < sections.length; i++) {
            String section = sections[i];
            log.debug("section: " + section);
            if (section.equals("user")) {
                String username = sections[i + 1];
                log.debug("username: " + username);
                log.debug("forwarding to: " + contextPath + idJsp);
                request.setAttribute("username", username);
                forward(request, response, idJsp);
                return;
            }//ww  w . j a  v  a  2s.c  o m
        }

    }
    filterChain.doFilter(req, res);
}

From source file:com.linkedin.flashback.http.HttpUtilities.java

/**
 * Converts a URL / POST parameter string to an ordered map of key / value pairs
 * @param paramsString the URL-encoded &-delimited string of key / value pairs
 * @return a LinkedHashMap representing the decoded parameters
 *//*  w w  w  . j  a  v a  2s.  c o m*/
static public Map<String, String> stringToUrlParams(String paramsString, String charset)
        throws UnsupportedEncodingException {
    Map<String, String> params = new LinkedHashMap<>();
    if (!StringUtils.isBlank(paramsString)) {
        for (String param : paramsString.split("&")) {
            String[] keyValue = param.split("=");
            assert (keyValue.length > 0);
            if (keyValue.length == 1) {
                params.put(URLDecoder.decode(keyValue[0], charset), "");
            } else {
                params.put(URLDecoder.decode(keyValue[0], charset), URLDecoder.decode(keyValue[1], charset));
            }
        }
    }
    return params;
}