List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public String calculateKPI(String modelSetId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/dashboardkpi/%s/calculatekpi", DefaultRestResource.REST_URI, modelSetId); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("modelsetid", modelSetId); getMethod.setQueryString(queryString); try {/*www. j ava 2 s .c o m*/ httpClient.executeMethod(getMethod); String url = getMethod.getResponseBodyAsString(); return url; } catch (IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } }
From source file:com.rallydev.integration.build.rest.RallyRestService.java
protected String queryForArtifact(String object, String queryStr, String workspaceRef, String fetch) { NameValuePair queryParam, fetchParam, wsParam; NameValuePair[] pairs;/*from w w w. ja v a 2 s. co m*/ String reqUrl = getUrl() + "/" + object; GetMethod get = new GetMethod(reqUrl); queryParam = new NameValuePair("query", queryStr); wsParam = new NameValuePair("workspace", workspaceRef); fetchParam = new NameValuePair("fetch", fetch); pairs = new NameValuePair[] { queryParam, wsParam, fetchParam }; get.setQueryString(pairs); try { String response = doGet(new HttpClient(), get); return response; } catch (IOException ex) { logMessage("IOException querying for artifact: " + object + ", with query " + queryStr + ", in workspace " + workspaceRef); logMessage("Exception message was" + ex.getMessage()); return null; } }
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
private ContextResult processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context, String serverId) { ContextResult response = new ContextResult(); // /*from w w w. ja va2s . c o m*/ if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg(",??serverId"); return response; } if (log.isDebugEnabled()) log.debug("processPulishAfterModifiedByDefinedServerId(" + dataId + "," + groupName + "," + context + "," + serverId + ")?"); // ?dataId,groupName? ContextResult result = null; result = queryByDataIdAndGroupName(dataId, groupName, serverId); if (null == result || !result.isSuccess()) { response.setSuccess(false); response.setStatusMsg("????!"); log.warn("????! dataId=" + dataId + ",group=" + groupName + ",serverId=" + serverId); return response; } // ? else { String postUrl = "/diamond-server/admin.do?method=updateConfig"; PostMethod post = new PostMethod(postUrl); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { NameValuePair dataId_value = new NameValuePair("dataId", dataId); NameValuePair group_value = new NameValuePair("group", groupName); NameValuePair content_value = new NameValuePair("content", context); // ? post.setRequestBody(new NameValuePair[] { dataId_value, group_value, content_value }); // ? ConfigInfo configInfo = new ConfigInfo(); configInfo.setDataId(dataId); configInfo.setGroup(groupName); configInfo.setContent(context); if (log.isDebugEnabled()) log.debug("?ConfigInfo: " + configInfo); // ?? response.setConfigInfo(configInfo); // http?? int status = client.executeMethod(post); response.setReceiveResult(post.getResponseBodyAsString()); response.setStatusCode(status); log.info("??" + status + ",?" + post.getResponseBodyAsString()); if (status == HttpStatus.SC_OK) { response.setSuccess(true); response.setStatusMsg("???"); log.info("???"); } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg( "??:" + require_timeout + ""); log.error("??:" + require_timeout + ", dataId=" + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId); } else { response.setSuccess(false); response.setStatusMsg( "??,ContextResultgetReceiveResult()"); log.error("??:" + response.getReceiveResult() + ",dataId=" + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("??HttpException" + e.getMessage()); log.error( "?processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)?HttpExceptiondataId=" + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId, e); return response; } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("??IOException" + e.getMessage()); log.error( "?processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context,String serverId)?IOExceptiondataId=" + dataId + ",group=" + groupName + ",content=" + context + ",serverId=" + serverId, e); return response; } finally { // ? post.releaseConnection(); } return response; } }
From source file:eu.learnpad.core.impl.or.XwikiBridgeInterfaceRestResource.java
@Override public KBProcessingStatus getHandlingProcessStatus(String kbProcessProcessId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/or/bridge/kb/getstatus", DefaultRestResource.REST_URI); GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader("Accept", "application/xml"); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("kbprocessprocessid", kbProcessProcessId); getMethod.setQueryString(queryString); KBProcessingStatus processingStatus = null; try {//ww w . j a va 2 s .c o m httpClient.executeMethod(getMethod); InputStream responseStream = getMethod.getResponseBodyAsStream(); if (responseStream != null) { JAXBContext jc = JAXBContext.newInstance(KBProcessingStatus.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); processingStatus = (KBProcessingStatus) unmarshaller.unmarshal(responseStream); } } catch (JAXBException | IOException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause()); } return processingStatus; }
From source file:edu.ku.brc.specify.config.init.RegisterSpecify.java
/** * Creates an array of POST method parameters to send with the version checking / usage tracking connection. * //from www.j a va2 s . co m * @param sendUsageStats if true, the POST parameters include usage stats * @return an array of POST parameters */ private NameValuePair[] createPostParameters(final RegisterType regType, final boolean isAnonymous, final boolean isForISANumber) { Vector<NameValuePair> postParams = new Vector<NameValuePair>(); // get the install ID String installID = UsageTracker.getInstallId(); postParams.add(new NameValuePair("id", installID)); //$NON-NLS-1$ // get the OS name and version postParams.add(new NameValuePair("reg_type", regType.toString()));//$NON-NLS-1$ postParams.add(new NameValuePair("os_name", System.getProperty("os.name"))); //$NON-NLS-1$ $NON-NLS-2$ postParams.add(new NameValuePair("os_version", System.getProperty("os.version"))); //$NON-NLS-1$ $NON-NLS-2$ postParams.add(new NameValuePair("java_version", System.getProperty("java.version"))); //$NON-NLS-1$ $NON-NLS-2$ postParams.add(new NameValuePair("java_vendor", System.getProperty("java.vendor"))); //$NON-NLS-1$ $NON-NLS-2$ postParams.add(new NameValuePair("is_anonymous", Boolean.toString(isAnonymous))); //$NON-NLS-1$ postParams.add(new NameValuePair("is_isa_anonymous", Boolean.toString(isAnonymous))); //$NON-NLS-1$ //postParams.add(new NameValuePair("user_name", System.getProperty("user.name"))); //$NON-NLS-1$ AppContextMgr acMgr = AppContextMgr.getInstance(); Institution inst = acMgr.getClassObject(Institution.class); Division division = acMgr.getClassObject(Division.class); Discipline discipline = acMgr.getClassObject(Discipline.class); Collection collection = acMgr.getClassObject(Collection.class); if (isForISANumber) { postParams.add(new NameValuePair("reg_isa", "true")); //$NON-NLS-1$ $NON-NLS-2$ postParams.add(new NameValuePair("reg_number", collection.getRegNumber())); //$NON-NLS-1$ } switch (regType) { case Institution: if (!isAnonymous) { postParams.add(new NameValuePair("Institution_name", fixParam(inst.getName()))); //$NON-NLS-1$ } break; case Division: postParams.add(new NameValuePair("Institution_number", fixParam(inst.getRegNumber()))); //$NON-NLS-1$ if (!isAnonymous) { postParams.add(new NameValuePair("Division_name", fixParam(division.getName()))); //$NON-NLS-1$ } break; case Discipline: postParams.add(new NameValuePair("Institution_number", fixParam(inst.getRegNumber()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Division_number", fixParam(division.getRegNumber()))); //$NON-NLS-1$ if (!isAnonymous) { postParams.add(new NameValuePair("Discipline_type", fixParam(discipline.getType()))); //$NON-NLS-1$ } break; case Collection: postParams.add(new NameValuePair("Institution_number", fixParam(inst.getRegNumber()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Division_number", fixParam(division.getRegNumber()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Discipline_number", fixParam(discipline.getRegNumber()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Collection_number", fixParam(collection.getRegNumber()))); //$NON-NLS-1$ if (!isAnonymous) { postParams.add(new NameValuePair("Discipline_type", fixParam(discipline.getType()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Collection_name", fixParam(collection.getCollectionName()))); //$NON-NLS-1$ postParams.add(new NameValuePair("ISA_Number", fixParam(collection.getIsaNumber()))); //$NON-NLS-1$ } break; } // switch if (!isAnonymous) { SpecifyUser user = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); //postParams.add(new NameValuePair("User_name", fixParam(user.getName()))); //$NON-NLS-1$ postParams.add(new NameValuePair("User_email", fixParam(user.getEmail()))); //$NON-NLS-1$ Address addr = inst.getAddress(); if (addr != null) { postParams.add(new NameValuePair("Address", fixParam(addr.getIdentityTitle()))); //$NON-NLS-1$ postParams.add(new NameValuePair("Phone", fixParam(addr.getPhone1()))); //$NON-NLS-1$ } } // Create an array from the params NameValuePair[] paramArray = new NameValuePair[postParams.size()]; for (int i = 0; i < paramArray.length; ++i) { paramArray[i] = postParams.get(i); } return paramArray; }
From source file:edu.ku.brc.util.WebStoreAttachmentMgr.java
@Override public String getMetaDataAsJSON(final int attachmentID) { String result = null;/* w ww. jav a2s . c om*/ String fileName = BasicSQLUtils.querySingleObj(ATTACHMENT_URL + attachmentID); if (StringUtils.isNotEmpty(fileName) && StringUtils.isNotEmpty(fileGetMetaDataURLStr)) { GetMethod method = new GetMethod(fileGetMetaDataURLStr); fillValuesArray(); method.setQueryString(new NameValuePair[] { new NameValuePair("dt", "json"), new NameValuePair("filename", fileName), new NameValuePair("token", generateToken(fileName)), new NameValuePair("coll", values[0]), new NameValuePair("disp", values[1]), new NameValuePair("div", values[2]), new NameValuePair("inst", values[3]) }); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); try { int status = client.executeMethod(method); updateServerTimeDelta(method); if (status == HttpStatus.SC_OK) { result = method.getResponseBodyAsString(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { method.releaseConnection(); } } return result; }
From source file:com.zenkey.net.prowser.Tab.java
/************************************************************************** * Adds form data to a POST method object. * /*from w w w.ja v a 2s. c om*/ * @param request The request object. * @param postMethod The POST method object. */ private static void addPostParameters(Request request, PostMethod postMethod) { // Convert the request's parameter map to an array of name-value pairs Map<String, String[]> parameterMap = request.getParameterMap(); ArrayList<NameValuePair> parameterList = new ArrayList<NameValuePair>(); for (String name : parameterMap.keySet()) { String[] values = request.getParameterValues(name); for (String value : values) { parameterList.add(new NameValuePair(name, value)); } } NameValuePair[] parameterPairs = parameterList.toArray(new NameValuePair[parameterList.size()]); // Add the parameters to the POST method postMethod.addParameters(parameterPairs); }
From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java
@SuppressWarnings("unchecked") protected <T> T executeRetrieveObject(final Type returnObjectType, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException { checkInvariants();/*from w ww .j av a 2s . c om*/ GetMethod gm = (GetMethod) createMethod("get", uri, _port); setHttpHeader(gm); if (parameters != null && !parameters.isEmpty()) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size()); for (Entry<String, String> e : parameters.entrySet()) { nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue())); } gm.setQueryString(nameValuePairs.toArray(new NameValuePair[0])); } executeMethod(gm); String hash = checkResponse(gm, "BigSwitch HTTP get failed: "); T returnValue; try { // CAUTIOUS: Safety margin of 2048 characters - extend if needed. returnValue = (T) gson.fromJson(gm.getResponseBodyAsString(2048), returnObjectType); } catch (IOException e) { S_LOGGER.error("IOException while retrieving response body", e); throw new BigSwitchBcfApiException(e); } finally { gm.releaseConnection(); } if (returnValue instanceof ControlClusterStatus) { if (HASH_CONFLICT.equals(hash)) { isMaster = true; ((ControlClusterStatus) returnValue).setTopologySyncRequested(true); } else if (!HASH_IGNORE.equals(hash) && !isMaster) { isMaster = true; ((ControlClusterStatus) returnValue).setTopologySyncRequested(true); } } return returnValue; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElementTest.java
/** * @throws Exception if the test fails/*from ww w.j a v a 2s . com*/ */ @Test public void inputNameChange() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function doTest(){\n" + " document.form1.textfield1.name = 'changed';\n" + " alert(document.form1.changed.name);\n" + "}\n" + "</script></head><body>\n" + "<p>hello world</p>\n" + "<form name='form1' method='post' onsubmit='doTest()'>\n" + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n" + " <input type='submit' name='button1' value='pushme' />\n" + "</form>\n" + "</body></html>"; final List<String> collectedAlerts = new ArrayList<String>(); final HtmlPage page = loadPage(getBrowserVersion(), html, collectedAlerts); final MockWebConnection connection = (MockWebConnection) page.getWebClient().getWebConnection(); final HtmlForm form = page.getFormByName("form1"); form.<HtmlInput>getInputByName("button1").click(); final String[] expectedAlerts = { "changed" }; assertEquals(expectedAlerts, collectedAlerts); final List<NameValuePair> expectedParameters = Arrays.asList(new NameValuePair[] { new NameValuePair("changed", "foo"), new NameValuePair("button1", "pushme") }); assertEquals(expectedParameters, connection.getLastParameters()); }
From source file:eu.learnpad.core.impl.cw.XwikiCoreFacadeRestResource.java
@Override public KBProcessingStatus getKPICalculationStatus(String kpiCalculationProcessId) throws LpRestException { HttpClient httpClient = this.getClient(); String uri = String.format("%s/learnpad/cw/corefacade/dashboardkpi/%s/status", DefaultRestResource.REST_URI, kpiCalculationProcessId);/*from w ww .j a v a 2s. c om*/ GetMethod getMethod = new GetMethod(uri); getMethod.addRequestHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("kpiCalculationProcessId", kpiCalculationProcessId); getMethod.setQueryString(queryString); KBProcessingStatus status = null; try { httpClient.executeMethod(getMethod); InputStream statusAsStream = getMethod.getResponseBodyAsStream(); JAXBContext jc = JAXBContext.newInstance(KBProcessingStatus.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); status = (KBProcessingStatus) unmarshaller.unmarshal(statusAsStream); } catch (IOException | JAXBException e) { throw new LpRestExceptionXWikiImpl(e.getMessage(), e); } return status; }