Here are the examples of the java api org.springframework.util.MultiValueMap.getFirst() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
62 Examples
19
View Source File : RequestResponseBodyMethodProcessorTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
String content = "fruit=apple&vegetable=kale";
this.servletRequest.setMethod("GET");
this.servletRequest.setContent(content.getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new AllEncompreplacedingFormHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked")
MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(paramMultiValueMap, container, request, factory);
replacedertNotNull(result);
replacedertEquals("apple", result.getFirst("fruit"));
replacedertEquals("kale", result.getFirst("vegetable"));
}
19
View Source File : FormHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readForm() throws Exception {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
replacedertEquals("Invalid result", 3, result.size());
replacedertEquals("Invalid result", "value 1", result.getFirst("name 1"));
List<String> values = result.get("name 2");
replacedertEquals("Invalid result", 2, values.size());
replacedertEquals("Invalid result", "value 2+1", values.get(0));
replacedertEquals("Invalid result", "value 2+2", values.get(1));
replacedertNull("Invalid result", result.getFirst("name 3"));
}
19
View Source File : FormHttpMessageReaderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readFormAsMono() {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.readMono(null, request, null).block();
replacedertEquals("Invalid result", 3, result.size());
replacedertEquals("Invalid result", "value 1", result.getFirst("name 1"));
List<String> values = result.get("name 2");
replacedertEquals("Invalid result", 2, values.size());
replacedertEquals("Invalid result", "value 2+1", values.get(0));
replacedertEquals("Invalid result", "value 2+2", values.get(1));
replacedertNull("Invalid result", result.getFirst("name 3"));
}
19
View Source File : FormHttpMessageReaderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readFormAsFlux() {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.read(null, request, null).single().block();
replacedertEquals("Invalid result", 3, result.size());
replacedertEquals("Invalid result", "value 1", result.getFirst("name 1"));
List<String> values = result.get("name 2");
replacedertEquals("Invalid result", 2, values.size());
replacedertEquals("Invalid result", "value 2+1", values.get(0));
replacedertEquals("Invalid result", "value 2+2", values.get(1));
replacedertNull("Invalid result", result.getFirst("name 3"));
}
19
View Source File : AbstractHttpSendingTransportHandler.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Nullable
protected final String getCallbackParam(ServerHttpRequest request) {
String query = request.getURI().getQuery();
MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams();
String value = params.getFirst("c");
if (StringUtils.isEmpty(value)) {
return null;
}
String result = UriUtils.decode(value, StandardCharsets.UTF_8);
return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null);
}
19
View Source File : FormParameters.java
License : MIT License
Project Creator : ljtfreitas
License : MIT License
Project Creator : ljtfreitas
@Override
public Object getFirst(String key) {
return map.getFirst(key);
}
19
View Source File : RequestResponseBodyMethodProcessorTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
String content = "fruit=apple&vegetable=kale";
this.servletRequest.setMethod("GET");
this.servletRequest.setContent(content.getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
converters.add(new AllEncompreplacedingFormHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked")
MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(paramMultiValueMap, mavContainer, webRequest, binderFactory);
replacedertNotNull(result);
replacedertEquals("apple", result.getFirst("fruit"));
replacedertEquals("kale", result.getFirst("vegetable"));
}
19
View Source File : ParamExpression.java
License : Apache License 2.0
Project Creator : alibaba
License : Apache License 2.0
Project Creator : alibaba
@Override
protected boolean matchValue(HttpRequest request) {
MultiValueMap<String, String> parametersMap = getParameters(request);
String parameterValue = parametersMap.getFirst(this.name);
return ObjectUtils.nullSafeEquals(this.value, parameterValue);
}
18
View Source File : PublicClientAuthenticationConverter.java
License : Apache License 2.0
Project Creator : spring-projects-experimental
License : Apache License 2.0
Project Creator : spring-projects-experimental
@Override
public Authentication convert(HttpServletRequest request) {
if (!OAuth2EndpointUtils.matchesPkceTokenRequest(request)) {
return null;
}
MultiValueMap<String, String> parameters = OAuth2EndpointUtils.getParameters(request);
// client_id (REQUIRED for public clients)
String clientId = parameters.getFirst(OAuth2ParameterNames.CLIENT_ID);
if (!StringUtils.hasText(clientId) || parameters.get(OAuth2ParameterNames.CLIENT_ID).size() != 1) {
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST));
}
// code_verifier (REQUIRED)
if (parameters.get(PkceParameterNames.CODE_VERIFIER).size() != 1) {
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST));
}
parameters.remove(OAuth2ParameterNames.CLIENT_ID);
return new OAuth2ClientAuthenticationToken(clientId, new HashMap<>(parameters.toSingleValueMap()));
}
18
View Source File : ClientSecretPostAuthenticationConverter.java
License : Apache License 2.0
Project Creator : spring-projects-experimental
License : Apache License 2.0
Project Creator : spring-projects-experimental
@Override
public Authentication convert(HttpServletRequest request) {
MultiValueMap<String, String> parameters = OAuth2EndpointUtils.getParameters(request);
// client_id (REQUIRED)
String clientId = parameters.getFirst(OAuth2ParameterNames.CLIENT_ID);
if (!StringUtils.hasText(clientId)) {
return null;
}
if (parameters.get(OAuth2ParameterNames.CLIENT_ID).size() != 1) {
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST));
}
// client_secret (REQUIRED)
String clientSecret = parameters.getFirst(OAuth2ParameterNames.CLIENT_SECRET);
if (!StringUtils.hasText(clientSecret)) {
return null;
}
if (parameters.get(OAuth2ParameterNames.CLIENT_SECRET).size() != 1) {
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST));
}
return new OAuth2ClientAuthenticationToken(clientId, clientSecret, ClientAuthenticationMethod.POST, extractAdditionalParameters(request));
}
18
View Source File : RequestResponseBodyMethodProcessorTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
String content = "fruit=apple&vegetable=kale";
this.servletRequest.setMethod("GET");
this.servletRequest.setContent(content.getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new AllEncompreplacedingFormHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked")
MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(paramMultiValueMap, container, request, factory);
replacedertThat(result).isNotNull();
replacedertThat(result.getFirst("fruit")).isEqualTo("apple");
replacedertThat(result.getFirst("vegetable")).isEqualTo("kale");
}
18
View Source File : FormHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readForm() throws Exception {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
replacedertThat(result.size()).as("Invalid result").isEqualTo(3);
replacedertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
replacedertThat(values.size()).as("Invalid result").isEqualTo(2);
replacedertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
replacedertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
replacedertThat(result.getFirst("name 3")).as("Invalid result").isNull();
}
18
View Source File : FormHttpMessageReaderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readFormAsFlux() {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.read(null, request, null).single().block();
replacedertThat(result.size()).as("Invalid result").isEqualTo(3);
replacedertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
replacedertThat(values.size()).as("Invalid result").isEqualTo(2);
replacedertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
replacedertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
replacedertThat(result.getFirst("name 3")).as("Invalid result").isNull();
}
18
View Source File : FormHttpMessageReaderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readFormAsMono() {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
MockServerHttpRequest request = request(body);
MultiValueMap<String, String> result = this.reader.readMono(null, request, null).block();
replacedertThat(result.size()).as("Invalid result").isEqualTo(3);
replacedertThat(result.getFirst("name 1")).as("Invalid result").isEqualTo("value 1");
List<String> values = result.get("name 2");
replacedertThat(values.size()).as("Invalid result").isEqualTo(2);
replacedertThat(values.get(0)).as("Invalid result").isEqualTo("value 2+1");
replacedertThat(values.get(1)).as("Invalid result").isEqualTo("value 2+2");
replacedertThat(result.getFirst("name 3")).as("Invalid result").isNull();
}
18
View Source File : XsuaaOAuth2TokenServicePasswordTest.java
License : Apache License 2.0
Project Creator : SAP
License : Apache License 2.0
Project Creator : SAP
private String valueOfParameter(String parameterKey, ArgumentCaptor<HttpEnreplacedy<MultiValueMap<String, String>>> requestEnreplacedyCaptor) {
MultiValueMap<String, String> body = requestEnreplacedyCaptor.getValue().getBody();
return body.getFirst(parameterKey);
}
17
View Source File : RequestMappingInfoHandlerMappingTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void handleMatchMatrixVariables() {
MockHttpServletRequest request;
MultiValueMap<String, String> matrixVariables;
Map<String, String> uriVariables;
// URI var parsed into path variable + matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "cars");
uriVariables = getUriTemplateVariables(request);
replacedertNotNull(matrixVariables);
replacedertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
replacedertEquals("2012", matrixVariables.getFirst("year"));
replacedertEquals("cars", uriVariables.get("cars"));
// URI var with regex for path variable, and URI var for matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars:[^;]+}{params}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertNotNull(matrixVariables);
replacedertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
replacedertEquals("2012", matrixVariables.getFirst("year"));
replacedertEquals("cars", uriVariables.get("cars"));
replacedertEquals(";colors=red,blue,green;year=2012", uriVariables.get("params"));
// URI var with regex for path variable, and (empty) URI var for matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars:[^;]+}{params}", "/cars");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertNull(matrixVariables);
replacedertEquals("cars", uriVariables.get("cars"));
replacedertEquals("", uriVariables.get("params"));
// SPR-11897
request = new MockHttpServletRequest();
handleMatch(request, "/{foo}", "/a=42;b=c");
matrixVariables = getMatrixVariables(request, "foo");
uriVariables = getUriTemplateVariables(request);
replacedertNotNull(matrixVariables);
replacedertEquals(2, matrixVariables.size());
replacedertEquals("42", matrixVariables.getFirst("a"));
replacedertEquals("c", matrixVariables.getFirst("b"));
replacedertEquals("a=42", uriVariables.get("foo"));
}
17
View Source File : SynchronossPartHttpMessageReaderTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
void resolveParts() {
ServerHttpRequest request = generateMultipartRequest();
MultiValueMap<String, Part> parts = this.reader.readMono(PARTS_ELEMENT_TYPE, request, emptyMap()).block();
replacedertThat(parts).containsOnlyKeys("filePart", "textPart");
Part part = parts.getFirst("filePart");
replacedertThat(part).isInstanceOf(FilePart.clreplaced);
replacedertThat(part.name()).isEqualTo("filePart");
replacedertThat(((FilePart) part).filename()).isEqualTo("foo.txt");
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
replacedertThat(DataBufferTestUtils.dumpString(buffer, StandardCharsets.UTF_8)).isEqualTo("Lorem Ipsum.");
DataBufferUtils.release(buffer);
part = parts.getFirst("textPart");
replacedertThat(part).isInstanceOf(FormFieldPart.clreplaced);
replacedertThat(part.name()).isEqualTo("textPart");
replacedertThat(((FormFieldPart) part).value()).isEqualTo("sample-text");
}
17
View Source File : MergeCartServerAuthenticationSuccessHandler.java
License : Apache License 2.0
Project Creator : making
License : Apache License 2.0
Project Creator : making
@Override
public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) {
final MultiValueMap<String, HttpCookie> cookies = webFilterExchange.getExchange().getRequest().getCookies();
if (!cookies.containsKey(CART_ID_COOKIE_NAME)) {
return Mono.empty();
}
final String sessionId = cookies.getFirst(CART_ID_COOKIE_NAME).getValue();
final String customerId = ((ShopUser) authentication.getPrincipal()).customerId();
log.info("Merge cart from {} to {}", sessionId, customerId);
return this.cartClient.mergeWithFallback(customerId, sessionId);
}
17
View Source File : RequestMappingInfoHandlerMappingTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void matrixVariables() {
MockHttpServletRequest request;
MultiValueMap<String, String> matrixVariables;
Map<String, String> uriVariables;
request = new MockHttpServletRequest();
testHandleMatch(request, "/{cars}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "cars");
uriVariables = getUriTemplateVariables(request);
replacedertNotNull(matrixVariables);
replacedertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
replacedertEquals("2012", matrixVariables.getFirst("year"));
replacedertEquals("cars", uriVariables.get("cars"));
request = new MockHttpServletRequest();
testHandleMatch(request, "/{cars:[^;]+}{params}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertNotNull(matrixVariables);
replacedertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
replacedertEquals("2012", matrixVariables.getFirst("year"));
replacedertEquals("cars", uriVariables.get("cars"));
replacedertEquals(";colors=red,blue,green;year=2012", uriVariables.get("params"));
request = new MockHttpServletRequest();
testHandleMatch(request, "/{cars:[^;]+}{params}", "/cars");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertNull(matrixVariables);
replacedertEquals("cars", uriVariables.get("cars"));
replacedertEquals("", uriVariables.get("params"));
}
17
View Source File : FormHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void readForm() throws Exception {
String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
Charset iso88591 = Charset.forName("ISO-8859-1");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(iso88591));
inputMessage.getHeaders().setContentType(new MediaType("application", "x-www-form-urlencoded", iso88591));
MultiValueMap<String, String> result = this.converter.read(null, inputMessage);
replacedertEquals("Invalid result", 3, result.size());
replacedertEquals("Invalid result", "value 1", result.getFirst("name 1"));
List<String> values = result.get("name 2");
replacedertEquals("Invalid result", 2, values.size());
replacedertEquals("Invalid result", "value 2+1", values.get(0));
replacedertEquals("Invalid result", "value 2+2", values.get(1));
replacedertNull("Invalid result", result.getFirst("name 3"));
}
17
View Source File : SpringCloudGatewayParamParserTest.java
License : Apache License 2.0
Project Creator : eacdy
License : Apache License 2.0
Project Creator : eacdy
@SuppressWarnings("unchecked")
private void mockSingleUrlParam(/*@Mock*/
ServerHttpRequest request, String key, String value) {
MultiValueMap<String, String> urlParams = mock(MultiValueMap.clreplaced);
when(request.getQueryParams()).thenReturn(urlParams);
when(urlParams.getFirst(key)).thenReturn(value);
}
17
View Source File : SpringCloudGatewayParamParserTest.java
License : Apache License 2.0
Project Creator : eacdy
License : Apache License 2.0
Project Creator : eacdy
@SuppressWarnings("unchecked")
private void mockUrlParams(/*@Mock*/
ServerHttpRequest request, Map<String, String> paramMap) {
MultiValueMap<String, String> urlParams = mock(MultiValueMap.clreplaced);
when(request.getQueryParams()).thenReturn(urlParams);
for (Map.Entry<String, String> e : paramMap.entrySet()) {
when(urlParams.getFirst(e.getKey())).thenReturn(e.getValue());
}
}
16
View Source File : SynchronossPartHttpMessageReaderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void resolveParts() {
ServerHttpRequest request = generateMultipartRequest();
ResolvableType elementType = forClreplacedWithGenerics(MultiValueMap.clreplaced, String.clreplaced, Part.clreplaced);
MultiValueMap<String, Part> parts = this.reader.readMono(elementType, request, emptyMap()).block();
replacedertEquals(2, parts.size());
replacedertTrue(parts.containsKey("fooPart"));
Part part = parts.getFirst("fooPart");
replacedertTrue(part instanceof FilePart);
replacedertEquals("fooPart", part.name());
replacedertEquals("foo.txt", ((FilePart) part).filename());
DataBuffer buffer = DataBufferUtils.join(part.content()).block();
replacedertEquals(12, buffer.readableByteCount());
byte[] byteContent = new byte[12];
buffer.read(byteContent);
replacedertEquals("Lorem Ipsum.", new String(byteContent));
replacedertTrue(parts.containsKey("barPart"));
part = parts.getFirst("barPart");
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("barPart", part.name());
replacedertEquals("bar", ((FormFieldPart) part).value());
}
16
View Source File : MultipartHttpMessageWriterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void writeMultipart() throws Exception {
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Resource utf8 = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg") {
@Override
public String getFilename() {
// SPR-12108
return "Hall\u00F6le.jpg";
}
};
Flux<DataBuffer> bufferPublisher = Flux.just(this.bufferFactory.wrap("Aa".getBytes(StandardCharsets.UTF_8)), this.bufferFactory.wrap("Bb".getBytes(StandardCharsets.UTF_8)), this.bufferFactory.wrap("Cc".getBytes(StandardCharsets.UTF_8)));
Part mockPart = mock(Part.clreplaced);
given(mockPart.content()).willReturn(bufferPublisher);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("name 1", "value 1");
bodyBuilder.part("name 2", "value 2+1");
bodyBuilder.part("name 2", "value 2+2");
bodyBuilder.part("logo", logo);
bodyBuilder.part("utf8", utf8);
bodyBuilder.part("json", new Foo("bar"), MediaType.APPLICATION_JSON);
bodyBuilder.asyncPart("publisher", Flux.just("foo", "bar", "baz"), String.clreplaced);
bodyBuilder.asyncPart("partPublisher", Mono.just(mockPart), Part.clreplaced);
Mono<MultiValueMap<String, HttpEnreplacedy<?>>> result = Mono.just(bodyBuilder.build());
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block(Duration.ofSeconds(5));
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertEquals(7, requestParts.size());
Part part = requestParts.getFirst("name 1");
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 1", part.name());
replacedertEquals("value 1", ((FormFieldPart) part).value());
List<Part> parts2 = requestParts.get("name 2");
replacedertEquals(2, parts2.size());
part = parts2.get(0);
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 2", part.name());
replacedertEquals("value 2+1", ((FormFieldPart) part).value());
part = parts2.get(1);
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 2", part.name());
replacedertEquals("value 2+2", ((FormFieldPart) part).value());
part = requestParts.getFirst("logo");
replacedertTrue(part instanceof FilePart);
replacedertEquals("logo", part.name());
replacedertEquals("logo.jpg", ((FilePart) part).filename());
replacedertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
replacedertEquals(logo.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("utf8");
replacedertTrue(part instanceof FilePart);
replacedertEquals("utf8", part.name());
replacedertEquals("Hall\u00F6le.jpg", ((FilePart) part).filename());
replacedertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
replacedertEquals(utf8.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("json");
replacedertEquals("json", part.name());
replacedertEquals(MediaType.APPLICATION_JSON, part.headers().getContentType());
String value = decodeToString(part);
replacedertEquals("{\"bar\":\"bar\"}", value);
part = requestParts.getFirst("publisher");
replacedertEquals("publisher", part.name());
value = decodeToString(part);
replacedertEquals("foobarbaz", value);
part = requestParts.getFirst("partPublisher");
replacedertEquals("partPublisher", part.name());
value = decodeToString(part);
replacedertEquals("AaBbCc", value);
}
16
View Source File : RequestMappingInfoHandlerMappingTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void handleMatchMatrixVariables() {
MockHttpServletRequest request;
MultiValueMap<String, String> matrixVariables;
Map<String, String> uriVariables;
// URI var parsed into path variable + matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "cars");
uriVariables = getUriTemplateVariables(request);
replacedertThat(matrixVariables).isNotNull();
replacedertThat(matrixVariables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
replacedertThat(matrixVariables.getFirst("year")).isEqualTo("2012");
replacedertThat(uriVariables.get("cars")).isEqualTo("cars");
// URI var with regex for path variable, and URI var for matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars:[^;]+}{params}", "/cars;colors=red,blue,green;year=2012");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertThat(matrixVariables).isNotNull();
replacedertThat(matrixVariables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
replacedertThat(matrixVariables.getFirst("year")).isEqualTo("2012");
replacedertThat(uriVariables.get("cars")).isEqualTo("cars");
replacedertThat(uriVariables.get("params")).isEqualTo(";colors=red,blue,green;year=2012");
// URI var with regex for path variable, and (empty) URI var for matrix params..
request = new MockHttpServletRequest();
handleMatch(request, "/{cars:[^;]+}{params}", "/cars");
matrixVariables = getMatrixVariables(request, "params");
uriVariables = getUriTemplateVariables(request);
replacedertThat(matrixVariables).isNull();
replacedertThat(uriVariables.get("cars")).isEqualTo("cars");
replacedertThat(uriVariables.get("params")).isEqualTo("");
// SPR-11897
request = new MockHttpServletRequest();
handleMatch(request, "/{foo}", "/a=42;b=c");
matrixVariables = getMatrixVariables(request, "foo");
uriVariables = getUriTemplateVariables(request);
replacedertThat(matrixVariables).isNotNull();
replacedertThat(matrixVariables.size()).isEqualTo(2);
replacedertThat(matrixVariables.getFirst("a")).isEqualTo("42");
replacedertThat(matrixVariables.getFirst("b")).isEqualTo("c");
replacedertThat(uriVariables.get("foo")).isEqualTo("a=42");
}
16
View Source File : StreamController.java
License : MIT License
Project Creator : segator
License : MIT License
Project Creator : segator
private boolean authenticate(HttpServletRequest request, HttpServletResponse response) throws Exception {
MultiValueMap<String, String> parameters = UriComponentsBuilder.fromUriString(ProxyLiveUtils.getURL(request)).build().getQueryParams();
String token = parameters.getFirst("token");
String username = parameters.getFirst("user");
if (token != null) {
return validateToken(token);
} else {
return validateUser(username, parameters.getFirst("preplaced"));
}
}
16
View Source File : WsTtyHandler.java
License : Apache License 2.0
Project Creator : codeabovelab
License : Apache License 2.0
Project Creator : codeabovelab
@Override
public void afterConnectionEstablished(WebSocketSession session) {
URI uri = session.getUri();
try {
UriComponents uc = UriComponentsBuilder.fromUri(uri).build();
MultiValueMap<String, String> params = uc.getQueryParams();
String containerId = params.getFirst("container");
try (TempAuth ta = withAuth(session)) {
connectToContainer(session, containerId);
}
} catch (Exception e) {
log.error("Can not establish connection for '{}' due to error:", uri, e);
}
}
15
View Source File : MultipartHttpMessageWriterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-16402
@Test
public void singleSubscriberWithResource() throws IOException {
UnicastProcessor<Resource> processor = UnicastProcessor.create();
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Mono.just(logo).subscribe(processor);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.asyncPart("logo", processor, Resource.clreplaced);
Mono<MultiValueMap<String, HttpEnreplacedy<?>>> result = Mono.just(bodyBuilder.build());
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block();
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertEquals(1, requestParts.size());
Part part = requestParts.getFirst("logo");
replacedertEquals("logo", part.name());
replacedertTrue(part instanceof FilePart);
replacedertEquals("logo.jpg", ((FilePart) part).filename());
replacedertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
replacedertEquals(logo.getFile().length(), part.headers().getContentLength());
}
15
View Source File : CookieWebSessionIdResolverTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void cookieInitializer() {
this.resolver.addCookieInitializer(builder -> builder.domain("example.org"));
this.resolver.addCookieInitializer(builder -> builder.sameSite("Strict"));
this.resolver.addCookieInitializer(builder -> builder.secure(false));
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
this.resolver.setSessionId(exchange, "123");
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
replacedertThat(cookies.size()).isEqualTo(1);
ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName());
replacedertThat(cookie).isNotNull();
replacedertThat(cookie.toString()).isEqualTo("SESSION=123; Path=/; Domain=example.org; HttpOnly; SameSite=Strict");
}
15
View Source File : CookieWebSessionIdResolverTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void setSessionId() {
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
this.resolver.setSessionId(exchange, "123");
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
replacedertThat(cookies.size()).isEqualTo(1);
ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName());
replacedertThat(cookie).isNotNull();
replacedertThat(cookie.toString()).isEqualTo("SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax");
}
15
View Source File : MultipartHttpMessageWriterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void writeMultipart() throws Exception {
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Resource utf8 = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg") {
@Override
public String getFilename() {
// SPR-12108
return "Hall\u00F6le.jpg";
}
};
Flux<DataBuffer> bufferPublisher = Flux.just(this.bufferFactory.wrap("Aa".getBytes(StandardCharsets.UTF_8)), this.bufferFactory.wrap("Bb".getBytes(StandardCharsets.UTF_8)), this.bufferFactory.wrap("Cc".getBytes(StandardCharsets.UTF_8)));
FilePart mockPart = mock(FilePart.clreplaced);
given(mockPart.content()).willReturn(bufferPublisher);
given(mockPart.filename()).willReturn("file.txt");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("name 1", "value 1");
bodyBuilder.part("name 2", "value 2+1");
bodyBuilder.part("name 2", "value 2+2");
bodyBuilder.part("logo", logo);
bodyBuilder.part("utf8", utf8);
bodyBuilder.part("json", new Foo("bar"), MediaType.APPLICATION_JSON);
bodyBuilder.asyncPart("publisher", Flux.just("foo", "bar", "baz"), String.clreplaced);
bodyBuilder.part("filePublisher", mockPart);
Mono<MultiValueMap<String, HttpEnreplacedy<?>>> result = Mono.just(bodyBuilder.build());
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block(Duration.ofSeconds(5));
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertThat(requestParts.size()).isEqualTo(7);
Part part = requestParts.getFirst("name 1");
boolean condition4 = part instanceof FormFieldPart;
replacedertThat(condition4).isTrue();
replacedertThat(part.name()).isEqualTo("name 1");
replacedertThat(((FormFieldPart) part).value()).isEqualTo("value 1");
List<Part> parts2 = requestParts.get("name 2");
replacedertThat(parts2.size()).isEqualTo(2);
part = parts2.get(0);
boolean condition3 = part instanceof FormFieldPart;
replacedertThat(condition3).isTrue();
replacedertThat(part.name()).isEqualTo("name 2");
replacedertThat(((FormFieldPart) part).value()).isEqualTo("value 2+1");
part = parts2.get(1);
boolean condition2 = part instanceof FormFieldPart;
replacedertThat(condition2).isTrue();
replacedertThat(part.name()).isEqualTo("name 2");
replacedertThat(((FormFieldPart) part).value()).isEqualTo("value 2+2");
part = requestParts.getFirst("logo");
boolean condition1 = part instanceof FilePart;
replacedertThat(condition1).isTrue();
replacedertThat(part.name()).isEqualTo("logo");
replacedertThat(((FilePart) part).filename()).isEqualTo("logo.jpg");
replacedertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
replacedertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
part = requestParts.getFirst("utf8");
boolean condition = part instanceof FilePart;
replacedertThat(condition).isTrue();
replacedertThat(part.name()).isEqualTo("utf8");
replacedertThat(((FilePart) part).filename()).isEqualTo("Hall\u00F6le.jpg");
replacedertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
replacedertThat(part.headers().getContentLength()).isEqualTo(utf8.getFile().length());
part = requestParts.getFirst("json");
replacedertThat(part.name()).isEqualTo("json");
replacedertThat(part.headers().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
String value = decodeToString(part);
replacedertThat(value).isEqualTo("{\"bar\":\"bar\"}");
part = requestParts.getFirst("publisher");
replacedertThat(part.name()).isEqualTo("publisher");
value = decodeToString(part);
replacedertThat(value).isEqualTo("foobarbaz");
part = requestParts.getFirst("filePublisher");
replacedertThat(part.name()).isEqualTo("filePublisher");
replacedertThat(((FilePart) part).filename()).isEqualTo("file.txt");
value = decodeToString(part);
replacedertThat(value).isEqualTo("AaBbCc");
}
15
View Source File : AbstractHttpSendingTransportHandler.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
protected final String getCallbackParam(ServerHttpRequest request) {
String query = request.getURI().getQuery();
MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams();
String value = params.getFirst("c");
if (StringUtils.isEmpty(value)) {
return null;
}
try {
String result = UriUtils.decode(value, "UTF-8");
return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null);
} catch (UnsupportedEncodingException ex) {
// should never happen
throw new SockJsException("Unable to decode callback query parameter", null, ex);
}
}
14
View Source File : AbstractHttpSendingTransportHandler.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Nullable
protected final String getCallbackParam(ServerHttpRequest request) {
String query = request.getURI().getQuery();
MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams();
String value = params.getFirst("c");
if (!StringUtils.hasLength(value)) {
return null;
}
String result = UriUtils.decode(value, StandardCharsets.UTF_8);
return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null);
}
14
View Source File : WebUtilsTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void parseMatrixVariablesString() {
MultiValueMap<String, String> variables;
variables = WebUtils.parseMatrixVariables(null);
replacedertEquals(0, variables.size());
variables = WebUtils.parseMatrixVariables("year");
replacedertEquals(1, variables.size());
replacedertEquals("", variables.getFirst("year"));
variables = WebUtils.parseMatrixVariables("year=2012");
replacedertEquals(1, variables.size());
replacedertEquals("2012", variables.getFirst("year"));
variables = WebUtils.parseMatrixVariables("year=2012;colors=red,blue,green");
replacedertEquals(2, variables.size());
replacedertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
replacedertEquals("2012", variables.getFirst("year"));
variables = WebUtils.parseMatrixVariables(";year=2012;colors=red,blue,green;");
replacedertEquals(2, variables.size());
replacedertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
replacedertEquals("2012", variables.getFirst("year"));
variables = WebUtils.parseMatrixVariables("colors=red;colors=blue;colors=green");
replacedertEquals(1, variables.size());
replacedertEquals(Arrays.asList("red", "blue", "green"), variables.get("colors"));
}
14
View Source File : CookieWebSessionIdResolverTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void setSessionId() {
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
this.resolver.setSessionId(exchange, "123");
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
replacedertEquals(1, cookies.size());
ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName());
replacedertNotNull(cookie);
replacedertEquals("SESSION=123; Path=/; Secure; HttpOnly; SameSite=Lax", cookie.toString());
}
14
View Source File : CookieWebSessionIdResolverTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void cookieInitializer() {
this.resolver.addCookieInitializer(builder -> builder.domain("example.org"));
this.resolver.addCookieInitializer(builder -> builder.sameSite("Strict"));
this.resolver.addCookieInitializer(builder -> builder.secure(false));
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.org/path").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
this.resolver.setSessionId(exchange, "123");
MultiValueMap<String, ResponseCookie> cookies = exchange.getResponse().getCookies();
replacedertEquals(1, cookies.size());
ResponseCookie cookie = cookies.getFirst(this.resolver.getCookieName());
replacedertNotNull(cookie);
replacedertEquals("SESSION=123; Path=/; Domain=example.org; HttpOnly; SameSite=Strict", cookie.toString());
}
14
View Source File : MultipartHttpMessageWriterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-16376
@Test
public void customContentDisposition() throws IOException {
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Flux<DataBuffer> buffers = DataBufferUtils.read(logo, new DefaultDataBufferFactory(), 1024);
long contentLength = logo.contentLength();
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("resource", logo).headers(h -> h.setContentDispositionFormData("resource", "spring.jpg"));
bodyBuilder.asyncPart("buffers", buffers, DataBuffer.clreplaced).headers(h -> {
h.setContentDispositionFormData("buffers", "buffers.jpg");
h.setContentType(MediaType.IMAGE_JPEG);
h.setContentLength(contentLength);
});
MultiValueMap<String, HttpEnreplacedy<?>> multipartData = bodyBuilder.build();
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(Mono.just(multipartData), null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block();
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertEquals(2, requestParts.size());
Part part = requestParts.getFirst("resource");
replacedertTrue(part instanceof FilePart);
replacedertEquals("spring.jpg", ((FilePart) part).filename());
replacedertEquals(logo.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("buffers");
replacedertTrue(part instanceof FilePart);
replacedertEquals("buffers.jpg", ((FilePart) part).filename());
replacedertEquals(logo.getFile().length(), part.headers().getContentLength());
}
14
View Source File : WebUtilsTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void parseMatrixVariablesString() {
MultiValueMap<String, String> variables;
variables = WebUtils.parseMatrixVariables(null);
replacedertThat(variables.size()).isEqualTo(0);
variables = WebUtils.parseMatrixVariables("year");
replacedertThat(variables.size()).isEqualTo(1);
replacedertThat(variables.getFirst("year")).isEqualTo("");
variables = WebUtils.parseMatrixVariables("year=2012");
replacedertThat(variables.size()).isEqualTo(1);
replacedertThat(variables.getFirst("year")).isEqualTo("2012");
variables = WebUtils.parseMatrixVariables("year=2012;colors=red,blue,green");
replacedertThat(variables.size()).isEqualTo(2);
replacedertThat(variables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
replacedertThat(variables.getFirst("year")).isEqualTo("2012");
variables = WebUtils.parseMatrixVariables(";year=2012;colors=red,blue,green;");
replacedertThat(variables.size()).isEqualTo(2);
replacedertThat(variables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
replacedertThat(variables.getFirst("year")).isEqualTo("2012");
variables = WebUtils.parseMatrixVariables("colors=red;colors=blue;colors=green");
replacedertThat(variables.size()).isEqualTo(1);
replacedertThat(variables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
}
14
View Source File : MultipartHttpMessageWriterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
// SPR-16402
@Test
public void singleSubscriberWithResource() throws IOException {
UnicastProcessor<Resource> processor = UnicastProcessor.create();
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Mono.just(logo).subscribe(processor);
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.asyncPart("logo", processor, Resource.clreplaced);
Mono<MultiValueMap<String, HttpEnreplacedy<?>>> result = Mono.just(bodyBuilder.build());
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block();
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertThat(requestParts.size()).isEqualTo(1);
Part part = requestParts.getFirst("logo");
replacedertThat(part.name()).isEqualTo("logo");
boolean condition = part instanceof FilePart;
replacedertThat(condition).isTrue();
replacedertThat(((FilePart) part).filename()).isEqualTo("logo.jpg");
replacedertThat(part.headers().getContentType()).isEqualTo(MediaType.IMAGE_JPEG);
replacedertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
}
14
View Source File : MultipartHttpMessageWriterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
// SPR-16376
@Test
public void customContentDisposition() throws IOException {
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Flux<DataBuffer> buffers = DataBufferUtils.read(logo, new DefaultDataBufferFactory(), 1024);
long contentLength = logo.contentLength();
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("resource", logo).headers(h -> h.setContentDispositionFormData("resource", "spring.jpg"));
bodyBuilder.asyncPart("buffers", buffers, DataBuffer.clreplaced).headers(h -> {
h.setContentDispositionFormData("buffers", "buffers.jpg");
h.setContentType(MediaType.IMAGE_JPEG);
h.setContentLength(contentLength);
});
MultiValueMap<String, HttpEnreplacedy<?>> multipartData = bodyBuilder.build();
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(Mono.just(multipartData), null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block();
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertThat(requestParts.size()).isEqualTo(2);
Part part = requestParts.getFirst("resource");
boolean condition1 = part instanceof FilePart;
replacedertThat(condition1).isTrue();
replacedertThat(((FilePart) part).filename()).isEqualTo("spring.jpg");
replacedertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
part = requestParts.getFirst("buffers");
boolean condition = part instanceof FilePart;
replacedertThat(condition).isTrue();
replacedertThat(((FilePart) part).filename()).isEqualTo("buffers.jpg");
replacedertThat(part.headers().getContentLength()).isEqualTo(logo.getFile().length());
}
14
View Source File : MultipartHttpMessageWriterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void writeMultipart() throws Exception {
Resource logo = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg");
Resource utf8 = new ClreplacedPathResource("/org/springframework/http/converter/logo.jpg") {
@Override
public String getFilename() {
// SPR-12108
return "Hall\u00F6le.jpg";
}
};
Publisher<String> publisher = Flux.just("foo", "bar", "baz");
MultipartBodyBuilder bodyBuilder = new MultipartBodyBuilder();
bodyBuilder.part("name 1", "value 1");
bodyBuilder.part("name 2", "value 2+1");
bodyBuilder.part("name 2", "value 2+2");
bodyBuilder.part("logo", logo);
bodyBuilder.part("utf8", utf8);
bodyBuilder.part("json", new Foo("bar"), MediaType.APPLICATION_JSON_UTF8);
bodyBuilder.asyncPart("publisher", publisher, String.clreplaced);
Mono<MultiValueMap<String, HttpEnreplacedy<?>>> result = Mono.just(bodyBuilder.build());
Map<String, Object> hints = Collections.emptyMap();
this.writer.write(result, null, MediaType.MULTIPART_FORM_DATA, this.response, hints).block(Duration.ofSeconds(5));
MultiValueMap<String, Part> requestParts = parse(hints);
replacedertEquals(6, requestParts.size());
Part part = requestParts.getFirst("name 1");
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 1", part.name());
replacedertEquals("value 1", ((FormFieldPart) part).value());
List<Part> parts2 = requestParts.get("name 2");
replacedertEquals(2, parts2.size());
part = parts2.get(0);
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 2", part.name());
replacedertEquals("value 2+1", ((FormFieldPart) part).value());
part = parts2.get(1);
replacedertTrue(part instanceof FormFieldPart);
replacedertEquals("name 2", part.name());
replacedertEquals("value 2+2", ((FormFieldPart) part).value());
part = requestParts.getFirst("logo");
replacedertTrue(part instanceof FilePart);
replacedertEquals("logo", part.name());
replacedertEquals("logo.jpg", ((FilePart) part).filename());
replacedertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
replacedertEquals(logo.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("utf8");
replacedertTrue(part instanceof FilePart);
replacedertEquals("utf8", part.name());
replacedertEquals("Hall\u00F6le.jpg", ((FilePart) part).filename());
replacedertEquals(MediaType.IMAGE_JPEG, part.headers().getContentType());
replacedertEquals(utf8.getFile().length(), part.headers().getContentLength());
part = requestParts.getFirst("json");
replacedertEquals("json", part.name());
replacedertEquals(MediaType.APPLICATION_JSON_UTF8, part.headers().getContentType());
String value = StringDecoder.textPlainOnly(false).decodeToMono(part.content(), ResolvableType.forClreplaced(String.clreplaced), MediaType.TEXT_PLAIN, Collections.emptyMap()).block(Duration.ZERO);
replacedertEquals("{\"bar\":\"bar\"}", value);
part = requestParts.getFirst("publisher");
replacedertEquals("publisher", part.name());
value = StringDecoder.textPlainOnly(false).decodeToMono(part.content(), ResolvableType.forClreplaced(String.clreplaced), MediaType.TEXT_PLAIN, Collections.emptyMap()).block(Duration.ZERO);
replacedertEquals("foobarbaz", value);
}
14
View Source File : WebAuth.java
License : Apache License 2.0
Project Creator : FlowCI
License : Apache License 2.0
Project Creator : FlowCI
/**
* Get user object from ws message header
* @param headers
* @return User object
* @exception AuthenticationException if Token header is missing or invalid token
*/
public User validate(MessageHeaders headers) {
MultiValueMap<String, String> map = headers.get(StompHeaderAccessor.NATIVE_HEADERS, MultiValueMap.clreplaced);
if (Objects.isNull(map)) {
throw new AuthenticationException("Invalid token");
}
String token = map.getFirst(HeaderToken);
if (!StringHelper.hasValue(token)) {
throw new AuthenticationException("Invalid token");
}
Optional<User> user = authService.get(token);
if (!user.isPresent()) {
throw new AuthenticationException("Invalid token");
}
return user.get();
}
13
View Source File : MutipartMixedConverterUnitTest.java
License : Apache License 2.0
Project Creator : xm-online
License : Apache License 2.0
Project Creator : xm-online
@Test
public void testRead() throws IOException {
when(httpInputMessage.getHeaders()).thenReturn(httpHeaders);
when(httpInputMessage.getBody()).thenReturn(IOUtils.toInputStream("text=value", Charsets.UTF_8));
MultiValueMap<String, String> result = multipartMixedConverter.read(null, httpInputMessage);
replacedertEquals("value", result.getFirst("text"));
}
13
View Source File : ValidateCodeFilter.java
License : MIT License
Project Creator : wells2333
License : MIT License
Project Creator : wells2333
/**
* 校验验证码
*
* @param serverHttpRequest serverHttpRequest
* @param loginType loginType
* @throws InvalidValidateCodeException
*/
private void checkCode(ServerHttpRequest serverHttpRequest, LoginTypeEnum loginType) throws InvalidValidateCodeException {
MultiValueMap<String, String> params = serverHttpRequest.getQueryParams();
// 验证码
String code = params.getFirst("code");
if (StrUtil.isBlank(code))
throw new InvalidValidateCodeException("请输入验证码.");
// 获取随机码
String randomStr = params.getFirst("randomStr");
// 随机数为空,则获取手机号
if (StrUtil.isBlank(randomStr))
randomStr = params.getFirst("mobile");
String key = CommonConstant.DEFAULT_CODE_KEY + loginType.getType() + "@" + randomStr;
// 验证码过期
if (!redisTemplate.hasKey(key))
throw new ValidateCodeExpiredException(GatewayConstant.EXPIRED_ERROR);
Object codeObj = redisTemplate.opsForValue().get(key);
if (codeObj == null)
throw new ValidateCodeExpiredException(GatewayConstant.EXPIRED_ERROR);
String saveCode = codeObj.toString();
if (StrUtil.isBlank(saveCode)) {
redisTemplate.delete(key);
throw new ValidateCodeExpiredException(GatewayConstant.EXPIRED_ERROR);
}
if (!StrUtil.equals(saveCode, code)) {
redisTemplate.delete(key);
throw new InvalidValidateCodeException("验证码错误.");
}
redisTemplate.delete(key);
}
13
View Source File : RequestMappingInfoHandlerMappingTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void handleMatchMatrixVariables() {
MultiValueMap<String, String> matrixVariables;
Map<String, String> uriVariables;
ServerWebExchange exchange = MockServerWebExchange.from(get("/cars;colors=red,blue,green;year=2012"));
handleMatch(exchange, "/{cars}");
matrixVariables = getMatrixVariables(exchange, "cars");
uriVariables = getUriTemplateVariables(exchange);
replacedertNotNull(matrixVariables);
replacedertEquals(Arrays.asList("red", "blue", "green"), matrixVariables.get("colors"));
replacedertEquals("2012", matrixVariables.getFirst("year"));
replacedertEquals("cars", uriVariables.get("cars"));
// SPR-11897
exchange = MockServerWebExchange.from(get("/a=42;b=c"));
handleMatch(exchange, "/{foo}");
matrixVariables = getMatrixVariables(exchange, "foo");
uriVariables = getUriTemplateVariables(exchange);
// Unlike Spring MVC, WebFlux currently does not support APIs like
// "/foo/{ids}" and URL "/foo/id=1;id=2;id=3" where the whole path
// segment is a sequence of name-value pairs.
replacedertNotNull(matrixVariables);
replacedertEquals(1, matrixVariables.size());
replacedertEquals("c", matrixVariables.getFirst("b"));
replacedertEquals("a=42", uriVariables.get("foo"));
}
13
View Source File : JsonpReceivingTransportHandler.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Override
protected String[] readMessages(ServerHttpRequest request) throws IOException {
SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec();
MediaType contentType = request.getHeaders().getContentType();
if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
MultiValueMap<String, String> map = this.formConverter.read(null, request);
String d = map.getFirst("d");
return (StringUtils.hasText(d) ? messageCodec.decode(d) : null);
} else {
return messageCodec.decodeInputStream(request.getBody());
}
}
12
View Source File : ControllerFilter.java
License : Apache License 2.0
Project Creator : turms-im
License : Apache License 2.0
Project Creator : turms-im
private boolean isValidDeleteRequest(HandlerMethod handlerMethod, ServerWebExchange exchange, DeleteMapping deleteMapping) {
String methodFilterName = null;
for (Parameter parameter : handlerMethod.getMethod().getParameters()) {
String name = parameter.getName();
if (DELETE_FILTER_PARAM_NAME.contains(name)) {
methodFilterName = name;
}
}
if (methodFilterName == null) {
return true;
} else {
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
String filterValue = queryParams.getFirst(methodFilterName);
return filterValue != null && !filterValue.isBlank();
}
}
12
View Source File : ControllerFilter.java
License : Apache License 2.0
Project Creator : turms-im
License : Apache License 2.0
Project Creator : turms-im
private DBObject parseValidParams(ServerHttpRequest request, HandlerMethod handlerMethod) {
MethodParameter[] methodParameters = handlerMethod.getMethodParameters();
MultiValueMap<String, String> queryParams = request.getQueryParams();
BasicDBObject params = null;
if (methodParameters.length > 0 && !queryParams.isEmpty()) {
params = new BasicDBObject(queryParams.size());
for (MethodParameter methodParameter : methodParameters) {
String parameterName = methodParameter.getParameterName();
if (parameterName != null) {
String value = queryParams.getFirst(parameterName);
if (value != null) {
params.put(parameterName, value);
}
}
}
if (params.isEmpty()) {
params = EMPTY_DBOJBECT;
}
}
return params;
}
12
View Source File : RequestMappingInfoHandlerMappingTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void handleMatchMatrixVariables() {
MultiValueMap<String, String> matrixVariables;
Map<String, String> uriVariables;
ServerWebExchange exchange = MockServerWebExchange.from(get("/cars;colors=red,blue,green;year=2012"));
handleMatch(exchange, "/{cars}");
matrixVariables = getMatrixVariables(exchange, "cars");
uriVariables = getUriTemplateVariables(exchange);
replacedertThat(matrixVariables).isNotNull();
replacedertThat(matrixVariables.get("colors")).isEqualTo(Arrays.asList("red", "blue", "green"));
replacedertThat(matrixVariables.getFirst("year")).isEqualTo("2012");
replacedertThat(uriVariables.get("cars")).isEqualTo("cars");
// SPR-11897
exchange = MockServerWebExchange.from(get("/a=42;b=c"));
handleMatch(exchange, "/{foo}");
matrixVariables = getMatrixVariables(exchange, "foo");
uriVariables = getUriTemplateVariables(exchange);
// Unlike Spring MVC, WebFlux currently does not support APIs like
// "/foo/{ids}" and URL "/foo/id=1;id=2;id=3" where the whole path
// segment is a sequence of name-value pairs.
replacedertThat(matrixVariables).isNotNull();
replacedertThat(matrixVariables.size()).isEqualTo(1);
replacedertThat(matrixVariables.getFirst("b")).isEqualTo("c");
replacedertThat(uriVariables.get("foo")).isEqualTo("a=42");
}
11
View Source File : PatreonAPI.java
License : GNU General Public License v3.0
Project Creator : JuniperBot
License : GNU General Public License v3.0
Project Creator : JuniperBot
private String getNextCursorFromDoreplacedent(JSONAPIDoreplacedent doreplacedent) {
Links links = doreplacedent.getLinks();
if (links == null) {
return null;
}
Link nextLink = links.getNext();
if (nextLink == null) {
return null;
}
String nextLinkString = URLDecoder.decode(nextLink.toString(), StandardCharsets.UTF_8);
MultiValueMap<String, String> queryParameters = UriComponentsBuilder.fromUriString(nextLinkString).build().getQueryParams();
return queryParameters.getFirst("page[cursor]");
}
See More Examples