Java Code Examples for org.apache.camel.Processor#process()

The following examples show how to use org.apache.camel.Processor#process() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthenticationCustomizerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
private static void assertHeaderSetTo(final ComponentProxyComponent component, final String headerName, final String headerValue) throws Exception {
    final Processor processor = component.getBeforeProducer();

    final Exchange exchange = mock(Exchange.class);
    final Message message = mock(Message.class);
    when(exchange.getIn()).thenReturn(message);
    when(exchange.getOut()).thenReturn(message);
    when(exchange.getPattern()).thenReturn(ExchangePattern.InOut);

    final ExtendedCamelContext context = mock(ExtendedCamelContext.class);
    when(exchange.getContext()).thenReturn(context);

    final AsyncProcessorAwaitManager async = mock(AsyncProcessorAwaitManager.class);
    when(context.getAsyncProcessorAwaitManager()).thenReturn(async);

    processor.process(exchange);

    verify(message).setHeader(headerName, headerValue);
}
 
Example 2
Source File: WebhookConnectorCustomizerTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldDestroyAllOutput() throws Exception {
    final WebhookConnectorCustomizer customizer = new WebhookConnectorCustomizer();
    final ExtendedCamelContext context = mock(ExtendedCamelContext.class);
    customizer.setCamelContext(context);

    when(context.adapt(ExtendedCamelContext.class)).thenReturn(context);

    customizer.customize(component, Collections.emptyMap());

    final Processor afterConsumer = component.getAfterConsumer();
    assertThat(afterConsumer).isNotNull();

    final Exchange exchange = mock(Exchange.class);
    final Message message = mock(Message.class);
    when(exchange.getMessage()).thenReturn(message);

    afterConsumer.process(exchange);

    verify(message).setBody("");
    verify(message).removeHeaders("*");
    verify(message).setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
    verify(message).setHeader(Exchange.HTTP_RESPONSE_TEXT, "No Content");
}
 
Example 3
Source File: WebhookConnectorCustomizerTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddWrapperProcessorIfSyndesisJsonSchemaGiven() throws Exception {
    final WebhookConnectorCustomizer customizer = new WebhookConnectorCustomizer();
    final ExtendedCamelContext context = mock(ExtendedCamelContext.class);
    customizer.setCamelContext(context);

    when(context.adapt(ExtendedCamelContext.class)).thenReturn(context);

    customizer.setOutputDataShape(new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).specification(SIMPLE_SCHEMA).build());

    customizer.customize(component, Collections.emptyMap());

    final Processor beforeConsumer = component.getBeforeConsumer();
    assertThat(beforeConsumer).isInstanceOf(Pipeline.class);
    final Pipeline pipeline = (Pipeline) beforeConsumer;
    final Collection<Processor> processors = pipeline.next();
    assertThat(processors).hasSize(3);
    assertThat(processors).anySatisfy(containsInstanceOf(HttpRequestWrapperProcessor.class));
    assertThat(processors).anySatisfy(containsInstanceOf(HttpMessageToDefaultMessageProcessor.class));

    final HttpRequestWrapperProcessor wrapper = (HttpRequestWrapperProcessor) processors.stream()
        .map(n -> ((Navigate<?>) n).next().get(0))
        .filter(HttpRequestWrapperProcessor.class::isInstance)
        .findFirst().get();
    assertThat(wrapper.getParameters()).containsOnly("source", "status");

    final Processor removeHeader = processors.stream().filter(p -> !(p instanceof HttpRequestWrapperProcessor)).findFirst().get();
    final Exchange exchange = mock(Exchange.class);
    final Message in = mock(Message.class);
    when(exchange.getIn()).thenReturn(in);
    removeHeader.process(exchange);
    verify(in).removeHeader(Exchange.HTTP_URI);
}
 
Example 4
Source File: MyInterceptor.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public Processor wrapProcessorInInterceptors(CamelContext context,
        ProcessorDefinition<?> definition, final Processor target,
        Processor nextTarget) throws Exception {

	return new DelegateAsyncProcessor(new Processor() {

		public void process(Exchange exchange) throws Exception {
			LOG.info("Before the processor...");
			target.process(exchange);
			LOG.info("After the processor...");
		}
	});
}
 
Example 5
Source File: MyInterceptor.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public Processor wrapProcessorInInterceptors(CamelContext context,
        ProcessorDefinition<?> definition, final Processor target,
        Processor nextTarget) throws Exception {

	return new DelegateAsyncProcessor(new Processor() {

		public void process(Exchange exchange) throws Exception {
			LOG.info("Before the processor...");
			target.process(exchange);
			LOG.info("After the processor...");
		}
	});
}
 
Example 6
Source File: MyCustomLoadBalancer.java    From camelinaction2 with Apache License 2.0 4 votes vote down vote up
public void process(Exchange exchange) throws Exception {
    Processor target = chooseProcessor(exchange);
    target.process(exchange);
}
 
Example 7
Source File: MyCustomLoadBalancer.java    From camelinaction with Apache License 2.0 4 votes vote down vote up
public void process(Exchange exchange) throws Exception {
    Processor target = chooseProcessor(exchange);
    target.process(exchange);
}
 
Example 8
Source File: AbstractAuthorizationPolicy.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@Override
public Processor wrap(final Route route, final Processor processor) {
    return new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            Subject subject = exchange.getIn().getHeader(Exchange.AUTHENTICATION, Subject.class);
            if (subject == null) {
                throw new SecurityException("Cannot obtain authentication subject from exchange: " + exchange);
            }
            String domain = null;
            String username = null;
            char[] password = null;
            for (Principal principal : subject.getPrincipals()) {
                if (principal instanceof UsernamePasswordPrincipal) {
                    username = principal.getName();
                    password = ((UsernamePasswordPrincipal) principal).getPassword();
                } else if (principal instanceof DomainPrincipal) {
                    domain = principal.getName();
                } else if (principal instanceof UsernamePasswordAuthenticationToken) {
                    username = principal.getName();
                    Object credentials = ((UsernamePasswordAuthenticationToken) principal).getCredentials();
                    if (credentials instanceof String) {
                        password = ((String) credentials).toCharArray();
                    } else if (credentials instanceof char[]) {
                        password = (char[]) credentials;
                    }
                }
            }
            if (username == null || password == null) {
                throw new SecurityException("Cannot obtain credentials from exchange: " + exchange);
            }

            LoginContext context = getLoginContext(domain, username, password);
            context.login();
            try {
                authorize(context);
                processor.process(exchange);
            } finally {
                context.logout();
            }
        }
    };
}