Пример #1
0
  @Override
  public Processor createProcessor(RouteContext routeContext) throws Exception {
    if (ObjectHelper.isEmpty(resourceUri) && ObjectHelper.isEmpty(resourceRef)) {
      throw new IllegalArgumentException(
          "Either uri or ref must be provided for resource endpoint");
    }

    // lookup endpoint
    Endpoint endpoint;
    if (resourceUri != null) {
      endpoint = routeContext.resolveEndpoint(resourceUri);
    } else {
      endpoint = routeContext.resolveEndpoint(null, resourceRef);
    }

    PollEnricher enricher;
    if (timeout != null) {
      enricher = new PollEnricher(null, endpoint.createPollingConsumer(), timeout);
    } else {
      // if no timeout then we should block, and there use a negative timeout
      enricher = new PollEnricher(null, endpoint.createPollingConsumer(), -1);
    }

    AggregationStrategy strategy = createAggregationStrategy(routeContext);
    if (strategy == null) {
      enricher.setDefaultAggregationStrategy();
    } else {
      enricher.setAggregationStrategy(strategy);
    }
    if (getAggregateOnException() != null) {
      enricher.setAggregateOnException(getAggregateOnException());
    }

    return enricher;
  }
    private void postMessage(final String type) {
      final String id = (String) list.getSelectedValue();
      if (id == null) {
        return;
      }
      list.clearSelection();

      //			final Endpoint endpoint = context.getEndpoint("http4://localhost:8122/");
      //			final Exchange exchange = endpoint.createExchange();
      //			exchange.getIn().setHeader(Exchange.HTTP_METHOD, "POST");
      //			exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "text/plain");
      //			exchange.getIn().setBody(id + ":" + type);
      //			producerTemplate.asyncSend(endpoint, exchange);

      // final String url = "jms:queue:itk-trunk/" + id + "/" + type.split("\\|")[0];

      final String url = "jms:topic:document-ebxml-acks";
      System.out.println("Sending message to: " + url);

      final Endpoint endpoint = context.getEndpoint(url);
      final Exchange exchange = endpoint.createExchange();
      exchange.getIn().setHeader("JMSCorrelationID", id);
      exchange.getIn().setBody(type.split("\\|")[1]);
      producerTemplate.send(endpoint, exchange);
    }
Пример #3
0
 public Endpoint resolveEndpoint(String uri, String ref) {
   Endpoint endpoint = null;
   if (uri != null) {
     endpoint = resolveEndpoint(uri);
     if (endpoint == null) {
       throw new NoSuchEndpointException(uri);
     }
   }
   if (ref != null) {
     endpoint = lookup(ref, Endpoint.class);
     if (endpoint == null) {
       throw new NoSuchEndpointException("ref:" + ref, "check your camel registry with id " + ref);
     }
     // Check the endpoint has the right CamelContext
     if (!this.getCamelContext().equals(endpoint.getCamelContext())) {
       throw new NoSuchEndpointException(
           "ref:" + ref, "make sure the endpoint has the same camel context as the route does.");
     }
     try {
       // need add the endpoint into service
       getCamelContext().addService(endpoint);
     } catch (Exception ex) {
       throw new RuntimeCamelException(ex);
     }
   }
   if (endpoint == null) {
     throw new IllegalArgumentException("Either 'uri' or 'ref' must be specified on: " + this);
   } else {
     return endpoint;
   }
 }
Пример #4
0
 protected ActivitiEndpoint getEndpoint(String key) {
   for (Endpoint e : camelContextObj.getEndpoints()) {
     if (e.getEndpointKey().equals(key) && (e instanceof ActivitiEndpoint)) {
       return (ActivitiEndpoint) e;
     }
   }
   throw new RuntimeException("Activiti endpoint not defined for " + key);
 }
Пример #5
0
 private Consumer createConsumerFor(String path) throws Exception {
   Endpoint endpoint = context.getEndpoint("cmis://" + path);
   return endpoint.createConsumer(
       new Processor() {
         public void process(Exchange exchange) throws Exception {
           template.send("mock:result", exchange);
         }
       });
 }
Пример #6
0
 private void prepareFtpServer() throws Exception {
   // prepares the FTP Server by creating a file on the server
   Endpoint endpoint = context.getEndpoint(getFtpUrl());
   Exchange exchange = endpoint.createExchange();
   exchange.getIn().setBody("Hello World");
   exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
   Producer producer = endpoint.createProducer();
   producer.start();
   producer.process(exchange);
   producer.stop();
 }
Пример #7
0
  public boolean canSendToEndpoint(String endpointUri) {
    try {
      Endpoint endpoint = context.getEndpoint(endpointUri);
      if (endpoint != null) {
        Producer producer = endpoint.createProducer();
        return producer != null;
      }
    } catch (Exception e) {
      // ignore
    }

    return false;
  }
  @Test
  public void testProducerSingletonism() throws Exception {
    // given
    Endpoint endpoint = context.getEndpoint("smslib://asdf");
    endpoint.createProducer();

    // when then
    try {
      endpoint.createProducer();
      fail();
    } catch (Exception e) {
      // expected
    }
  }
