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; }
public Map<String, Object> defineNamedParameters(@Body Account account) { Map<String, Object> map = new HashMap<String, Object>(); map.put("CLIENT_ID", account.getClientId()); map.put("SALES_CONTACT", account.getSalesRepresentative()); map.put("COMPANY_NAME", account.getCompany().getName()); map.put("COMPANY_GEO", account.getCompany().getGeo()); map.put("COMPANY_ACTIVE", account.getCompany().isActive()); map.put("CONTACT_FIRST_NAME", account.getContact().getFirstName()); map.put("CONTACT_LAST_NAME", account.getContact().getLastName()); map.put("CONTACT_ADDRESS", account.getContact().getStreetAddr()); map.put("CONTACT_CITY", account.getContact().getCity()); map.put("CONTACT_STATE", account.getContact().getState()); map.put("CONTACT_ZIP", account.getContact().getZip()); map.put("CONTACT_PHONE", account.getContact().getPhone()); map.put("CREATION_DATE", getCurrentTime()); map.put("CREATION_USER", "fuse_usecase"); return map; }
/** * The split message method returns something that is iteratable such as a java.util.List. * * @param header the header of the incoming message with the name user * @param body the payload of the incoming message * @return a list containing each part splitted */ public List<Message> splitMessage(@Header(value = "user") String header, @Body String body) { // we can leverage the Parameter Binding Annotations // http://camel.apache.org/parameter-binding-annotations.html // to access the message header and body at same time, // then create the message that we want, splitter will // take care rest of them. // *NOTE* this feature requires Camel version >= 1.6.1 List<Message> answer = new ArrayList<Message>(); String[] parts = header.split(","); for (String part : parts) { DefaultMessage message = new DefaultMessage(); message.setHeader("user", part); message.setBody(body); answer.add(message); } return answer; }
public List<Message> createXMLDocument(@Body final List<Object> ediLines, @Property(value = Exchange.FILE_NAME) final String CamelFileName, @Property(value = EDIOrderRoute.EDI_ORDER_EDIMessageDatePattern) final String EDIMessageDatePattern, @Property(value = EDIOrderRoute.EDI_ORDER_ADClientValue) final String ADClientValue, @Property(value = EDIOrderRoute.EDI_ORDER_ADOrgID) final BigInteger ADOrgID, @Property(value = EDIOrderRoute.EDI_ORDER_ADInputDataDestination_InternalName) final String ADInputDataDestination_InternalName, @Property(value = EDIOrderRoute.EDI_ORDER_ADInputDataSourceID) final BigInteger ADInputDataSourceID, @Property(value = EDIOrderRoute.EDI_ORDER_ADUserEnteredByID) final BigInteger ADUserEnteredByID, @Property(value = EDIOrderRoute.EDI_ORDER_DELIVERY_RULE) final String DeliveryRule, @Property(value = EDIOrderRoute.EDI_ORDER_DELIVERY_VIA_RULE) final String DeliveryViaRule) { final List<OrderEDI> ediDocuments = getEDIDocumentObjects(ediLines); final EDIConfigurationContext ctx = new EDIConfigurationContext(CamelFileName, EDIMessageDatePattern, ADClientValue, ADOrgID, ADInputDataDestination_InternalName, ADInputDataSourceID, ADUserEnteredByID, DeliveryRule, DeliveryViaRule); final List<Message> olCandMessages = createOLCandMessages(ctx, ediDocuments); return olCandMessages; }
@Override public void store(@Body InputStream input, Exchange exchange) { FileOutputStream fos = null; try { String fileName = ExpressionBuilder.simpleExpression(fileNameExpression).evaluate(exchange,String.class); File outputFile = new File(baseDir,fileName); fos = new FileOutputStream(outputFile); IOUtils.copyLarge(input,fos); exchange.getIn().setHeader(MessageStore.MESSAGE_STORE_REF,outputFile.getAbsolutePath()); } catch (IOException e) { //throw this so it propergates back to the sender because if we can't persist message we shouldn't accept them throw new RuntimeException("currently unable to persist messages in message store " + e,e); } finally { IOUtils.closeQuietly(fos); } }
/** * Partially reads the input message and determines what type of message this is * * (right now this it pretty dumb the goal for this would to replace this with some sort of message codec) * * @param input - the message input stream * @param headers- the message headers that we will add the additional headers to contain the message version details * @throws IOException */ public void parse(@Body InputStream input, @Headers Map<String, Object> headers) throws IOException { try { byte [] msgData = new byte[20480]; int count = input.read(msgData); if(count > 0) { String msg = new String(msgData); //should be able to use a header to determine encoding //First determine if the message is a SOAP 1.1 or 1.2 message by default we will assume 1.1 String soapVersion = msg.contains(EbmsConstants.SOAP_1_2_NAMESPACE) ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL; headers.put(EbmsConstants.SOAP_VERSION,soapVersion); //next determine what version of ebms message is it, by default assume ebms V2 String ebmsVersion = msg.contains(EbmsConstants.EBXML_V3_NAMESPACE) ? EbmsConstants.EBMS_V3 : EbmsConstants.EBMS_V2; headers.put(EbmsConstants.EBMS_VERSION,ebmsVersion); headers.put(EbmsConstants.MESSAGE_ID, getMessageId(msg)); headers.put(EbmsConstants.REF_TO_MESSAGE_ID, getRefMessageId(msg)); headers.put(EbmsConstants.MESSAGE_TYPE, getMessageType(msg).name()); } } finally { input.reset(); } }
public void authenticate(@Header("user") String user, @Body String pass, Exchange exchange) throws AuthenticationException { if (StringUtils.isBlank(user) || StringUtils.isBlank(pass)) { LOG.info("User '{}' attempted to login with a blank username or password.", user); throw new AuthenticationException("User was not logged in."); } try { authenticationProvider.authenticateUser(user, pass); } catch (Exception e) { throw new AuthenticationException(e); } AuthDetails authDetails = new AuthDetails(user); tokens.put(authDetails.getToken().toString(), authDetails); Map<String, String> response = new HashMap<String, String>(); response.put("error",""); response.put("token",authDetails.getToken().toString()); exchange.getOut().setHeader("authDetails",authDetails); exchange.getOut().setBody(response); }
public boolean shouldProcessMessage(@Body AbstractMessage message) throws HL7Exception { boolean outcome = true; if (messageType.equals("O01")) outcome = checkOrderMessage(message); else // "R01" outcome = checkResultMessage(message); if (this.verify) { return (outcome); } else { return !(outcome); } }
public boolean shouldProcessMessage(@Body AbstractMessage body) throws HL7Exception { PV1 pv1 = HapiUtil.get(body, PV1.class); String patientLocation = StringUtils.defaultString(pv1 .getAssignedPatientLocation() .getPointOfCare() .getValue()); if (patientLocation.startsWith("CDU")) { return false; } else { return true; } }
public boolean shouldProcessMessage(@Body ORU_R01 r01) throws HL7Exception { boolean conformsFiller = true; boolean conformsService = true; int resultCount = r01.getPATIENT_RESULT().getORDER_OBSERVATIONReps(); for (int i = 0; i < resultCount && conformsFiller && conformsService; i++) { OBR obr = r01.getPATIENT_RESULT().getORDER_OBSERVATION(i).getOBR(); conformsFiller = this.checkFillerOrderNumberConforms(obr .getObr3_FillerOrderNumber().getEi1_EntityIdentifier() .getValue()); conformsService = this.checkDiagnosticServiceConforms(obr .getObr24_DiagnosticServSectID().getValue()); } return (conformsFiller && conformsService); }
public void dispatchProcessFixture(@Header(HL7AdditionalConstants.HL7_SOURCE_MESSAGE) ADT_A01 from, @Body ADT_A01 to) throws HL7Exception { this.changeMessageEventType(to, "A11"); this.tranformPid(to.getPID()); Segment zrf = this.promoteZrfSegment(from); this.transformZrf(zrf, to.getPV1()); this.transform(to.getPV1(), zrf); to.addNonstandardSegment("ZRF"); Segment toZrf = (Segment) to.insertRepetition("ZRF", 0); DeepCopy.copy(zrf, toZrf); }
public void dispatchProcessFixture(@Header(HL7AdditionalConstants.HL7_SOURCE_MESSAGE) ADT_A01 from, @Body ADT_A01 to) throws HL7Exception { this.changeMessageEventType(to, "A12"); this.tranformPid(to.getPID()); Segment zrf = this.promoteZrfSegment(from); this.transformZrf(zrf, to.getPV1()); this.transform(to.getPV1(), zrf); to.addNonstandardSegment("ZRF"); Segment toZrf = (Segment) to.insertRepetition("ZRF", 0); DeepCopy.copy(zrf, toZrf); }
@Handler public void log(@Body Object body){ if(trace) { LOGGER.trace("Body is: {}",body); } else { LOGGER.info("Body is: {}",body); } }
public static void processResultset( @Body List<Map<String,Object>> resultset, @ExchangeProperty("city") City city) { List<String> zips = resultset.stream() .map(m->(String)m.get("ZIP")) .collect(Collectors.toList()); city.setZips(zips); }
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()); }
@SyndesisExtensionAction( id = "my-step", name = "My Step", description = "A simple step", entrypoint = "direct:my-step" ) public void log(@Body Object body) { LOGGER.info("Body is: {}", body); }
public boolean retry(@Header(Exchange.REDELIVERY_COUNTER) Integer counter, @Body String body, @ExchangeException Exception causedBy) { // NOTE: counter is the redelivery attempt, will start from 1 invoked.incrementAndGet(); // we can of course do what ever we want to determine the result but this is a unit test so we end after 3 attempts return counter < 3; }
public boolean retry(@Header(Exchange.REDELIVERY_COUNTER) Integer counter, @Body String body, @ExchangeException Exception causedBy) { // NOTE: counter is the redelivery attempt, will start from 1 invoked++; assertEquals("Hello World", body); assertTrue(causedBy instanceof MyFunctionalException); // we can of course do what ever we want to determine the result but this is a unit test so we end after 3 attempts return counter < 3; }
/** * This method handle our order input and return the order * * @param in the in headers * @param payload the in payload * @param out the out headers * @return the out payload * @throws OrderFailedException is thrown if the order cannot be processed */ public Object handleOrder(@Headers Map<?, ?> in, @Body String payload, @OutHeaders Map<String, Object> out) throws OrderFailedException { out.put("customerid", in.get("customerid")); if ("Order: kaboom".equals(payload)) { throw new OrderFailedException("Cannot order: kaboom"); } else { out.put("orderid", "123"); return "Order OK"; } }
public void checkLuggage(Exchange exchange, @Body String body, @XPath("/order/@custId") String custId) { // store the message body into the data store, using the custId as the claim check dataStore.put(custId, body); // add the claim check as a header exchange.getIn().setHeader("claimCheck", custId); // remove the body from the message exchange.getIn().setBody(null); }
public void myMethod(@Properties Map<?, ?> foo, @Headers Map<?, ?> bar, @Body String body) { this.foo = foo; this.bar = bar; this.body = body; assertNotNull(toString()); }
public String doSomething(@Body String body, @Headers Map<?, ?> headers, @OutHeaders Map<String, Object> outHeaders) { if (outHeaders != null) { outHeaders.put("out", 123); } return "Hello!"; }
@Consume(uri = "activemq:queue:foo") public void doSomething(@Header("JMSReplyTo") Destination jmsReplyTo, @Body String body) throws Exception { assertEquals("Hello World", body); String endpointName = "activemq:" + jmsReplyTo.toString(); endpointName = endpointName.replaceAll("//", ":"); tempName = endpointName; latch.countDown(); template.sendBody(tempName, "Bye World"); }
@Consume(uri = "activemq:queue:foo") public void doSomething(@Header("JMSReplyTo") Destination jmsReplyTo, @Body String body) throws Exception { assertEquals("Hello World", body); String endpointName = "activemq:" + jmsReplyTo.toString(); template.sendBody(endpointName, "Bye World"); }
@Handler public void handle(@Body CannotMarshal body) { if (body.getMessageNo() == 2) { // fail on second message throw new RuntimeException("Kaboom"); } }
public Date getPubDate(@Body Object body) { SyndFeed feed = (SyndFeed) body; SyndEntry syndEntry = (SyndEntry) feed.getEntries().get(0); Date date = syndEntry.getUpdatedDate(); if (date == null) { date = syndEntry.getPublishedDate(); } return date; }
/** * This method handle our order input and return the order * * @param in the in headers * @param payload the in payload * @param out the out headers * @return the out payload * @throws OrderFailedException is thrown if the order cannot be processed */ public Object handleOrder(@Headers Map<String, Object> in, @Body String payload, @OutHeaders Map<String, Object> out) throws OrderFailedException { out.put("customerid", in.get("customerid")); if ("Order: kaboom".equals(payload)) { throw new OrderFailedException("Cannot order: kaboom"); } else { out.put("orderid", "123"); return "Order OK"; } }
public String hello(@Body String body, @Header("foo") String foo, @Headers Map<String, Object> headers) { String s = body.replaceFirst("Hello", "Bye"); if (!foo.equals("ABC")) { throw new IllegalArgumentException("Foo has not expected value ABC but " + foo); } headers.put("foo", 123); return s; }
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); }
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; }
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; }
public List<Exec> splitBody(@Body ExecList body) { List<Exec> answer = new ArrayList<Exec>(); for (Exec exec : body.getExecList()) { answer.add(exec); } return answer; }
/** * The split message method returns something that is iteratable such as a java.util.List. * * @param body the payload of the incoming message * @return a list containing each part splitted */ public List<VariableBinding> splitMessage(@Body Vector<? extends VariableBinding> body) { List<VariableBinding> answer = new ArrayList<VariableBinding>(); for (VariableBinding var : body) { OID oid = var.getOid(); Variable variable = var.getVariable(); LOG.debug("oid: {}, value: {}, syntax: {}",oid,variable.toLong(),variable.getSyntaxString()); answer.add(var); } return answer; }
public void setArgs(@OutHeaders Map headers, @Body Notification notification) { ArrayList<String> args = new ArrayList<String>(); Event event = notification.getEvent(); args.add("msend.pl"); args.add("-o"); args.add(event.getSource().getName()); args.add("-r"); args.add(event.getSeverity().toString()); headers.put(EXEC_COMMAND_ARGS, args); headers.put(EXEC_COMMAND_EXECUTABLE, "echo"); }
@Handler public SyncHelloResponse composeGreeting(@Body SyncHelloRequest req) { Assert.notNull(req, "req must not be null"); String greeting = "Hello " + req.getName(); SyncHelloResponse res = new SyncHelloResponse(); res.setGreeting(greeting); return res; }
@Handler public void printGreeting(@Body AsyncHelloRequest req) { Assert.notNull(req, "req must not be null"); String greeting = "Hello " + req.getName(); Log.debug("Greeting: " + greeting); }