List of usage examples for org.apache.commons.httpclient.methods PostMethod setRequestBody
public void setRequestBody(NameValuePair[] paramArrayOfNameValuePair) throws IllegalArgumentException
From source file:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
@Override public BatchContextResult<ConfigInfoEx> batchAddOrUpdate(String serverId, String groupName, Map<String, String> dataId2ContentMap) { // // w ww .j a va 2 s .com BatchContextResult<ConfigInfoEx> response = new BatchContextResult<ConfigInfoEx>(); // map?null if (dataId2ContentMap == null) { log.error("dataId2ContentMap cannot be null, serverId=" + serverId + " ,group=" + groupName); response.setSuccess(false); response.setStatusMsg("dataId2ContentMap cannot be null"); return response; } // dataIdcontentmap???? StringBuilder allDataIdAndContentBuilder = new StringBuilder(); for (String dataId : dataId2ContentMap.keySet()) { String content = dataId2ContentMap.get(dataId); allDataIdAndContentBuilder.append(dataId + Constants.WORD_SEPARATOR + content) .append(Constants.LINE_SEPARATOR); } String allDataIdAndContent = allDataIdAndContentBuilder.toString(); // if (!login(serverId)) { response.setSuccess(false); response.setStatusMsg("login fail, serverId=" + serverId); return response; } // HTTP method PostMethod post = new PostMethod("/diamond-server/admin.do?method=batchAddOrUpdate"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); try { // ? NameValuePair dataId_value = new NameValuePair("allDataIdAndContent", allDataIdAndContent); NameValuePair group_value = new NameValuePair("group", groupName); post.setRequestBody(new NameValuePair[] { dataId_value, group_value }); // http?? int status = client.executeMethod(post); response.setStatusCode(status); String responseMsg = post.getResponseBodyAsString(); response.setResponseMsg(responseMsg); if (status == HttpStatus.SC_OK) { String json = null; try { json = responseMsg; // ???json, ??BatchContextResult List<ConfigInfoEx> configInfoExList = new LinkedList<ConfigInfoEx>(); Object resultObj = JSONUtils.deserializeObject(json, new TypeReference<List<ConfigInfoEx>>() { }); if (!(resultObj instanceof List<?>)) { throw new RuntimeException("batch write deserialize type error, not list, json=" + json); } List<ConfigInfoEx> resultList = (List<ConfigInfoEx>) resultObj; for (ConfigInfoEx configInfoEx : resultList) { configInfoExList.add(configInfoEx); } response.getResult().addAll(configInfoExList); // ????, ??? response.setStatusMsg("batch write success"); log.info("batch write success,serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json); } catch (Exception e) { response.setSuccess(false); response.setStatusMsg("batch write deserialize error"); log.error("batch write deserialize error, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName + ",json=" + json, e); } } else if (status == HttpStatus.SC_REQUEST_TIMEOUT) { response.setSuccess(false); response.setStatusMsg("batch write timeout, socket timeout(ms):" + require_timeout); log.error("batch write timeout, socket timeout(ms):" + require_timeout + ", serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } else { response.setSuccess(false); response.setStatusMsg("batch write fail, status:" + status); log.error("batch write fail, status:" + status + ", response:" + responseMsg + ",serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName); } } catch (HttpException e) { response.setSuccess(false); response.setStatusMsg("batch write http exception" + e.getMessage()); log.error("batch write http exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } catch (IOException e) { response.setSuccess(false); response.setStatusMsg("batch write io exception" + e.getMessage()); log.error("batch write io exception, serverId=" + serverId + ",allDataIdAndContent=" + allDataIdAndContent + ",group=" + groupName, e); } finally { // ? post.releaseConnection(); } return response; }
From source file:com.taobao.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
private ContextResult processPulishAfterModifiedByDefinedServerId(String dataId, String groupName, String context, String serverId) { ContextResult response = new ContextResult(); // /*from w w w . j a v a2 s. 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:cn.leancloud.diamond.sdkapi.impl.DiamondSDKManagerImpl.java
/** * httpclient?//from w w w. j a va2s . c om * * @return true:?,false: */ private boolean login(String serverId) { // serverId if (StringUtils.isEmpty(serverId) || StringUtils.isBlank(serverId)) return false; DiamondSDKConf defaultConf = diamondSDKConfMaps.get(serverId); log.info("[login] serverId:" + serverId + "," + defaultConf); if (null == defaultConf) return false; RandomDiamondUtils util = new RandomDiamondUtils(); // ??? util.init(defaultConf.getDiamondConfs()); if (defaultConf.getDiamondConfs().size() == 0) return false; boolean flag = false; log.info("[randomSequence] ?: " + util.getSequenceToString()); // ???diamondConf while (util.getRetry_times() < util.getMax_times()) { // ??diamondConf DiamondConf diamondConf = util.generatorOneDiamondConf(); log.info("" + util.getRetry_times() + "?:" + diamondConf); if (diamondConf == null) break; client.getHostConfiguration().setHost(diamondConf.getDiamondIp(), Integer.parseInt(diamondConf.getDiamondPort()), "http"); PostMethod post = new PostMethod("/diamond-server/login.do?method=login"); // post.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, require_timeout); // ??? NameValuePair username_value = new NameValuePair("username", diamondConf.getDiamondUsername()); NameValuePair password_value = new NameValuePair("password", diamondConf.getDiamondPassword()); // post.setRequestBody(new NameValuePair[] { username_value, password_value }); log.info("diamondIp: " + diamondConf.getDiamondIp() + ",diamondPort: " + diamondConf.getDiamondPort() + ",diamondUsername: " + diamondConf.getDiamondUsername() + ",diamondPassword: " + diamondConf.getDiamondPassword() + "diamondServerUrl: [" + diamondConf.getDiamondConUrl() + "]"); try { int state = client.executeMethod(post); log.info("??" + state); // ??200?,true if (state == HttpStatus.SC_OK) { log.info("" + util.getRetry_times() + "??"); flag = true; break; } } catch (HttpException e) { log.error("?HttpException", e); } catch (IOException e) { log.error("?IOException", e); } finally { post.releaseConnection(); } } if (flag == false) { log.error( "?login?diamondServer?????serverId=" + serverId); } return flag; }
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(); // /*w w w .java 2 s . com*/ 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:com.intranet.intr.sms.EmpControllerSms.java
@RequestMapping(value = "ESMS.htm", method = RequestMethod.POST) public String addEstudio_post(@ModelAttribute("mensaje") sms mensaje, BindingResult result, ModelMap map) { try {/*from ww w . j a va2 s .co m*/ map.addAttribute("msg", "success"); HttpClient client = new HttpClient(); client.setStrictMode(true); //Se fija el tiempo maximo de espera de la respuesta del servidor client.setTimeout(60000); //Se fija el tiempo maximo de espera para conectar con el servidor client.setConnectionTimeout(5000); PostMethod post = null; //Se fija la URL sobre la que enviar la peticion POST //Como ejemplo la peticion se enva a www.altiria.net/sustituirPOSTsms //Se debe reemplazar la cadena /sustituirPOSTsms por la parte correspondiente //de la URL suministrada por Altiria al dar de alta el servicio post = new PostMethod("http://www.altiria.net/api/http"); //Se fija la codificacion de caracteres en la cabecera de la peticion post.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); //Se crea la lista de parametros a enviar en la peticion POST NameValuePair[] parametersList = new NameValuePair[6]; //XX, YY y ZZ se corresponden con los valores de identificacion del //usuario en el sistema. parametersList[0] = new NameValuePair("cmd", "sendsms"); parametersList[1] = new NameValuePair("domainId", "comercial"); parametersList[2] = new NameValuePair("login", "jfruano"); parametersList[3] = new NameValuePair("passwd", "wrnkmekt"); parametersList[4] = new NameValuePair("dest", "34" + mensaje.getNum()); parametersList[5] = new NameValuePair("msg", "" + mensaje.getTexto()); //Se rellena el cuerpo de la peticion POST con los parametros post.setRequestBody(parametersList); int httpstatus = 0; String response = null; try { //Se enva la peticion httpstatus = client.executeMethod(post); //Se consigue la respuesta response = post.getResponseBodyAsString(); } catch (Exception e) { //Habra que prever la captura de excepciones } finally { //En cualquier caso se cierra la conexion post.releaseConnection(); } //Habra que prever posibles errores en la respuesta del servidor if (httpstatus != 200) { } else { //Se procesa la respuesta capturada en la cadena response } } catch (Exception ex) { ex.printStackTrace(); } return "redirect:ESMS.htm"; }
From source file:com.intranet.intr.sms.SupControllerSms.java
@RequestMapping(value = "SMS.htm", method = RequestMethod.POST) public String addEstudio_post(@ModelAttribute("mensaje") sms mensaje, BindingResult result, ModelMap map) { //String mensaje=""; try {/*from w ww. j av a 2 s .c om*/ map.addAttribute("msg", "success"); HttpClient client = new HttpClient(); client.setStrictMode(true); //Se fija el tiempo maximo de espera de la respuesta del servidor client.setTimeout(60000); //Se fija el tiempo maximo de espera para conectar con el servidor client.setConnectionTimeout(5000); PostMethod post = null; //Se fija la URL sobre la que enviar la peticion POST //Como ejemplo la peticion se enva a www.altiria.net/sustituirPOSTsms //Se debe reemplazar la cadena /sustituirPOSTsms por la parte correspondiente //de la URL suministrada por Altiria al dar de alta el servicio post = new PostMethod("http://www.altiria.net/api/http"); //Se fija la codificacion de caracteres en la cabecera de la peticion post.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); //Se crea la lista de parametros a enviar en la peticion POST NameValuePair[] parametersList = new NameValuePair[6]; //XX, YY y ZZ se corresponden con los valores de identificacion del //usuario en el sistema. parametersList[0] = new NameValuePair("cmd", "sendsms"); parametersList[1] = new NameValuePair("domainId", "comercial"); parametersList[2] = new NameValuePair("login", "jfruano"); parametersList[3] = new NameValuePair("passwd", "wrnkmekt"); parametersList[4] = new NameValuePair("dest", "34" + mensaje.getNum()); parametersList[5] = new NameValuePair("msg", "" + mensaje.getTexto()); //Se rellena el cuerpo de la peticion POST con los parametros post.setRequestBody(parametersList); int httpstatus = 0; String response = null; try { //Se enva la peticion httpstatus = client.executeMethod(post); //Se consigue la respuesta response = post.getResponseBodyAsString(); } catch (Exception e) { //Habra que prever la captura de excepciones } finally { //En cualquier caso se cierra la conexion post.releaseConnection(); } //Habra que prever posibles errores en la respuesta del servidor if (httpstatus != 200) { } else { //Se procesa la respuesta capturada en la cadena response } } catch (Exception ex) { ex.printStackTrace(); } return "redirect:SMS.htm"; }
From source file:com.chengfeng.ne.basicInterface.service.impl.BasicInterfaceServiceImpl.java
/** * ??/*ww w . j a v a 2 s . c om*/ */ @Override public String sendRequest(String data, String url) throws ServiceException { final List<NameValuePair> nameValueList = new ArrayList<NameValuePair>(); // ?? nameValueList.add(new NameValuePair("param", data)); HttpClientParams httpClientParams = new HttpClientParams(); httpClientParams.setConnectionManagerTimeout(1000); final HttpClient httpClient = new HttpClient(httpClientParams, new SimpleHttpConnectionManager(true)); final PostMethod postMethod = new PostMethod(url); postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); postMethod.setRequestBody(nameValueList.toArray(new NameValuePair[nameValueList.size()])); postMethod.addRequestHeader("Connection", "close"); String result = ""; try { try { httpClient.executeMethod(postMethod); result = postMethod.getResponseBodyAsString(); } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String str = result; log.info("" + str); return str; } finally { postMethod.releaseConnection(); } }
From source file:com.celamanzi.liferay.portlets.rails286.OnlineClient.java
/** * POST//from ww w. jav a 2 s. c om * * Posts the parametersBody * @throws RailsAppException */ protected byte[] post(NameValuePair[] parametersBody, Map<String, Object[]> files) throws HttpException, IOException, RailsAppException { // Response body from the web server byte[] responseBody = null; statusCode = -1; List<File> tempFiles = null; HttpClient client = preparedClient(); // Create a method instance. PostMethod method = new PostMethod(requestURL.toString()); HttpMethod _method = (HttpMethod) method; String action = "POST action request URL: " + requestURL.toString(); if (ajax) { log.debug("Ajax " + action); _method.setRequestHeader("X_REQUESTED_WITH", "XMLHttpRequest"); _method.setRequestHeader("ACCEPT", "text/javascript, text/html, application/xml, text/xml, */*"); _method.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8"); } else log.debug(action); // finalize method method = (PostMethod) prepareMethodHeaders(_method); if (files != null && files.size() > 0) { tempFiles = new ArrayList<File>(); createMultipartRequest(parametersBody, files, method, tempFiles); } else { // Array of parameters may not be null, so init empty NameValuePair[] if (parametersBody == null) { parametersBody = new NameValuePair[0]; } method.setRequestBody(parametersBody); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); } try { // Execute the method. statusCode = client.executeMethod(method); if ((statusCode == HttpStatus.SC_MOVED_TEMPORARILY) || (statusCode == HttpStatus.SC_MOVED_PERMANENTLY) || (statusCode == HttpStatus.SC_SEE_OTHER) || (statusCode == HttpStatus.SC_TEMPORARY_REDIRECT)) { // get Location String location = ((Header) method.getResponseHeader("Location")).getValue(); requestURL = new URL(location); log.debug("POST status code: " + method.getStatusLine()); log.debug("Redirect to location: " + location); // server may add another cookie before redirect.. cookies = client.getState().getCookies(); // Note that this GET overwrites the previous POST method, // so it should set statusCode and cookies correctly. responseBody = get(); } else { // the original POST method was OK, pass // No more redirects! Response should be 200 OK if (statusCode != HttpStatus.SC_OK) { String errorMessage = "Method failed: " + method.getStatusLine(); log.error(errorMessage); throw new RailsAppException(errorMessage, new String(method.getResponseBody())); } else { log.debug("POST status code: " + method.getStatusLine()); } // Read the response body. responseBody = method.getResponseBody(); // Keep the headers for future usage (render or resource phase) configureHeader(method.getResponseHeaders()); // Get session cookies cookies = client.getState().getCookies(); } } finally { // Release the connection method.releaseConnection(); // Delete temp files deleteFiles(tempFiles); } return responseBody; }
From source file:com.cerema.cloud2.operations.OAuth2GetAccessToken.java
@Override protected RemoteOperationResult run(OwnCloudClient client) { RemoteOperationResult result = null; PostMethod postMethod = null; try {// w ww .j a va2 s . com parseAuthorizationResponse(); if (mOAuth2ParsedAuthorizationResponse.keySet().contains(OAuth2Constants.KEY_ERROR)) { if (OAuth2Constants.VALUE_ERROR_ACCESS_DENIED .equals(mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_ERROR))) { result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR_ACCESS_DENIED); } else { result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR); } } if (result == null) { NameValuePair[] nameValuePairs = new NameValuePair[4]; nameValuePairs[0] = new NameValuePair(OAuth2Constants.KEY_GRANT_TYPE, mGrantType); nameValuePairs[1] = new NameValuePair(OAuth2Constants.KEY_CODE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_CODE)); nameValuePairs[2] = new NameValuePair(OAuth2Constants.KEY_REDIRECT_URI, mRedirectUri); nameValuePairs[3] = new NameValuePair(OAuth2Constants.KEY_CLIENT_ID, mClientId); //nameValuePairs[4] = new NameValuePair(OAuth2Constants.KEY_SCOPE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_SCOPE)); postMethod = new PostMethod(client.getWebdavUri().toString()); postMethod.setRequestBody(nameValuePairs); int status = client.executeMethod(postMethod); String response = postMethod.getResponseBodyAsString(); if (response != null && response.length() > 0) { JSONObject tokenJson = new JSONObject(response); parseAccessTokenResult(tokenJson); if (mResultTokenMap.get(OAuth2Constants.KEY_ERROR) != null || mResultTokenMap.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) { result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR); } else { result = new RemoteOperationResult(true, status, postMethod.getResponseHeaders()); ArrayList<Object> data = new ArrayList<Object>(); data.add(mResultTokenMap); result.setData(data); } } else { client.exhaustResponse(postMethod.getResponseBodyAsStream()); result = new RemoteOperationResult(false, status, postMethod.getResponseHeaders()); } } } catch (Exception e) { result = new RemoteOperationResult(e); } finally { if (postMethod != null) postMethod.releaseConnection(); // let the connection available for other methods if (result.isSuccess()) { Log_OC.i(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage()); } else if (result.getException() != null) { Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage(), result.getException()); } else if (result.getCode() == ResultCode.OAUTH2_ERROR) { Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL")); } else { Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage()); } } return result; }
From source file:com.sourcesense.confluence.servlets.CMISProxyServlet.java
/** * Sets up the given {@link PostMethod} to send the same standard POST * data as was sent in the given {@link HttpServletRequest} * * @param postMethodProxyRequest The {@link PostMethod} that we are * configuring to send a standard POST request * @param httpServletRequest The {@link HttpServletRequest} that contains * the POST data to be sent via the {@link PostMethod} *//*ww w .j a v a 2s .c o m*/ @SuppressWarnings({ "unchecked", "ToArrayCallWithZeroLengthArrayArgument" }) private void handleStandardPost(PostMethod postMethodProxyRequest, HttpServletRequest httpServletRequest) { // 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); } } // Set the proxy request POST data postMethodProxyRequest.setRequestBody(listNameValuePairs.toArray(new NameValuePair[] {})); }