Пример #9
0
  protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
      throws Exception {
    // split remaining path to get API name and method
    final String[] pathElements = remaining.split("/");
    String apiNameStr;
    String methodName;
    switch (pathElements.length) {
      case 1:
        apiNameStr = "";
        methodName = pathElements[0];
        break;
      case 2:
        apiNameStr = pathElements[0];
        methodName = pathElements[1];
        break;
      default:
        throw new CamelException(
            "Invalid URI path ["
                + remaining
                + "], must be of the format "
                + collection.getApiNames()
                + "/<operation-name>");
    }

    try {
      // get API enum from apiName string
      final E apiName = getApiName(apiNameStr);

      final T endpointConfiguration = createEndpointConfiguration(apiName);
      final Endpoint endpoint = createEndpoint(uri, methodName, apiName, endpointConfiguration);

      // set endpoint property inBody
      setProperties(endpoint, parameters);

      // configure endpoint properties and initialize state
      endpoint.configureProperties(parameters);

      return endpoint;
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof IllegalArgumentException) {
        throw new CamelException(
            "Invalid URI path prefix ["
                + remaining
                + "], must be one of "
                + collection.getApiNames());
      }
      throw e;
    }
  }
  public void testConsumerSingletonism() throws Exception {
    // given
    Endpoint endpoint = context.getEndpoint("smslib://asdf");
    Processor mockProcessor = mock(Processor.class);
    endpoint.createConsumer(mockProcessor);
    Processor anotherMockProcessor = mock(Processor.class);

    // when then
    try {
      endpoint.createConsumer(anotherMockProcessor);
      fail("Should only be able to create a single consumer.");
    } catch (Exception e) {
      // expected
    }
  }
Пример #11
0
 /**
  * Factory method to lazily create the complete list of services required for this route such as
  * adding the processor or consumer
  */
 @Override
 protected void addServices(List<Service> services) throws Exception {
   Endpoint endpoint = getEndpoint();
   consumer = endpoint.createConsumer(processor);
   if (consumer != null) {
     services.add(consumer);
     if (consumer instanceof RouteAware) {
       ((RouteAware) consumer).setRoute(this);
     }
   }
   Processor processor = getProcessor();
   if (processor instanceof Service) {
     services.add((Service) processor);
   }
 }
  @Test
  public void sendLongSubmitSM() throws Exception {
    result.expectedMessageCount(2);

    Exchange exchange = start.createExchange(ExchangePattern.InOnly);
    exchange
        .getIn()
        .setBody(
            "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "); // 270 chars

    template.send(start, exchange);

    assertMockEndpointsSatisfied();
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        result.getExchanges().get(0).getIn().getHeader(SmppConstants.MESSAGE_TYPE));
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        result.getExchanges().get(1).getIn().getHeader(SmppConstants.MESSAGE_TYPE));

    assertNotNull(exchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(2, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
  }
  @Test
  public void sendSubmitSMInOnly() throws Exception {
    result.expectedMessageCount(1);

    Exchange exchange = start.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody("Hello SMPP World!");

    template.send(start, exchange);

    assertMockEndpointsSatisfied();
    Exchange resultExchange = result.getExchanges().get(0);
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE));
    assertEquals("Hello SMPP World!", resultExchange.getIn().getBody());
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED));
    assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED));
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE));
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE));
    assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR));

    assertNotNull(exchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
  }
Пример #14
0
 public void setEndpoint(Endpoint endpoint) {
   this.endpoint = endpoint;
   this.uri = null;
   if (endpoint != null) {
     this.uri = endpoint.getEndpointUri();
   }
 }
Пример #15
0
 /** Returns the endpoint URI or the name of the reference to it */
 public Object getUriOrRef() {
   if (ObjectHelper.isNotEmpty(uri)) {
     return uri;
   } else if (endpoint != null) {
     return endpoint.getEndpointUri();
   }
   return ref;
 }
