Java源码示例:org.apache.camel.Body
示例1
@Handler
public void handle(@Body String body, @Headers Map headers, Exchange exchange) {
Random random = new Random(System.currentTimeMillis());
if( random.nextBoolean() ) {
throw new RuntimeCamelException("Random error.. try your luck again next time.");
}
}
示例2
@Handler
public List<Out> process(@Body In body) {
List<Out> out = new ArrayList<>();
out.add(new Out());
return out;
}
示例3
@Handler
public List<Out> process(@Body In body) {
List<Out> out = new ArrayList<>();
out.add(new Out());
return out;
}
示例4
@Handler
public void log(@Body Object body){
if(trace) {
LOGGER.trace("Body is: {}",body);
} else {
LOGGER.info("Body is: {}",body);
}
}
示例5
public void prepareJdbcHeaders(@Body Measure measure, @Headers Map<String, Object> headers) {
headers.put("sensor_type", measure.getSensorType());
headers.put("data_type", measure.getDataType());
headers.put("device_id", measure.getDeviceId());
headers.put("category", measure.getCategory());
headers.put("payload", measure.getPayload());
headers.put("error_code", measure.getErrorCode());
headers.put("error_message", measure.getErrorMessage());
headers.put("time_stamp", measure.getTimestamp());
}
示例6
public Measure processRules(@Body Measure measure) {
KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(
kieHost, kieUser,
kiePassword);
Set<Class<?>> jaxBClasses = new HashSet<Class<?>>();
jaxBClasses.add(Measure.class);
config.addJaxbClasses(jaxBClasses);
config.setMarshallingFormat(MarshallingFormat.JAXB);
RuleServicesClient client = KieServicesFactory.newKieServicesClient(config)
.getServicesClient(RuleServicesClient.class);
List<Command<?>> cmds = new ArrayList<Command<?>>();
KieCommands commands = KieServices.Factory.get().getCommands();
cmds.add(commands.newInsert(measure));
GetObjectsCommand getObjectsCommand = new GetObjectsCommand();
getObjectsCommand.setOutIdentifier("objects");
cmds.add(commands.newFireAllRules());
cmds.add(getObjectsCommand);
BatchExecutionCommand myCommands = CommandFactory.newBatchExecution(cmds,
"DecisionTableKS");
ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("iot-ocp-businessrules-service", myCommands);
List responseList = (List) response.getResult().getValue("objects");
Measure responseMeasure = (Measure) responseList.get(0);
return responseMeasure;
}
示例7
public void addItem(@Header("sessionId") String sessionId, @Body CartDto dto) {
LOG.info("addItem {} {}", sessionId, dto);
Set<CartDto> dtos = content.get(sessionId);
if (dtos == null) {
dtos = new LinkedHashSet<>();
content.put(sessionId, dtos);
}
dtos.add(dto);
}
示例8
public void addItem(@Header("sessionId") String sessionId, @Body CartDto dto) {
LOG.info("addItem {} {}", sessionId, dto);
Set<CartDto> dtos = content.get(sessionId);
if (dtos == null) {
dtos = new LinkedHashSet<>();
content.put(sessionId, dtos);
}
dtos.add(dto);
}
示例9
public Document handleIncomingOrder(@Body Document xml,
@XPath("/order/@customerId") int customerId,
@Bean(ref = "guid", method = "generate") int orderId) {
Attr attr = xml.createAttribute("orderId");
attr.setValue("" + orderId);
Node node = xml.getElementsByTagName("order").item(0);
node.getAttributes().setNamedItem(attr);
return xml;
}
示例10
public Document handleIncomingOrder(@Body Document xml,
@XPath(value = "/c:order/@customerId",
namespaces = @NamespacePrefix(
prefix = "c",
uri = "http://camelinaction.com/order")) int customerId,
@Bean(ref = "guid", method = "generate") int orderId) {
Attr attr = xml.createAttribute("orderId");
attr.setValue("" + orderId);
Node node = xml.getElementsByTagName("order").item(0);
node.getAttributes().setNamedItem(attr);
return xml;
}
示例11
public Document handleIncomingOrder(@Body Document xml,
@XPath("/order/@customerId") int customerId,
@Bean(ref = "guid", method = "generate") int orderId) {
Attr attr = xml.createAttribute("orderId");
attr.setValue("" + orderId);
Node node = xml.getElementsByTagName("order").item(0);
node.getAttributes().setNamedItem(attr);
return xml;
}
示例12
public Document handleIncomingOrder(@Body Document xml,
@XPath(value = "/c:order/@customerId",
namespaces = @NamespacePrefix(
prefix = "c",
uri = "http://camelinaction.com/order")) int customerId,
@Bean(ref = "guid", method = "generate") int orderId) {
Attr attr = xml.createAttribute("orderId");
attr.setValue("" + orderId);
Node node = xml.getElementsByTagName("order").item(0);
node.getAttributes().setNamedItem(attr);
return xml;
}
示例13
@Handler
public Map getProcessVariables(@Body String body,
@Header(Exchange.FILE_NAME) String filename,
@Simple("${date:now:yyyy-MM-dd kk:mm:ss}") String timestamp) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("message", body);
variables.put("orderid", filename);
variables.put("timestamp", timestamp);
return variables;
}
示例14
@Handler
public String apply(@Body String body) {
return "Hello " + body;
}
示例15
@Handler
public int apply(@Body String body) {
return body.hashCode();
}
示例16
@Handler
public String[] apply(@Body String body) {
return new String[]{ "Hiram", "World" };
}
示例17
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例18
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例19
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例20
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例21
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例22
public String process(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例23
@SuppressWarnings("static-method")
public String myProcessor(@Body String body) {
return body.toUpperCase(Locale.US);
}
示例24
@Handler
public void handle(@Body String body) {
// NO-OP
}
示例25
public void getPerson(@Body String id,Exchange exchange){
Person result = persons.get(Integer.parseInt(id));
checkResult(id, exchange, result);
}
示例26
public void deletePerson(@Body String id,Exchange exchange){
Person result = persons.remove(Integer.parseInt(id));
checkResult(id, exchange, result);
}
示例27
public String orderStatus(@Header("customerId") Integer customerId, @Body Integer orderId) {
return "Order " + orderId + " from customer " + customerId;
}
示例28
public String sayHello(@Body String message) {
return "Hello " + message;
}