use of java.lang.reflect.Field in project camel by apache.
the class Injectors method tryCloseJitBindings.
private static void tryCloseJitBindings(Closer closer, Injector injector, Class<? extends Annotation> scopeAnnotationToClose, CloseErrors errors) {
Class<? extends Injector> type = injector.getClass();
Field field;
try {
field = type.getDeclaredField("jitBindings");
field.setAccessible(true);
Object bindings = field.get(injector);
if (bindings != null) {
if (bindings instanceof Map) {
Map<Key<?>, BindingImpl<?>> map = (Map<Key<?>, BindingImpl<?>>) bindings;
Set<Entry<Key<?>, BindingImpl<?>>> entries = map.entrySet();
for (Entry<Key<?>, BindingImpl<?>> entry : entries) {
closeBinding(entry.getKey(), entry.getValue(), scopeAnnotationToClose, closer, errors);
}
}
}
} catch (NoSuchFieldException e) {
// ignore - Guice has refactored so we can't access the jit bindings
// System.out.println("No such field! " + e);
} catch (IllegalAccessException e) {
// ignore - Guice has refactored so we can't access the jit bindings
// System.out.println("Failed to access field: " + field +
// ". Reason: " + e);
}
}
use of java.lang.reflect.Field in project camel by apache.
the class IgniteEventsEndpoint method setEvents.
/**
* Sets the event types to subscribe to as a comma-separated string of event constants as defined in {@link EventType}.
* <p>
* For example: EVT_CACHE_ENTRY_CREATED,EVT_CACHE_OBJECT_REMOVED,EVT_IGFS_DIR_CREATED.
*
* @param events
*/
public void setEvents(String events) {
this.events = new HashSet<>();
Set<String> requestedEvents = new HashSet<>(Arrays.asList(events.toUpperCase().split(",")));
Field[] fields = EventType.class.getDeclaredFields();
for (Field field : fields) {
if (!requestedEvents.contains(field.getName())) {
continue;
}
try {
this.events.add(field.getInt(null));
} catch (Exception e) {
throw new IllegalArgumentException("Problem while resolving event type. See stacktrace.", e);
}
}
}
use of java.lang.reflect.Field in project camel by apache.
the class JsonPathSourceTest method switchToDefaultCharset.
private static void switchToDefaultCharset(String charset) {
try {
Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
defaultCharset.setAccessible(true);
defaultCharset.set(null, Charset.forName(charset));
} catch (Exception e) {
// Do nothing here
}
}
use of java.lang.reflect.Field in project camel by apache.
the class MinaLoggerOptionTest method testNoLoggerOption.
@Test
public void testNoLoggerOption() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT default be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
use of java.lang.reflect.Field in project camel by apache.
the class MinaLoggerOptionTest method testLoggerOptionFalse.
@Test
public void testLoggerOptionFalse() throws Exception {
final String uri = "mina:tcp://localhost:{{port}}?textline=true&minaLogger=false&sync=false";
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from(uri).to("mock:result");
}
});
MockEndpoint mock = this.getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Exchange exchange = endpoint.createExchange();
Producer producer = endpoint.createProducer();
producer.start();
// set input and execute it
exchange.getIn().setBody("Hello World");
producer.process(exchange);
Field field = producer.getClass().getDeclaredField("session");
field.setAccessible(true);
IoSession session = (IoSession) field.get(producer);
assertFalse("There should NOT be a logger filter", session.getFilterChain().contains("logger"));
producer.stop();
assertMockEndpointsSatisfied();
}
Aggregations