本文整理汇总了Java中org.springframework.web.client.RestTemplate.postForLocation方法的典型用法代码示例。如果您正苦于以下问题:Java RestTemplate.postForLocation方法的具体用法?Java RestTemplate.postForLocation怎么用?Java RestTemplate.postForLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.client.RestTemplate
的用法示例。
在下文中一共展示了RestTemplate.postForLocation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setGitHubOAuthToken
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Uploads the Github oAuth token to the workspace so that the developer can send push requests
*
* @param cheServerURL
* @param gitHubToken
* @throws IOException
* @throws GitHubOAthTokenException
*/
public void setGitHubOAuthToken(final String cheServerURL, final String gitHubToken, final String keycloakToken)
throws IOException, GitHubOAthTokenException {
String url = cheServerURL + CheRestEndpoints.SET_OAUTH_TOKEN_V1.getEndpoint().replace("{provider}", "github");
Token token = new Token();
token.setToken(gitHubToken);
RestTemplate template = new KeycloakRestTemplate(keycloakToken);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<Token> entity = new HttpEntity<Token>(token, headers);
try {
template.postForLocation(url, entity);
} catch (Exception e) {
LOG.info("Trying new version of API - Unable to set GitHub OAuth token via '{}'", url);
try {
setGitHubOAuthTokenVersion2(cheServerURL, template, entity);
} catch (Exception ex) {
throw new GitHubOAthTokenException("Error setting GitHub OAuth token", ex);
}
}
}
示例2: startWorkspace
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
/**
* Starts and gets a workspace by its name.
*
* @param cheServerURL
* Che server URL
* @param workspaceName
* name of workspace to start
* @return started workspace
* @throws WorkspaceNotFound
*/
public Workspace startWorkspace(String cheServerURL, String workspaceName, String masterUrl, String namespace,
String openShiftToken, String keycloakToken) throws WorkspaceNotFound {
List<Workspace> workspaces = listWorkspaces(cheServerURL, keycloakToken);
boolean alreadyStarted = false;
Workspace workspaceToStart = null;
for (Workspace workspace : workspaces) {
if (workspace.getConfig().getName().equals(workspaceName)) {
workspaceToStart = workspace;
if (WorkspaceState.RUNNING.toString().equals(workspace.getStatus())
|| WorkspaceState.STARTING.toString().equals(workspace.getStatus())) {
alreadyStarted = true;
}
} else if (!WorkspaceState.STOPPED.toString().equals(workspace.getStatus())) {
stopWorkspace(cheServerURL, workspace, keycloakToken);
waitUntilWorkspaceIsStopped(masterUrl, namespace, openShiftToken, cheServerURL, workspace, keycloakToken);
}
}
if (workspaceToStart == null) {
throw new WorkspaceNotFound("Workspace '" + workspaceName + "' does not exist.");
}
if (!alreadyStarted) {
String url = CheRestEndpoints.START_WORKSPACE.generateUrl(cheServerURL, workspaceToStart.getId());
RestTemplate template = new KeycloakRestTemplate(keycloakToken);
template.postForLocation(url, null);
}
return workspaceToStart;
}
示例3: sendCollectedData
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public void sendCollectedData(RestTemplate restTemplate, String collectedXmlData) {
Map<String, String> params = new HashMap<String, String>();
params.put(Constants.TOOL_TYPE, XS2);
params.put(Constants.FEEDBACK_MAIL, collectedXmlData);
restTemplate.postForLocation(Configuration.getInstance().getMailApiUrl(), params);
}
示例4: sendViaMailgunApi
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
public void sendViaMailgunApi(EmailParams emailParams) {
String apiUrl = jHipsterProperties.getMailgun().getApiUrl();
String apiKey = jHipsterProperties.getMailgun().getApiKey();
MultiValueMap<String, Object> vars = new LinkedMultiValueMap<>();
vars.add("from", jHipsterProperties.getMailgun().getFrom());
vars.add("to", emailParams.getTo());
vars.add("subject", emailParams.getSubject());
vars.add("html", emailParams.getContent());
RestTemplate restTemplate = new BasicAuthRestTemplate(MAILGUN_USER_NAME, apiKey);
restTemplate.postForLocation(apiUrl, vars);
log.debug("Email sent successfully.");
}
示例5: setGitHubOAuthTokenVersion2
import org.springframework.web.client.RestTemplate; //导入方法依赖的package包/类
private void setGitHubOAuthTokenVersion2(String cheServerURL, RestTemplate template, HttpEntity<Token> entity) {
String url = cheServerURL + CheRestEndpoints.SET_OAUTH_TOKEN_V2.getEndpoint();
template.postForLocation(url, entity);
LOG.info("GitHub OAuth token has been successfully set via '{}'", url);
}