1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.onehippo.forge.camel.scheduling;
17
18 import javax.jcr.RepositoryException;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.onehippo.forge.camel.util.CamelContextUtils;
22 import org.onehippo.repository.scheduling.RepositoryJob;
23 import org.onehippo.repository.scheduling.RepositoryJobExecutionContext;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27
28
29
30
31
32
33
34
35
36
37 public class DefaultCamelRepositoryJob implements RepositoryJob {
38
39 private static Logger log = LoggerFactory.getLogger(DefaultCamelRepositoryJob.class);
40
41 public static final String CAMEL_ENDPOINT_URI_ATTR = "camel.endpoint.uri";
42
43 public static final String CAMEL_CONTEXT_ID_ATTR = "camel.context.id";
44
45 @Override
46 public void execute(RepositoryJobExecutionContext context) throws RepositoryException {
47 String endpointUri = context.getAttribute(CAMEL_ENDPOINT_URI_ATTR);
48
49 if (StringUtils.isBlank(endpointUri)) {
50 throw new RepositoryException("Invalid Camel Endpoint URI: '" + endpointUri + "'.");
51 }
52
53 String camelContextId = context.getAttribute(CAMEL_CONTEXT_ID_ATTR);
54
55 CamelContextUtils.invokeManagedCamelContextMBean(camelContextId,
56 "sendBody",
57 new Object[] { endpointUri, context },
58 new String[] { "java.lang.String", "java.lang.Object" });
59 }
60
61 }