List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.alehuo.wepas2016projekti.controller.ProfileController.java
/** * Profiilin selaus//from ww w. j ava 2s . com * * @param a Autentikoini * @param username Kyttjnimi * @param m Malli * @param l Lokalisaatio * @return * @throws UnsupportedEncodingException */ @RequestMapping("/profile/{username}") public String viewProfile(Authentication a, @PathVariable String username, Model m, Locale l) throws UnsupportedEncodingException { UserAccount loggedInUser = userService.getUserByUsername(a.getName()); m.addAttribute("user", loggedInUser); String profileUsername = URLDecoder.decode(username, "UTF-8"); UserAccount u = userService.getUserByUsername(profileUsername); m.addAttribute("userProfile", u); //Jos kyttj ei ole tyhj, lis kyttjn lismt kuvat if (u != null) { List<Image> images = imageService.findAllByUserAccount(u); m.addAttribute("userImages", images); } LOG.log(Level.INFO, "Kayttaja ''{0}'' selasi kayttajan ''{1}'' profiilia.", new Object[] { a.getName(), username }); return "profile"; }
From source file:org.dspace.identifier.ezid.EZIDResponse.java
public EZIDResponse(HttpResponse response) throws IdentifierException { this.response = response; HttpEntity responseBody = response.getEntity(); // Collect the content of the percent-encoded response. String body;//from w w w . jav a 2 s . c om try { body = EntityUtils.toString(responseBody, UTF_8); } catch (IOException ex) { log.error(ex.getMessage()); throw new IdentifierException("EZID response not understood: " + ex.getMessage()); } catch (ParseException ex) { log.error(ex.getMessage()); throw new IdentifierException("EZID response not understood: " + ex.getMessage()); } String[] parts; String[] lines = body.split("[\\n\\r]"); // First line is request status and message or value parts = lines[0].split(":", 2); status = parts[0].trim(); if (parts.length > 1) { statusValue = parts[1].trim(); } else { statusValue = null; } // Remaining lines are key: value pairs for (int i = 1; i < lines.length; i++) { parts = lines[i].split(":", 2); String key = null, value = null; try { key = URLDecoder.decode(parts[0], UTF_8).trim(); if (parts.length > 1) { value = URLDecoder.decode(parts[1], UTF_8).trim(); } else { value = null; } } catch (UnsupportedEncodingException e) { // XXX SNH, we always use UTF-8 which is required by the Java spec. } attributes.put(key, value); } }
From source file:com.ims.surport.security.Encodes.java
/** * URL ?, EncodeUTF-8.//from w w w .j av a2 s . c o m */ public static String urlDecode(String part, String encode) { try { return URLDecoder.decode(part, StringUtils.isEmpty(encode) ? DEFAULT_URL_ENCODING : encode); } catch (UnsupportedEncodingException e) { throw Exceptions.unchecked(e); } }
From source file:com.atinternet.tracker.Tool.java
/** * Decoding a string/*from www. j a va 2 s . com*/ * * @param s String * @return String */ static String percentDecode(String s) { try { s = URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return s; }
From source file:de.fhg.iais.asc.xslt.binaries.download.Downloader.java
public static URI createDownloadableURI(String path) { URI uri;//from ww w .j a v a2 s . c o m try { try { uri = new URI(path); } catch (URISyntaxException e) { String decoded = URLDecoder.decode(path, Charsets.UTF_8.name()); URL url = new URL(decoded); uri = createURI(url); } } catch (Exception e) { // give up return null; } return isDownloadableURI(uri) ? uri : null; }
From source file:net.shibboleth.idp.oidc.config.ShibbolethOAuth2RequestFactory.java
@Override public AuthorizationRequest createAuthorizationRequest(final Map<String, String> inputParams) { final AuthorizationRequest request = super.createAuthorizationRequest(inputParams); if (inputParams.containsKey(OIDCConstants.ACR_VALUES)) { try {//from w ww . j ava 2 s .c o m log.debug("Authorization request contains {}. Decoding and storing values into the request", OIDCConstants.ACR_VALUES); request.getExtensions().put(OIDCConstants.ACR_VALUES, URLDecoder.decode(inputParams.get(OIDCConstants.ACR_VALUES), "UTF-8")); } catch (final Exception e) { log.warn("Unable to decode acr_values in the authorization request", e); } } return request; }
From source file:com.mycompany.allasync.NHttpRequestHandler.java
private void handleInternal(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) { throw new MethodNotSupportedException(method + " method not supported"); }//from w ww .j av a2s. c o m String target = request.getRequestLine().getUri(); final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8")); if (!file.exists()) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); NStringEntity entity = new NStringEntity( "<html><body><h1>File" + file.getPath() + " not found</h1></body></html>", ContentType.create("text/html", "UTF-8")); response.setEntity(entity); System.out.println("File " + file.getPath() + " not found"); } else if (!file.canRead() || file.isDirectory()) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); NStringEntity entity = new NStringEntity("<html><body><h1>Access denied</h1></body></html>", ContentType.create("text/html", "UTF-8")); response.setEntity(entity); System.out.println("Cannot read file " + file.getPath()); } else { NHttpConnection conn = (NHttpConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION); response.setStatusCode(HttpStatus.SC_OK); NFileEntity body = new NFileEntity(file, ContentType.create("text/html")); response.setEntity(body); System.out.println(conn + ": serving file " + file.getPath()); } }
From source file:de.dfki.km.perspecting.obie.corpus.BBCMusicCorpus.java
public Reader getGroundTruth(final URI uri) throws Exception { if (labelFileMediaType == MediaType.DIRECTORY) { return new StringReader(FileUtils.readFileToString(new File(uri))); } else if (labelFileMediaType == MediaType.ZIP) { ZipFile zipFile = new ZipFile(labelFolder); String[] entryName = uri.toURL().getFile().split("/"); ZipEntry entry = zipFile.getEntry( URLDecoder.decode(entryName[entryName.length - 1], "utf-8").replace("txt", "dumps") + ".rdf"); if (entry != null) { log.info("found labels for: " + uri.toString()); } else {//from w w w. j ava2s .co m throw new Exception("did not found labels for: " + uri.toString()); } return new InputStreamReader(zipFile.getInputStream(entry)); } else { throw new Exception("Unsupported media format for labels: " + labelFileMediaType + ". " + "Please use zip or plain directories instead."); } }
From source file:com.mockey.storage.file.FileUploadOctetStreamReaderServlet.java
/** * Handles the HTTP <code>POST</code> method. * /*from w ww .j av a 2s . c o m*/ * @param request * servlet request * @param response * servlet response * @throws ServletException * if a servlet-specific error occurs * @throws IOException * if an I/O error occurs */ @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException { PrintWriter writer = null; InputStream is = null; FileOutputStream fos = null; try { writer = response.getWriter(); } catch (IOException ex) { log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } try { String filename = URLDecoder.decode(request.getHeader("X-File-Name"), "UTF-8"); is = request.getInputStream(); FileSystemManager fsm = new FileSystemManager(); File fileToWriteTo = fsm.getImageFile(filename); fos = new FileOutputStream(fileToWriteTo); IOUtils.copy(is, fos); response.setStatus(HttpServletResponse.SC_OK); writer.print("{success: true}"); } catch (FileNotFoundException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } catch (IOException ex) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); writer.print("{success: false}"); log(FileUploadOctetStreamReaderServlet.class.getName() + "has thrown an exception: " + ex.getMessage()); } finally { try { if (fos != null) { fos.close(); } } catch (IOException ignored) { } try { if (is != null) { is.close(); } } catch (IOException ignored) { } } writer.flush(); writer.close(); }
From source file:com.andrewkroh.cisco.xmlservices.HttpTestServerHandler.java
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof FullHttpRequest) { FullHttpRequest httpRequest = (FullHttpRequest) msg; String content = httpRequest.content().toString(CharsetUtil.ISO_8859_1); content = content.replaceAll("XML=", ""); content = URLDecoder.decode(content, CharsetUtil.ISO_8859_1.name()); // Store the received request: httpRequestFuture.set(content);//from w ww .ja v a 2 s . c o m // Write the given response: HttpResponse response = httpResponseRef.get(); if (response != null) { ctx.writeAndFlush(response).sync(); } } }