List of usage examples for java.net URL getQuery
public String getQuery()
From source file:com.wso2telco.dep.mediator.impl.smsmessaging.southbound.RetrieveSMSSouthboundHandler.java
@Override public boolean handle(MessageContext context) throws CustomException, AxisFault, Exception { SOAPBody body = context.getEnvelope().getBody(); Gson gson = new GsonBuilder().serializeNulls().create(); Properties prop = new Properties(); String reqType = "retrive_sms"; String requestid = UID.getUniqueID(Type.SMSRETRIVE.getCode(), context, executor.getApplicationid()); int batchSize = 100; URL retrieveURL = new URL("http://example.com/smsmessaging/v1" + executor.getSubResourcePath()); String urlQuery = retrieveURL.getQuery(); if (urlQuery != null) { if (urlQuery.contains("maxBatchSize")) { String queryParts[] = urlQuery.split("="); if (queryParts.length > 1) { if (Integer.parseInt(queryParts[1]) < 100) { batchSize = Integer.parseInt(queryParts[1]); }/*from w w w. j a v a 2 s . c om*/ } } } List<OperatorEndpoint> endpoints = occi.getAPIEndpointsByApp(API_TYPE, executor.getSubResourcePath(), executor.getValidoperators()); log.info("Endpoints size: " + endpoints.size()); Collections.shuffle(endpoints); int perOpCoLimit = batchSize / (endpoints.size()); log.info("Per OpCo limit :" + perOpCoLimit); JSONArray results = new JSONArray(); int execCount = 0; int forLoopCount = 0; boolean retryFlag = true; FileReader fileReader = new FileReader(); String file = CarbonUtils.getCarbonConfigDirPath() + File.separator + FileNames.MEDIATOR_CONF_FILE.getFileName(); Map<String, String> mediatorConfMap = fileReader.readPropertyFile(file); Boolean retry = false; retry = Boolean.valueOf(mediatorConfMap.get("retry_on_fail")); Integer retryCount = Integer.valueOf(mediatorConfMap.get("retry_count")); ArrayList<String> responses = new ArrayList<String>(); while ((results.length() < batchSize) && (retryFlag == true)) { execCount++; log.info("SB aEndpoint : " + endpoints.size()); for (int i = 0; i < endpoints.size(); i++) { forLoopCount++; log.info("Default forLoopCount : " + forLoopCount); OperatorEndpoint aEndpoint = endpoints.remove(0); log.info("SB aEndpoint : " + aEndpoint.getEndpointref().getAddress()); endpoints.add(aEndpoint); String url = aEndpoint.getEndpointref().getAddress(); APICall ac = apiUtil.setBatchSize(url, body.toString(), reqType, perOpCoLimit); JSONObject obj = ac.getBody(); String retStr = null; log.info("Retrieving messages of operator: " + aEndpoint.getOperator()); if (context.isDoingGET()) { log.info("Doing makeRequest"); retStr = executor.makeRequest(aEndpoint, ac.getUri(), obj.toString(), true, context, false); } else { continue; } log.info("Retrieved messages of " + aEndpoint.getOperator() + " operator: " + retStr); if (retStr != null) { JSONArray resList = apiUtil.getResults(reqType, retStr); if (resList != null) { for (int t = 0; t < resList.length(); t++) { results.put(resList.get(t)); } responses.add(retStr); } } if (results.length() >= batchSize) { break; } } if (retry == false) { retryFlag = false; log.info("11 Final value of retryFlag :" + retryFlag); } if (execCount >= retryCount) { retryFlag = false; log.info("22 Final value of retryFlag :" + retryFlag); } log.info("Final value of count :" + execCount); log.info("Results length of retrieve messages: " + results.length()); } JSONObject paylodObject = apiUtil.generateResponse(context, reqType, results, responses, requestid); String strjsonBody = paylodObject.toString(); /*add resourceURL to the southbound response*/ SouthboundRetrieveResponse sbRetrieveResponse = gson.fromJson(strjsonBody, SouthboundRetrieveResponse.class); if (sbRetrieveResponse != null && sbRetrieveResponse.getInboundSMSMessageList() != null) { String resourceURL = sbRetrieveResponse.getInboundSMSMessageList().getResourceURL(); InboundSMSMessage[] inboundSMSMessageResponses = sbRetrieveResponse.getInboundSMSMessageList() .getInboundSMSMessage(); for (int i = 0; i < inboundSMSMessageResponses.length; i++) { String messageId = inboundSMSMessageResponses[i].getMessageId(); inboundSMSMessageResponses[i].setResourceURL(resourceURL + "/" + messageId); } sbRetrieveResponse.getInboundSMSMessageList().setInboundSMSMessage(inboundSMSMessageResponses); } executor.removeHeaders(context); executor.setResponse(context, gson.toJson(sbRetrieveResponse)); ((Axis2MessageContext) context).getAxis2MessageContext().setProperty("messageType", "application/json"); return true; }
From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java
/** * Parse url and return various components of the URL. * If accept any null arguments, return null. * * @param urlStr URL string.//from w w w . ja v a 2 s . c o m * @param partToExtract determines which components would return. * accept values: * HOST,PATH,QUERY,REF, * PROTOCOL,FILE,AUTHORITY,USERINFO * @return target value. */ public static String parseUrl(String urlStr, String partToExtract) { URL url; try { url = URL_CACHE.get(urlStr); } catch (Exception e) { LOG.error("Parse URL error: " + urlStr, e); return null; } if ("HOST".equals(partToExtract)) { return url.getHost(); } if ("PATH".equals(partToExtract)) { return url.getPath(); } if ("QUERY".equals(partToExtract)) { return url.getQuery(); } if ("REF".equals(partToExtract)) { return url.getRef(); } if ("PROTOCOL".equals(partToExtract)) { return url.getProtocol(); } if ("FILE".equals(partToExtract)) { return url.getFile(); } if ("AUTHORITY".equals(partToExtract)) { return url.getAuthority(); } if ("USERINFO".equals(partToExtract)) { return url.getUserInfo(); } return null; }
From source file:eu.esdihumboldt.hale.io.geoserver.rest.AbstractResourceManager.java
/** * Constructor./* w w w .j av a 2 s .c o m*/ * * @param geoserverUrl the base GeoServer URL */ public AbstractResourceManager(URL geoserverUrl) { if (geoserverUrl == null || geoserverUrl.getQuery() != null) { throw new IllegalArgumentException( "GeoServer base URL must not be null and must not contain a query part"); } this.geoserverUrl = geoserverUrl; this.executor = Executor.newInstance(); }
From source file:net.javacoding.jspider.extension.rule.IncreasingRule.java
/** * * * @param context/*from w w w . j a v a 2 s .com*/ * @param currentSite * @param url * @return */ @Override public Decision apply(SpiderContext context, Site currentSite, URL url) { URL orgin = url; Object[] pts = null; if (map.containsKey(url.toString())) { // remove ! pts = map.remove(url.toString()); orgin = (URL) pts[0]; } else { String path = url.getPath(); if (this.queryEnable) { if (url.getQuery() != null) { path += "?" + url.getQuery(); } } Matcher mt = pattern.matcher(path); if (mt.matches()) { orgin = url; int size = mt.groupCount(); pts = new Object[size + 2]; pts[0] = url; for (int i = 1; i <= size; i++) { pts[i] = mt.group(i); } } } if (pts != null) { URL find = this.getNexturl(pts, orgin); if (find != null) { log.debug("Increasing page " + find); map.put(find.toString(), pts); context.getAgent().registerEvent(orgin, new URLFoundEvent(context, orgin, find)); } } return new DecisionInternal(DecisionInternal.RULE_ACCEPT); }
From source file:org.lockss.util.UrlUtil.java
/** Normalize URL to a canonical form: lowercase scheme and hostname, * normalize path. Removes any reference part. XXX need to add * character escaping/*from w w w . jav a 2s . c o m*/ * @throws MalformedURLException */ public static String normalizeUrl(String urlString, int pathTraversalAction) throws MalformedURLException { log.debug3("Normalizing " + urlString); urlString = trimNewlinesAndLeadingWhitespace(urlString); if ("".equals(urlString)) { // permit empty return urlString; } URL url = new URL(urlString); String protocol = url.getProtocol(); // returns lowercase proto String host = url.getHost(); int port = url.getPort(); String path = url.getPath(); String query = url.getQuery(); if (log.isDebug3()) { log.debug3("protocol: " + protocol); log.debug3("host: " + host); log.debug3("port: " + port); log.debug3("path: " + path); log.debug3("query: " + query); } boolean changed = false; if (!urlString.startsWith(protocol)) { // protocol was lowercased changed = true; } if (normalizeAkamaiUrl && StringUtil.endsWithIgnoreCase(host, ".akamai.net")) { Matcher m = AKAMAI_PATH_PAT.matcher(path); if (m.find()) { host = m.group(1); path = m.group(2); changed = true; log.debug2("Akamai rewrite newhost, newpath: " + host + ", " + path); } } // if ("http".equals(protocol) || "ftp".equals(protocol)) { if (host != null) { String newHost = host.toLowerCase(); // lowercase host if (!host.equals(newHost)) { host = newHost; changed = true; } } if (port == getDefaultPort(protocol)) { // if url includes a port that is the default port for the protocol, // remove it (by passing port -1 to constructor) port = -1; changed = true; } if (StringUtil.isNullString(path)) { path = "/"; changed = true; } else { String normPath = normalizePath(path, pathTraversalAction); if (!normPath.equals(path)) { if (log.isDebug3()) log.debug3("Normalized " + path + " to " + normPath); path = normPath; changed = true; } } if (!StringUtil.isNullString(query)) { String normQuery = normalizeUrlEncodingCase(query); if (!normQuery.equals(query)) { if (log.isDebug3()) log.debug3("Normalized query " + query + " to " + normQuery); query = normQuery; changed = true; } } else if (normalizeEmptyQuery && "".equals(query)) { query = null; changed = true; } if (url.getRef() != null) { // remove the ref changed = true; } // } if (changed) { urlString = new URL(protocol, host, port, (StringUtil.isNullString(query) ? path : (path + "?" + query))).toString(); log.debug3("Changed, so returning " + urlString); } return urlString; }
From source file:com.adito.core.CoreUtil.java
/** * @param redirect//from www . j av a 2s.c o m * @return String */ static String processRefererString(String redirect) { try { URL u = new URL(redirect); String query = u.getQuery(); if (query != null && !query.equals("")) { StringBuffer nq = new StringBuffer(); StringTokenizer t = new StringTokenizer(query, "&"); String parm = null; while (t.hasMoreTokens()) { parm = t.nextToken(); if (!parm.startsWith("referer=") && !parm.startsWith("vpnMessage=") && !parm.startsWith("vpnError=")) { if (nq.length() > 0) { nq.append("&"); } nq.append(parm); } } query = nq.length() == 0 ? null : nq.toString(); } StringBuffer file = new StringBuffer(); if (u.getPath() != null) { file.append(u.getPath()); } if (query != null) { file.append("?"); file.append(query); } if (u.getRef() != null) { file.append("#"); file.append(u.getRef()); } u = new URL(u.getProtocol(), u.getHost(), u.getPort(), file.toString()); return u.toExternalForm(); } catch (MalformedURLException mrule) { int idx = redirect.indexOf("?"); if (idx != -1) { String query = redirect.substring(idx + 1); redirect = redirect.substring(0, idx); if (query.length() > 0) { StringBuffer nq = new StringBuffer(); StringTokenizer t = new StringTokenizer(query, "&"); String parm = null; while (t.hasMoreTokens()) { parm = t.nextToken(); if (!parm.startsWith("vpnMessage=") && !parm.startsWith("vpnError=")) { if (nq.length() > 0) { nq.append("&"); } nq.append(parm); } } query = nq.length() == 0 ? null : nq.toString(); if (query != null) { redirect = redirect + "?" + query; } } } return redirect; } }
From source file:com.apigee.sdk.apm.http.impl.client.cache.URIExtractor.java
public String canonicalizeUri(String uri) { try {/*from w ww. j a va2s .c o m*/ URL u = new URL(uri); String protocol = u.getProtocol().toLowerCase(); String hostname = u.getHost().toLowerCase(); int port = canonicalizePort(u.getPort(), protocol); String path = canonicalizePath(u.getPath()); if ("".equals(path)) path = "/"; String query = u.getQuery(); String file = (query != null) ? (path + "?" + query) : path; URL out = new URL(protocol, hostname, port, file); return out.toString(); } catch (MalformedURLException e) { return uri; } }
From source file:com.crazytest.config.TestCase.java
protected void postWithoutToken(String endpoint, List<NameValuePair> params) throws Exception { String endpointString = hostUrl + endpoint; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPost postRequest = new HttpPost(uri); postRequest.setEntity(new UrlEncodedFormEntity(params)); postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); postRequest.setHeader("User-Agent", "Safari"); this.postRequest = postRequest; LOGGER.info("request: {}", postRequest.getRequestLine()); }
From source file:com.crazytest.config.TestCase.java
protected void post(String endpoint, List<NameValuePair> params) throws Exception { String endpointString = hostUrl + endpoint + "?auth-key=" + this.authToken + "&token=" + this.authToken + "&userID=" + this.userID; URL url = new URL(endpointString); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); HttpPost postRequest = new HttpPost(uri); postRequest.setEntity(new UrlEncodedFormEntity(params)); postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded"); postRequest.setHeader("User-Agent", "Safari"); this.postRequest = postRequest; LOGGER.info("request: {}", postRequest.getRequestLine()); }