org.apache.camel.Producer Java Examples

The following examples show how to use org.apache.camel.Producer. 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: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createSwiftContainer() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    when(containerService.create(anyString(), nullable(CreateUpdateContainerOptions.class))).thenReturn(actionResponse);
    when(actionResponse.isSuccess()).thenReturn(true);

    SwiftEndpoint endpoint = Mockito.mock(SwiftEndpoint.class);
    Producer producer = new ContainerProducer(endpoint, client);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);

    producer.process(exchange);

    ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class);

    verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture());
    assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
    assertNull(optionsCaptor.getValue());
}
 
Example #2
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createNeutronNetwork() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName());
    msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType());
    msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId());

    NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class);
    Producer producer = new NetworkProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class);
    verify(networkService).create(captor.capture());

    assertEqualsNetwork(dummyNetwork, captor.getValue());
    assertNotNull(msg.getBody(Network.class).getId());
}
 
Example #3
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createKeystoneProject() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyProject.getName());
    msg.setHeader(KeystoneConstants.DESCRIPTION, dummyProject.getDescription());
    msg.setHeader(KeystoneConstants.DOMAIN_ID, dummyProject.getDomainId());
    msg.setHeader(KeystoneConstants.PARENT_ID, dummyProject.getParentId());

    KeystoneEndpoint endpoint = Mockito.mock(KeystoneEndpoint.class);
    Producer producer = new ProjectProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<Project> captor = ArgumentCaptor.forClass(Project.class);
    verify(projectService).create(captor.capture());

    assertEqualsProject(dummyProject, captor.getValue());
}
 
Example #4
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void reserveGlanceImage() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    GlanceEndpoint endpoint = Mockito.mock(GlanceEndpoint.class);
    when(endpoint.getOperation()).thenReturn(GlanceConstants.RESERVE);

    Message msg = new DefaultMessage(camelContext);
    msg.setBody(dummyImage);

    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    Producer producer = new GlanceProducer(endpoint, client);
    producer.process(exchange);
    ArgumentCaptor<Image> captor = ArgumentCaptor.forClass(Image.class);
    verify(imageService).reserve(captor.capture());
    assertEquals(dummyImage, captor.getValue());

    Image result = msg.getBody(Image.class);
    assertNotNull(result.getId());
    assertEqualsImages(dummyImage, result);
}
 
Example #5
Source File: OAuthRefreshingEndpoint.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public OAuthRefreshingEndpoint(final ComponentProxyComponent component, final Endpoint endpoint,
    final OAuthRefreshTokenOnFailProcessor retryProcessor) {
    super(endpoint.getEndpointUri(), component, endpoint);
    delegate = endpoint;

    final Producer producer;
    try {
        producer = endpoint.createProducer();
    } catch (final Exception e) {
        throw new ExceptionInInitializerError(e);
    }

    final Processor catchBody = retryProcessor;

    final Processor catchProcessor = new CatchProcessor(EXCEPTIONS_HANDLED, catchBody, null, null);

    final Processor tryProcessor = new TryProcessor(component.getCamelContext(), producer,
        singletonList(catchProcessor), null);

    pipeline = new Pipeline(delegate.getCamelContext(), singletonList(tryProcessor));
}
 
Example #6
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void createCinderVolume() throws Exception {
    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    CinderEndpoint endpoint = Mockito.mock(CinderEndpoint.class);
    when(endpoint.getOperation()).thenReturn(OpenstackConstants.CREATE);
    msg.setBody(dummyVolume);

    Producer producer = new VolumeProducer(endpoint, client);
    producer.process(exchange);
    assertEqualVolumes(dummyVolume, msg.getBody(Volume.class));
}
 
Example #7
Source File: CamelBridgeImpl.java    From vertx-camel-bridge with Apache License 2.0 6 votes vote down vote up
private void createOutboundBridge(Vertx vertx, OutboundMapping outbound) {
  Endpoint endpoint = validate(outbound);

  Producer producer;
  try {
    producer = endpoint.createProducer();
    camelProducers.add(producer);
  } catch (Exception e) {
    throw new IllegalStateException("The endpoint " + outbound.getUri() + " does not support producers", e);
  }

  LOGGER.debug("Creating Vert.x message consumer for " + outbound.getUri() + " receiving messages from "
    + outbound.getAddress());

  vertxConsumers.add(vertx.eventBus().consumer(outbound.getAddress(),
      new FromVertxToCamelProducer(vertx, producer, outbound, outbound.isBlocking(), outbound.getWorkerExecutor())));

  LOGGER.info("Created Vert.x message consumer for " + outbound.getUri() + " receiving messages from "
    + outbound.getAddress());
}
 
