本文整理匯總了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);
}