[jboss-svn-commits] JBL Code SVN: r34929 - in labs/jbossrules/trunk: drools-camel/src/main/java/org/drools/jax/soap and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Aug 29 20:27:23 EDT 2010
Author: lucazamador
Date: 2010-08-29 20:27:22 -0400 (Sun, 29 Aug 2010)
New Revision: 34929
Added:
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfTransportSoapProcessor.java
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfTransportSoapProcessor.java
Removed:
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoap.java
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoap.java
Modified:
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/camel/component/DroolsPolicy.java
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoapProcessor.java
labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoapProcessor.java
labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/cxf/CxfSoapTest.java
labs/jbossrules/trunk/drools-server/src/main/resources/camel-server.xml
Log:
JBRULES-2664 Soap support in drools-camel
-SOAP support improved
Modified: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/camel/component/DroolsPolicy.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/camel/component/DroolsPolicy.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/camel/component/DroolsPolicy.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -26,6 +26,7 @@
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.component.cxf.CxfConstants;
+import org.apache.camel.component.cxf.CxfSpringEndpoint;
import org.apache.camel.model.BeanDefinition;
import org.apache.camel.model.DataFormatDefinition;
import org.apache.camel.model.MarshalDefinition;
@@ -54,8 +55,10 @@
import org.drools.command.runtime.rule.RetractCommand;
import org.drools.common.DefaultFactHandle;
import org.drools.core.util.StringUtils;
-import org.drools.jax.soap.PostCxfSoap;
-import org.drools.jax.soap.PreCxfSoap;
+import org.drools.jax.soap.PostCxfSoapProcessor;
+import org.drools.jax.soap.PostCxfTransportSoapProcessor;
+import org.drools.jax.soap.PreCxfSoapProcessor;
+import org.drools.jax.soap.PreCxfTransportSoapProcessor;
import org.drools.runtime.CommandExecutor;
import org.drools.runtime.impl.ExecutionResultImpl;
import org.drools.runtime.rule.impl.FlatQueryResults;
@@ -64,7 +67,8 @@
public class DroolsPolicy
implements
Policy {
- private DroolsEndpoint dep;
+ private static boolean augmented;
+ private DroolsEndpoint dep;
public void beforeWrap(RouteContext routeContext,
ProcessorDefinition processorDefinition) {
@@ -119,12 +123,13 @@
}
else if (to.getUri().startsWith( "cxf" ) && !visited.contains( to ) ) {
BeanDefinition beanDef = new BeanDefinition();
- beanDef.setBeanType( PreCxfSoap.class );
+ beanDef.setBeanType( PreCxfSoapProcessor.class );
outputs.add( i, beanDef ); // insert before cxf
beanDef = new BeanDefinition();
- beanDef.setBeanType( PostCxfSoap.class );
+ beanDef.setBeanType( PostCxfSoapProcessor.class );
outputs.add( i+2, beanDef ); // insert after cxf
i = i + 2;// adjust for the two inserts
+ augmented = true;
}
} else if ( child instanceof MarshalDefinition ) {
MarshalDefinition m = (MarshalDefinition) child;
@@ -310,7 +315,15 @@
exchange.setProperty( "drools-context",
context );
+ boolean soap = false;
+ if (!augmented && exchange.getFromEndpoint() instanceof CxfSpringEndpoint) {
+ new PreCxfTransportSoapProcessor().process( exchange );
+ soap = true;
+ }
processor.process( exchange );
+ if (soap) {
+ new PostCxfTransportSoapProcessor().process( exchange );
+ }
} finally {
Thread.currentThread().setContextClassLoader( originalClassLoader );
}
Deleted: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoap.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoap.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoap.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -1,50 +0,0 @@
-/**
- * Copyright 2010 JBoss Inc
- *
- * Licensed 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.
- */
-
-/**
- *
- */
-package org.drools.jax.soap;
-
-import java.io.InputStream;
-
-import javax.xml.namespace.QName;
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.SOAPBody;
-import javax.xml.soap.SOAPBodyElement;
-import javax.xml.soap.SOAPMessage;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.drools.core.util.StringUtils;
-
-public class PostCxfSoap implements Processor {
-
- public void process(Exchange exchange) throws Exception {
- InputStream is = (InputStream) exchange.getIn().getBody();
- if (is != null) {
- SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
- SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
- QName payloadName = new QName("http://soap.jax.drools.org", "executeResponse", "ns1");
- SOAPBodyElement payload = body.addBodyElement(payloadName);
- payload.addChildElement("responseType");
- body.addTextNode(StringUtils.toString( is ));
- exchange.getOut().setBody( soapMessage );
- }
-
- }
-
-}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoapProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoapProcessor.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfSoapProcessor.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -1,7 +1,25 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed 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.
+ */
+
+/**
+ *
+ */
package org.drools.jax.soap;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
@@ -16,21 +34,16 @@
public class PostCxfSoapProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
- byte[] body = (byte[]) exchange.getIn().getBody();
+ InputStream is = (InputStream) exchange.getIn().getBody();
+ if (is != null) {
+ SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
+ SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
+ QName payloadName = new QName("http://soap.jax.drools.org", "executeResponse", "ns1");
+ SOAPBodyElement payload = body.addBodyElement(payloadName);
+ payload.addChildElement("responseType");
+ body.addTextNode(StringUtils.toString( is ));
+ exchange.getOut().setBody( soapMessage );
+ }
+ }
- ByteArrayInputStream bais = new ByteArrayInputStream(body);
-
- SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
- SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
- QName payloadName = new QName("http://soap.jax.drools.org", "executeResponse", "ns1");
- SOAPBodyElement payload = soapBody.addBodyElement(payloadName);
- payload.addChildElement("responseType");
- soapBody.addTextNode(StringUtils.toString(bais));
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- soapMessage.writeTo(baos);
-
- exchange.getOut().setBody(new String(baos.toByteArray()));
- }
-
-}
+}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfTransportSoapProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfTransportSoapProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfTransportSoapProcessor.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -0,0 +1,52 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed 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.
+ */
+package org.drools.jax.soap;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPBodyElement;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.drools.core.util.StringUtils;
+
+public class PostCxfTransportSoapProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+
+ byte[] body2 = (byte[]) exchange.getOut().getBody();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(body2);
+
+ SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
+ SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
+ QName payloadName = new QName("http://soap.jax.drools.org", "executeResponse", "ns1");
+ SOAPBodyElement payload = soapBody.addBodyElement(payloadName);
+ payload.addChildElement("responseType");
+ soapBody.addTextNode(StringUtils.toString(bais));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ soapMessage.writeTo(baos);
+
+ exchange.getOut().setBody(new String(baos.toByteArray()));
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PostCxfTransportSoapProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Deleted: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoap.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoap.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoap.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -1,43 +0,0 @@
-/**
- * Copyright 2010 JBoss Inc
- *
- * Licensed 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.
- */
-
-/**
- *
- */
-package org.drools.jax.soap;
-
-import javax.xml.soap.SOAPMessage;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.cxf.service.model.BindingOperationInfo;
-
-public class PreCxfSoap implements Processor {
-
- private static final transient Log LOG = LogFactory.getLog(PreCxfSoap.class);
-
- public void process(Exchange exchange) throws Exception {
- exchange.setPattern(ExchangePattern.InOut);
- BindingOperationInfo boi = (BindingOperationInfo)exchange.getProperty(BindingOperationInfo.class.toString());
- if (boi != null) {
- LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
- }
- SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody();
- exchange.getOut().setBody(soapMessage.getSOAPBody().getTextContent());
- }
-}
Modified: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoapProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoapProcessor.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfSoapProcessor.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -1,26 +1,43 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed 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.
+ */
+
+/**
+ *
+ */
package org.drools.jax.soap;
-import java.io.InputStream;
-import java.util.Map;
-
-import javax.xml.soap.MessageFactory;
-import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPMessage;
-
import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.service.model.BindingOperationInfo;
public class PreCxfSoapProcessor implements Processor {
+ private static final transient Log LOG = LogFactory.getLog(PreCxfSoapProcessor.class);
+
public void process(Exchange exchange) throws Exception {
- InputStream is = (InputStream)exchange.getIn().getBody();
- Map<String, Object> headers = exchange.getIn().getHeaders();
- MimeHeaders mimeHeaders = new MimeHeaders();
- for (String header : headers.keySet()) {
- mimeHeaders.addHeader(header, (String) headers.get(header));
+ exchange.setPattern(ExchangePattern.InOut);
+ BindingOperationInfo boi = (BindingOperationInfo)exchange.getProperty(BindingOperationInfo.class.toString());
+ if (boi != null) {
+ LOG.info("boi.isUnwrapped" + boi.isUnwrapped());
}
- SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(mimeHeaders, is);
+ SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody();
exchange.getOut().setBody(soapMessage.getSOAPBody().getTextContent());
- }
-
+ }
}
Added: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfTransportSoapProcessor.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfTransportSoapProcessor.java (rev 0)
+++ labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfTransportSoapProcessor.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2010 JBoss Inc
+ *
+ * Licensed 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.
+ */
+package org.drools.jax.soap;
+
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+
+public class PreCxfTransportSoapProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ InputStream is = (InputStream)exchange.getIn().getBody();
+ Map<String, Object> headers = exchange.getIn().getHeaders();
+ MimeHeaders mimeHeaders = new MimeHeaders();
+ for (String header : headers.keySet()) {
+ mimeHeaders.addHeader(header, (String) headers.get(header));
+ }
+ SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(mimeHeaders, is);
+ exchange.getOut().setBody(soapMessage.getSOAPBody().getTextContent().trim());
+ exchange.getIn().setBody(soapMessage.getSOAPBody().getTextContent().trim());
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-camel/src/main/java/org/drools/jax/soap/PreCxfTransportSoapProcessor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/cxf/CxfSoapTest.java
===================================================================
--- labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/cxf/CxfSoapTest.java 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-camel/src/test/java/org/drools/camel/component/cxf/CxfSoapTest.java 2010-08-30 00:27:22 UTC (rev 34929)
@@ -57,19 +57,13 @@
body.addTextNode(cmd);
- OutputStream out = new ByteArrayOutputStream();
- soapMessage.writeTo(out);
-
- String request = out.toString();
- System.out.println("Request = " + request);
-
Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);
- System.out.println(object.getClass().getCanonicalName());
+
+ OutputStream out = new ByteArrayOutputStream();
out = new ByteArrayOutputStream();
soapMessage = (SOAPMessage) object;
soapMessage.writeTo(out);
String response = out.toString();
- System.out.println("Response = "+response);
assertTrue(response.contains("fact-handle identifier=\"salaboy\""));
}
Modified: labs/jbossrules/trunk/drools-server/src/main/resources/camel-server.xml
===================================================================
--- labs/jbossrules/trunk/drools-server/src/main/resources/camel-server.xml 2010-08-29 23:51:50 UTC (rev 34928)
+++ labs/jbossrules/trunk/drools-server/src/main/resources/camel-server.xml 2010-08-30 00:27:22 UTC (rev 34929)
@@ -62,11 +62,6 @@
</cxf:properties>
</cxf:cxfEndpoint>
- <!-- Beans to transform the soap invocation -->
- <bean id="preCxfSoapProcessor" class="org.drools.jax.soap.PreCxfSoapProcessor" />
-
- <bean id="postCxfSoapProcessor" class="org.drools.jax.soap.PostCxfSoapProcessor" />
-
<!-- Leave this, as it's needed to make Camel "drools" aware -->
<bean id="droolsPolicy" class="org.drools.camel.component.DroolsPolicy" />
@@ -88,13 +83,11 @@
<route>
<from uri="cxf://bean://soapServer"/>
- <process ref="preCxfSoapProcessor" />
<policy ref="droolsPolicy">
<unmarshal ref="xstream" />
<to uri="drools:node1/ksession1" />
<marshal ref="xstream" />
</policy>
- <process ref="postCxfSoapProcessor" />
</route>
</camelContext>
More information about the jboss-svn-commits
mailing list