Example #8
Source File: SoapCxfProxyComponent.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
protected Endpoint createDelegateEndpoint(ComponentDefinition definition, String scheme,
                                          Map<String, String> options) {

    final Endpoint delegateEndpoint = super.createDelegateEndpoint(definition, scheme, options);

    // wrap the delegate in a proxy that decorates the CXF producer
    final boolean isSoap11 = Soap11.getInstance().equals(soapVersion);
    return new ComponentProxyEndpoint(delegateEndpoint.getEndpointUri(), this, delegateEndpoint) {

        @Override
        public Producer createProducer() throws Exception {
            final CamelContext context = getCamelContext();

            // replace with a try-catch pipeline to handle SOAP faults
            return new ComponentProxyProducer(this, Pipeline.newInstance(context,
                new TryProcessor(context, super.createProducer(),
                    Collections.singletonList(new CatchProcessor(Collections.singletonList(SoapFault.class),
                        (isSoap11 ? new Soap11FaultSoapPayloadConverter(exceptionMessageCauseEnabled) :
                            new Soap12FaultSoapPayloadConverter(exceptionMessageCauseEnabled)), null, null)), null)));
        }
    };
}
 
Example #9
Source File: TestComponent.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Override
protected Endpoint createEndpoint(final String uri, final String remaining, final Map<String, Object> parameters) throws Exception {
    final String value = String.class.cast(parameters.remove("value"));
    return new DefaultEndpoint() {
        @Override
        protected String createEndpointUri() {
            return uri;
        }

        @Override
        public Producer createProducer() throws Exception {
            return new DefaultProducer(this) {
                @Override
                public void process(final Exchange exchange) throws Exception {
                    exchange.getIn().setBody(exchange.getIn().getBody(String.class) + value);
                }
            };
        }

        @Override
        public Consumer createConsumer(final Processor processor) throws Exception {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean isSingleton() {
            return true;
        }
    };
}
 
Example #10
Source File: GoalEndpoint.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    // load games from resource
    InputStream is = getResourceAsInputStream();
    String text = IOHelper.loadText(is);

    // store games in a list
    Stream<String> stream = Arrays.stream(text.split("\n"));
    List<String> games = stream.collect(Collectors.toList());

    // create producer with the games
    return new GoalProducer(this, games);
}
 
Example #11
Source File: FlowableEndpoint.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    FlowableProducer producer = new FlowableProducer(this, getTimeout(), getTimeResolution());
    producer.setRuntimeService(runtimeService);
    producer.setIdentityService(identityService);
    producer.setRepositoryService(repositoryService);
    producer.setManagementService(managementService);
    return producer;
}
 
Example #12
Source File: OpenstackIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testNovaKeypair() throws Exception {
    when(osTestKeypair.getName()).thenReturn(KEYPAIR_NAME);
    when(osTestKeypair.getPublicKey()).thenReturn(dummyKeypair.getPublicKey());
    when(osTestKeypair.getFingerprint()).thenReturn("fp");
    when(osTestKeypair.getPrivateKey()).thenReturn("prk");

    ExtendedCamelContext camelContext = Mockito.mock(ExtendedCamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());

    Message msg = new DefaultMessage(camelContext);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, KEYPAIR_NAME);

    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);

    NovaEndpoint endpoint = Mockito.mock(NovaEndpoint.class);
    Producer producer = new KeypairProducer(endpoint, client);
    producer.process(exchange);

    ArgumentCaptor<String> nameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> keypairCaptor = ArgumentCaptor.forClass(String.class);
    verify(keypairService).create(nameCaptor.capture(), keypairCaptor.capture());

    assertEquals(KEYPAIR_NAME, nameCaptor.getValue());
    assertNull(keypairCaptor.getValue());

    Keypair result = msg.getBody(Keypair.class);
    assertEquals("fp", result.getFingerprint());
    assertEquals("prk", result.getPrivateKey());
    assertEquals(dummyKeypair.getName(), result.getName());
    assertEquals(dummyKeypair.getPublicKey(), result.getPublicKey());
}
 
Example #13
Source File: K8KafkaEndpoint.java    From funktion-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    KafkaProducer producer = createProducer(this);
    if (isSynchronous()) {
        return new SynchronousDelegateProducer(producer);
    } else {
        return producer;
    }
}
 
Example #14
Source File: AcmeEndpoint.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    return new DefaultProducer(this) {
        @Override
        public void process(Exchange exchange) throws Exception {
            // no-op
        }
    };
}
 
