List of usage examples for org.springframework.http HttpMethod POST
HttpMethod POST
To view the source code for org.springframework.http HttpMethod POST.
Click Source Link
From source file:com.marklogic.mgmt.admin.AdminManager.java
/** * Set whether SSL FIPS is enabled on the cluster or not by running against /v1/eval on the given appServicesPort. *//*from ww w.j a v a 2 s . c om*/ public void setSslFipsEnabled(final boolean enabled, final int appServicesPort) { final String xquery = "import module namespace admin = 'http://marklogic.com/xdmp/admin' at '/MarkLogic/admin.xqy'; " + "admin:save-configuration(admin:cluster-set-ssl-fips-enabled(admin:get-configuration(), " + enabled + "()))"; invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { RestTemplate rt = RestTemplateUtil.newRestTemplate(adminConfig.getHost(), appServicesPort, adminConfig.getUsername(), adminConfig.getPassword()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("xquery", xquery); HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>( map, headers); String url = format("http://%s:%d/v1/eval", adminConfig.getHost(), appServicesPort); if (logger.isInfoEnabled()) { logger.info("Setting SSL FIPS enabled: " + enabled); } rt.exchange(url, HttpMethod.POST, entity, String.class); if (logger.isInfoEnabled()) { logger.info("Finished setting SSL FIPS enabled: " + enabled); } return true; } }); }
From source file:org.apigw.authserver.ServerRunning.java
@SuppressWarnings("rawtypes") public ResponseEntity<Map> postForMap(String path, HttpHeaders headers, MultiValueMap<String, String> formData) { if (headers.getContentType() == null) { headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); }/*from ww w . j a va 2 s . co m*/ return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), Map.class); }
From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java
@Test public void testFormEncodedAutologinRequest() throws Exception { HttpHeaders headers = getAppBasicAuthHttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>(); requestBody.add("username", testAccounts.getUserName()); requestBody.add("password", testAccounts.getPassword()); ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class); String autologinCode = (String) autologinResponseEntity.getBody().get("code"); assertEquals(6, autologinCode.length()); }
From source file:com.appglu.impl.SyncTemplateTest.java
@Test public void changesForTablesUsingCallback_EmptyChanges() { mockServer.expect(requestTo("http://localhost/appglu/v1/sync/changes")).andExpect(method(HttpMethod.POST)) .andExpect(header("Content-Type", jsonMediaType.toString())) .andExpect(content().string(compactedJson("data/sync_changes_for_tables_request"))) .andRespond(withStatus(HttpStatus.OK).body(compactedJson("data/sync_parser_empty_changes")) .headers(responseHeaders)); MemoryTableChangesCallback callback = new MemoryTableChangesCallback(); TableVersion loggedTable = new TableVersion("logged_table"); TableVersion otherTable = new TableVersion("other_table", 1); this.syncOperations.changesForTables(callback, loggedTable, otherTable); this.assertChanges(callback.getTableChanges(), false, true); mockServer.verify();/* w w w. ja va 2 s. c om*/ }
From source file:com.jvoid.core.controller.HomeController.java
@RequestMapping("/login-tester") public @ResponseBody String jvoidLoginTester(@RequestParam("params") String jsonParams) { System.out.println("login-tester: jsonParams=>" + jsonParams); JSONObject jsonObj = null;/*from ww w . j av a2 s. c om*/ try { jsonObj = new JSONObject(jsonParams); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("Login-tester:jsonObj=>" + jsonObj); RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:9080/jvoidcore/login") .queryParam("params", jsonObj); HttpEntity<?> entity = new HttpEntity<>(headers); HttpEntity<String> returnString = restTemplate.exchange(builder.build().toUri(), HttpMethod.POST, entity, String.class); System.out.println("returnString=>" + returnString); JSONObject returnJsonObj = null; try { returnJsonObj = new JSONObject(); returnJsonObj.put("result", returnString); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return returnJsonObj.toString(); }
From source file:access.deploy.geoserver.PiazzaEnvironment.java
/** * Creates the Piazza workspace// w ww .ja va2 s . c o m */ private void createWorkspace() { // POST the Workspace authHeaders.setContentType(MediaType.APPLICATION_XML); String body = "<workspace><name>piazza</name></workspace>"; HttpEntity<String> request = new HttpEntity<>(body, authHeaders.get()); String uri = String.format("%s/rest/workspaces", accessUtilities.getGeoServerBaseUrl()); try { pzLogger.log(String.format("Creating Piazza Workspace to %s", uri), Severity.INFORMATIONAL, new AuditElement(ACCESS, "tryCreateGeoServerWorkspace", uri)); restTemplate.exchange(uri, HttpMethod.POST, request, String.class); try { // Hack/Workaround: With certain versions of GeoServer, The workspace is not entirely created with this // POST request. // In order to properly have layers in this workspace succeed, we must first modify the workspace. // Perform // a PUT request that does nothing - but internally in GeoServer this fixes some configuration bug where // the // workspace would otherwise not perform properly. String updateWorkspaceUri = String.format("%s/rest/workspaces/piazza.xml", accessUtilities.getGeoServerBaseUrl()); restTemplate.exchange(updateWorkspaceUri, HttpMethod.PUT, request, String.class); } catch (HttpClientErrorException | HttpServerErrorException exception) { String error = String.format( "Failed to execute a PUT request on the newly-created workspace: %s. This may indicate the workspace may not be fully configured for use.", exception.getResponseBodyAsString()); LOGGER.info(error, exception); pzLogger.log(error, Severity.WARNING); } } catch (HttpClientErrorException | HttpServerErrorException exception) { String error = String.format("HTTP Error occurred while trying to create Piazza Workspace: %s", exception.getResponseBodyAsString()); LOGGER.info(error, exception); pzLogger.log(error, Severity.ERROR); determineExit(); } catch (Exception exception) { String error = String.format("Unexpected Error occurred while trying to create Piazza Workspace: %s", exception.getMessage()); LOGGER.error(error, exception); pzLogger.log(error, Severity.ERROR); determineExit(); } }
From source file:de.zib.vold.client.VolDClient.java
/** * Refresh a set of keys.//from w w w . ja v a2s . c o m * * @param source The source of the keys. * @param set The set keys to refresh. * @param timeStamp The timeStamp of this operation */ public Map<String, String> refresh(String source, Set<Key> set, final long timeStamp) { // guard { log.trace("Refresh: " + set.toString()); checkState(); if (null == set) { throw new IllegalArgumentException("null is no valid argument!"); } } // build greatest common scope String commonscope; { List<String> scopes = new ArrayList<String>(set.size()); for (Key k : set) { scopes.add(k.get_scope()); } commonscope = getGreatestCommonPrefix(scopes); } // build request body Set<Key> keys = new HashSet<Key>(); { for (Key entry : set) { // remove common prefix from scope final String scope = entry.get_scope().substring(commonscope.length()); final String type = entry.get_type(); final String keyname = entry.get_keyname(); keys.add(new Key(scope, type, keyname)); } } // build variable map String url; { url = buildURL(commonscope, keys); log.debug("REFRESH URL: " + url); } // get response from Server ResponseEntity<Map> responseEntity; { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("TIMESTAMP", String.valueOf(timeStamp)); HttpEntity<Map<String, String>> requestEntity = new HttpEntity<Map<String, String>>(null, requestHeaders); responseEntity = rest.exchange(url, HttpMethod.POST, requestEntity, Map.class); //Object obj = rest.postForEntity( url, null, HashMap.class ); } return responseEntity.getBody(); }
From source file:fragment.web.BillingControllerTest.java
@Test public void testRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = this.getServletInstance(); Class<?> controllerClass = controller.getClass(); Method expected = locateMethod(controllerClass, "showSubscriptions", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, Long.class, Long.class, ModelMap.class, HttpServletRequest.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/billing/subscriptions")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showUtilityCharges", new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, Long.class, Long.class, ModelMap.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/billing/utility_charges")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showSubscriptionDetails", new Class[] { String.class, String.class, ModelMap.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/billing/subscriptions/showDetails")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "showUtilityChargeDetails", new Class[] { String.class, String.class, ModelMap.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/billing/utility_charges/showDetails")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "viewInitialDeposit", new Class[] { String.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/billing/viewInitialDeposit")); Assert.assertEquals(expected, handler); }
From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.implicit.Oauth2ImplicitFlowPredefinedTests.java
@Test public void obtainTokenFromOuth2LoginEndpoint() throws Exception { UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(authServerBaseUrl + oauth2AuthorizeEndpointPath); builder.queryParam("username", getUsername()); builder.queryParam("password", getPassword()); builder.queryParam("client_id", getClientId()); builder.queryParam("response_type", "token"); builder.queryParam("redirect_uri", "http://anywhere"); HttpEntity<String> entity = new HttpEntity<>(""); ResponseEntity<String> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, String.class); // This means the user was correctly authenticated, then a redirection was performed to /oauth/authorize to obtain the token. // Then the token was sucessfully obtained (authenticating the client properly) and a last redirection was performed to the // redirect_uri with the token after # assertEquals(HttpStatus.FOUND, result2.getStatusCode()); // Obtain the token from redirection URL after # URI location = result2.getHeaders().getLocation(); accessToken = extractToken(location.getFragment().toString()); assertNotNull(accessToken);/*from w w w .j a v a2 s. co m*/ if (!isJwtTokenStore) { // Temporarily we can't not apply the default token enhacer adding the authorities if we use a JwtTokenStore // TODO: Put again the login endpoint separated for CSRF and return the authorities there // Obtain the user credentials from redirection URL after # String extractUserAuthorities = extractUserAuthorities(location.getFragment().toString()); assertNotNull(extractUserAuthorities); } }
From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java
@Override public Boolean verifyEmail(VerifyEmailDTO emailDTO) throws ResourceNotFoundException { HttpEntity<VerifyEmailDTO> entity = new HttpEntity<VerifyEmailDTO>(emailDTO); ResponseEntity<Boolean> verificationStatus = restTemplate.exchange( env.getProperty("rest.host") + "/customer/quickregister/verifyEmailHash", HttpMethod.POST, entity, Boolean.class); if (verificationStatus.getStatusCode() == HttpStatus.OK) return verificationStatus.getBody(); else/* w w w . jav a2s .c om*/ throw new ResourceNotFoundException(); }