List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:eu.learnpad.core.impl.dash.XwikiBridgeInterfaceRestResource.java
@Override public void loadKPIValues(String modelSetId, KPIValuesFormat format, String businessActorId, InputStream cockpitContent) throws LpRestException { String contentType = "application/xml"; HttpClient httpClient = this.getAnonymousClient(); String uri = String.format("%s/learnpad/dash/bridge/loadkpivalues/%s", this.restPrefix, modelSetId); PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Content-Type", contentType); NameValuePair[] queryString = new NameValuePair[2]; queryString[0] = new NameValuePair("format", format.toString()); queryString[1] = new NameValuePair("businessactor", businessActorId); putMethod.setQueryString(queryString); RequestEntity requestEntity = new InputStreamRequestEntity(cockpitContent); putMethod.setRequestEntity(requestEntity); try {/*from www. j a v a2s .c o m*/ httpClient.executeMethod(putMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:au.org.ala.cas.client.WebServiceAuthenticationHelper.java
/** * Authenticates user credentials with CAS server and obtains a Ticket Granting ticket. * // ww w . j a va 2 s . c o m * @param server CAS server URI * @param username User name * @param password Password * @return The Ticket Granting Ticket id */ private String getTicketGrantingTicket(final String server, final String username, final String password) { final HttpClient client = new HttpClient(); final PostMethod post = new PostMethod(server + CAS_CONTEXT); post.setRequestBody(new NameValuePair[] { new NameValuePair("username", username), new NameValuePair("password", password) }); try { client.executeMethod(post); final String response = post.getResponseBodyAsString(); switch (post.getStatusCode()) { case 201: { final Matcher matcher = Pattern.compile(".*action=\".*/(.*?)\".*").matcher(response); if (matcher.matches()) return matcher.group(1); logger.warn("Successful ticket granting request, but no ticket found!"); logger.info("Response (1k): " + getMaxString(response)); break; } default: logger.warn("Invalid response code (" + post.getStatusCode() + ") from CAS server!"); logger.info("Response (1k): " + getMaxString(response)); break; } } catch (final IOException e) { logger.warn(e.getMessage(), e); } finally { post.releaseConnection(); } return null; }
From source file:com.nextcloud.android.sso.InputStreamBinder.java
private NameValuePair[] convertMapToNVP(Map<String, String> map) { NameValuePair[] nvp = new NameValuePair[map.size()]; int i = 0;//from w ww. jav a2 s. c o m for (String key : map.keySet()) { nvp[i] = new NameValuePair(key, map.get(key)); i++; } return nvp; }
From source file:com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; int status = -1; GetMethod get = null;/*w w w. j a va2 s. c om*/ try { // Get Method get = new GetMethod(client.getBaseUri() + ShareUtils.SHARING_API_PATH); // Add Parameters to Get Method get.setQueryString(new NameValuePair[] { new NameValuePair(PARAM_PATH, mRemoteFilePath), new NameValuePair(PARAM_RESHARES, String.valueOf(mReshares)), new NameValuePair(PARAM_SUBFILES, String.valueOf(mSubfiles)) }); get.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE); status = client.executeMethod(get); if (isSuccess(status)) { String response = get.getResponseBodyAsString(); result = new RemoteOperationResult(ResultCode.OK); // Parse xml response --> obtain the response in ShareFiles ArrayList // convert String into InputStream InputStream is = new ByteArrayInputStream(response.getBytes()); ShareXMLParser xmlParser = new ShareXMLParser(); mShares = xmlParser.parseXMLResponse(is); if (mShares != null) { Log_OC.d(TAG, "Got " + mShares.size() + " shares"); result = new RemoteOperationResult(ResultCode.OK); ArrayList<Object> sharesObjects = new ArrayList<Object>(); for (OCShare share : mShares) { // Build the link if (share.getToken().length() > 0) { share.setShareLink( client.getBaseUri() + ShareUtils.SHARING_LINK_TOKEN + share.getToken()); } sharesObjects.add(share); } result.setData(sharesObjects); } } else { result = new RemoteOperationResult(false, status, get.getResponseHeaders()); } } catch (Exception e) { result = new RemoteOperationResult(e); Log_OC.e(TAG, "Exception while getting shares", e); } finally { if (get != null) { get.releaseConnection(); } } return result; }
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClientIT.java
@Test public void hostConfig() throws Exception { HttpClient client = new HttpClient(); client.getParams().setConnectionManagerTimeout(CONNECTION_TIMEOUT); client.getParams().setSoTimeout(SO_TIMEOUT); HostConfiguration config = new HostConfiguration(); config.setHost("weather.naver.com", 80, "http"); GetMethod method = new GetMethod("/rgn/cityWetrMain.nhn"); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); method.setQueryString(new NameValuePair[] { new NameValuePair("key2", "value2") }); try {//from ww w.j a v a 2s. c o m // Execute the method. client.executeMethod(config, method); } catch (Exception ignored) { } finally { method.releaseConnection(); } PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); verifier.printCache(); }
From source file:com.mirth.connect.client.core.MessageListHandler.java
private List<MessageObject> getMessagesByPage(int page) throws ListHandlerException { NameValuePair[] params = {//from w w w. j a v a2 s .com (tempEnabled ? new NameValuePair("op", Operations.MESSAGE_GET_BY_PAGE.getName()) : new NameValuePair("op", Operations.MESSAGE_GET_BY_PAGE_LIMIT.getName())), new NameValuePair("page", String.valueOf(page)), new NameValuePair("pageSize", String.valueOf(pageSize)), new NameValuePair("maxMessages", String.valueOf(size)), new NameValuePair("uid", uid), (tempEnabled ? new NameValuePair("filter", "") : new NameValuePair("filter", serializer.toXML(filter))) }; try { return (List<MessageObject>) serializer .fromXML(connection.executePostMethod(Client.MESSAGE_SERVLET, params)); } catch (ClientException e) { throw new ListHandlerException(e); } }
From source file:br.org.acessobrasil.silvinha.util.versoes.AtualizadorDeVersoes.java
public boolean baixarVersao() { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); NameValuePair param = new NameValuePair("param", "update"); method.setRequestBody(new NameValuePair[] { param }); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); JFrame down = new JFrame("Download"); File downFile = null;//from w w w. j a va2 s.c o m InputStream is = null; FileOutputStream fos = null; try { int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { log.error("Method failed: " + method.getStatusLine()); } Header header = method.getResponseHeader("Content-Disposition"); String fileName = "silvinha.exe"; if (header != null) { fileName = header.getValue().split("=")[1]; } // Read the response body. is = method.getResponseBodyAsStream(); down.pack(); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(down, TradAtualizadorDeVersoes.FAZ_DOWNLOAD_FILE + fileName, is); pmis.getProgressMonitor().setMinimum(0); pmis.getProgressMonitor().setMaximum((int) method.getResponseContentLength()); downFile = new File(fileName); fos = new FileOutputStream(downFile); int c; while (((c = pmis.read()) != -1) && (!pmis.getProgressMonitor().isCanceled())) { fos.write(c); } fos.flush(); fos.close(); String msgOK = TradAtualizadorDeVersoes.DOWNLOAD_EXITO + TradAtualizadorDeVersoes.DESEJA_ATUALIZAR_EXECUTAR + TradAtualizadorDeVersoes.ARQUIVO_DE_NOME + fileName + TradAtualizadorDeVersoes.LOCALIZADO_NA + TradAtualizadorDeVersoes.PASTA_INSTALACAO + TradAtualizadorDeVersoes.APLICACAO_DEVE_SER_ENCERRADA + TradAtualizadorDeVersoes.DESEJA_CONTINUAR_ATUALIZACAO; if (JOptionPane.showConfirmDialog(null, msgOK, TradAtualizadorDeVersoes.ATUALIZACAO_DO_PROGRAMA, JOptionPane.YES_NO_OPTION) == 0) { return true; } else { return false; } } catch (HttpException he) { log.error("Fatal protocol violation: " + he.getMessage(), he); return false; } catch (InterruptedIOException iioe) { method.abort(); String msg = GERAL.OP_CANCELADA_USUARIO + TradAtualizadorDeVersoes.DIRECIONADO_A_APLICACAO; JOptionPane.showMessageDialog(down, msg); try { if (fos != null) { fos.close(); } } catch (IOException ioe) { method.releaseConnection(); System.exit(0); } if (downFile != null && downFile.exists()) { downFile.delete(); } return false; // System.err.println("Fatal transport error: " + iioe.getMessage()); // iioe.printStackTrace(); } catch (IOException ioe) { log.error("Fatal transport error: " + ioe.getMessage(), ioe); return false; } finally { //Release the connection. method.releaseConnection(); } }
From source file:com.ltasks.LtasksNameFinderClient.java
/** * Annotate a filtered normalized text from a URL * /* ww w . j a v a 2 s . co m*/ * @param aUrl * the URL * @param filterOptions * the html filter options * @return the annotation object * @throws HttpException * Got a protocol error. * @throws IOException * Failed to communicate or to read the result. * @throws IllegalArgumentException * The data received from server was invalid. */ public LtasksObject processUrl(URL aUrl, HtmlFilterOptions filterOptions) throws HttpException, IOException, IllegalArgumentException { return post(createNameValuePairs(new NameValuePair("url", aUrl.toString()), filterOptions)); }
From source file:easyshop.downloadhelper.HttpPageGetter.java
public OriHttpPage getPost(HttpClient client, String code) { NameValuePair[] data = { new NameValuePair("username", "jan"), new NameValuePair("password", "197675"), new NameValuePair("returl", "http://www.netsun.com/member/Action.cgi?t=mjk&id=4234123"), new NameValuePair("f", "login"), new NameValuePair("v_id", "161073"), new NameValuePair("v_secret", code), new NameValuePair("v_digest", "6bfd3517e5bd86ed1d24520600f62ff4") }; String urlstr = "http://www.netsun.com/member/index.cgi"; return getPost(client, urlstr, data); }
From source file:cn.newtouch.util.HttpClientUtil.java
/** * // www . ja va 2 s . co m * List ? * * @since 2011-11-25 * @param url * @param params * ? * @return */ public static String post(String url, List<LabelValue> params) { HttpClient client = new HttpClient(); PostMethod postMethod = new PostMethod(url); try { client.getParams().setContentCharset(ENCODING_UTF);// ? for (LabelValue temp : params) { postMethod.addParameter(new NameValuePair(temp.getValue(), temp.getValue()));// username?values } int tmpStatusCode = client.executeMethod(postMethod); // ? if (tmpStatusCode == HttpStatus.SC_OK) { return postMethod.getResponseBodyAsString(); } else { return null; } } catch (Exception e) { System.err.println(e); } finally { postMethod.releaseConnection(); } return null; }