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:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsServiceEnabledPredefinedTests.java
@Test public void simpleAuthenticationRemoteLogServiceEnabledTest() throws Exception { TestLoginInfo loginInfo = simpleLogin(); RemoteLogRequestVO logRequestVO = new RemoteLogRequestVO(); logRequestVO.setMessage("Test mesage!"); logRequestVO.setLogLevel("DEBUG"); // This test requires the test CSRF Token. This implies passing JSESSIONID and CSRF Token HttpHeaders headers = new HttpHeaders(); headers.set("Cookie", loginInfo.getJsessionid()); HttpEntity<RemoteLogRequestVO> entity = new HttpEntity<RemoteLogRequestVO>(logRequestVO, headers); UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl("http://localhost:" + port + baseApiPath + remoteLogEndpointPath) .queryParam(DEFAULT_CSRF_PARAMETER_NAME, loginInfo.getXsrfToken()); ResponseEntity<String> responseEntity = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, String.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); }
From source file:jp.go.aist.six.util.core.web.spring.SpringHttpClientImpl.java
/** * HTTP POST: Reads the contents from the specified reader and sends them to the URL. * * @return/*from w w w. ja v a 2 s .co m*/ * the location, as an URI, where the resource is created. * @throws HttpException * when an exceptional condition occurred during the HTTP method execution. */ public String postByRead(final String url, final Reader input, final String media_type) { String location = _execute(url, HttpMethod.POST, new ReaderRequestCallback(input, MediaType.parseMediaType(media_type)), new LocationHeaderResponseExtractor()); return location; }
From source file:com.javafxpert.wikibrowser.WikiVisGraphController.java
/** * Calls the Neo4j Transactional Cypher service and returns an object that holds results * @param neoCypherUrl//from w ww . j a va 2 s . c o m * @param postString * @return */ private VisGraphResponseNear queryProcessSearchResponse(String neoCypherUrl, String postString) { log.info("neoCypherUrl: " + neoCypherUrl); log.info("postString: " + postString); RestTemplate restTemplate = new RestTemplate(); HttpHeaders httpHeaders = WikiBrowserUtils.createHeaders(wikiBrowserProperties.getCypherUsername(), wikiBrowserProperties.getCypherPassword()); httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity request = new HttpEntity(postString, httpHeaders); GraphResponseFar graphResponseFar = null; VisGraphResponseNear visGraphResponseNear = new VisGraphResponseNear(); try { ResponseEntity<GraphResponseFar> result = restTemplate.exchange(neoCypherUrl, HttpMethod.POST, request, GraphResponseFar.class); graphResponseFar = result.getBody(); log.info("graphResponseFar: " + graphResponseFar); // Populate VisGraphResponseNear instance from GraphResponseFar instance HashMap<String, VisGraphNodeNear> visGraphNodeNearMap = new HashMap<>(); HashMap<String, VisGraphEdgeNear> visGraphEdgeNearMap = new HashMap<>(); List<ResultFar> resultFarList = graphResponseFar.getResultFarList(); if (resultFarList.size() > 0) { List<DataFar> dataFarList = resultFarList.get(0).getDataFarList(); Iterator<DataFar> dataFarIterator = dataFarList.iterator(); while (dataFarIterator.hasNext()) { GraphFar graphFar = dataFarIterator.next().getGraphFar(); List<GraphNodeFar> graphNodeFarList = graphFar.getGraphNodeFarList(); Iterator<GraphNodeFar> graphNodeFarIterator = graphNodeFarList.iterator(); while (graphNodeFarIterator.hasNext()) { GraphNodeFar graphNodeFar = graphNodeFarIterator.next(); VisGraphNodeNear visGraphNodeNear = new VisGraphNodeNear(); //visGraphNodeNear.setDbId(graphNodeFar.getId()); // Database ID for this node visGraphNodeNear.setDbId(graphNodeFar.getGraphNodePropsFar().getItemId().substring(1)); visGraphNodeNear.setTitle(graphNodeFar.getGraphNodePropsFar().getTitle()); visGraphNodeNear.setLabelsList(graphNodeFar.getLabelsList()); visGraphNodeNear.setItemId(graphNodeFar.getGraphNodePropsFar().getItemId()); String itemId = visGraphNodeNear.getItemId(); String articleTitle = visGraphNodeNear.getTitle(); // Retrieve the article's image String thumbnailUrl = null; String articleLang = "en"; // TODO: Add a language property to Item nodes stored in Neo4j that aren't currently in English, // and use that property to mutate articleTitleLang // First, try to get the thumbnail by ID from cache thumbnailUrl = ThumbnailCache.getThumbnailUrlById(itemId, articleLang); if (thumbnailUrl == null) { // If not available, try to get thumbnail by ID from ThumbnailService try { String thumbnailByIdUrl = this.wikiBrowserProperties .getThumbnailByIdServiceUrl(itemId, articleLang); thumbnailUrl = new RestTemplate().getForObject(thumbnailByIdUrl, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { // If thumbnail isn't available by ID, try to get thumbnail by article title try { String thumbnailByTitleUrl = this.wikiBrowserProperties .getThumbnailByTitleServiceUrl(articleTitle, articleLang); thumbnailUrl = new RestTemplate().getForObject(thumbnailByTitleUrl, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { visGraphNodeNear.setImageUrl(""); } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?title=" + articleTitle + " : " + e); } } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?id=" + itemId + " : " + e); } } else { visGraphNodeNear.setImageUrl(thumbnailUrl); } /* // Check cache for thumbnail thumbnailUrl = ThumbnailCache.getThumbnailUrlById(itemId, articleLang); if (thumbnailUrl != null && thumbnailUrl.length() > 0) { // Thumbnail image found in cache by ID, which is the preferred location visGraphNodeNear.setImageUrl(thumbnailUrl); } else { // Thumbnail image not found in cache by ID, so look with Wikimedia API by article title log.info("Thumbnail not found in cache for itemId: " + itemId + ", lang: " + articleLang + " so looking with Wikimedia API by article title"); try { String url = this.wikiBrowserProperties.getThumbnailByTitleServiceUrl(articleTitle, articleLang); thumbnailUrl = new RestTemplate().getForObject(url, String.class); if (thumbnailUrl != null && thumbnailUrl.length() > 0) { visGraphNodeNear.setImageUrl(thumbnailUrl); } else { log.info("Thumbnail not found for articleTitle: " + articleTitle + ", trying by itemId: " + itemId); try { String url = this.wikiBrowserProperties.getThumbnailByIdServiceUrl(itemId, articleLang); thumbnailUrl = new RestTemplate().getForObject(url, String.class); if (thumbnailUrl != null) { visGraphNodeNear.setImageUrl(thumbnailUrl); // Because successful, cache by article title ThumbnailCache.setThumbnailUrlByTitle(articleTitle, articleLang, thumbnailUrl); } else { visGraphNodeNear.setImageUrl(""); } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?id=" + itemId + " : " + e); } } //log.info("thumbnailUrl:" + thumbnailUrl); } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling /thumbnail?title=" + articleTitle + " : " + e); } } */ // Note: The key in the graphNodeNearMap is the Neo4j node id, not the Wikidata item ID visGraphNodeNearMap.put(graphNodeFar.getId(), visGraphNodeNear); } List<GraphRelationFar> graphRelationFarList = graphFar.getGraphRelationFarList(); Iterator<GraphRelationFar> graphRelationFarIterator = graphRelationFarList.iterator(); while (graphRelationFarIterator.hasNext()) { GraphRelationFar graphRelationFar = graphRelationFarIterator.next(); VisGraphEdgeNear visGraphEdgeNear = new VisGraphEdgeNear(); // Use the Neo4j node ids from the relationship to retrieve the Wikidata Item IDs from the graphNodeNearMap String neo4jStartNodeId = graphRelationFar.getStartNode(); String wikidataStartNodeItemId = visGraphNodeNearMap.get(neo4jStartNodeId).getItemId(); String neo4jEndNodeId = graphRelationFar.getEndNode(); String wikidataEndNodeItemId = visGraphNodeNearMap.get(neo4jEndNodeId).getItemId(); //visGraphEdgeNear.setFromDbId(neo4jStartNodeId); visGraphEdgeNear.setFromDbId(wikidataStartNodeItemId.substring(1)); //visGraphEdgeNear.setToDbId(neo4jEndNodeId); visGraphEdgeNear.setToDbId(wikidataEndNodeItemId.substring(1)); visGraphEdgeNear.setLabel(graphRelationFar.getType()); visGraphEdgeNear.setArrowDirection("to"); visGraphEdgeNear.setPropId(graphRelationFar.getGraphRelationPropsFar().getPropId()); visGraphEdgeNear.setFromItemId(wikidataStartNodeItemId); visGraphEdgeNear.setToItemId(wikidataEndNodeItemId); // Note: The key in the graphLinkNearMap is the Neo4j node id, not the Wikidata item ID visGraphEdgeNearMap.put(graphRelationFar.getId(), visGraphEdgeNear); } } // Create and populate a List of nodes to set into the graphResponseNear instance List<VisGraphNodeNear> visGraphNodeNearList = new ArrayList<>(); visGraphNodeNearMap.forEach((k, v) -> { visGraphNodeNearList.add(v); }); visGraphResponseNear.setVisGraphNodeNearList(visGraphNodeNearList); // Create and populate a List of links to set into the graphResponseNear instance List<VisGraphEdgeNear> visGraphEdgeNearList = new ArrayList<>(); visGraphEdgeNearMap.forEach((k, v) -> { visGraphEdgeNearList.add(v); }); visGraphResponseNear.setVisGraphEdgeNearList(visGraphEdgeNearList); } } catch (Exception e) { e.printStackTrace(); log.info("Caught exception when calling Neo Cypher service " + e); } return visGraphResponseNear; }
From source file:com.orange.ngsi.client.NgsiRestClient.java
/** * Add a subscription//ww w. j av a 2s .c o m * @param url the URL of the broker * @param httpHeaders the HTTP header to use, or null for default * @param subscribeContext the parameters for subscription * @return a future for an SubscribeContextResponse */ public ListenableFuture<SubscribeContextResponse> appendContextSubscription(String url, HttpHeaders httpHeaders, SubscribeContext subscribeContext) { return request(HttpMethod.POST, url + subscriptionsPath, httpHeaders, subscribeContext, SubscribeContextResponse.class); }
From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java
private BaseClientDetails createClient(String grantTypes) throws Exception { BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar", grantTypes, "uaa.none"); client.setClientSecret("secret"); client.setAdditionalInformation(Collections.<String, Object>singletonMap("foo", Arrays.asList("bar"))); ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange( serverRunning.getUrl("/oauth/clients"), HttpMethod.POST, new HttpEntity<BaseClientDetails>(client, headers), Void.class); assertEquals(HttpStatus.CREATED, result.getStatusCode()); return client; }
From source file:com.projectx.mvc.servicehandler.quickregister.QuickRegisterHandler.java
@Override public Boolean reSetEmailHash(CustomerIdTypeEmailTypeDTO customerDTO) { HttpEntity<CustomerIdTypeEmailTypeDTO> entity = new HttpEntity<CustomerIdTypeEmailTypeDTO>(customerDTO); ResponseEntity<Boolean> detailsSentStatus = restTemplate.exchange( env.getProperty("rest.host") + "/customer/quickregister/resetEmailHash", HttpMethod.POST, entity, Boolean.class); if (detailsSentStatus.getStatusCode() == HttpStatus.OK) return detailsSentStatus.getBody(); else// w w w .j a va 2 s . c om throw new ResourceNotFoundException(); }
From source file:com.citrix.g2w.webdriver.dependencies.AccountServiceQAIImpl.java
/** * Method used to create license for user account. * //from w w w . j a va 2s. c o m * @param accountKey * (user account key) * @param enabled * (user enabled) * @param serviceType * (user service type) * @param roles * (user roles) * @param seats * (user seats) * @param channel * (user channel) * @return licenseKey */ private String createLicenseForAccount(final Long accountKey, final boolean enabled, final String serviceType, final String[] roles, final int seats, final String channel, int tier) { String licenseKey; try { JSONObject requestJson = new JSONObject(); requestJson.put("enabled", enabled); requestJson.put("serviceType", serviceType); requestJson.put("description", "G2W License"); requestJson.put("roles", roles); requestJson.put("seats", seats); requestJson.put("channel", channel); requestJson.put("tier", tier); HttpEntity entityLicense = new HttpEntity(requestJson.toString(), this.accountSvcHeaders); licenseKey = this.restTemplate.exchange(this.accountSvcUrl + "/accounts/" + accountKey + "/licenses", HttpMethod.POST, entityLicense, String.class).getBody(); // Set maxAttendees on license for G2W JSONObject entitlementRequestJson = new JSONObject(); entitlementRequestJson.put("maxAttendees", tier); this.restTemplate.exchange(this.accountSvcUrl + "/licenses/" + licenseKey + "/products/g2w", HttpMethod.PUT, new HttpEntity(entitlementRequestJson.toString(), this.accountSvcHeaders), null); } catch (Throwable t) { throw new RuntimeException(t); } return licenseKey; }
From source file:com.formkiq.web.AbstractIntegrationTest.java
/** * Adds User thru webservice.//w ww . j ava2 s .com * @param email {@link String} */ protected void addUser(final String email) { String token = login(getDefaultEmail()); setProperty(token, INVITE_ONLY, "false"); String url = getDefaultHostAndPort() + API_USER_SAVE + "?email=" + email + "&password=" + DEFAULT_PASS + "&confirmpassword=" + DEFAULT_PASS; ResponseEntity<String> entity = exchangeRestBasicAuth(HttpMethod.POST, url); assertEquals(SC_OK, entity.getStatusCode().value()); assertEquals("{\"message\":\"User has been saved\"}", entity.getBody()); }
From source file:fragment.web.RegistrationControllerTest.java
@SuppressWarnings({ "rawtypes" }) @Test/*from w w w .j av a 2s. c o m*/ public void testRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = this.getServletInstance(); Class controllerClass = RegistrationController.class; Method expected = locateMethod(controllerClass, "signupStep1", new Class[] { ModelMap.class, HttpServletRequest.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/account_type")); expected = locateMethod(controllerClass, "register", new Class[] { UserRegistration.class, BindingResult.class, String.class, String.class, ModelMap.class, String.class, SessionStatus.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/register")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "validateUsername", new Class[] { String.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/validate_username")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "updatePasswordAndVerifyEmail", new Class[] { String.class, String.class, HttpServletRequest.class, ModelMap.class, HttpSession.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/verify_user")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "verifyPhoneVerificationPIN", new Class[] { String.class, String.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/phoneverification/verify_pin")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "verifyEmail", new Class[] { HttpServletRequest.class, ModelMap.class, HttpSession.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/verify_email")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "requestCall", new Class[] { String.class, String.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/request_call")); Assert.assertEquals(expected, handler); expected = locateMethod(controllerClass, "requestSMS", new Class[] { String.class, String.class, HttpServletRequest.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/request_sms")); Assert.assertEquals(expected, handler); }
From source file:org.appverse.web.framework.backend.test.util.oauth2.tests.predefined.authorizationcode.Oauth2AuthorizationCodeFlowPredefinedTests.java
@Test public void obtainTokenFromOuth2LoginEndpoint() throws Exception { obtainAuthorizationCode();/*from w ww .jav a 2 s . c o m*/ UriComponentsBuilder builder = UriComponentsBuilder .fromHttpUrl(authServerBaseUrl + oauth2TokenEndpointPath); // Here we don't authenticate the user, we authenticate the client and we pass the authcode proving that the user has accepted and loged in builder.queryParam("client_id", getClientId()); builder.queryParam("grant_type", "authorization_code"); builder.queryParam("code", authorizationCode); builder.queryParam("redirect_uri", "http://anywhere"); // Add Basic Authorization headers for CLIENT authentication (user was authenticated in previous request (authorization code) HttpHeaders headers = new HttpHeaders(); Encoder encoder = Base64.getEncoder(); headers.add("Authorization", "Basic " + encoder.encodeToString((getClientId() + ":" + getClientSecret()).getBytes())); HttpEntity<String> entity = new HttpEntity<>("", headers); ResponseEntity<OAuth2AccessToken> result2 = restTemplate.exchange(builder.build().encode().toUri(), HttpMethod.POST, entity, OAuth2AccessToken.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.OK, result2.getStatusCode()); // Obtain and keep the token accessToken = result2.getBody().getValue(); assertNotNull(accessToken); refreshToken = result2.getBody().getRefreshToken().getValue(); assertNotNull(refreshToken); }