Example #15
Source File: ComponentProxyEndpoint.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public Producer createProducer() throws Exception {
    final Producer producer = endpoint.createProducer();

    final Processor beforeProducer = getBeforeProducer();
    final Processor afterProducer = getAfterProducer();

    // use a pipeline to process before, producer, after in that order
    // create producer with the pipeline
    final Processor pipeline = Pipeline.newInstance(getCamelContext(), beforeProducer, producer, afterProducer);

    return new ComponentProxyProducer(endpoint, pipeline);
}
 
Example #16
Source File: ActivitiEndpoint.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public Producer createProducer() throws Exception {
  ActivitiProducer producer = new ActivitiProducer(this, getTimeout(), getTimeResolution());
  producer.setRuntimeService(runtimeService);
  producer.setIdentityService(identityService);
  producer.setRepositoryService(repositoryService);
  return producer;
}
 
Example #17
Source File: KnativeTransportNoop.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public Producer createProducer(Endpoint endpoint, KnativeTransportConfiguration configuration, KnativeEnvironment.KnativeServiceDefinition service) {
    return new DefaultProducer(endpoint) {
        @Override
        public void process(Exchange exchange) throws Exception {
        }
    };
}
 
Example #18
Source File: HipchatEndpointSupport.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public Producer createProducer() throws Exception {
    return new HipchatProducer(this) {
        @Override
        protected StatusLine post(String urlPath, Map<String, String> postParam) throws IOException {
            callback.call(postParam);
            return new BasicStatusLine(new ProtocolVersion("any", 1, 1), 204, "");
        }
    };
}
 
Example #19
Source File: SyndesisRestSwaggerComponent.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("PMD.ExcessiveParameterList") // overriden method
public Producer createProducer(final CamelContext camelContext, final String host, final String verb, final String basePath, final String uriTemplate,
    final String queryParameters, final String consumes, final String produces, final RestConfiguration configuration, final Map<String, Object> parameters)
    throws Exception {

    final HttpProducer producer = (HttpProducer) super.createProducer(camelContext, host, verb, basePath, uriTemplate, queryParameters, consumes, produces,
        configuration, parameters);

    for (final Consumer<HttpProducer> customizer : CUSTOMIZERS) {
        customizer.accept(producer);
    }

    return producer;
}
 
Example #20
Source File: file_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
protected static void setToEndpoint(Exchange exchange, Processor processor) {
    if (processor instanceof Producer) {
        Producer producer = (Producer) processor;
        exchange.setProperty(Exchange.TO_ENDPOINT, producer.getEndpoint().getEndpointUri());
    }
}
 
Example #21
Source File: patched.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
public Producer getProducer() {
    if (processor instanceof Producer) {
        return (Producer) processor;
    }
    return null;
}
 
Example #22
Source File: patched.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void doProcessParallel(final ProcessorExchangePair pair) throws Exception {
    final Exchange exchange = pair.getExchange();
    Processor processor = pair.getProcessor();
    Producer producer = pair.getProducer();

    TracedRouteNodes traced = exchange.getUnitOfWork() != null ? exchange.getUnitOfWork().getTracedRouteNodes() : null;

    // compute time taken if sending to another endpoint
    StopWatch watch = null;
    if (producer != null) {
        watch = new StopWatch();
    }

    try {
        // prepare tracing starting from a new block
        if (traced != null) {
            traced.pushBlock();
        }

        if (producer != null) {
            EventHelper.notifyExchangeSending(exchange.getContext(), exchange, producer.getEndpoint());
        }
        // let the prepared process it, remember to begin the exchange pair
        AsyncProcessor async = AsyncProcessorConverterHelper.convert(processor);
        pair.begin();
        // we invoke it synchronously as parallel async routing is too hard
        AsyncProcessorHelper.process(async, exchange);
    } finally {
        pair.done();
        // pop the block so by next round we have the same staring point and thus the tracing looks accurate
        if (traced != null) {
            traced.popBlock();
        }
        if (producer != null) {
            long timeTaken = watch.stop();
            Endpoint endpoint = producer.getEndpoint();
            // emit event that the exchange was sent to the endpoint
            // this is okay to do here in the finally block, as the processing is not using the async routing engine
            //( we invoke it synchronously as parallel async routing is too hard)
            EventHelper.notifyExchangeSent(exchange.getContext(), exchange, endpoint, timeTaken);
        }
    }
}
 
