List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.websso.direct.DirectLoginHttpFacade.java
/** * Select the authentication service URL. Step 2. *//*from w w w.j a v a 2 s.c o m*/ public void selectAuthenticationService(String url) throws IOException { this.authenticationServiceUrl = url; log.trace("POSTing to {} to select authentication service {}", getLoginUrl(), url); PostMethod post = createLoginPostMethod(); post.addParameter(EVENT_ID_PARAMETER, "selectAuthenticationService"); post.addParameter(CREDENTIAL_PROVIDER_PARAMETER, this.dorianName); post.addParameter(LOGIN_TICKET_PARAMETER, this.lt); post.addParameter(AUTHENTICATION_SERVICE_URL_PARAMETER, this.authenticationServiceUrl); LoginFormReader form = new LoginFormReader(doIntermediatePost(post)); if (!form.hasUsernameAndPasswordFields()) { log.debug( "After selecting the authentication system, there are no username & password fields on the page. Cannot proceed."); throw new CasDirectException( "After selecting the authentication system, there are no username & password fields on the page. Cannot proceed."); } }
From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java
public void AddUser(String authName, String target, String rigthTarget, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed/" + target); postMethod.addParameter("authName", authName); postMethod.addParameter("rigthTarget", rigthTarget); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;/*from w w w . j a va 2 s. c o m*/ case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_FORBIDDEN: throw new ForbiddenException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.group.RemoveUserFromGroup.java
public void RemoveUser(String groupName, String targetName, String authName) throws IOException, UnauthorizedException, BadRequestException, UnknownResponseException, InternalServerErrorException { PostMethod postMethod = new PostMethod( baseUri + "/client/groups/remove/user/" + groupName + "/" + targetName); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;/* w w w .j a v a 2 s . com*/ case HttpStatus.SC_FORBIDDEN: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:com.jaspersoft.jasperserver.war.common.HeartbeatClientInfo.java
public void contributeToHttpCall(PostMethod post) { post.addParameter("navAppName[]", getNavigatorAppName() == null ? "" : getNavigatorAppName()); post.addParameter("navAppVersion[]", getNavigatorAppVersion() == null ? "" : getNavigatorAppVersion()); post.addParameter("navLocale[]", getNavigatorLocale() == null ? "" : getNavigatorLocale().toString()); post.addParameter("userLocale[]", getUserLocale() == null ? "" : getUserLocale().toString()); post.addParameter("scrWidth[]", getScreenWidth() == null ? "" : getScreenWidth().toString()); post.addParameter("scrHeight[]", getScreenHeight() == null ? "" : getScreenHeight().toString()); post.addParameter("scrColorDepth[]", getScreenColorDepth() == null ? "" : getScreenColorDepth().toString()); post.addParameter("userAgent[]", getUserAgent() == null ? "" : getUserAgent()); post.addParameter("clientCount[]", String.valueOf(getCount())); }
From source file:es.carebear.rightmanagement.client.group.RemoveGroupRight.java
public void RemoveRight(String targetGroup, String removedGroup, String authName) throws IOException, UnauthorizedException, BadRequestException, UnknownResponseException, InternalServerErrorException { PostMethod postMethod = new PostMethod( baseUri + "/client/groups/remove/group/" + targetGroup + "/" + removedGroup); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;// ww w. j av a 2 s . c om case HttpStatus.SC_FORBIDDEN: throw new UnauthorizedException(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:net.navasoft.madcoin.backend.services.push.AndroidPushNotificationServiceImpl.java
/** * Do send notification./*from w ww .j a va 2 s . co m*/ * * @param notification * the notification * @throws PushNotificationException * the push notification exception * @since 27/07/2014, 06:48:42 PM */ protected void doSendNotification(Notification notification) throws PushNotificationException { try { PostMethod method = new PostMethod("https://android.apis.google.com/c2dm/send"); method.addParameter("registration_id", notification.getDeviceToken()); method.addParameter("collapse_key", "collapse"); method.addParameter("data.payload", String.valueOf(notification.getBadge())); Header header = new Header("Authorization", "GoogleLogin auth=" + notification.getGeneratedToken()); method.addRequestHeader(header); service.executeMethod(method); byte[] responseBody = method.getResponseBody(); String response = new String(responseBody); System.out.println(response); } catch (HttpException e) { e.printStackTrace(); throw new PushNotificationException("HTTP ", e); } catch (IOException e) { e.printStackTrace(); throw new PushNotificationException("IO ", e); } }
From source file:com.tops.hotelmanager.util.CommonHttpClient.java
private static String executePOSTRequestV1(String url, Map<String, Object> requestData, Map<String, String> headerMap, String contentType, int timeOut, int retry) { PostMethod post = new PostMethod(url); Gson gson = new Gson(); String errorMsg = "error~Request Failed"; try {//ww w . j av a2 s. co m HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setSoTimeout(timeOut); client.getHttpConnectionManager().getParams().setConnectionTimeout(timeOut); if (requestData == null || requestData.isEmpty()) { throw new CustomException("Request data is null"); } if (contentType != null && contentType.equals(CommonHttpClient.CONTENT_TYPE_JSON)) { StringRequestEntity requestEntity = new StringRequestEntity(gson.toJson(requestData), contentType, "UTF-8"); post.setRequestEntity(requestEntity); } else { // SET REQUEST PARAMETER for (Map.Entry<String, Object> entry : requestData.entrySet()) { post.addParameter(entry.getKey(), String.valueOf(entry.getValue())); } } // SET REQUEST HEADER if (headerMap != null) { for (Map.Entry<String, String> entry : headerMap.entrySet()) { post.addRequestHeader(entry.getKey(), entry.getValue()); } } int status = client.executeMethod(post); // System.out.println("URL:" + url); // System.out.println("\n REQUEST HEADERS:"); // Header[] requestHeaders = post.getRequestHeaders(); // for (Header header : requestHeaders) { // System.out.println(header.getName() + "=" + header.getValue()); // } // System.out.println("\n RESPONSE HEADERS:"); // Header[] responseHeaders = post.getResponseHeaders(); // for (Header header : responseHeaders) { // System.out.println(header.getName() + "=" + header.getValue()); // } // System.out.println(post.getStatusText()); // System.out.println(post.getStatusLine().getReasonPhrase()); // System.out.println(post.getResponseBodyAsString()); if (status == HttpStatus.SC_OK) { return post.getResponseBodyAsString(); } else if (status == HttpStatus.SC_TEMPORARY_REDIRECT) { Header header = post.getResponseHeader("Location"); if (retry != 1) { errorMsg = executePOSTRequestV1(header.getValue(), requestData, headerMap, contentType, timeOut, retry++); } } else { errorMsg += ",HttpStatus:" + status; } } catch (Exception ex) { logger.error("executePOSTRequestV1 url: " + url + ", Parameters: " + requestData, ex); errorMsg = errorMsg + ":" + ex.getMessage(); } finally { post.releaseConnection(); } return errorMsg; }
From source file:hydrograph.server.service.HydrographServiceClient.java
public void calltoReadService() throws IOException { HttpClient httpClient = new HttpClient(); PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/read"); postMethod.addParameter("jobId", JOB_ID); postMethod.addParameter("componentId", COMPONENT_ID); postMethod.addParameter("socketId", SOCKET_ID); postMethod.addParameter("basePath", BASE_PATH); postMethod.addParameter("userId", USER_ID); postMethod.addParameter("password", PASSWORD); postMethod.addParameter("file_size", FILE_SIZE_TO_READ); postMethod.addParameter("host_name", HOST_NAME); InputStream inputStream = postMethod.getResponseBodyAsStream(); byte[] buffer = new byte[1024 * 1024 * 5]; String path = null;//from ww w . j a va 2 s . co m int length; while ((length = inputStream.read(buffer)) > 0) { path = new String(buffer); } System.out.println("response of service: " + path); }
From source file:com.alternatecomputing.jschnizzle.renderer.YUMLRenderer.java
public BufferedImage render(Diagram diagram) { String script = diagram.getScript(); if (script == null) { throw new RendererException("no script defined."); }/*from ww w.ja va 2s . co m*/ StringTokenizer st = new StringTokenizer(script.trim(), "\n"); StringBuilder buffer = new StringBuilder(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.startsWith("#")) { continue; // skip over comments } buffer.append(token.trim()); if (st.hasMoreTokens()) { buffer.append(", "); } } buffer.append(".svg"); String style = diagram.getStyle().getValue(); String baseURL = getBaseURL(); try { HttpClient client = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) { client.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } String postURI = baseURL + "diagram/" + style + "/" + diagram.getType().getUrlModifier() + "/"; LOGGER.debug(postURI); PostMethod postMethod = new PostMethod(postURI); postMethod.addParameter("dsl_text", buffer.toString()); client.executeMethod(postMethod); String svgResourceName = postMethod.getResponseBodyAsString(); postMethod.releaseConnection(); LOGGER.debug(svgResourceName); String getURI = baseURL + svgResourceName; LOGGER.debug(getURI); GetMethod getMethod = new GetMethod(getURI); client.executeMethod(getMethod); String svgContents = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); LOGGER.debug(svgContents); diagram.setEncodedImage(svgContents); TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContents.getBytes())); BufferedImageTranscoder imageTranscoder = new BufferedImageTranscoder(); imageTranscoder.transcode(input, null); return imageTranscoder.getBufferedImage(); } catch (MalformedURLException e) { throw new RendererException(e); } catch (IOException e) { throw new RendererException(e); } catch (TranscoderException e) { throw new RendererException(e); } }
From source file:hydrograph.server.service.HydrographServiceClient.java
public void calltoFilterService() throws IOException { HttpClient httpClient = new HttpClient(); // String json = // "{\"condition\":\"abc\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.math.BigDecimal\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":1,\"jobDetails\":{\"host\":\"127.0.0.1\",\"port\":\"8005\",\"username\":\"hduser\",\"password\":\"Bitwise2012\",\"basepath\":\"C:/Users/santlalg/git/Hydrograph/hydrograph.engine/hydrograph.engine.command-line\",\"uniqueJobID\":\"debug_job\",\"componentID\":\"input\",\"componentSocketID\":\"out0\",\"isRemote\":false}}"; String json = "{\"condition\":\"(f1 LIKE 'should')\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Float\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Double\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":" + FILE_SIZE_TO_READ + ",\"jobDetails\":{\"host\":\"" + HOST_NAME + "\",\"port\":\"" + PORT + "\",\"username\":\"" + USER_ID + "\",\"password\":\"" + PASSWORD + "\",\"basepath\":\"" + BASE_PATH + "\",\"uniqueJobID\":\"" + JOB_ID + "\",\"componentID\":\"" + COMPONENT_ID + "\",\"componentSocketID\":\"" + SOCKET_ID + "\",\"isRemote\":false}}"; PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/filter"); postMethod.addParameter("request_parameters", json); int response = httpClient.executeMethod(postMethod); InputStream inputStream = postMethod.getResponseBodyAsStream(); byte[] buffer = new byte[1024 * 1024 * 5]; String path = null;//from w w w .j ava 2 s . c om int length; while ((length = inputStream.read(buffer)) > 0) { path = new String(buffer); } System.out.println("response of service: " + path); }