Пример #16
0
  private void prepareFtpServer() throws Exception {
    // prepares the FTP Server by creating a file on the server that we want to unit
    // test that we can pool and store as a local file
    Endpoint endpoint = context.getEndpoint(getFtpUrl());
    Exchange exchange = endpoint.createExchange();
    exchange.getIn().setBody("Hello World this file will be moved");
    exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);
    producer.stop();

    // assert file is created
    File file = new File(FTP_ROOT_DIR + "movefile/hello.txt");
    file = file.getAbsoluteFile();
    assertTrue("The file should exists", file.exists());
  }
  @Test
  public void sendDataSM() throws Exception {
    Exchange exchange = start.createExchange(ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");

    template.send(start, exchange);

    assertNotNull(exchange.getOut().getHeader(SmppConstants.ID));
  }
Пример #18
0
 public String getUri() {
   if (uri != null) {
     return uri;
   } else if (endpoint != null) {
     return endpoint.getEndpointUri();
   } else {
     return null;
   }
 }
  private Exchange sendExchange(boolean setException) throws Exception {
    Endpoint endpoint =
        context.getEndpoint(
            "mina:tcp://localhost:{{port}}?sync=true&encoding=UTF-8&transferExchange=true");
    Exchange exchange = endpoint.createExchange();

    Message message = exchange.getIn();
    message.setBody("Hello!");
    message.setHeader("cheese", "feta");
    exchange.setProperty("ham", "old");
    exchange.setProperty("setException", setException);

    Producer producer = endpoint.createProducer();
    producer.start();
    producer.process(exchange);

    return exchange;
  }
  @Test
  public void sendCancelSM() throws Exception {
    Exchange exchange = start.createExchange(ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "CancelSm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");

    template.send(start, exchange);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
  }
Пример #21
0
 // Implementation methods
 // -----------------------------------------------------------------------
 protected static String description(String uri, String ref, Endpoint endpoint) {
   if (ref != null) {
     return "ref:" + ref;
   } else if (endpoint != null) {
     return endpoint.getEndpointUri();
   } else if (uri != null) {
     return uri;
   } else {
     return "no uri or ref supplied!";
   }
 }
  @Test
  public void sendReplaceSM() throws Exception {
    Exchange exchange = start.createExchange(ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "ReplaceSm");
    exchange.getIn().setBody("Hello Camel World!");
    exchange.getIn().setHeader(SmppConstants.ID, "1");

    template.send(start, exchange);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
  }
  @Test
  public void sendQuerySM() throws Exception {
    Exchange exchange = start.createExchange(ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "QuerySm");
    exchange.getIn().setHeader(SmppConstants.ID, "1");

    template.send(start, exchange);

    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals((byte) 0, exchange.getOut().getHeader(SmppConstants.ERROR));
    assertNotNull(exchange.getOut().getHeader(SmppConstants.FINAL_DATE));
    assertEquals("DELIVERED", exchange.getOut().getHeader(SmppConstants.MESSAGE_STATE));
  }
Пример #24
0
  @Override
  protected void doStart() throws Exception {
    ObjectHelper.notNull(camelContext, "camelContext", this);
    if (endpoint == null && endpointUri == null) {
      throw new IllegalArgumentException("Either endpoint or endpointUri must be configured");
    }

    if (endpoint == null) {
      endpoint = camelContext.getEndpoint(endpointUri);
    }

    producer = endpoint.createProducer();
    ServiceHelper.startService(producer);
  }
 private static final void setEndpointUri(Endpoint endpoint, String namespace) {
   if (endpoint instanceof DefaultEndpoint) {
     String old_uri = endpoint.getEndpointUri();
     String new_uri = addNamespaceParameter(old_uri, namespace);
     if (!old_uri.equals(new_uri)) {
       try {
         Method setEndpointUri =
             DefaultEndpoint.class.getDeclaredMethod("setEndpointUri", new Class[] {String.class});
         new MethodAccess<String>(null, setEndpointUri).write((DefaultEndpoint) endpoint, new_uri);
       } catch (NoSuchMethodException nsfe) {
         throw new SwitchYardException(nsfe);
       }
     }
   }
 }
  @Test
  public void sendSubmitMultiSM() throws Exception {
    Exchange exchange = start.createExchange(ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange
        .getIn()
        .setBody(
            "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "); // 270 chars

    template.send(start, exchange);

    assertNotNull(exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals(2, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
  }
  /**
   * Test method for {@link
   * org.apache.camel.component.websocket.WebsocketConsumer#sendExchange(java.lang.String,
   * java.lang.String)} .
   */
  @Test
  public void testSendExchange() throws Exception {
    when(endpoint.createExchange()).thenReturn(exchange);
    when(exchange.getOut()).thenReturn(outMessage);

    websocketConsumer.sendExchange(CONNECTION_KEY, MESSAGE);

    InOrder inOrder = inOrder(endpoint, exceptionHandler, processor, exchange, outMessage);
    inOrder.verify(endpoint, times(1)).createExchange();
    inOrder.verify(exchange, times(1)).getOut();
    inOrder
        .verify(outMessage, times(1))
        .setHeader(WebsocketConstants.CONNECTION_KEY, CONNECTION_KEY);
    inOrder.verify(exchange, times(1)).getOut();
    inOrder.verify(outMessage, times(1)).setBody(MESSAGE);
    inOrder.verify(processor, times(1)).process(exchange);
    inOrder.verifyNoMoreInteractions();
  }
Пример #28
0
 public DefaultExchange(Endpoint fromEndpoint, ExchangePattern pattern) {
   this(fromEndpoint.getCamelContext(), pattern);
   this.fromEndpoint = fromEndpoint;
 }
Пример #29
0
 @Override
 public String toString() {
   return "Consumer[" + URISupport.sanitizeUri(endpoint.getEndpointUri()) + "]";
 }
 public void setDeadLetter(Endpoint deadLetter) {
   this.deadLetter = deadLetter;
   this.deadLetterUri = deadLetter.getEndpointUri();
 }