List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:org.dataconservancy.ui.it.support.CreateIdApiRequest.java
public HttpPost asHttpPost() { HttpPost post = new HttpPost(urlConfig.getCreateIdApiUrl().toString()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("type", type.name())); UrlEncodedFormEntity entity = null;// ww w . ja va2 s. c o m try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } post.setEntity(entity); return post; }
From source file:securitytools.nessus.http.request.LogoutRequest.java
/** * /*from w w w .ja v a2s .c o m*/ * @param sequenceId A unique number that will be echoed back to identify * this response. */ public LogoutRequest(long sequenceId) { super("/logout"); if (ValidationUtils.isNegative(sequenceId)) { throw new IllegalArgumentException("\"sequenceId\" argument cannot be less than zero."); } List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("seq", String.valueOf(sequenceId))); setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8)); }
From source file:securitytools.nessus.http.request.GetFeedRequest.java
/** * /* w w w. j a v a 2 s . c om*/ * @param sequenceId A unique number that will be echoed back to identify * this response. */ public GetFeedRequest(long sequenceId) { super("/feed"); if (ValidationUtils.isNegative(sequenceId)) { throw new IllegalArgumentException("\"sequenceId\" argument cannot be less than zero."); } List<NameValuePair> formparams = new ArrayList<NameValuePair>(); formparams.add(new BasicNameValuePair("seq", String.valueOf(sequenceId))); setEntity(new UrlEncodedFormEntity(formparams, Consts.UTF_8)); }
From source file:org.opencastproject.videoeditor.remote.VideoEditorServiceRemote.java
@Override public List<Job> processSmil(Smil smil) throws ProcessFailedException { HttpPost post = new HttpPost("/process-smil"); List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); try {//from ww w .ja v a2 s . c om params.add(new BasicNameValuePair("smil", smil.toXML())); post.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (Exception e) { throw new ProcessFailedException( "Unable to assemble a remote videoeditor request for smil " + smil.getId()); } HttpResponse response = null; try { response = getResponse(post); if (response != null) { String entity = EntityUtils.toString(response.getEntity()); if (StringUtils.isNotEmpty(entity)) { List<Job> jobs = new LinkedList<Job>(); for (Job job : JobParser.parseJobList(entity).getJobs()) { jobs.add(job); } logger.info("Start proccessing smil '{}' on remote videoeditor service", smil.getId()); return jobs; } } } catch (Exception e) { throw new ProcessFailedException( "Unable to proccess smil " + smil.getId() + " using a remote videoeditor service", e); } finally { closeConnection(response); } throw new ProcessFailedException( "Unable to proccess smil " + smil.getId() + " using a remote videoeditor service."); }
From source file:com.jgoetsch.eventtrader.source.WordPressLoginFilter.java
public void doAction(HttpClient client, AbstractHttpMsgSource httpMsgSource) { try {// w ww . j av a2 s . c o m if (getLoginUrl() == null || getLoginUrl().length() == 0) throw new IllegalStateException("Required property \"loginUrl\" not set"); else { HttpPost post = new HttpPost(getLoginUrl()); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("log", httpMsgSource.getUsername())); nvps.add(new BasicNameValuePair("pwd", httpMsgSource.getPassword())); nvps.add(new BasicNameValuePair("redirect_to", "wp-admin/")); nvps.add(new BasicNameValuePair("testcookie", "1")); post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpParams postParams = new BasicHttpParams(); postParams.setBooleanParameter("http.protocol.handle-redirects", false); post.setParams(postParams); HttpResponse rsp = client.execute(post); HttpEntity entity = rsp.getEntity(); if (entity != null) entity.consumeContent(); // release connection gracefully if (rsp.getStatusLine().getStatusCode() >= 400) throw new IOException("Login POST request failed with error code " + rsp.getStatusLine()); else if (rsp.getStatusLine().getStatusCode() != 302) throw new IOException( "Login failed, redirect response not received (probably incorrect username/password)"); else { log.debug("Successfully logged into " + getLoginUrl() + " as user " + httpMsgSource.getUsername()); } } } catch (IOException e) { log.error("Wordpress site login failed", e); } }
From source file:org.wso2.am.integration.ui.tests.util.TestUtil.java
/** * Login to API Store or Publisher//w w w . j a v a 2 s . co m * * @param userName * @param password * @param URL API Store or Publisher URL * @return * @throws Exception */ public static HttpContext login(String userName, String password, String URL) throws Exception { CookieStore cookieStore = new BasicCookieStore(); HttpContext httpContext = new BasicHttpContext(); httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(URL + APIMTestConstants.APISTORE_LOGIN_URL); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(3); params.add(new BasicNameValuePair(APIMTestConstants.API_ACTION, APIMTestConstants.API_LOGIN_ACTION)); params.add(new BasicNameValuePair(APIMTestConstants.APISTORE_LOGIN_USERNAME, userName)); params.add(new BasicNameValuePair(APIMTestConstants.APISTORE_LOGIN_PASSWORD, password)); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = httpclient.execute(httppost, httpContext); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); boolean isError = Boolean.parseBoolean(responseString.split(",")[0].split(":")[1].split("}")[0].trim()); if (isError) { String errorMsg = responseString.split(",")[1].split(":")[1].split("}")[0].trim(); throw new Exception("Error while Login to API Publisher : " + errorMsg); } else { return httpContext; } }
From source file:com.mirth.connect.client.core.ConnectServiceUtil.java
public static void registerUser(String serverId, String mirthVersion, User user, String[] protocols, String[] cipherSuites) throws ClientException { CloseableHttpClient httpClient = null; CloseableHttpResponse httpResponse = null; NameValuePair[] params = { new BasicNameValuePair("serverId", serverId), new BasicNameValuePair("version", mirthVersion), new BasicNameValuePair("user", ObjectXMLSerializer.getInstance().serialize(user)) }; HttpPost post = new HttpPost(); post.setURI(URI.create(URL_CONNECT_SERVER + URL_REGISTRATION_SERVLET)); post.setEntity(new UrlEncodedFormEntity(Arrays.asList(params), Charset.forName("UTF-8"))); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(TIMEOUT) .setConnectionRequestTimeout(TIMEOUT).setSocketTimeout(TIMEOUT).build(); try {/* ww w. ja v a 2 s.c o m*/ HttpClientContext postContext = HttpClientContext.create(); postContext.setRequestConfig(requestConfig); httpClient = getClient(protocols, cipherSuites); httpResponse = httpClient.execute(post, postContext); StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if ((statusCode != HttpStatus.SC_OK) && (statusCode != HttpStatus.SC_MOVED_TEMPORARILY)) { throw new Exception("Failed to connect to update server: " + statusLine); } } catch (Exception e) { throw new ClientException(e); } finally { HttpClientUtils.closeQuietly(httpResponse); HttpClientUtils.closeQuietly(httpClient); } }
From source file:com.ninehcom.userinfo.util.HttpUtils.java
/** * post form/*w ww . j a va 2s . c o m*/ * * @param host * @param path * @param method * @param headers * @param querys * @param bodys * @return * @throws Exception */ public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys) throws Exception { HttpClient httpClient = wrapClient(host); HttpPost request = new HttpPost(buildUrl(host, path, querys)); for (Map.Entry<String, String> e : headers.entrySet()) { request.addHeader(e.getKey(), e.getValue()); } if (bodys != null) { List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); for (String key : bodys.keySet()) { nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); } UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); request.setEntity(formEntity); } return httpClient.execute(request); }