You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hise-commits@incubator.apache.org by rr...@apache.org on 2010/09/06 23:29:28 UTC
svn commit: r993179 - in /incubator/hise/trunk/hise-services: ./
src/main/java/org/apache/hise/engine/
src/main/java/org/apache/hise/engine/store/
src/main/java/org/apache/hise/runtime/ src/test/java/org/apache/hise/
src/test/resources/
Author: rr
Date: Mon Sep 6 23:29:27 2010
New Revision: 993179
URL: http://svn.apache.org/viewvc?rev=993179&view=rev
Log:
HISE-30: Camel integration
Added:
incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/store/HISERouteBuilder.java
incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/HISECamelTest.java
incubator/hise/trunk/hise-services/src/test/resources/approve.xml
incubator/hise/trunk/hise-services/src/test/resources/hiseCamelTest.xml
incubator/hise/trunk/hise-services/src/test/resources/testCamelHtd.xml
Modified:
incubator/hise/trunk/hise-services/pom.xml
incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/Task.java
Modified: incubator/hise/trunk/hise-services/pom.xml
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/pom.xml?rev=993179&r1=993178&r2=993179&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/pom.xml (original)
+++ incubator/hise/trunk/hise-services/pom.xml Mon Sep 6 23:29:27 2010
@@ -299,5 +299,16 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>2.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <version>2.3.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java?rev=993179&r1=993178&r2=993179&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java (original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/HISEEngineImpl.java Mon Sep 6 23:29:27 2010
@@ -147,6 +147,7 @@ public class HISEEngineImpl implements H
}
public static String fetchCreatedBy(Node requestHeader) {
+ if (requestHeader == null) return "";
log.debug("header " + DOMUtils.domToString(requestHeader));
XQueryEvaluator e = new XQueryEvaluator();
e.declareNamespace("htd", "http://www.example.org/WS-HT");
Added: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/store/HISERouteBuilder.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/store/HISERouteBuilder.java?rev=993179&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/store/HISERouteBuilder.java (added)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/engine/store/HISERouteBuilder.java Mon Sep 6 23:29:27 2010
@@ -0,0 +1,93 @@
+package org.apache.hise.engine.store;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.hise.api.HISEEngine;
+import org.apache.hise.api.Handler;
+import org.apache.hise.api.Sender;
+import org.apache.hise.lang.HumanInteractions;
+import org.apache.hise.lang.TaskDefinition;
+import org.springframework.core.io.Resource;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class HISERouteBuilder extends RouteBuilder {
+ private HISEEngine hiseEngine;
+ private Resource humanInteractionsResource;
+ private PlatformTransactionManager transactionManager;
+
+ @Override
+ public void configure() throws Exception {
+ HISEDD dd = new HISEDD();
+ dd.setHumanInteractionsResource(humanInteractionsResource);
+
+ HumanInteractions tasks = HumanInteractionsCompiler.compile(humanInteractionsResource);
+ for (TaskDefinition t : tasks.getTaskDefinitions().values()) {
+ final QName requestService = t.getTaskInterface().getPortType();
+ final QName responseService = t.getTaskInterface().getResponsePortType();
+ final TaskDD taskDD = new TaskDD();
+ taskDD.setTaskName(t.getTaskName());
+ taskDD.setHandler(new CamelHandler());
+ final Sender sender = new Sender() {
+ public Node invoke(Node message, Node epr) {
+ getContext().createProducerTemplate().sendBody("direct:" + responseService, message);
+ return null;
+ }
+ };
+ taskDD.setSender(sender);
+
+ org.apache.hise.api.HISEEngine.TaskInfo ti = new org.apache.hise.api.HISEEngine.TaskInfo();
+ ti.dd = taskDD;
+ ti.parent = dd;
+ ti.taskDefinition = t;
+ hiseEngine.registerTask(ti);
+
+
+ from("direct:" + requestService).convertBodyTo(Node.class).process(new Processor() {
+ public void process(final Exchange e) throws Exception {
+ final Element body = ((Document) e.getIn().getBody()).getDocumentElement();
+ TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
+ transactionTemplate.execute(new TransactionCallback() {
+ public Object doInTransaction(TransactionStatus arg0) {
+ try {
+ Node response = hiseEngine.receive(taskDD.handler, requestService, "default", body, null);
+ e.getIn().setBody(response);
+ return null;
+ } catch (Exception e) {
+ throw new RuntimeException("Error during receiving message ", e);
+ }
+ }
+ });
+ }
+ });
+ }
+ }
+
+ public void setHiseEngine(HISEEngine hiseEngine) {
+ this.hiseEngine = hiseEngine;
+ }
+
+ public void setHumanInteractionsResource(Resource humanInteractionsResource) {
+ this.humanInteractionsResource = humanInteractionsResource;
+ }
+
+ public void setTransactionManager(PlatformTransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
+ public static class CamelHandler implements Handler {
+ public String getId() {
+ return null;
+ }
+ }
+}
Modified: incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/Task.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/Task.java?rev=993179&r1=993178&r2=993179&view=diff
==============================================================================
--- incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/Task.java (original)
+++ incubator/hise/trunk/hise-services/src/main/java/org/apache/hise/runtime/Task.java Mon Sep 6 23:29:27 2010
@@ -191,8 +191,6 @@ public class Task {
Validate.isTrue(!taskDefinition.isNotification());
Map<String, Node> inputParts = findInputParts(taskDefinition, requestXml);
-
-
t.taskDefinition = taskDefinition;
org.apache.hise.dao.Task taskDto = new org.apache.hise.dao.Task();
@@ -207,7 +205,7 @@ public class Task {
//TODO
}
}
- taskDto.setSoapHeader(DOMUtils.domToString(requestHeader));
+ taskDto.setSoapHeader(requestHeader == null ? null : DOMUtils.domToString(requestHeader));
taskDto.setCreatedOn(new Date());
taskDto.setActivationTime(new Date());
taskDto.setEscalated(false);
@@ -308,6 +306,12 @@ public class Task {
static Map<String, Node> findInputParts(TaskDefinition taskDefinition, Node requestXml) {
Map<String, Node> inputParts = new HashMap<String, Node>();
+ if (taskDefinition.getPortType() == null) {
+ //Non wsdl task (for camel integration layer)
+ inputParts.put("message", requestXml);
+ return inputParts;
+ }
+
Operation operation = taskDefinition.getPortType().getOperation(taskDefinition.getTaskInterface().getOperation(), null, null);
if(operation == null) {
LogFactory.getLog(Task.class).error("Operation: " + taskDefinition.getTaskInterface().getOperation() + " not found in port type definition.");
Added: incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/HISECamelTest.java
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/HISECamelTest.java?rev=993179&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/HISECamelTest.java (added)
+++ incubator/hise/trunk/hise-services/src/test/java/org/apache/hise/HISECamelTest.java Mon Sep 6 23:29:27 2010
@@ -0,0 +1,28 @@
+package org.apache.hise;
+
+import org.apache.camel.CamelContext;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.hise.dao.HISEDao;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration(locations = "classpath:/hiseCamelTest.xml")
+public class HISECamelTest extends AbstractJUnit4SpringContextTests {
+
+ @Autowired
+ private HISEDao hiseDao;
+
+ @Autowired
+ private CamelContext camelContext;
+
+ @Autowired
+ private JpaTransactionManager transactionManager;
+
+ @Test
+ public void testCreateTask() throws Exception {
+ camelContext.createProducerTemplate().sendBody("direct:ClaimsHandling", IOUtils.toString(getClass().getResourceAsStream("/approve.xml")));
+ }
+}
\ No newline at end of file
Added: incubator/hise/trunk/hise-services/src/test/resources/approve.xml
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/resources/approve.xml?rev=993179&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/resources/approve.xml (added)
+++ incubator/hise/trunk/hise-services/src/test/resources/approve.xml Mon Sep 6 23:29:27 2010
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<message xmlns:cla="http://www.insurance.example.com/claims/">
+ <cla:cust>
+ <cla:id>123</cla:id>
+ <cla:firstname>Edmund</cla:firstname>
+ <cla:lastname>Zorn</cla:lastname>
+ </cla:cust>
+ <cla:amount>1234</cla:amount>
+ <cla:region>usa</cla:region>
+ <cla:prio>2</cla:prio>
+ <cla:activateAt>2009-01-02T12:00:00</cla:activateAt>
+</message>
Added: incubator/hise/trunk/hise-services/src/test/resources/hiseCamelTest.xml
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/resources/hiseCamelTest.xml?rev=993179&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/resources/hiseCamelTest.xml (added)
+++ incubator/hise/trunk/hise-services/src/test/resources/hiseCamelTest.xml Mon Sep 6 23:29:27 2010
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one ~ or more contributor license agreements. See the NOTICE file ~ distributed with this work for additional information ~ regarding copyright ownership. The ASF licenses this file ~ to you under the Apache License, Version 2.0 (the ~ "License"); you may not use this file except in compliance ~ with the License. You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, ~ software distributed under the License is distributed on an ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~ KIND, either express or implied. See the License for the ~ specific
+ language governing permissions and limitations ~ under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:cxf="http://cxf.apache.org/core" xmlns:htd="http://www.example.org/WS-HT" xmlns:htda="http://www.example.org/WS-HT/api" xmlns:htdt="http://www.example.org/WS-HT/api/xsd" xmlns:htdaw="http://www.example.org/WS-HT/api/wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins="http://www.insurance.example.com/claims"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
+ http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+ http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <import resource="classpath:dao.xml"/>
+
+ <bean id="hiseEngine" class="org.apache.hise.engine.HISEEngineImpl">
+ <property name="hiseDao" ref="hiseDao"/>
+ <property name="hiseScheduler" ref="hiseScheduler"/>
+ </bean>
+
+ <bean id="hiseScheduler" class="org.apache.hise.engine.HISEScheduler" init-method="init" destroy-method="destroy">
+ <property name="hiseEngine" ref="hiseEngine"/>
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+
+ <bean id="hiseRouteBuilder" class="org.apache.hise.engine.store.HISERouteBuilder">
+ <property name="humanInteractionsResource" value="classpath:testCamelHtd.xml"/>
+ <property name="hiseEngine" ref="hiseEngine"/>
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+
+ <camel:camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="hiseRouteBuilder"/>
+ </camel:camelContext>
+</beans>
+
Added: incubator/hise/trunk/hise-services/src/test/resources/testCamelHtd.xml
URL: http://svn.apache.org/viewvc/incubator/hise/trunk/hise-services/src/test/resources/testCamelHtd.xml?rev=993179&view=auto
==============================================================================
--- incubator/hise/trunk/hise-services/src/test/resources/testCamelHtd.xml (added)
+++ incubator/hise/trunk/hise-services/src/test/resources/testCamelHtd.xml Mon Sep 6 23:29:27 2010
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a0c9ce4c-ee02-2a10-4b96-cb205464aa02
+ © 2007 Active Endpoints Inc., Adobe Systems Inc., BEA Systems Inc., International
+ Business Machines Corporation, Oracle Inc., and SAP AG. All rights reserved. -->
+<htd:humanInteractions xmlns:htd="http://www.example.org/WS-HT"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://www.insurance.example.com/claims/" targetNamespace="http://www.insurance.example.com/claims/"
+ xsi:schemaLocation="http://www.example.org/WS-HT file:/usr/share/schemas/ws-humantask.xsd">
+
+ <htd:logicalPeopleGroups>
+ <htd:logicalPeopleGroup name="lpg1">
+ <htd:documentation xml:lang="en-US">Employee group.
+ </htd:documentation>
+ <htd:parameter name="region" type="xsd:string" />
+ </htd:logicalPeopleGroup>
+ </htd:logicalPeopleGroups>
+
+ <htd:tasks>
+ <htd:task name="Task1">
+ <htd:documentation xml:lang="en-US">This task is used to
+ handle claims that require manual approval. </htd:documentation>
+ <htd:interface portType="ClaimsHandling" operation="default"
+ responsePortType="ClaimsResolving" responseOperation="default" />
+ <htd:priority>htd:getInput("message")/tns:prio</htd:priority>
+
+ <htd:peopleAssignments>
+ <htd:potentialOwners>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:users>
+ <htd:user>user1</htd:user>
+ </htd:users>
+ </htd:organizationalEntity>
+ </htd:literal>
+ </htd:from>
+ </htd:potentialOwners>
+
+ <htd:businessAdministrators>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:groups>
+ <htd:group>group1</htd:group>
+ <htd:group>group2</htd:group>
+ </htd:groups>
+ </htd:organizationalEntity>
+ </htd:literal>
+ </htd:from>
+ </htd:businessAdministrators>
+
+ <htd:businessAdministrators>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:users>
+ <htd:user>user1</htd:user>
+ <htd:user>user2</htd:user>
+ </htd:users>
+ </htd:organizationalEntity>
+ </htd:literal>
+ </htd:from>
+ </htd:businessAdministrators>
+
+ <htd:businessAdministrators>
+ <htd:from logicalPeopleGroup="lpg1">
+ <htd:argument name="region">
+ htd:getInput("ClahimApprovalRequest")/region </htd:argument>
+ </htd:from>
+ </htd:businessAdministrators>
+
+ <htd:taskStakeholders>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:users>
+ <htd:user>user3</htd:user>
+ </htd:users>
+ </htd:organizationalEntity>
+ </htd:literal>
+ </htd:from>
+ </htd:taskStakeholders>
+
+ </htd:peopleAssignments>
+
+ <htd:delegation potentialDelegatees="nobody" />
+
+ <htd:presentationElements>
+
+ <htd:name xml:lang="en-US"> Approve Claim </htd:name>
+
+ <htd:presentationParameters>
+
+ <htd:presentationParameter name="firstname"
+ type="xsd:string">
+ htd:getInput("ClaimApprovalRequest")/cust/firstname </htd:presentationParameter>
+
+ <htd:presentationParameter name="lastname"
+ type="xsd:string">
+ htd:getInput("ClaimApprovalRequest")/cust/lastname </htd:presentationParameter>
+
+ <htd:presentationParameter name="euroAmount"
+ type="xsd:double">
+ htd:getInput("ClaimApprovalRequest")/amount </htd:presentationParameter>
+
+ </htd:presentationParameters>
+
+ <htd:subject xml:lang="en-US"> Approve the insurance claim for
+ PLN $euroAmount$ on behalf of $firstname$ $lastname$ </htd:subject>
+
+ <htd:description xml:lang="en-US" contentType="text/plain">
+ Approve this claim following corporate guideline #4711.0815/7 ...
+ </htd:description>
+
+ </htd:presentationElements>
+ <htd:outcome>someOutput</htd:outcome>
+
+ <htd:deadlines>
+ <htd:startDeadline>
+ <htd:for>'PT5S'</htd:for>
+ <htd:escalation name="reassignTask3">
+ <htd:reassignment>
+ <htd:potentialOwners>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:users>
+ <htd:user>user3</htd:user>
+ </htd:users>
+ </htd:organizationalEntity>
+
+ </htd:literal>
+ </htd:from>
+ </htd:potentialOwners>
+ </htd:reassignment>
+ </htd:escalation>
+ </htd:startDeadline>
+ <htd:completionDeadline>
+ <htd:for>'PT10S'</htd:for>
+ <htd:escalation name="reassignTask3Completion">
+ <htd:reassignment>
+ <htd:potentialOwners>
+ <htd:from>
+ <htd:literal>
+ <htd:organizationalEntity>
+ <htd:users>
+ <htd:user>user4</htd:user>
+ </htd:users>
+ </htd:organizationalEntity>
+ </htd:literal>
+ </htd:from>
+ </htd:potentialOwners>
+ </htd:reassignment>
+ </htd:escalation>
+ </htd:completionDeadline>
+ </htd:deadlines>
+ </htd:task>
+ </htd:tasks>
+</htd:humanInteractions>