List of usage examples for java.net URLEncoder encode
public static String encode(String s, Charset charset)
From source file:org.runway.utils.StringEncryptDecryptUtil.java
public static String urlEncrypt(String value) throws RunwaySecurityException { String enc = encrypt(value);/*from w w w . j a va 2 s.c o m*/ String result = null; try { result = URLEncoder.encode(enc, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RunwaySecurityException(e); } return result; }
From source file:org.manalith.ircbot.plugin.weather.WeatherPlugin.java
@BotCommand("") public String getYahooWeather(@Option(name = "", help = " ? ? ") String keyword) { try {// w w w. j av a 2 s .c o m // TODO WOEID ? final String url_woeid = "http://query.yahooapis.com/v1/public/yql" + "?q=select%20woeid%20from%20geo.places%20where%20text%3D%22" + URLEncoder.encode(keyword, "UTF-8") + "%20ko-KR%22%20limit%201"; final String url_forecast = "http://weather.yahooapis.com/forecastrss?w=%s&u=c"; final String error_woeid = "23424868"; Document doc = Jsoup.connect(url_woeid).get(); // example : http://query.yahooapis.com/v1/public/yql?q=select woeid // from geo.places where text%3D\"%2C ko-KR\" limit 1 String woeid = doc.select("woeid").text(); if (!woeid.equals(error_woeid)) { // example: // http://weather.yahooapis.com/forecastrss?w=1132599&u=c doc = Jsoup.connect(String.format(url_forecast, woeid)).get(); String location = doc.getElementsByTag("yweather:location").attr("city"); String condition = doc.getElementsByTag("yweather:condition").attr("text"); String temp = doc.getElementsByTag("yweather:condition").attr("temp"); String humidity = doc.getElementsByTag("yweather:atmosphere").attr("humidity"); String windCondition = doc.getElementsByTag("yweather:wind").attr("speed"); return String.format("[%s] %s ? %s, ? %s%%, ?? %skm/h", location, condition, temp, humidity, windCondition); } else { return String.format( "[%s] ? ? . ? ?.", keyword); } } catch (IOException e) { logger.error("failed to run command", e); return " ? : " + e.getMessage(); } }
From source file:com.cybozu.kintone.gpsPunch.GpsPunchRequestManager.java
public String addSpot(long id, String companyName, String address, String tel) { String endPoint = "spots?"; String parm = ""; int responseStatus = 0; String body = ""; String spotId = ""; // ????// w ww. j a va 2 s .c o m try { parm = "company_id=" + URLEncoder.encode(companyId, "utf-8") + "&spot_code=" + String.valueOf(id) + "&spot_name=" + URLEncoder.encode(companyName, "utf-8") + "&address=" + URLEncoder.encode(address, "utf-8") + "&tel=" + URLEncoder.encode(tel, "utf-8"); } catch (Exception e) { e.printStackTrace(); System.exit(1); } // ?? try { // POST HttpPost httpPost = new HttpPost(target + endPoint + parm); HttpResponse response = httpClient.execute(httpPost); responseStatus = response.getStatusLine().getStatusCode(); body = EntityUtils.toString(response.getEntity(), "UTF-8"); // ?200???????ID? if (responseStatus == 200) { Map map = JSON.decode(body, HashMap.class); spotId = (String) map.get("spot_id"); } else { System.out.println( "??????????"); System.exit(1); } } catch (Exception e) { System.out.println(responseStatus); Map map = JSON.decode(body, HashMap.class); String err = map.toString(); System.out.println(err); e.printStackTrace(); } return spotId; }
From source file:ext.sns.config.special.DoubanConfig.java
@Override public String getRequestAuthFullURI(Map<String, String> callbackParam, String specialParamKey) { SNSConfig snsConfig = ConfigManager.getSNSConfig(); // URI,?response_typeclient_idredirect_uriscopestate StringBuilder requestURI = new StringBuilder(getAuthURI()); requestURI.append(WSUtil.getURIQueryStringPrefix(getAuthURI())); requestURI.append("response_type=code"); requestURI.append("&client_id=").append(getClientId()); String fullRedirectURI = generateRedirectURI(getName(), snsConfig.getAuthRedirectUri()); // callbackParamcookie if (MapUtils.isNotEmpty(callbackParam)) { Context.current().response().setCookie(CALLBACK_PARAM_COOKIENAME, AuthUtil.encodeState(callbackParam), 15 * 60, "/", null, false, true); }/* www . jav a 2s . co m*/ try { requestURI.append("&redirect_uri=").append(URLEncoder.encode(fullRedirectURI, "utf-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } if (StringUtils.isNotBlank(getScope())) { requestURI.append("&scope=").append(getScope()); } if (MapUtils.isNotEmpty(getSpecialParam()) && StringUtils.isNotBlank(specialParamKey)) { if (getSpecialParam().containsKey(specialParamKey)) { requestURI.append("&").append(getSpecialParam().get(specialParamKey)); } } return requestURI.toString(); }
From source file:com.wondersgroup.api.framework.utils.Encodes.java
/** * URL ?, EncodeUTF-8./*from w ww . j a v a2s. c o m*/ */ public static String urlEncode(String part) { try { return URLEncoder.encode(part, DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { return null; } }
From source file:de.anycook.social.facebook.FacebookHandler.java
@SuppressWarnings("unchecked") public static String publishtoWall(long facebookID, String accessToken, String message, String header) throws IOException { StringBuilder out = new StringBuilder(); StringBuilder data = new StringBuilder(); data.append("access_token=").append(URLEncoder.encode(accessToken, "UTF-8")); data.append("&message=").append(URLEncoder.encode(message, "UTF-8")); data.append("&name=").append(URLEncoder.encode(header, "UTF-8")); URL url = new URL("https://api.facebook.com/" + facebookID + "/feed"); URLConnection conn = url.openConnection(); conn.setDoOutput(true);//from ww w. jav a 2 s . co m try (OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream())) { wr.write(data.toString()); wr.flush(); try (BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { String line; while ((line = rd.readLine()) != null) { out.append(line); } } } return out.toString(); }
From source file:controllers.CodeApp.java
@IsAllowed(Operation.READ) public static Result codeBrowser(String userName, String projectName) throws IOException, UnsupportedOperationException, ServletException { Project project = Project.findByOwnerAndProjectName(userName, projectName); if (!RepositoryService.VCS_GIT.equals(project.vcs) && !RepositoryService.VCS_SUBVERSION.equals(project.vcs)) { return status(Http.Status.NOT_IMPLEMENTED, project.vcs + " is not supported!"); }//from w w w .j ava2 s .c om PlayRepository repository = RepositoryService.getRepository(project); if (repository.isEmpty()) { switch (project.vcs) { case RepositoryService.VCS_GIT: return ok(nohead.render(project)); case RepositoryService.VCS_SUBVERSION: return ok(nohead_svn.render(project)); } } String defaultBranch = project.defaultBranch(); if (defaultBranch == null) { defaultBranch = "HEAD"; } else if (defaultBranch.split("/").length >= 3) { defaultBranch = defaultBranch.split("/", 3)[2]; } defaultBranch = URLEncoder.encode(defaultBranch, "UTF-8"); return redirect(routes.CodeApp.codeBrowserWithBranch(userName, projectName, defaultBranch, "")); }
From source file:fr.aliasource.webmail.server.OBMSSOProvider.java
@Override public Credentials obtainCredentials(Map<String, String> settings, HttpServletRequest req) { String ticket = req.getParameter("ticket"); if (ticket == null) { logger.warn("no ticket in url"); return null; }//from ww w.j a va2 s .co m try { String logoutUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/session;jsessionid=" + req.getSession().getId(); URL url = new URL(settings.get(SSO_SERVER_URL) + "?action=validate&ticket=" + ticket + "&logout=" + URLEncoder.encode(logoutUrl, "UTF-8")); InputStream in = url.openStream(); String content = IOUtils.toString(in); in.close(); if (logger.isDebugEnabled()) { logger.debug("SSO server returned:\n" + content); } Credentials creds = null; if (!content.equals("invalidOBMTicket")) { String[] ssoServerReturn = content.split("&password="); String login = ssoServerReturn[0].substring("login=".length()); String pass = ssoServerReturn[1]; creds = new Credentials(URLDecoder.decode(login, "UTF-8"), URLDecoder.decode(pass, "UTF-8")); } return creds; } catch (Exception e) { logger.error("Ticket validation error: " + e.getMessage(), e); return null; } }
From source file:com.baoyz.bigbang.segment.NetworkParser.java
@Nullable private Request createRequest(String text) { Request request = null;/* www .j av a 2s. co m*/ try { request = new Request.Builder().get() .url("http://fenci.kitdroid.org:3000/?text=" + URLEncoder.encode(text, "utf-8")).build(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return request; }
From source file:net.longfalcon.newsj.util.EncodingUtil.java
public static String urlEncode(String input) { try {/* www . j av a 2 s. c o m*/ return URLEncoder.encode(input, _UTF8); } catch (UnsupportedEncodingException e) { _log.error(e); } return BLANK_STRING; }