List of usage examples for org.apache.commons.httpclient HttpURL setQuery
public void setQuery(String[] paramArrayOfString1, String[] paramArrayOfString2) throws URIException, NullPointerException
From source file:com.linkedin.pinot.tools.admin.command.ChangeTableState.java
@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); }//from w w w .jav a 2 s . c om String stateValue = _state.toLowerCase(); if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) { throw new IllegalArgumentException( "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop"); } HttpClient httpClient = new HttpClient(); HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName); url.setQuery("state", stateValue); GetMethod httpGet = new GetMethod(url.getEscapedURI()); int status = httpClient.executeMethod(httpGet); if (status != 200) { throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString()); } return true; }
From source file:com.idega.slide.business.IWSlideServiceBean.java
@Override public WebdavExtendedResource getWebdavExtendedResource(String path, UsernamePasswordCredentials credentials, boolean localResource) throws HttpException, IOException, RemoteException, RemoteException { HttpURL url = getWebdavServerURL(credentials, getPath(path), getWebdavServerURI(), localResource); if (url == null) { throw new IOException("[IWSlideService] WebdavServerURL could not be retrieved for " + path + ", using credentials: " + credentials); }/*from ww w . j a v a2 s . c o m*/ WebdavExtendedResource resource = null; if (localResource && isLocalResourceEnabled()) { if (!Domain.isInitialized()) { DomainConfig domainConfig = ELUtil.getInstance().getBean(DomainConfig.SPRING_BEAN_IDENTIFIER); domainConfig.initialize(); } HttpSession currentSession = getCurrentSession(); if (currentSession != null) { url.setQuery(CoreConstants.PARAMETER_SESSION_ID.toLowerCase(), currentSession.getId()); } try { resource = new WebdavLocalResource(getHttpClient(url, credentials)); resource.setHttpURL(url); } catch (Exception e) { e.printStackTrace(); } } if (resource == null) { resource = new WebdavExtendedResource(url); } return resource; }
From source file:org.eclipse.swordfish.internal.resolver.backend.base.impl.HttpClientProxy.java
private ClientResponse doInvoke(ClientRequest request) { ClientResponse response = RegistryProxyFactory.getInstance().createResponse(); HttpMethod method = getMethod(request.getMethod()); try {//from w w w . ja v a2 s . co m String escapedRequestUrl = request.getURI().toASCIIString(); HttpURL requestUrl = new HttpURL(escapedRequestUrl.toCharArray()); if (request.getProperties() != null) { Map<String, String> properties = request.getProperties(); String[] queryNames = properties.keySet().toArray(new String[0]); String[] queryValues = properties.values().toArray(new String[0]); requestUrl.setQuery(queryNames, queryValues); } method.setURI(requestUrl); int statusCode = getClient().executeMethod(method); response.setStatus(Status.get(statusCode)); String responseBody = method.getResponseBodyAsString(); if (request.getEntityType() != null) { response.setEntity(mapResponse(responseBody, request.getEntityType())); } else { response.setEntity(responseBody); } } catch (HttpException e) { LOG.error("Couldn't perform call to registry: ", e); response.setStatus(Status.ERROR); response.setEntity(e); } catch (IOException e) { LOG.error("Couldn't perform call to registry: ", e); response.setStatus(Status.ERROR); response.setEntity(e); } finally { if (method != null) { method.releaseConnection(); } } return response; }
From source file:org.eclipse.swordfish.internal.resolver.backend.base.impl.HttpClientProxyTest.java
private String convertToQuery(Map<String, String> properties) throws Exception { HttpURL url = new HttpURL(DESCRIPTION_URL); String[] queryNames = properties.keySet().toArray(new String[0]); String[] queryValues = properties.values().toArray(new String[0]); url.setQuery(queryNames, queryValues); return url.getQuery(); }
From source file:org.jahia.modules.jahiademo.filter.StockWidgetFilter.java
/** * * @param path//from w ww. j a v a 2s . c o m * @param params * @return * @throws RepositoryException */ private JSONObject queryGoogleFinanceAPI(final String path, final String... params) throws RepositoryException { try { final HttpClient httpClient = new HttpClient(); final HttpURL url = new HttpURL(API_URL, -1, path); final Map<String, String> m = new LinkedHashMap<String, String>(); for (int i = 0; i < params.length; i += 2) { m.put(params[i], params[i + 1]); } url.setQuery(m.keySet().toArray(new String[m.size()]), m.values().toArray(new String[m.size()])); final long l = System.currentTimeMillis(); LOGGER.debug("Start request : " + url); final GetMethod httpMethod = new GetMethod(url.toString()); try { httpClient.getParams().setSoTimeout(1000); httpClient.executeMethod(httpMethod); return new JSONObject(httpMethod.getResponseBodyAsString()); } finally { httpMethod.releaseConnection(); LOGGER.debug("Request " + url + " done in " + (System.currentTimeMillis() - l) + "ms"); } } catch (java.net.SocketTimeoutException te) { LOGGER.warn("Timeout Exception on request to Google Finance API"); return null; } catch (Exception e) { LOGGER.error(e.getMessage(), e); return null; } }