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 Project: syndesis   Author: syndesisio   File: OAuthRefreshingEndpoint.java    License: 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 #2
Source Project: syndesis   Author: syndesisio   File: SoapCxfProxyComponent.java    License: 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 #3
Source Project: vertx-camel-bridge   Author: vert-x3   File: CamelBridgeImpl.java    License: 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 #4
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #5
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #6
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #7
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #8
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #9
Source Project: camel-k-runtime   Author: apache   File: KnativeTransportNoop.java    License: 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 #10
Source Project: activiti6-boot2   Author: dingziyang   File: ActivitiEndpoint.java    License: 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 #11
Source Project: syndesis   Author: syndesisio   File: ComponentProxyEndpoint.java    License: 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 #12
Source Project: syndesis   Author: syndesisio   File: AcmeEndpoint.java    License: 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 #13
Source Project: syndesis   Author: syndesisio   File: SyndesisRestSwaggerComponent.java    License: 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 #14
Source Project: funktion-connectors   Author: funktionio   File: K8KafkaEndpoint.java    License: 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 #15
Source Project: flowable-engine   Author: flowable   File: FlowableEndpoint.java    License: 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 #16
Source Project: camelinaction2   Author: camelinaction   File: GoalEndpoint.java    License: 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 #17
Source Project: wildfly-camel   Author: wildfly-extras   File: OpenstackIntegrationTest.java    License: 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 #18
Source Project: wildfly-camel   Author: wildfly-extras   File: HipchatEndpointSupport.java    License: 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 Project: incubator-batchee   Author: apache   File: TestComponent.java    License: 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 #20
Source Project: camel-quarkus   Author: apache   File: WebhookComponentProducer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    return this.producer != null ? this.producer.get() : null;
}
 
Example #21
Source Project: camel-spring-boot   Author: apache   File: DummyEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    throw new UnsupportedOperationException("Cannot produce");
}
 
Example #22
Source Project: camel-k-runtime   Author: apache   File: DummyWebhookComponent.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    throw new UnsupportedOperationException();
}
 
Example #23
Source Project: camel-k-runtime   Author: apache   File: KnativeHttpTransport.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer(Endpoint endpoint, KnativeTransportConfiguration config, KnativeEnvironment.KnativeServiceDefinition service) {
    return new KnativeHttpProducer(this, endpoint, service, this.router.vertx(), vertxHttpClientOptions);
}
 
Example #24
Source Project: syndesis   Author: syndesisio   File: OAuthRefreshingEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    return new ComponentProxyProducer(delegate, pipeline);
}
 
Example #25
Source Project: funktion-connectors   Author: funktionio   File: K8NatsEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    return new NatsProducer(this);
}
 
Example #26
Source Project: funktion-connectors   Author: funktionio   File: JsonEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
    return new JsonProducer(this);
}
 
Example #27
Source Project: DataVec   Author: deeplearning4j   File: DataVecEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public Producer createProducer() throws Exception {
    return new DataVecProducer(this);
}
 
Example #28
Source Project: Ardulink-2   Author: Ardulink   File: ArdulinkEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Producer createProducer() throws Exception {
	return new ArdulinkProducer(this, this.link);
}
 
Example #29
Source Project: mdw   Author: CenturyLinkCloud   File: MdwEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public Producer createProducer() throws Exception {
    return new MdwProducer(this);
}
 
Example #30
Source Project: camelinaction2   Author: camelinaction   File: ErpEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public Producer createProducer() throws Exception {
    return new ErpProducer(this);
}