List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:hydrograph.ui.communication.debugservice.method.Provider.java
/** * Method to get hive table details// www .j a v a2 s. c om * @param jsonString Db name and table details * @param jobDetails * @param userCredentials * @return * @throws NumberFormatException * @throws MalformedURLException */ public PostMethod readMetaDataMethod(MetaDataDetails metaDataDetails, String host, String port) throws NumberFormatException, MalformedURLException { URL url = new URL(POST_PROTOCOL, host, Integer.valueOf(port), DebugServiceMethods.READ_METASTORE); PostMethod postMethod = new PostMethod(url.toString()); Gson gson = new Gson(); postMethod.addParameter(DebugServicePostParameters.REQUEST_PARAMETERS, gson.toJson(metaDataDetails)); LOGGER.debug("Calling Metadata service to get Metadata details through url :: " + url); return postMethod; }
From source file:gobblin.kafka.schemareg.LiKafkaSchemaRegistry.java
/** * Register a schema to the Kafka schema registry * * @param schema/*w ww. ja v a2s . c o m*/ * @return schema ID of the registered schema * @throws SchemaRegistryException if registration failed */ public synchronized MD5Digest register(Schema schema) throws SchemaRegistryException { LOG.info("Registering schema " + schema.toString()); PostMethod post = new PostMethod(url); post.addParameter("schema", schema.toString()); HttpClient httpClient = this.borrowClient(); try { LOG.debug("Loading: " + post.getURI()); int statusCode = httpClient.executeMethod(post); if (statusCode != HttpStatus.SC_CREATED) { throw new SchemaRegistryException("Error occurred while trying to register schema: " + statusCode); } String response; response = post.getResponseBodyAsString(); if (response != null) { LOG.info("Received response " + response); } String schemaKey; Header[] headers = post.getResponseHeaders(SCHEMA_ID_HEADER_NAME); if (headers.length != 1) { throw new SchemaRegistryException( "Error reading schema id returned by registerSchema call: headers.length = " + headers.length); } else if (!headers[0].getValue().startsWith(SCHEMA_ID_HEADER_PREFIX)) { throw new SchemaRegistryException( "Error parsing schema id returned by registerSchema call: header = " + headers[0].getValue()); } else { LOG.info("Registered schema successfully"); schemaKey = headers[0].getValue().substring(SCHEMA_ID_HEADER_PREFIX.length()); } MD5Digest schemaId = MD5Digest.fromString(schemaKey); return schemaId; } catch (Throwable t) { throw new SchemaRegistryException(t); } finally { post.releaseConnection(); this.httpClientPool.returnObject(httpClient); } }
From source file:com.benfante.jslideshare.SlideShareConnectorImpl.java
public InputStream sendMessage(String url, Map<String, String> parameters) throws IOException, SlideShareErrorException { HttpClient client = createHttpClient(); PostMethod method = new PostMethod(url); method.addParameter("api_key", this.apiKey); Iterator<Map.Entry<String, String>> entryIt = parameters.entrySet().iterator(); while (entryIt.hasNext()) { Map.Entry<String, String> entry = entryIt.next(); method.addParameter(entry.getKey(), entry.getValue()); }// w ww . ja va2s. c om Date now = new Date(); String ts = Long.toString(now.getTime() / 1000); String hash = DigestUtils.shaHex(this.sharedSecret + ts).toLowerCase(); method.addParameter("ts", ts); method.addParameter("hash", hash); logger.debug("Sending POST message to " + method.getURI().getURI() + " with parameters " + Arrays.toString(method.getParameters())); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { logger.debug("Server replied with a " + statusCode + " HTTP status code (" + HttpStatus.getStatusText(statusCode) + ")"); throw new SlideShareErrorException(statusCode, HttpStatus.getStatusText(statusCode)); } if (logger.isDebugEnabled()) { logger.debug(method.getResponseBodyAsString()); } InputStream result = new ByteArrayInputStream(method.getResponseBody()); method.releaseConnection(); return result; }
From source file:edu.htwm.vsp.phoebook.rest.client.RestClient.java
public PhoneUser verifyAddUser(String userName, int expectedStatusCode, String contentType) throws IOException, JAXBException, Exception { System.out.println("create new PhoneUser: " + userName + " ... \n"); HttpClient client = new HttpClient(); // -- build HTTP POST request PostMethod method = new PostMethod(getServiceBaseURI() + "/users"); method.addParameter("name", userName); // -- determine the mime type you wish to receive here method.setRequestHeader("Accept", contentType); int responseCode = client.executeMethod(method); assertEquals(expectedStatusCode, responseCode); String response = responseToString(method.getResponseBodyAsStream()); System.out.println(response); String content = method.getResponseHeader("Content-Type").getValue(); /* Antwort zurckgeben */ return getUserFromResponse(response, content); }
From source file:gobblin.metrics.kafka.KafkaAvroSchemaRegistry.java
/** * Register a schema to the Kafka schema registry * * @param schema// w w w .j a v a 2s.c o m * @return schema ID of the registered schema * @throws SchemaRegistryException if registration failed */ @Override public synchronized String register(Schema schema) throws SchemaRegistryException { LOG.info("Registering schema " + schema.toString()); PostMethod post = new PostMethod(url); post.addParameter("schema", schema.toString()); HttpClient httpClient = this.borrowClient(); try { LOG.debug("Loading: " + post.getURI()); int statusCode = httpClient.executeMethod(post); if (statusCode != HttpStatus.SC_CREATED) { throw new SchemaRegistryException("Error occurred while trying to register schema: " + statusCode); } String response; response = post.getResponseBodyAsString(); if (response != null) { LOG.info("Received response " + response); } String schemaKey; Header[] headers = post.getResponseHeaders(SCHEMA_ID_HEADER_NAME); if (headers.length != 1) { throw new SchemaRegistryException( "Error reading schema id returned by registerSchema call: headers.length = " + headers.length); } else if (!headers[0].getValue().startsWith(SCHEMA_ID_HEADER_PREFIX)) { throw new SchemaRegistryException( "Error parsing schema id returned by registerSchema call: header = " + headers[0].getValue()); } else { LOG.info("Registered schema successfully"); schemaKey = headers[0].getValue().substring(SCHEMA_ID_HEADER_PREFIX.length()); } return schemaKey; } catch (Throwable t) { throw new SchemaRegistryException(t); } finally { post.releaseConnection(); this.httpClientPool.returnObject(httpClient); } }
From source file:egpi.tes.ahv.servicio.MenuReporteJasper.java
public boolean validarUsuario(AutenticacionVO authVO) throws ReporteJasperException { try {//from w ww.j ava 2 s. c o m boolean resul = false; authVO.setServerUrl(properties.getProperty("urllogueo")); PostMethod postMethod = new PostMethod(authVO.getServerUrl()); postMethod.addParameter("j_username", authVO.getUsername()); postMethod.addParameter("j_password", authVO.getPassword()); status = client.executeMethod(postMethod); System.out.println("status 00 " + status); if (status == 200) { resul = true; } else { throw new ReporteJasperException(this.properties.getProperty("msg_" + String.valueOf(status))); } return resul; } catch (IOException ex) { throw new ReporteJasperException(ex.getMessage()); } }
From source file:com.intellij.tasks.fogbugz.FogBugzRepository.java
private PostMethod getLoginMethod() { PostMethod method = new PostMethod(getUrl() + "/api.asp"); method.addParameter("cmd", "logon"); method.addParameter("email", getUsername()); method.addParameter("password", getPassword()); return method; }
From source file:dashboard.ImportCSV.java
public void postRequest(String url, String p1, String v1, String p2, String v2) { try {/*from w ww .ja v a2 s.co m*/ String contents = ""; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(url); // Configure the form parameters method.addParameter(p1, v1); method.addParameter(p2, v2); // Add more details in the POST response method.addParameter("verbose", "1"); // Execute the POST method int statusCode = client.executeMethod(method); contents = method.getResponseBodyAsString(); postStatus = Integer.toString(statusCode); postResponse = contents; method.releaseConnection(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.adamcin.granite.client.packman.http3.Http3PackageManagerClient.java
private boolean loginLegacy(String username, String password) throws IOException { PostMethod request = new PostMethod(getBaseUrl() + LEGACY_PATH); request.addParameter(LEGACY_PARAM_USERID, username); request.addParameter(LEGACY_PARAM_PASSWORD, password); request.addParameter(LEGACY_PARAM_WORKSPACE, LEGACY_VALUE_WORKSPACE); request.addParameter(LEGACY_PARAM_TOKEN, LEGACY_VALUE_TOKEN); request.addParameter(LOGIN_PARAM_CHARSET, LOGIN_VALUE_CHARSET); return getClient().executeMethod(request) == 200; }
From source file:com.intellij.tasks.fogbugz.FogBugzRepository.java
private Task[] getCases(String q) throws Exception { HttpClient client = login(getLoginMethod()); PostMethod method = new PostMethod(getUrl() + "/api.asp"); method.addParameter("token", token); method.addParameter("cmd", "search"); method.addParameter("q", q); method.addParameter("cols", "sTitle,fOpen,dtOpened,dtLastUpdated,ixCategory"); int status = client.executeMethod(method); if (status != 200) { throw new Exception("Error listing cases: " + method.getStatusLine()); }// w w w .ja va 2 s.c om Document document = new SAXBuilder(false).build(method.getResponseBodyAsStream()).getDocument(); XPath path = XPath.newInstance("/response/cases/case"); final XPath commentPath = XPath.newInstance("events/event"); @SuppressWarnings("unchecked") final List<Element> nodes = (List<Element>) path.selectNodes(document); final List<Task> tasks = ContainerUtil.mapNotNull(nodes, new NotNullFunction<Element, Task>() { @Nonnull @Override public Task fun(Element element) { return createCase(element, commentPath); } }); return tasks.toArray(new Task[tasks.size()]); }