use of org.springframework.beans.PropertyAccessor in project dkpro-lab by dkpro.
the class DefaultLifeCycleManager method configure.
@Override
public void configure(TaskContext aParentContext, Task aTask, Map<String, Object> aConfiguration) {
PropertyAccessor paBean = PropertyAccessorFactory.forBeanPropertyAccess(aTask);
PropertyAccessor paDirect = PropertyAccessorFactory.forDirectFieldAccess(aTask);
for (Entry<String, Object> property : aConfiguration.entrySet()) {
String key = property.getKey();
Object value = property.getValue();
// a non-default name and might apply.
for (String prop : ParameterUtil.findBeanPropertiesWithName(aTask, key)) {
// Try setter - there may be extra logic in the setter
if (paBean.isWritableProperty(prop)) {
paBean.setPropertyValue(prop, value);
} else // Otherwise try direct access
if (paDirect.isWritableProperty(prop)) {
paDirect.setPropertyValue(prop, value);
}
}
// Try setter - there may be extra logic in the setter
if (paBean.isWritableProperty(key)) {
paBean.setPropertyValue(key, value);
} else // Otherwise try direct access
if (paDirect.isWritableProperty(key)) {
paDirect.setPropertyValue(key, value);
}
}
if (aTask instanceof ConfigurationAware) {
((ConfigurationAware) aTask).setConfiguration(aConfiguration);
}
if (aParentContext != null) {
aParentContext.message("Injected parameters into [" + aTask.getType() + "]");
}
}
use of org.springframework.beans.PropertyAccessor in project spring-integration by spring-projects.
the class HttpProxyScenarioTests method testHttpProxyScenario.
@Test
public void testHttpProxyScenario() throws Exception {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.RFC_1123_DATE_TIME;
ZoneId GMT = ZoneId.of("GMT");
Calendar c = Calendar.getInstance();
c.set(Calendar.MILLISECOND, 0);
final long ifModifiedSince = c.getTimeInMillis();
Instant instant = Instant.ofEpochMilli(ifModifiedSince);
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, GMT);
String ifModifiedSinceValue = dateTimeFormatter.format(zonedDateTime);
c.add(Calendar.DATE, -1);
long ifUnmodifiedSince = c.getTimeInMillis();
instant = Instant.ofEpochMilli(ifUnmodifiedSince);
zonedDateTime = ZonedDateTime.ofInstant(instant, GMT);
final String ifUnmodifiedSinceValue = dateTimeFormatter.format(zonedDateTime);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
request.setQueryString("foo=bar&FOO=BAR");
request.addHeader("If-Modified-Since", ifModifiedSinceValue);
request.addHeader("If-Unmodified-Since", ifUnmodifiedSinceValue);
request.addHeader("Connection", "Keep-Alive");
request.setContentType("text/plain");
Object handler = this.handlerMapping.getHandler(request).getHandler();
assertNotNull(handler);
MockHttpServletResponse response = new MockHttpServletResponse();
RestTemplate template = Mockito.spy(new RestTemplate());
final String contentDispositionValue = "attachment; filename=\"test.txt\"";
Mockito.doAnswer(invocation -> {
URI uri = invocation.getArgument(0);
assertEquals(new URI("http://testServer/test?foo=bar&FOO=BAR"), uri);
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
HttpHeaders httpHeaders = httpEntity.getHeaders();
assertEquals(ifModifiedSince, httpHeaders.getIfModifiedSince());
assertEquals(ifUnmodifiedSinceValue, httpHeaders.getFirst("If-Unmodified-Since"));
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
responseHeaders.set("Connection", "close");
responseHeaders.set("Content-Disposition", contentDispositionValue);
return new ResponseEntity<>(responseHeaders, HttpStatus.OK);
}).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), (Class<?>) isNull());
PropertyAccessor dfa = new DirectFieldAccessor(this.handler);
dfa.setPropertyValue("restTemplate", template);
RequestAttributes attributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(attributes);
this.handlerAdapter.handle(request, response, handler);
assertEquals(ifModifiedSinceValue, response.getHeaderValue("If-Modified-Since"));
assertEquals(ifUnmodifiedSinceValue, response.getHeaderValue("If-Unmodified-Since"));
assertEquals("close", response.getHeaderValue("Connection"));
assertEquals(contentDispositionValue, response.getHeader("Content-Disposition"));
assertEquals("text/plain", response.getContentType());
Message<?> message = this.checkHeadersChannel.receive(2000);
MessageHeaders headers = message.getHeaders();
assertEquals(ifModifiedSince, headers.get("If-Modified-Since"));
assertEquals(ifUnmodifiedSince, headers.get("If-Unmodified-Since"));
RequestContextHolder.resetRequestAttributes();
}
use of org.springframework.beans.PropertyAccessor in project spring-integration by spring-projects.
the class HttpProxyScenarioTests method testHttpMultipartProxyScenario.
@Test
public void testHttpMultipartProxyScenario() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/testmp");
request.addHeader("Connection", "Keep-Alive");
request.setContentType("multipart/form-data;boundary=----WebKitFormBoundarywABD2xqC1FLBijlQ");
request.setContent("foo".getBytes());
Object handler = this.handlerMapping.getHandler(request).getHandler();
assertNotNull(handler);
MockHttpServletResponse response = new MockHttpServletResponse();
RestTemplate template = Mockito.spy(new RestTemplate());
Mockito.doAnswer(invocation -> {
URI uri = invocation.getArgument(0);
assertEquals(new URI("http://testServer/testmp"), uri);
HttpEntity<?> httpEntity = (HttpEntity<?>) invocation.getArguments()[2];
HttpHeaders httpHeaders = httpEntity.getHeaders();
assertEquals("Keep-Alive", httpHeaders.getFirst("Connection"));
assertEquals("multipart/form-data;boundary=----WebKitFormBoundarywABD2xqC1FLBijlQ", httpHeaders.getContentType().toString());
HttpEntity<?> entity = (HttpEntity<?>) invocation.getArguments()[2];
assertThat(entity.getBody(), instanceOf(byte[].class));
assertEquals("foo", new String((byte[]) entity.getBody()));
MultiValueMap<String, String> responseHeaders = new LinkedMultiValueMap<String, String>(httpHeaders);
responseHeaders.set("Connection", "close");
responseHeaders.set("Content-Type", "text/plain");
return new ResponseEntity<Object>(responseHeaders, HttpStatus.OK);
}).when(template).exchange(Mockito.any(URI.class), Mockito.any(HttpMethod.class), Mockito.any(HttpEntity.class), (Class<?>) isNull());
PropertyAccessor dfa = new DirectFieldAccessor(this.handlermp);
dfa.setPropertyValue("restTemplate", template);
RequestAttributes attributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(attributes);
this.handlerAdapter.handle(request, response, handler);
assertEquals("close", response.getHeaderValue("Connection"));
assertEquals("text/plain", response.getContentType());
RequestContextHolder.resetRequestAttributes();
}
use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.
the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideNormalPrefix.
@Test
public void overrideNormalPrefix() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.normalPrefix:normal/");
assertThat(accessor.getPropertyValue("normalPrefix")).isEqualTo("normal/");
}
use of org.springframework.beans.PropertyAccessor in project spring-boot by spring-projects.
the class DeviceDelegatingViewResolverAutoConfigurationTests method overrideEnableFallback.
@Test
public void overrideEnableFallback() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor("spring.mobile.devicedelegatingviewresolver.enabled:true", "spring.mobile.devicedelegatingviewresolver.enableFallback:true");
assertThat(accessor.getPropertyValue("enableFallback")).isEqualTo(Boolean.TRUE);
}
Aggregations