Search in sources :

Example 21 with Field

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);
    }
}
Also used : Field(java.lang.reflect.Field) BindingImpl(com.google.inject.internal.BindingImpl) Entry(java.util.Map.Entry) Map(java.util.Map) Key(com.google.inject.Key)

Example 22 with Field

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);
        }
    }
}
Also used : Field(java.lang.reflect.Field) HashSet(java.util.HashSet)

Example 23 with Field

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
    }
}
Also used : Field(java.lang.reflect.Field)

Example 24 with Field

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();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Example 25 with Field

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();
}
Also used : Exchange(org.apache.camel.Exchange) Field(java.lang.reflect.Field) RouteBuilder(org.apache.camel.builder.RouteBuilder) Endpoint(org.apache.camel.Endpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Producer(org.apache.camel.Producer) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) IoSession(org.apache.mina.common.IoSession) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)4517 Method (java.lang.reflect.Method)500 Test (org.junit.Test)475 ArrayList (java.util.ArrayList)434 IOException (java.io.IOException)276 HashMap (java.util.HashMap)263 Map (java.util.Map)253 List (java.util.List)146 InvocationTargetException (java.lang.reflect.InvocationTargetException)136 Pattern (java.util.regex.Pattern)121 Matcher (java.util.regex.Matcher)115 File (java.io.File)93 HashSet (java.util.HashSet)91 Support_Field (tests.support.Support_Field)82 Annotation (java.lang.annotation.Annotation)77 Collection (java.util.Collection)70 SienaException (siena.SienaException)65 Test (org.testng.annotations.Test)64 Before (org.junit.Before)61 Type (java.lang.reflect.Type)57