List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
@Override public void updateSimulationScore(String modelSetId, String simulationSessionId, String processArtifactId, Long timestamp, String userId, SimulationScoresMap scoreMap) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/%s/simulationscore", DefaultRestResource.REST_URI, modelSetId);/*from w w w .j a v a 2 s .co m*/ PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML); String contentType = "application/xml"; NameValuePair[] queryString = new NameValuePair[4]; queryString[0] = new NameValuePair("simulationsessionid", simulationSessionId); queryString[1] = new NameValuePair("processartifactid", processArtifactId); queryString[2] = new NameValuePair("timestamp", timestamp.toString()); queryString[3] = new NameValuePair("userid", userId); postMethod.setQueryString(queryString); try { Writer scoreMapWriter = new StringWriter(); JAXBContext jc = JAXBContext.newInstance(SimulationScoresMap.class); jc.createMarshaller().marshal(scoreMap, scoreMapWriter); RequestEntity requestEntity = new StringRequestEntity(scoreMapWriter.toString(), contentType, "UTF-8"); postMethod.setRequestEntity(requestEntity); httpClient.executeMethod(postMethod); } catch (IOException | JAXBException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } }
From source file:com.funambol.json.dao.JsonDAOImpl.java
public JsonResponse getNewItemKeys(String token, long since, long until) throws HttpException, IOException { String request = Utility.getUrl(jsonServerUrl, resourceType, GET_NEW_ITEM_KEYS_URL); if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: start getNewItemKeys '" + since + "; '" + until + "'"); }// w w w.java2 s . c o m GetMethod get = new GetMethod(request); get.setRequestHeader(Utility.TOKEN_HEADER_NAME, token); NameValuePair[] httpParameters = { new NameValuePair(SINCE, Long.toString(since)), new NameValuePair(UNTIL, Long.toString(until)) }; get.setQueryString(httpParameters); int statusCode = 0; String responseBody = null; try { statusCode = httpClient.executeMethod(get); responseBody = get.getResponseBodyAsString(); } finally { get.releaseConnection(); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: getNewItemKeys " + responseBody); log.trace("JsonDAOImpl: finish getNewItemKeys"); } JsonResponse response = new JsonResponse(statusCode, responseBody); return response; }
From source file:com.delmar.station.service.impl.WFDetailServiceImpl.java
/** * POST// w ww.java 2 s . c o m * @param url * @param parms * @return * @throws java.io.UnsupportedEncodingException */ private static HttpMethod buildPostMethod(String url, Map<String, String> parms) throws UnsupportedEncodingException { //?? NameValuePair[] data = new NameValuePair[parms.keySet().size()]; Iterator<Entry<String, String>> it = parms.entrySet().iterator(); int i = 0; while (it.hasNext()) { Entry<String, String> entry = (Entry) it.next(); String key = entry.getKey(); String value = entry.getValue(); //System.out.println(key+":"+value); data[i] = new NameValuePair(key, value); i++; } PutMethod method = new PutMethod(url); method.setQueryString(data); //.setRequestBody(data); return method; }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public InputStream transform(ModelSetType type, InputStream model) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/transform", DefaultRestResource.REST_URI); PostMethod postMethod = new PostMethod(uri); postMethod.addRequestHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM); postMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type.toString()); postMethod.setQueryString(queryString); RequestEntity requestEntity = new InputStreamRequestEntity(model); postMethod.setRequestEntity(requestEntity); try {//from w w w.ja v a 2 s . co m httpClient.executeMethod(postMethod); return postMethod.getResponseBodyAsStream(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:cuanto.api.CuantoConnector.java
/** * Gets all TestOutcomes for the specified TestCase in the specified TestRun. In most normal Cuanto usages, a TestRun * will only have a single TestOutcome per TestCase. TestOutcomes will be in descending order by their finishedAt * values (if they have them) or dateCreated otherwise. * * @param testRun The TestRun to search. * @param testCase The TestCase for which to retrieve TestOutcomes. * @return A list of all the TestOutcomes for the specified TestCase and TestRun. *//* www .j a va 2s . co m*/ public List<TestOutcome> getTestCaseOutcomesForTestRun(TestCase testCase, TestRun testRun) { if (testRun.id == null) { throw new IllegalArgumentException( "The TestRun has no id. Query for the TestRun before getting it's TestOutcomes."); } if (testCase.id == null) { throw new IllegalArgumentException( "The TestCase has no id. Query for the TestCase before getting it's TestOutcomes."); } GetMethod get = (GetMethod) getHttpMethod(HTTP_GET, getCuantoUrl() + "/api/getTestCaseOutcomesForTestRun"); get.setQueryString(new NameValuePair[] { new NameValuePair("testRun", testRun.id.toString()), new NameValuePair("testCase", testCase.id.toString()) }); try { int httpStatus = getHttpClient().executeMethod(get); if (httpStatus == HttpStatus.SC_OK) { JSONObject jsonResponse = JSONObject.fromObject(getResponseBodyAsString(get)); JSONArray jsonOutcomes = jsonResponse.getJSONArray("testOutcomes"); List<TestOutcome> outcomesToReturn = new ArrayList<TestOutcome>(jsonOutcomes.size()); for (Object obj : jsonOutcomes) { JSONObject jsonOutcome = (JSONObject) obj; outcomesToReturn.add(TestOutcome.fromJSON(jsonOutcome)); } return outcomesToReturn; } else { throw new RuntimeException("Getting the TestOutcome failed with HTTP status code " + httpStatus + ":\n" + getResponseBodyAsString(get)); } } catch (IOException e) { throw new RuntimeException(e); } catch (ParseException e) { throw new RuntimeException("Unable to parse JSON response: " + e.getMessage(), e); } }
From source file:io.fabric8.gateway.servlet.ProxyServlet.java
/** * Sets up the given {@link PostMethod} to send the same standard * data as was sent in the given {@link javax.servlet.http.HttpServletRequest} * * @param entityEnclosingMethod The {@link EntityEnclosingMethod} that we are * configuring to send a standard request * @param httpServletRequest The {@link javax.servlet.http.HttpServletRequest} that contains * the data to be sent via the {@link EntityEnclosingMethod} *///from w w w.j a v a 2s . c o m @SuppressWarnings("unchecked") private void handleEntity(EntityEnclosingMethod entityEnclosingMethod, HttpServletRequest httpServletRequest) throws IOException { // Get the client POST data as a Map Map<String, String[]> mapPostParameters = (Map<String, String[]>) httpServletRequest.getParameterMap(); // Create a List to hold the NameValuePairs to be passed to the PostMethod List<NameValuePair> listNameValuePairs = new ArrayList<NameValuePair>(); // Iterate the parameter names for (String stringParameterName : mapPostParameters.keySet()) { // Iterate the values for each parameter name String[] stringArrayParameterValues = mapPostParameters.get(stringParameterName); for (String stringParamterValue : stringArrayParameterValues) { // Create a NameValuePair and store in list NameValuePair nameValuePair = new NameValuePair(stringParameterName, stringParamterValue); listNameValuePairs.add(nameValuePair); } } RequestEntity entity = null; String contentType = httpServletRequest.getContentType(); if (contentType != null) { contentType = contentType.toLowerCase(); if (contentType.contains("json") || contentType.contains("xml") || contentType.contains("application") || contentType.contains("text")) { String body = IOHelpers.readFully(httpServletRequest.getReader()); entity = new StringRequestEntity(body, contentType, httpServletRequest.getCharacterEncoding()); entityEnclosingMethod.setRequestEntity(entity); } } NameValuePair[] parameters = listNameValuePairs.toArray(new NameValuePair[] {}); if (entity != null) { // TODO add as URL parameters? //postMethodProxyRequest.addParameters(parameters); } else { // Set the proxy request POST data if (entityEnclosingMethod instanceof PostMethod) { ((PostMethod) entityEnclosingMethod).setRequestBody(parameters); } } }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public String startAnalysis(String id, String language, List<String> options, InputStream body) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/analyze", DefaultRestResource.REST_URI); PostMethod postMethod = new PostMethod(uri); NameValuePair[] queryString = new NameValuePair[2 + options.size()]; queryString[0] = new NameValuePair("id", id); queryString[1] = new NameValuePair("language", language); int count = 2; for (String option : options) { queryString[count] = new NameValuePair("option", option); count++;/*from w w w. j av a 2 s . c o m*/ } postMethod.setQueryString(queryString); RequestEntity requestEntity = new InputStreamRequestEntity(body); postMethod.setRequestEntity(requestEntity); try { httpClient.executeMethod(postMethod); return postMethod.getResponseBodyAsString(); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:com.funambol.json.dao.JsonDAOImpl.java
public JsonResponse getUpdatedItemKeys(String token, long since, long until) throws HttpException, IOException { String request = Utility.getUrl(jsonServerUrl, resourceType, GET_UPDATED_ITEM_KEYS_URL); if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: start getUpdatedItemKeys '" + since + "; '" + until + "'"); }/* ww w. ja va2 s .c om*/ GetMethod get = new GetMethod(request); get.setRequestHeader(Utility.TOKEN_HEADER_NAME, token); NameValuePair[] httpParameters = { new NameValuePair(SINCE, Long.toString(since)), new NameValuePair(UNTIL, Long.toString(until)) }; get.setQueryString(httpParameters); int statusCode = 0; String responseBody = null; try { statusCode = httpClient.executeMethod(get); responseBody = get.getResponseBodyAsString(); } finally { get.releaseConnection(); } if (log.isTraceEnabled()) { log.trace("JsonDAOImpl: getUpdatedItemKeys " + responseBody); log.trace("JsonDAOImpl: finish getUpdatedItemKeys"); } JsonResponse response = new JsonResponse(statusCode, responseBody); return response; }
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
@Override public void kpisImported(String modelSetId, String kpisId, KPIsFormat type) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/kpisimported/%s/%s", DefaultRestResource.REST_URI, modelSetId, kpisId);//from w w w . ja v a2 s.c om PutMethod putMethod = new PutMethod(uri); putMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type.toString()); putMethod.setQueryString(queryString); try { httpClient.executeMethod(putMethod); } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:edu.ku.brc.specify.tasks.StatsTrackerTask.java
/** * @throws Exception//from w w w. j a va 2 s.c o m */ private void sendActivityStats(final boolean isLoggingIn) throws Exception { String url = getResourceString("StatsTrackerTask.ACTIVITYSURL"); //$NON-NLS-1$ if (StringUtils.isNotEmpty(url)) { Vector<NameValuePair> stats = createPostParameters(false); appendBasicCollStats(stats); stats.add(new NameValuePair("Type", isLoggingIn ? "0" : "1")); //$NON-NLS-1$ sendStats(url, stats, getClass().getName()); } }