本文整理汇总了Java中org.springframework.web.client.RestTemplate.postForEntity方法的典型用法代码示例。如果您正苦于以下问题:Java RestTemplate.postForEntity方法的具体用法?Java RestTemplate.postForEntity怎么用?Java RestTemplate.postForEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.RestTemplate
的用法示例。
在下文中一共展示了RestTemplate.postForEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enviar
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public void enviar(String direccion, String subject, String body){
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> email= new LinkedMultiValueMap<String, String>();
email.add("email", direccion);
email.add("subject", subject);
email.add("body", body);
ResponseEntity<String> response = restTemplate.postForEntity(URL,email,String.class);
}
示例2: create
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Create occurrence.
*
* @param occurrence the occurrence
* @return the occurrence
*/
public Occurrence create(Occurrence occurrence) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("message", createMessage(occurrence));
map.add("link", occurrence.getUrl());
map.add("place", occurrence.getEvent().flatMap(Event::getLocation).map(Location::getFacebookId).map(String::valueOf).orElse(""));
map.add("published", "false");
map.add("scheduled_publish_time", String.valueOf(occurrence.getStartTime().minusHours((int) (Math.random() * 6 + 1)).getMillis() / 1000));
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<FacebookPost> response = restTemplate.postForEntity(generateRequestUrl(), request, FacebookPost.class);
occurrence.setFacebookPostId(response.getBody().getId());
return occurrence;
}
示例3: authenticate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
public boolean authenticate(final Credentials creds) {
boolean allowed = false;
try {
LOG.info("authenticate call: starting...");
RestTemplate rt = restManager.getRestTemplate("keystone-auth");
LOG.info("posting to " + keystoneTokenURI.toString());
ResponseEntity<String> resp =
rt.postForEntity(keystoneTokenURI, KeystoneUtils.getUnscopedAuth(creds), String.class);
if (resp != null) {
LOG.info("response is not null: " + resp.getStatusCode());
if (resp.getStatusCode() == HttpStatus.CREATED) {
LOG.info("response is CREATED");
String token = resp.getHeaders().getFirst("X-Subject-Token");
if (token != null) {
LOG.info("response contains header X-Subject-Token with value: " + token);
TokenManager.getInstance().setTokenHolder(creds.getUsername(), new TokenHolder(token));
allowed = true;
}
}
}
} catch (HttpClientErrorException ex) {
// LOG.error(ex);
// LOG.error("authentication refused for user: "+ creds.getUsername(),ex);
LOG.error("authentication refused for user: " + creds.getUsername() + " - " + ex.getMessage());
}
LOG.info("authenticate call: and we're done...");
return allowed;
}
示例4: oldSchool
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void oldSchool(RestTemplate restTemplate) {
final ObjectNode body = getAllCategoryMissionWithFacets();
logger.debug("query body: {}", body.toString());
final ResponseEntity<ObjectNode> objectNodeResponseEntity =
restTemplate.postForEntity(alfredUrl + AlfredConstants.SEARCH, body, ObjectNode.class);
if (objectNodeResponseEntity.getStatusCode().equals(HttpStatus.OK)) {
final ObjectNode bodyResponse = objectNodeResponseEntity.getBody();
final JsonNode nodeRefs = bodyResponse.get("noderefs");
nodeRefs.elements()
.forEachRemaining(node -> {
logger.info("{}: {}", node, getNodeName(restTemplate, node.asText()));
});
} else {
logger.warn("Problème pour retrouver les informations: {}", objectNodeResponseEntity.getStatusCode());
}
}
示例5: setInternal
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
protected MultifactorAuthenticationTrustRecord setInternal(final MultifactorAuthenticationTrustRecord record) {
final RestTemplate restTemplate = new RestTemplate();
final ResponseEntity<Object> response = restTemplate.postForEntity(this.endpoint, record, Object.class);
if (response != null && response.getStatusCode() == HttpStatus.OK) {
return record;
}
return null;
}
示例6: sendEvaluationRequest
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public ResponseEntity<PolicyEvaluationResult> sendEvaluationRequest(final RestTemplate restTemplate,
final HttpHeaders headers, final PolicyEvaluationRequestV1 randomEvalRequest) {
ResponseEntity<PolicyEvaluationResult> evaluationResponse = restTemplate.postForEntity(
this.zoneFactory.getAcsBaseURL() + ACS_POLICY_EVAL_API_PATH,
new HttpEntity<>(randomEvalRequest, headers), PolicyEvaluationResult.class);
return evaluationResponse;
}
示例7: callRestEndpointForMultifactor
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Call rest endpoint for multifactor.
*
* @param principal the principal
* @param context the context
* @return return the rest response, typically the mfa id.
*/
protected String callRestEndpointForMultifactor(final Principal principal, final RequestContext context) {
final RestTemplate restTemplate = new RestTemplate();
final Service resolvedService = resolveServiceFromAuthenticationRequest(context);
final RestEndpointEntity entity = new RestEndpointEntity(principal.getId(), resolvedService.getId());
final ResponseEntity<String> responseEntity = restTemplate.postForEntity(restEndpoint, entity, String.class);
if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
return responseEntity.getBody();
}
return null;
}
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:RestEndpointMultifactorAuthenticationPolicyEventResolver.java
示例8: testPolicyEvalWithNoOauthToken
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Test(dataProvider = "endpointProvider")
public void testPolicyEvalWithNoOauthToken(final String endpoint) {
RestTemplate acs = new RestTemplate();
// Use vanilla rest template with no oauth token.
try {
acs.postForEntity(endpoint + PolicyHelper.ACS_POLICY_EVAL_API_PATH,
new HttpEntity<>(this.policyHelper.createEvalRequest(MARISSA_V1.getSubjectIdentifier(), "sanramon"),
this.acsitSetUpFactory.getZone1Headers()),
PolicyEvaluationResult.class);
Assert.fail("No exception thrown when making policy evaluation request without token.");
} catch (HttpClientErrorException e) {
Assert.assertEquals(e.getStatusCode(), HttpStatus.UNAUTHORIZED);
}
}
示例9: performAction
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void performAction(final String serverId, final JsonAction jsonAction) {
String resourcesUri = jsonEndpoint.getUrl() + "/" + getUriSuffix() + "s/" + serverId + "/action";
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
try {
rt.postForEntity(resourcesUri, jsonAction, String.class);
} catch (HttpStatusCodeException ex) {
// check if it's a 401
if (ex.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new AuthenticationFailureException(ex);
} else {
throw ex;
}
}
}
示例10: createInstance
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
public JsonServers createInstance(final JsonServers server) {
System.out.println(RestUtils.toJson(server));
String url = jsonEndpoint.getUrl() + "/" + getUriSuffix() + "s";
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
ResponseEntity<JsonServers> result = rt.postForEntity(url, server, JsonServers.class);
return result.getBody();
}
示例11: authenticate
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Authenticate for the given baseUrl, username and password.
*
* @param baseUrl keystone url to try authenticating against
* @param username username
* @param password password
* @return true if it was successful
*/
public boolean authenticate(final String baseUrl, final String username, final String password) {
boolean allowed = false;
try {
URI keystoneTokenURI = EndpointUtils.keystoneTokenURINoCatalog(baseUrl);
RestTemplate rt = openstackApp.getRestManager().getRestTemplate("keystone-auth");
JsonAuth auth = KeystoneUtils.getUnscopedAuth(username, password);
LOG.info("AUTH " + keystoneTokenURI);
LOG.info("AUTH " + RestUtils.toJson(auth));
ResponseEntity<JsonTokens> resp = rt.postForEntity(keystoneTokenURI, auth, JsonTokens.class);
if (resp != null) {
if (resp.getStatusCode() == HttpStatus.CREATED) {
String token = resp.getHeaders().getFirst("X-Subject-Token");
LOG.info("AUTH token1 " + token);
if (token != null) {
TokenHolder tokenHolder = new TokenHolder(token);
openstackApp.getTokenManager().setTokenHolder(tokenHolder);
openstackApp.getTokenManager().setJsonUser(resp.getBody().getToken().getUser());
LOG.info("AUTH token2 " + resp.getBody().getToken());
allowed = true;
}
}
}
} catch (HttpClientErrorException ex) {
LOG.error("authentication refused for user: " + username + " - " + ex.getMessage());
}
return allowed;
}
示例12: getServiceCatalog
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Gets the service catalog for a given project id and stores it with the project name.
*
* @param projectId project id to get catalog for
* @param projectName project name to get catalog for
*/
public void getServiceCatalog(final String projectId, final String projectName) {
try {
URI keystoneTokenURI = EndpointUtils.keystoneTokenURIWithCatalog(openstackApp.getKeystoneUriBase());
RestTemplate rt = openstackApp.getRestManager().getRestTemplate("keystone-auth");
JsonAuth auth = KeystoneUtils.getScopedAuth(openstackApp.getTokenManager().getTokenHolder().getUnscoped(),
projectId);
ResponseEntity<JsonTokens> resp = rt.postForEntity(keystoneTokenURI, auth, JsonTokens.class);
String token = null;
JsonToken jsonToken = null;
if (resp != null) {
if (resp.getStatusCode() == HttpStatus.CREATED) {
token = resp.getHeaders().getFirst("X-Subject-Token");
jsonToken = resp.getBody().getToken();
}
}
if (token != null && token.length() > MAX_HEADER_SIZE) {
keystoneTokenURI = EndpointUtils.keystoneTokenURINoCatalog(openstackApp.getKeystoneUriBase());
resp = rt.postForEntity(keystoneTokenURI, auth, JsonTokens.class);
if (resp != null) {
if (resp.getStatusCode() == HttpStatus.CREATED) {
token = resp.getHeaders().getFirst("X-Subject-Token");
}
}
}
if (token != null && jsonToken != null) {
openstackApp.getTokenManager().getTokenHolder().setScopedToken(projectId, projectName, token,
jsonToken);
}
} catch (HttpClientErrorException ex) {
LOG.error("authentication refused for user: " + projectId + " - " + ex.getMessage());
}
if (LOG.isInfoEnabled()) {
LOG.info("authenticate call: and we're done...");
}
}
示例13: createVolume
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
public JsonVolumes createVolume(final String projectId, final JsonVolumes volumes) {
String url = jsonEndpoint.getUrl() + "/volumes";
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
ResponseEntity<JsonVolumes> result = rt.postForEntity(url, volumes, JsonVolumes.class);
return result.getBody();
}
示例14: createSubnets
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
public JsonSubnets createSubnets(final JsonSubnets subnets) {
String url = getUri();
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
ResponseEntity<JsonSubnets> result = rt.postForEntity(url, subnets, JsonSubnets.class);
return result.getBody();
}
示例15: createNetworks
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
@Override
public JsonNetworks createNetworks(final JsonNetworks networks) {
String url = getUri();
RestTemplate rt = getRestTemplate(jsonEndpoint.getProjectId());
ResponseEntity<JsonNetworks> result = rt.postForEntity(url, networks, JsonNetworks.class);
return result.getBody();
}