use of org.springframework.util.LinkedMultiValueMap in project profile by craftercms.
the class ProfileServiceRestClient method addProfileAttachment.
@Override
public ProfileAttachment addProfileAttachment(String profileId, String attachmentName, InputStream file) throws ProfileException {
MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
params.add(PARAM_ACCESS_TOKEN_ID, accessTokenIdResolver.getAccessTokenId());
params.add(PARAM_FILENAME, attachmentName);
String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_UPLOAD_ATTACHMENT);
File tmpFile = null;
try {
tmpFile = File.createTempFile(profileId + "-" + attachmentName, "attachment");
FileUtils.copyInputStreamToFile(file, tmpFile);
params.add("attachment", new FileSystemResource(tmpFile));
return doPostForUpload(url, params, ProfileAttachment.class, profileId);
} catch (IOException e) {
throw new I10nProfileException(ERROR_KEY_TMP_COPY_FAILED, e, attachmentName, profileId);
} finally {
try {
file.close();
FileUtils.forceDelete(tmpFile);
} catch (Throwable e) {
}
}
}
use of org.springframework.util.LinkedMultiValueMap in project seldon-core by SeldonIO.
the class InternalPredictionService method queryREST.
private SeldonMessage queryREST(String path, String dataString, PredictiveUnitState state, Endpoint endpoint, boolean isDefault) {
long timeNow = System.currentTimeMillis();
URI uri;
try {
URIBuilder builder = new URIBuilder().setScheme("http").setHost(endpoint.getServiceHost()).setPort(endpoint.getServicePort()).setPath("/" + path);
uri = builder.build();
} catch (URISyntaxException e) {
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_ENDPOINT_URL, "Host: " + endpoint.getServiceHost() + " port:" + endpoint.getServicePort());
}
try {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
headers.add(MODEL_NAME_HEADER, state.name);
headers.add(MODEL_IMAGE_HEADER, state.imageName);
headers.add(MODEL_VERSION_HEADER, state.imageVersion);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("json", dataString);
map.add("isDefault", Boolean.toString(isDefault));
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
logger.info("Requesting " + uri.toString());
ResponseEntity<String> httpResponse = restTemplate.postForEntity(uri, request, String.class);
try {
if (httpResponse.getStatusCode().is2xxSuccessful()) {
SeldonMessage.Builder builder = SeldonMessage.newBuilder();
String response = httpResponse.getBody();
logger.info(response);
JsonFormat.parser().ignoringUnknownFields().merge(response, builder);
return builder.build();
} else {
logger.error("Couldn't retrieve prediction from external prediction server -- bad http return code: " + httpResponse.getStatusCode());
throw new APIException(APIException.ApiExceptionType.ENGINE_MICROSERVICE_ERROR, String.format("Bad return code %d", httpResponse.getStatusCode()));
}
} finally {
if (logger.isDebugEnabled())
logger.debug("External prediction server took " + (System.currentTimeMillis() - timeNow) + "ms");
}
} catch (IOException e) {
logger.error("Couldn't retrieve prediction from external prediction server - ", e);
throw new APIException(APIException.ApiExceptionType.ENGINE_MICROSERVICE_ERROR, e.toString());
} catch (Exception e) {
logger.error("Couldn't retrieve prediction from external prediction server - ", e);
throw new APIException(APIException.ApiExceptionType.ENGINE_MICROSERVICE_ERROR, e.toString());
} finally {
}
}
use of org.springframework.util.LinkedMultiValueMap in project spring-boot-admin by codecentric.
the class JdkPerInstanceCookieStoreTest method cookies_should_be_fetched_and_converted_from_store.
@Test
void cookies_should_be_fetched_and_converted_from_store() throws IOException {
MultiValueMap<String, String> storeMap = new LinkedMultiValueMap<>();
storeMap.add("Cookie", "name=value");
storeMap.add("Cookie", "name2=tricky=value");
final URI uri = URI.create("http://localhost/test");
when(cookieHandler.get(eq(uri), any())).thenReturn(storeMap);
final MultiValueMap<String, String> cookieMap = store.get(INSTANCE_ID, uri, new LinkedMultiValueMap<>());
assertThat(cookieMap).containsEntry("name", singletonList("value"));
assertThat(cookieMap).containsEntry("name2", singletonList("tricky=value"));
}
use of org.springframework.util.LinkedMultiValueMap in project spring-security by spring-projects.
the class OAuth2ClientBeanDefinitionParserTests method requestWhenAuthorizationResponseMatchThenProcess.
@Test
public void requestWhenAuthorizationResponseMatchThenProcess() throws Exception {
this.spring.configLocations(xml("CustomConfiguration")).autowire();
ClientRegistration clientRegistration = this.clientRegistrationRepository.findByRegistrationId("google");
OAuth2AuthorizationRequest authorizationRequest = createAuthorizationRequest(clientRegistration);
given(this.authorizationRequestRepository.loadAuthorizationRequest(any())).willReturn(authorizationRequest);
given(this.authorizationRequestRepository.removeAuthorizationRequest(any(), any())).willReturn(authorizationRequest);
OAuth2AccessTokenResponse accessTokenResponse = TestOAuth2AccessTokenResponses.accessTokenResponse().build();
given(this.accessTokenResponseClient.getTokenResponse(any())).willReturn(accessTokenResponse);
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("code", "code123");
params.add("state", authorizationRequest.getState());
// @formatter:off
this.mvc.perform(get(authorizationRequest.getRedirectUri()).params(params)).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl(authorizationRequest.getRedirectUri()));
// @formatter:on
ArgumentCaptor<OAuth2AuthorizedClient> authorizedClientCaptor = ArgumentCaptor.forClass(OAuth2AuthorizedClient.class);
verify(this.authorizedClientRepository).saveAuthorizedClient(authorizedClientCaptor.capture(), any(), any(), any());
OAuth2AuthorizedClient authorizedClient = authorizedClientCaptor.getValue();
assertThat(authorizedClient.getClientRegistration()).isEqualTo(clientRegistration);
assertThat(authorizedClient.getAccessToken()).isEqualTo(accessTokenResponse.getAccessToken());
}
use of org.springframework.util.LinkedMultiValueMap in project spring-security by spring-projects.
the class JwtBearerGrantRequestEntityConverter method createParameters.
@Override
protected MultiValueMap<String, String> createParameters(JwtBearerGrantRequest jwtBearerGrantRequest) {
ClientRegistration clientRegistration = jwtBearerGrantRequest.getClientRegistration();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add(OAuth2ParameterNames.GRANT_TYPE, jwtBearerGrantRequest.getGrantType().getValue());
parameters.add(OAuth2ParameterNames.ASSERTION, jwtBearerGrantRequest.getJwt().getTokenValue());
if (!CollectionUtils.isEmpty(clientRegistration.getScopes())) {
parameters.add(OAuth2ParameterNames.SCOPE, StringUtils.collectionToDelimitedString(clientRegistration.getScopes(), " "));
}
if (ClientAuthenticationMethod.CLIENT_SECRET_POST.equals(clientRegistration.getClientAuthenticationMethod()) || ClientAuthenticationMethod.POST.equals(clientRegistration.getClientAuthenticationMethod())) {
parameters.add(OAuth2ParameterNames.CLIENT_ID, clientRegistration.getClientId());
parameters.add(OAuth2ParameterNames.CLIENT_SECRET, clientRegistration.getClientSecret());
}
return parameters;
}
Aggregations