List of usage examples for org.apache.commons.httpclient.methods GetMethod setQueryString
public void setQueryString(String queryString)
From source file:org.eclipse.orion.server.cf.commands.GetSpaceCommand.java
@Override protected ServerStatus _doIt() { try {//w w w. ja va 2 s. c o m URI targetURI = URIUtil.toURI(getCloud().getUrl()); /* get space */ URI spacesURI = targetURI.resolve("/v2/spaces/" + this.spaceId); GetMethod getSpaceMethod = new GetMethod(spacesURI.toString()); HttpUtil.configureHttpMethod(getSpaceMethod, getCloud()); getSpaceMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$ ServerStatus status = HttpUtil.executeMethod(getSpaceMethod); if (!status.isOK()) return status; space = new Space().setCFJSON(status.getJsonData()); JSONObject result = space.toJSON(); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result); } catch (ConnectTimeoutException e) { String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_GATEWAY_TIMEOUT, msg, e); } catch (Exception e) { String msg = NLS.bind("An error occurred when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:org.eclipse.orion.server.cf.commands.GetStackByNameCommand.java
@Override protected ServerStatus _doIt() { try {/*from w w w . java 2 s . c o m*/ URI targetURI = URIUtil.toURI(target.getUrl()); URI servicesURI = targetURI.resolve("/v2/stacks"); //$NON-NLS-0$//$NON-NLS-1$ GetMethod getStacksMethod = new GetMethod(servicesURI.toString()); NameValuePair[] params = new NameValuePair[] { // new NameValuePair("q", "name:" + stackName), //$NON-NLS-0$ //$NON-NLS-1$ new NameValuePair("inline-relations-depth", "1") //$NON-NLS-0$ //$NON-NLS-1$ }; getStacksMethod.setQueryString(params); ServerStatus confStatus = HttpUtil.configureHttpMethod(getStacksMethod, target.getCloud()); if (!confStatus.isOK()) return confStatus; ServerStatus getStacksStatus = HttpUtil.executeMethod(getStacksMethod); if (!getStacksStatus.isOK()) return getStacksStatus; JSONObject stacksJSON = getStacksStatus.getJsonData(); if (stacksJSON.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) { return getStacksStatus; } JSONArray resources = stacksJSON.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES); JSONObject stackJSON = resources.getJSONObject(0); stack = new Stack().setCFJSON(stackJSON); return getStacksStatus; } catch (Exception e) { String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$ logger.error(msg, e); return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); } }
From source file:org.eclipse.orion.server.cf.handlers.v1.AppsHandlerV1.java
private IStatus getApps(Target target) throws Exception { String appsUrl = target.getSpace().getCFJSON().getJSONObject("entity").getString("apps_url"); // appsUrl = appsUrl.replaceAll("apps", "summary"); URI appsURI = URIUtil.toURI(target.getUrl()).resolve(appsUrl); GetMethod getAppsMethod = new GetMethod(appsURI.toString()); HttpUtil.configureHttpMethod(getAppsMethod, target); getAppsMethod.setQueryString("inline-relations-depth=2"); //$NON-NLS-1$ ServerStatus getAppsStatus = HttpUtil.executeMethod(getAppsMethod); if (!getAppsStatus.isOK()) return getAppsStatus; /* extract available apps */ JSONObject appsJSON = getAppsStatus.getJsonData(); if (appsJSON.getInt(CFProtocolConstants.V2_KEY_TOTAL_RESULTS) < 1) { return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null); }//from w w w. jav a2 s . c o m JSONObject result = new JSONObject(); JSONArray resources = appsJSON.getJSONArray(CFProtocolConstants.V2_KEY_RESOURCES); for (int k = 0; k < resources.length(); ++k) { JSONObject appJSON = resources.getJSONObject(k); App2 app = new App2(); app.setCFJSON(appJSON); result.append("Apps", app.toJSON()); } return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, result); }
From source file:org.eclipse.orion.server.cf.handlers.v1.SpacesHandlerV1.java
@Override protected CFJob handleGet(Space space, HttpServletRequest request, HttpServletResponse response, final String pathString) { final JSONObject targetJSON = extractJSONData( IOUtilities.getQueryParameter(request, CFProtocolConstants.KEY_TARGET)); return new CFJob(request, false) { @Override//from w w w . ja v a2s . c o m protected IStatus performJob() { try { URL targetUrl = null; if (targetJSON != null) { try { targetUrl = new URL(targetJSON.getString(CFProtocolConstants.KEY_URL)); } catch (Exception e) { // do nothing } } Target target = CFActivator.getDefault().getTargetRegistry().getTarget(userId, targetUrl); if (target == null) { return HttpUtil.createErrorStatus(IStatus.WARNING, "CF-TargetNotSet", "Target not set"); } IPath path = new Path(pathString); final String spaceId = path.segment(0); /* get space */ URI targetURI = URIUtil.toURI(target.getUrl()); URI orgsURI = targetURI.resolve("/v2/spaces/" + spaceId); GetMethod getDomainsMethod = new GetMethod(orgsURI.toString()); HttpUtil.configureHttpMethod(getDomainsMethod, target); getDomainsMethod.setQueryString("inline-relations-depth=1"); //$NON-NLS-1$ ServerStatus status = HttpUtil.executeMethod(getDomainsMethod); if (!status.isOK()) return status; Space space = new Space().setCFJSON(status.getJsonData()); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, space.toJSON()); } catch (Exception e) { String msg = NLS.bind("Failed to handle request for {0}", pathString); //$NON-NLS-1$ ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); logger.error(msg, e); return status; } } }; }
From source file:org.eclipse.php.composer.core.HttpHelper.java
public static HttpMethodBase createGetRequest(String url, Map<String, String> params) { GetMethod method = new GetMethod(url); if (params != null) { NameValuePair[] query = new NameValuePair[params.size()]; Set<String> keyList = params.keySet(); int i = 0; for (String key : keyList) { query[i++] = new NameValuePair(key, params.get(key)); }//from w w w.j a va 2s . co m method.setQueryString(query); } return method; }
From source file:org.eclipse.winery.highlevelrestapi.HighLevelRestApi.java
/** * This method implements the HTTP Get Method * /*w w w .j a v a 2 s.c o m*/ * @param uri Resource URI * @return Content represented by the Resource URI */ public static HttpResponseMessage Get(String uri, String acceptHeaderValue) { System.out.println("Setting URI to: \n"); System.out.println(uri); GetMethod method = null; if (uri.contains("?")) { System.out.println("Found query trying to split"); String[] split = uri.split("\\?"); System.out.println("Raw URI part: " + split[0]); System.out.println("Raw Query part: " + split[1]); method = new GetMethod(split[0]); method.setQueryString(HighLevelRestApi.createNameValuePairArrayFromQuery(split[1])); } else { method = new GetMethod(uri); } HighLevelRestApi.setAcceptHeader(method, acceptHeaderValue); HttpResponseMessage responseMessage = LowLevelRestApi.executeHttpMethod(method); HighLevelRestApi.cleanResponseBody(responseMessage); return responseMessage; }
From source file:org.eclipsetrader.directa.internal.core.connector.StreamingConnector.java
private HttpMethod createMethod(String as[], String mode, String host, String urt, String prt) throws MalformedURLException { GetMethod method = new GetMethod("http://" + host + "/preqs/getdata.php"); //$NON-NLS-1$ //$NON-NLS-2$ StringBuffer s = new StringBuffer(); for (int i = 0; i < as.length; i++) { s.append(as[i]);/*w w w.ja v a2s . c o m*/ s.append("|"); //$NON-NLS-1$ } method.setQueryString(new NameValuePair[] { new NameValuePair("modo", mode), //$NON-NLS-1$ new NameValuePair("u", urt), //$NON-NLS-1$ new NameValuePair("p", prt), //$NON-NLS-1$ new NameValuePair("out", "p"), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("listaid", s.toString()), //$NON-NLS-1$ new NameValuePair("lb", "20"), //$NON-NLS-1$ //$NON-NLS-2$ }); return method; }
From source file:org.eclipsetrader.directa.internal.core.WebConnector.java
public boolean sendOrder(OrderMonitor tracker) { boolean ok = false; boolean confirm = false; String inputLine;//w ww . j a v a2 s . c o m IOrder order = tracker.getOrder(); List<NameValuePair> query = new ArrayList<NameValuePair>(); query.add(new NameValuePair("ACQAZ", //$NON-NLS-1$ order.getSide() == IOrderSide.Buy ? String.valueOf(order.getQuantity()) : "")); //$NON-NLS-1$ query.add(new NameValuePair("VENAZ", //$NON-NLS-1$ order.getSide() == IOrderSide.Sell ? String.valueOf(order.getQuantity()) : "")); //$NON-NLS-1$ query.add(new NameValuePair("PRZACQ", //$NON-NLS-1$ order.getType() != IOrderType.Market ? numberFormatter.format(order.getPrice()) : "")); //$NON-NLS-1$ query.add(new NameValuePair("SCTLX", "immetti Borsa Ita")); //$NON-NLS-1$ //$NON-NLS-2$ query.add(new NameValuePair("USER", user)); //$NON-NLS-1$ query.add(new NameValuePair("GEST", "AZIONARIO")); //$NON-NLS-1$ //$NON-NLS-2$ query.add(new NameValuePair("TITO", getSecurityFeedSymbol(order.getSecurity()))); //$NON-NLS-1$ query.add(new NameValuePair("QPAR", "")); //$NON-NLS-1$ //$NON-NLS-2$ if (order.getValidity() == IOrderValidity.GoodTillCancel || order.getValidity() == BrokerConnector.Valid30Days) { query.add(new NameValuePair("VALID", "M")); //$NON-NLS-1$ //$NON-NLS-2$ } query.add(new NameValuePair("FAS5", //$NON-NLS-1$ order.getRoute() != null ? order.getRoute().getId() : BrokerConnector.Immediate.getId())); // Inserisce l'ordine di acquisto try { GetMethod method = new GetMethod("https://" + HOST + "/trading/ordimm5c"); //$NON-NLS-1$ //$NON-NLS-2$ method.setFollowRedirects(true); query.add(new NameValuePair("MODO", "C")); //$NON-NLS-1$ //$NON-NLS-2$ method.setQueryString(query.toArray(new NameValuePair[query.size()])); logger.debug(method.getURI().toString()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((inputLine = in.readLine()) != null) { logger.debug(inputLine); if (inputLine.indexOf("VI TRASMETTO L'ORDINE DI") != -1) { //$NON-NLS-1$ ok = true; confirm = true; } if (inputLine.indexOf("ORDINE IMMESSO") != -1) { //$NON-NLS-1$ ok = true; confirm = false; } if (!confirm && tracker.getId() == null) { int s = inputLine.indexOf("<i>rif. "); //$NON-NLS-1$ if (s != -1) { s = inputLine.indexOf(">", s + 13) + 1; //$NON-NLS-1$ int e = inputLine.indexOf("<", s); //$NON-NLS-1$ tracker.setId(inputLine.substring(s, e)); } } } in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error sending order [" + order.toString() + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ Activator.log(status); } // Se viene richiesta invia anche la conferma d'ordine if (ok && confirm) { ok = false; try { GetMethod method = new GetMethod("https://" + HOST + "/trading/ordimm5c"); //$NON-NLS-1$ //$NON-NLS-2$ method.setFollowRedirects(true); query.remove(new NameValuePair("MODO", "C")); //$NON-NLS-1$ //$NON-NLS-2$ query.add(new NameValuePair("MODO", "V")); //$NON-NLS-1$ //$NON-NLS-2$ method.setQueryString(query.toArray(new NameValuePair[query.size()])); logger.debug(method.getURI().toString()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((inputLine = in.readLine()) != null) { logger.debug(inputLine); if (inputLine.indexOf("ORDINE IMMESSO") != -1) { //$NON-NLS-1$ ok = true; } if (ok && tracker.getId() == null) { int s = inputLine.indexOf("<i>rif. "); //$NON-NLS-1$ if (s != -1) { s = inputLine.indexOf(">", s) + 1; //$NON-NLS-1$ int e = inputLine.indexOf("<", s); //$NON-NLS-1$ tracker.setId(inputLine.substring(s, e)); } } } in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error confirming order [" + order.toString() + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ Activator.log(status); } } if (ok) { if (logger.isInfoEnabled()) { StringBuilder sb = new StringBuilder("Order Submitted:"); sb.append(" id=" + tracker.getId()); sb.append(", instrument=" + tracker.getOrder().getSecurity().getName()); sb.append(", type=" + tracker.getOrder().getType()); sb.append(", side=" + tracker.getOrder().getSide()); sb.append(", qty=" + tracker.getOrder().getQuantity()); if (tracker.getOrder().getPrice() != null) { sb.append(", price=" + tracker.getOrder().getPrice()); } if (tracker.getOrder().getReference() != null) { sb.append(", reference=" + tracker.getOrder().getReference()); } logger.info(sb.toString()); } tracker.setStatus(IOrderStatus.PendingNew); } return ok; }
From source file:org.eclipsetrader.directa.internal.core.WebConnector.java
public boolean cancelOrder(OrderMonitor tracker) { boolean ok = false; String inputLine;/*from ww w.ja v a 2s .c om*/ try { GetMethod method = new GetMethod("https://" + HOST + "/trading/ordmod5c"); //$NON-NLS-1$ //$NON-NLS-2$ method.setQueryString(new NameValuePair[] { new NameValuePair("TAST", "REVOCA"), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("USER", user), //$NON-NLS-1$ new NameValuePair("RIF", tracker.getId()), //$NON-NLS-1$ new NameValuePair("TIPO", "I"), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("PRZO", ""), //$NON-NLS-1$ //$NON-NLS-2$ new NameValuePair("TITO", getSecurityFeedSymbol(tracker.getOrder().getSecurity())), //$NON-NLS-1$ new NameValuePair("FILL", "REVOCA"), //$NON-NLS-1$ //$NON-NLS-2$ }); logger.debug(method.getURI().toString()); client.executeMethod(method); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); while ((inputLine = in.readLine()) != null) { logger.debug(inputLine); if (inputLine.indexOf("INOLTRATA LA RICHIESTA DI REVOCA") != -1 //$NON-NLS-1$ || inputLine.indexOf("RICH.ANN.") != -1) { //$NON-NLS-1$ ok = true; } } in.close(); } catch (Exception e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error canceling order [" + tracker.toString() + "]", e); //$NON-NLS-1$ //$NON-NLS-2$ Activator.log(status); } if (ok) { tracker.setStatus(IOrderStatus.PendingCancel); } return ok; }
From source file:org.eclipsetrader.directa.internal.core.WebConnector.java
public void importWatchlists() { try {//from w ww .j a v a2 s . c om GetMethod method = new GetMethod("https://" + HOST + "/trading/select"); //$NON-NLS-1$ //$NON-NLS-2$ method.setFollowRedirects(true); method.setQueryString(new NameValuePair[] { new NameValuePair("USER", user), //$NON-NLS-1$ new NameValuePair("INCR", "N"), //$NON-NLS-1$ //$NON-NLS-2$ }); logger.debug(method.getURI().toString()); client.executeMethod(method); Parser parser = Parser.createParser(method.getResponseBodyAsString(), ""); //$NON-NLS-1$ NodeList list = parser.extractAllNodesThatMatch(new HasAttributeFilter("name", "DEVAR")); //$NON-NLS-1$ //$NON-NLS-2$ for (SimpleNodeIterator iter = list.elements(); iter.hasMoreNodes();) { Object o = iter.nextNode(); if (o instanceof SelectTag) { OptionTag[] options = ((SelectTag) o).getOptionTags(); for (int i = 0; i < options.length; i++) { if (options[i].getValue().equals("A0") || options[i].getValue().equals("AX")) { //$NON-NLS-1$ //$NON-NLS-2$ continue; } System.out.println(options[i].getValue() + " -> " + options[i].getOptionText()); //$NON-NLS-1$ getWatchlist(options[i].getValue(), options[i].getOptionText()); } } } } catch (Exception e) { e.printStackTrace(); } }