Example #23
Source File: patched.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
protected static void setToEndpoint(Exchange exchange, Processor processor) {
    if (processor instanceof Producer) {
        Producer producer = (Producer) processor;
        exchange.setProperty(Exchange.TO_ENDPOINT, producer.getEndpoint().getEndpointUri());
    }
}
 
Example #24
Source File: original.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
public Producer getProducer() {
    if (processor instanceof Producer) {
        return (Producer) processor;
    }
    return null;
}
 
Example #25
Source File: original.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void doProcessParallel(final ProcessorExchangePair pair) throws Exception {
    final Exchange exchange = pair.getExchange();
    Processor processor = pair.getProcessor();
    Producer producer = pair.getProducer();

    TracedRouteNodes traced = exchange.getUnitOfWork() != null ? exchange.getUnitOfWork().getTracedRouteNodes() : null;

    // compute time taken if sending to another endpoint
    StopWatch watch = null;
    if (producer != null) {
        watch = new StopWatch();
    }

    try {
        // prepare tracing starting from a new block
        if (traced != null) {
            traced.pushBlock();
        }

        if (producer != null) {
            EventHelper.notifyExchangeSending(exchange.getContext(), exchange, producer.getEndpoint());
        }
        // let the prepared process it, remember to begin the exchange pair
        AsyncProcessor async = AsyncProcessorConverterHelper.convert(processor);
        pair.begin();
        // we invoke it synchronously as parallel async routing is too hard
        AsyncProcessorHelper.process(async, exchange);
    } finally {
        pair.done();
        // pop the block so by next round we have the same staring point and thus the tracing looks accurate
        if (traced != null) {
            traced.popBlock();
        }
        if (producer != null) {
            long timeTaken = watch.stop();
            Endpoint endpoint = producer.getEndpoint();
            // emit event that the exchange was sent to the endpoint
            // this is okay to do here in the finally block, as the processing is not using the async routing engine
            //( we invoke it synchronously as parallel async routing is too hard)
            EventHelper.notifyExchangeSent(exchange.getContext(), exchange, endpoint, timeTaken);
        }
    }
}
 
Example #26
Source File: original.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
protected static void setToEndpoint(Exchange exchange, Processor processor) {
    if (processor instanceof Producer) {
        Producer producer = (Producer) processor;
        exchange.setProperty(Exchange.TO_ENDPOINT, producer.getEndpoint().getEndpointUri());
    }
}
 
Example #27
Source File: file_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
public Producer getProducer() {
    if (processor instanceof Producer) {
        return (Producer) processor;
    }
    return null;
}
 
Example #28
Source File: file_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void doProcessParallel(final ProcessorExchangePair pair) throws Exception {
    final Exchange exchange = pair.getExchange();
    Processor processor = pair.getProcessor();
    Producer producer = pair.getProducer();

    TracedRouteNodes traced = exchange.getUnitOfWork() != null ? exchange.getUnitOfWork().getTracedRouteNodes() : null;

    // compute time taken if sending to another endpoint
    StopWatch watch = null;
    if (producer != null) {
        watch = new StopWatch();
    }

    try {
        // prepare tracing starting from a new block
        if (traced != null) {
            traced.pushBlock();
        }

        if (producer != null) {
            EventHelper.notifyExchangeSending(exchange.getContext(), exchange, producer.getEndpoint());
        }
        // let the prepared process it, remember to begin the exchange pair
        AsyncProcessor async = AsyncProcessorConverterHelper.convert(processor);
        pair.begin();
        // we invoke it synchronously as parallel async routing is too hard
        AsyncProcessorHelper.process(async, exchange);
    } finally {
        pair.done();
        // pop the block so by next round we have the same staring point and thus the tracing looks accurate
        if (traced != null) {
            traced.popBlock();
        }
        if (producer != null) {
            long timeTaken = watch.stop();
            Endpoint endpoint = producer.getEndpoint();
            // emit event that the exchange was sent to the endpoint
            // this is okay to do here in the finally block, as the processing is not using the async routing engine
            //( we invoke it synchronously as parallel async routing is too hard)
            EventHelper.notifyExchangeSent(exchange.getContext(), exchange, endpoint, timeTaken);
        }
    }
}
 
Example #29
Source File: file_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
protected static void setToEndpoint(Exchange exchange, Processor processor) {
    if (processor instanceof Producer) {
        Producer producer = (Producer) processor;
        exchange.setProperty(Exchange.TO_ENDPOINT, producer.getEndpoint().getEndpointUri());
    }
}
 
Example #30
Source File: file_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
public Producer getProducer() {
    if (processor instanceof Producer) {
        return (Producer) processor;
    }
    return null;
}