You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/03/23 14:13:41 UTC
svn commit: r388165 - in /incubator/servicemix/trunk/servicemix-bpe: ./
src/main/java/org/apache/servicemix/bpe/
src/main/java/org/apache/servicemix/bpe/external/
src/main/java/org/apache/servicemix/bpe/timer/ src/test/java/loanbroker/
src/test/java/or...
Author: gnodet
Date: Thu Mar 23 05:13:37 2006
New Revision: 388165
URL: http://svn.apache.org/viewcvs?rev=388165&view=rev
Log:
SM-364: Add xbean configuration support for servicemix-bpe
Added:
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPESpringComponent.java
incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/
incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/Bank.java
incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/CreditAgency.java
incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPESpringComponentTest.java
incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/
incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/
incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/
incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/
incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/spring.xml
Modified:
incubator/servicemix/trunk/servicemix-bpe/maven.xml
incubator/servicemix/trunk/servicemix-bpe/project.xml
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEComponent.java
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEDeployer.java
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEEndpoint.java
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/external/JbiInvokeAction.java
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerJdk.java
incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerServiceJdk.java
incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPEComponentTest.java
Modified: incubator/servicemix/trunk/servicemix-bpe/maven.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/maven.xml?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/maven.xml (original)
+++ incubator/servicemix/trunk/servicemix-bpe/maven.xml Thu Mar 23 05:13:37 2006
@@ -20,6 +20,27 @@
<project default="default" xmlns:ant="jelly:ant">
- <!-- default goal is defined in /etc/ -->
+ <postGoal name="java:compile">
+ <attainGoal name="xbean:generate" />
+ </postGoal>
+ <goal name="xbean:generate" description="Generates the XBean XSD, documentation and META-INF/services files.">
+ <path id="test.classpath">
+ <pathelement path="${maven.build.dest}" />
+ <pathelement path="${basedir}/target/classes" />
+ <pathelement path="${basedir}/target/test-classes" />
+ <path refid="maven.dependency.classpath" />
+ </path>
+
+ <taskdef name="xsdGenerate" classname="org.apache.xbean.spring.generator.MappingGeneratorTask">
+ <classpath refid="test.classpath" />
+ </taskdef>
+ <xsdGenerate
+ destFile="${basedir}/target/servicemix-bpe-${pom.currentVersion}.xsd" namespace="http://servicemix.apache.org/bpe/1.0"
+ classpathref="test.classpath" srcdir="${basedir}/src/main/java" metaInfDir="${basedir}/target/generated/"/>
+ <copy file="${basedir}/target/servicemix-bpe-${pom.currentVersion}.xsd" todir="${basedir}/target/generated/"/>
+ <copy file="${basedir}/target/servicemix-bpe-${pom.currentVersion}.xsd" todir="${basedir}/../xdocs"/>
+ <copy file="${basedir}/target/servicemix-bpe-${pom.currentVersion}.xsd.html" todir="${basedir}/../xdocs"/>
+ </goal>
+
</project>
Modified: incubator/servicemix/trunk/servicemix-bpe/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/project.xml?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-bpe/project.xml Thu Mar 23 05:13:37 2006
@@ -335,4 +335,35 @@
</dependency>
</dependencies>
+ <build>
+ <unitTest>
+ <resources>
+ <resource>
+ <directory>src/test/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ <includes>
+ <include>**/*Test.*</include>
+ </includes>
+ <excludes>
+ </excludes>
+ </unitTest>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>target/generated</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
</project>
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEComponent.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEComponent.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEComponent.java Thu Mar 23 05:13:37 2006
@@ -26,14 +26,17 @@
public static String PART_PAYLOAD = "payload";
- private static BPEComponent INSTANCE;
+ private static final ThreadLocal COMPONENT = new ThreadLocal();
- public static BPEComponent getInstance() {
- return INSTANCE;
+ public static BPEComponent getCurrent() {
+ return (BPEComponent) COMPONENT.get();
+ }
+
+ public static void setCurrent(BPEComponent component) {
+ COMPONENT.set(component);
}
public BPEComponent() {
- INSTANCE = this;
}
protected BaseLifeCycle createLifeCycle() {
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEDeployer.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEDeployer.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEDeployer.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEDeployer.java Thu Mar 23 05:13:37 2006
@@ -61,6 +61,7 @@
import org.apache.ode.bpe.wsdl.extensions.BPEVariableMap;
import org.apache.ode.bpe.wsdl.extensions.BPEVariableMapSerializer;
import org.apache.ode.bpe.wsdl.extensions.ExtentionConstants;
+import org.w3c.dom.Document;
public class BPEDeployer extends AbstractDeployer {
@@ -88,6 +89,7 @@
su.setRootPath(serviceUnitRootPath);
Definition rootDef = loadMainWsdl(serviceUnitRootPath);
checkDefinition(rootDef);
+ Document description = WSDLFactory.newInstance().newWSDLWriter().getDocument(rootDef);
for (Iterator it = rootDef.getServices().values().iterator(); it.hasNext();) {
Service svc = (Service) it.next();
for (Iterator it2 = svc.getPorts().values().iterator(); it2.hasNext();) {
@@ -97,6 +99,8 @@
ep.setInterfaceName(pt.getBinding().getPortType().getQName());
ep.setService(svc.getQName());
ep.setEndpoint(pt.getName());
+ ep.setDefinition(rootDef);
+ ep.setDescription(description);
// Retrieve wsdl
su.addEndpoint(ep);
}
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEEndpoint.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPEEndpoint.java Thu Mar 23 05:13:37 2006
@@ -78,6 +78,7 @@
} else if (exchange.getStatus() == ExchangeStatus.ERROR) {
return;
}
+
BPELStaticKey bsk = new BPELStaticKey();
bsk.setTargetNamespace(getInterfaceName().getNamespaceURI());
bsk.setPortType(getInterfaceName().getLocalPart());
@@ -92,7 +93,13 @@
EventDirector ed = ((BPEComponent) getServiceUnit().getComponent()).getEventDirector();
try {
- IResponseMessage response = ed.sendEvent(msg, true);
+ IResponseMessage response;
+ try {
+ BPEComponent.setCurrent((BPEComponent) serviceUnit.getComponent());
+ response = ed.sendEvent(msg, true);
+ } finally {
+ BPEComponent.setCurrent(null);
+ }
IInteraction payload = response.getPart(BPEComponent.PART_PAYLOAD);
if (response.getFault() != null) {
Exception e = response.getFault().getFaultException();
Added: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPESpringComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPESpringComponent.java?rev=388165&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPESpringComponent.java (added)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/BPESpringComponent.java Thu Mar 23 05:13:37 2006
@@ -0,0 +1,109 @@
+package org.apache.servicemix.bpe;
+
+import java.io.File;
+
+import org.apache.servicemix.common.BaseLifeCycle;
+import org.apache.servicemix.common.ServiceUnit;
+import org.springframework.core.io.Resource;
+
+/**
+ *
+ * @author gnodet
+ * @version $Revision: 376451 $
+ * @org.apache.xbean.XBean element="component"
+ * description="A BPE component"
+ */
+public class BPESpringComponent extends BPEComponent {
+
+ private String name;
+ private Resource bpelResource;
+
+ /* (non-Javadoc)
+ * @see org.servicemix.common.BaseComponent#createLifeCycle()
+ */
+ protected BaseLifeCycle createLifeCycle() {
+ return new LifeCycle();
+ }
+
+ public class LifeCycle extends BPELifeCycle {
+
+ protected ServiceUnit su;
+
+ public LifeCycle() {
+ super(BPESpringComponent.this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.servicemix.common.BaseLifeCycle#doInit()
+ */
+ protected void doInit() throws Exception {
+ super.doInit();
+ if (bpelResource == null) {
+ throw new IllegalArgumentException("bpelResource must be configured");
+ }
+ File bpelFile = bpelResource.getFile();
+ String fileName = bpelFile.getName();
+ if (!fileName.endsWith(".bpel")) {
+ throw new IllegalArgumentException("bpelResource must resolve to a .bpel file");
+ }
+ if (name == null) {
+ name = fileName.substring(0, fileName.length() - 5);
+ }
+ su = new BPEDeployer(BPESpringComponent.this).deploy(name, bpelFile.getParent());
+ getRegistry().registerServiceUnit(su);
+ }
+
+ /* (non-Javadoc)
+ * @see org.servicemix.common.BaseLifeCycle#doStart()
+ */
+ protected void doStart() throws Exception {
+ super.doStart();
+ su.start();
+ }
+
+ /* (non-Javadoc)
+ * @see org.servicemix.common.BaseLifeCycle#doStop()
+ */
+ protected void doStop() throws Exception {
+ su.stop();
+ super.doStop();
+ }
+
+ /* (non-Javadoc)
+ * @see org.servicemix.common.BaseLifeCycle#doShutDown()
+ */
+ protected void doShutDown() throws Exception {
+ su.shutDown();
+ super.doShutDown();
+ }
+ }
+
+ /**
+ * @return Returns the bpelResource.
+ */
+ public Resource getBpelResource() {
+ return bpelResource;
+ }
+
+ /**
+ * @param bpelResource The bpelResource to set.
+ */
+ public void setBpelResource(Resource bpelResource) {
+ this.bpelResource = bpelResource;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/external/JbiInvokeAction.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/external/JbiInvokeAction.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/external/JbiInvokeAction.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/external/JbiInvokeAction.java Thu Mar 23 05:13:37 2006
@@ -31,6 +31,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpe.action.external.ActionSystemException;
+import org.apache.ode.bpe.action.external.IExternalAction;
+import org.apache.ode.bpe.action.external.IURIResolver;
+import org.apache.ode.bpe.client.IFormattableValue;
+import org.apache.ode.bpe.interaction.XMLInteractionObject;
+import org.apache.ode.bpe.scope.service.BPRuntimeException;
import org.apache.servicemix.bpe.BPEComponent;
import org.apache.servicemix.bpe.BPELifeCycle;
import org.apache.servicemix.common.ExchangeProcessor;
@@ -40,13 +46,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.apache.ode.bpe.action.external.ActionSystemException;
-import org.apache.ode.bpe.action.external.IExternalAction;
-import org.apache.ode.bpe.action.external.IURIResolver;
-import org.apache.ode.bpe.client.IFormattableValue;
-import org.apache.ode.bpe.interaction.XMLInteractionObject;
-import org.apache.ode.bpe.scope.service.BPRuntimeException;
-
public class JbiInvokeAction implements IExternalAction, ExchangeProcessor {
public static final String INTERFACE_NAMESPACE = "interfaceNamespace";
@@ -63,9 +62,6 @@
private static Log log = LogFactory.getLog(JbiInvokeAction.class);
private Properties properties;
- private DeliveryChannel channel;
- private MessageExchangeFactory factory;
- private BPEComponent component;
private QName interfaceName;
private QName serviceName;
private String endpointName;
@@ -87,16 +83,6 @@
log.debug("init");
}
this.properties = props;
- component = BPEComponent.getInstance();
- if (component == null) {
- throw new BPRuntimeException("BPEComponent has not been created", "");
- }
- try {
- channel = ((BPELifeCycle) component.getLifeCycle()).getContext().getDeliveryChannel();
- factory = channel.createExchangeFactory();
- } catch (MessagingException e) {
- throw new BPRuntimeException("Could not retrieve DeliveryChannel", e);
- }
extractInformations();
if (serviceName == null && interfaceName == null) {
throw new BPRuntimeException("Interface, Service or Endpoint should be specified", "");
@@ -153,6 +139,9 @@
Source inputSource = getSourceFromPayload(payload);
// Create and send exchange
try {
+ BPEComponent component = BPEComponent.getCurrent();
+ DeliveryChannel channel = ((BPELifeCycle) component.getLifeCycle()).getContext().getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory();
// TODO: need to configure mep
MessageExchange me = factory.createExchange(this.mep);
me.setInterfaceName(interfaceName);
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerJdk.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerJdk.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerJdk.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerJdk.java Thu Mar 23 05:13:37 2006
@@ -31,9 +31,11 @@
private static Log log = LogFactory.getLog(BPETimerJdk.class);
private ITimerEvent te;
+ private BPEComponent component;
- public BPETimerJdk(ITimerEvent te) {
+ public BPETimerJdk(ITimerEvent te, BPEComponent component) {
this.te = te;
+ this.component = component;
}
public Object getId() {
@@ -49,8 +51,13 @@
if (log.isDebugEnabled()) {
log.debug("Timer " + te + " elapsed at " + new Date());
}
- EventDirector ed = BPEComponent.getInstance().getEventDirector();
- ed.getIInternalEventDirector().sendEvent(this, true);
+ EventDirector ed = component.getEventDirector();
+ try {
+ BPEComponent.setCurrent(component);
+ ed.getIInternalEventDirector().sendEvent(this, true);
+ } finally {
+ BPEComponent.setCurrent(null);
+ }
} catch (Exception e) {
e.printStackTrace();
}
Modified: incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerServiceJdk.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerServiceJdk.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerServiceJdk.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/main/java/org/apache/servicemix/bpe/timer/BPETimerServiceJdk.java Thu Mar 23 05:13:37 2006
@@ -26,6 +26,7 @@
import org.apache.ode.bpe.timerservice.IBPETimerService;
import org.apache.ode.bpe.util.BPEProperties;
import org.apache.ode.bpe.util.BPException;
+import org.apache.servicemix.bpe.BPEComponent;
public class BPETimerServiceJdk implements IBPETimerService {
@@ -40,7 +41,7 @@
if (log.isDebugEnabled()) {
log.debug("Schedule timer " + timerEvent + " for " + startDuration);
}
- BPETimerJdk tt = new BPETimerJdk(timerEvent);
+ BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEComponent.getCurrent());
timer.schedule(tt, startDuration);
return tt;
}
@@ -49,7 +50,7 @@
if (log.isDebugEnabled()) {
log.debug("Schedule timer " + timerEvent + " at " + startTime);
}
- BPETimerJdk tt = new BPETimerJdk(timerEvent);
+ BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEComponent.getCurrent());
timer.schedule(tt, startTime);
return tt;
}
Added: incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/Bank.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/Bank.java?rev=388165&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/Bank.java (added)
+++ incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/Bank.java Thu Mar 23 05:13:37 2006
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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 loanbroker;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+public class Bank extends ComponentSupport implements MessageExchangeListener {
+
+ public Bank(int number) {
+ setService(new QName("urn:logicblaze:soa:bank", "Bank" + number));
+ setEndpoint("bank");
+ }
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ InOut inOut = (InOut) exchange;
+ if (inOut.getStatus() == ExchangeStatus.DONE) {
+ return;
+ } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
+ return;
+ }
+ System.err.println(getService().getLocalPart() + " requested");
+ try {
+ String output = "<getLoanQuoteResponse xmlns=\"urn:logicblaze:soa:bank\"><rate>" + (Math.ceil(1000 * Math.random()) / 100) + "</rate></getLoanQuoteResponse>";
+ NormalizedMessage answer = inOut.createMessage();
+ answer.setContent(new StringSource(output));
+ answer(inOut, answer);
+ } catch (Exception e) {
+ throw new MessagingException(e);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/CreditAgency.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/CreditAgency.java?rev=388165&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/CreditAgency.java (added)
+++ incubator/servicemix/trunk/servicemix-bpe/src/test/java/loanbroker/CreditAgency.java Thu Mar 23 05:13:37 2006
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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 loanbroker;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+import com.sun.org.apache.xpath.internal.CachedXPathAPI;
+
+public class CreditAgency extends ComponentSupport implements MessageExchangeListener {
+
+ public CreditAgency() {
+ setService(new QName("urn:logicblaze:soa:creditagency", "CreditAgencyService"));
+ setEndpoint("agency");
+ }
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ InOut inOut = (InOut) exchange;
+ if (inOut.getStatus() == ExchangeStatus.DONE) {
+ return;
+ } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
+ return;
+ }
+ try {
+ Document doc = (Document) new SourceTransformer().toDOMNode(inOut.getInMessage());
+ String ssn = textValueOfXPath(doc, "//*[local-name()='ssn']");
+ if (ssn == null || ssn.length() == 0) {
+ fail(exchange, new NullPointerException());
+ return;
+ }
+ if (!ssn.startsWith("1")) {
+ Fault fault = inOut.createFault();
+ fault.setContent(new StringSource("<InvalidSSN xmlns=\"urn:logicblaze:soa:creditagency\"><ssn>" + ssn + "</ssn></InvalidSSN>"));
+ fail(inOut, fault);
+ } else {
+ String operation = null;
+ if (inOut.getOperation() != null) {
+ operation = inOut.getOperation().getLocalPart();
+ } else {
+ operation = doc.getDocumentElement().getLocalName();
+ }
+ String output;
+ if ("getCreditScore".equals(operation)) {
+ output = "<getCreditScoreResponse xmlns=\"urn:logicblaze:soa:creditagency\"><score>" + getCreditScore(ssn) + "</score></getCreditScoreResponse>";
+ } else if ("getCreditHistoryLength".equals(operation)) {
+ output = "<getCreditHistoryLengthResponse xmlns=\"urn:logicblaze:soa:creditagency\"><length>" + getCreditHistoryLength(ssn) + "</length></getCreditHistoryLengthResponse>";
+ } else {
+ throw new UnsupportedOperationException(operation);
+ }
+ NormalizedMessage answer = inOut.createMessage();
+ answer.setContent(new StringSource(output));
+ answer(inOut, answer);
+ }
+ } catch (Exception e) {
+ throw new MessagingException(e);
+ }
+ }
+ int getCreditScore(String ssn) {
+ //return ((int) (Math.random() * 600) + 300);
+ return 1000;
+ }
+ int getCreditHistoryLength(String ssn) {
+ //return ((int) (Math.random() * 19) + 1);
+ return 10;
+ }
+
+ protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
+ Node root = iterator.nextNode();
+ if (root instanceof Element) {
+ Element element = (Element) root;
+ if (element == null) {
+ return "";
+ }
+ String text = DOMUtil.getElementText(element);
+ return text;
+ }
+ else if (root != null) {
+ return root.getNodeValue();
+ } else {
+ return null;
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPEComponentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPEComponentTest.java?rev=388165&r1=388164&r2=388165&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPEComponentTest.java (original)
+++ incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPEComponentTest.java Thu Mar 23 05:13:37 2006
@@ -24,21 +24,15 @@
import java.net.URL;
import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.Fault;
-import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessagingException;
-import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;
-import javax.xml.transform.TransformerException;
import junit.framework.TestCase;
+import loanbroker.Bank;
+import loanbroker.CreditAgency;
-import org.apache.servicemix.MessageExchangeListener;
-import org.apache.servicemix.bpe.BPEComponent;
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.client.ServiceMixClient;
-import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.http.HttpEndpoint;
import org.apache.servicemix.http.HttpSpringComponent;
import org.apache.servicemix.jbi.container.ActivationSpec;
@@ -46,13 +40,6 @@
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
-import org.apache.servicemix.jbi.util.DOMUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.traversal.NodeIterator;
-
-import com.sun.org.apache.xpath.internal.CachedXPathAPI;
public class BPEComponentTest extends TestCase {
@@ -244,109 +231,4 @@
assertNotNull(me.getError());
}
- public static class Bank extends ComponentSupport implements MessageExchangeListener {
-
- public Bank(int number) {
- setService(new QName("urn:logicblaze:soa:bank", "Bank" + number));
- setEndpoint("bank");
- }
-
- public void onMessageExchange(MessageExchange exchange) throws MessagingException {
- InOut inOut = (InOut) exchange;
- if (inOut.getStatus() == ExchangeStatus.DONE) {
- return;
- } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
- done(inOut);
- return;
- }
- System.err.println(getService().getLocalPart() + " requested");
- try {
- String output = "<getLoanQuoteResponse xmlns=\"urn:logicblaze:soa:bank\"><rate>" + (Math.ceil(1000 * Math.random()) / 100) + "</rate></getLoanQuoteResponse>";
- NormalizedMessage answer = inOut.createMessage();
- answer.setContent(new StringSource(output));
- answer(inOut, answer);
- } catch (Exception e) {
- throw new MessagingException(e);
- }
- }
- }
-
- public static class CreditAgency extends ComponentSupport implements MessageExchangeListener {
-
- public CreditAgency() {
- setService(new QName("urn:logicblaze:soa:creditagency", "CreditAgencyService"));
- setEndpoint("agency");
- }
-
- public void onMessageExchange(MessageExchange exchange) throws MessagingException {
- InOut inOut = (InOut) exchange;
- if (inOut.getStatus() == ExchangeStatus.DONE) {
- return;
- } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
- done(inOut);
- return;
- }
- try {
- Document doc = (Document) new SourceTransformer().toDOMNode(inOut.getInMessage());
- String ssn = textValueOfXPath(doc, "//*[local-name()='ssn']");
- if (ssn == null || ssn.length() == 0) {
- fail(exchange, new NullPointerException());
- return;
- }
- if (!ssn.startsWith("1")) {
- Fault fault = inOut.createFault();
- fault.setContent(new StringSource("<InvalidSSN xmlns=\"urn:logicblaze:soa:creditagency\"><ssn>" + ssn + "</ssn></InvalidSSN>"));
- fail(inOut, fault);
- } else {
- String operation = null;
- if (inOut.getOperation() != null) {
- operation = inOut.getOperation().getLocalPart();
- } else {
- operation = doc.getDocumentElement().getLocalName();
- }
- String output;
- if ("getCreditScore".equals(operation)) {
- output = "<getCreditScoreResponse xmlns=\"urn:logicblaze:soa:creditagency\"><score>" + getCreditScore(ssn) + "</score></getCreditScoreResponse>";
- } else if ("getCreditHistoryLength".equals(operation)) {
- output = "<getCreditHistoryLengthResponse xmlns=\"urn:logicblaze:soa:creditagency\"><length>" + getCreditHistoryLength(ssn) + "</length></getCreditHistoryLengthResponse>";
- } else {
- throw new UnsupportedOperationException(operation);
- }
- NormalizedMessage answer = inOut.createMessage();
- answer.setContent(new StringSource(output));
- answer(inOut, answer);
- }
- } catch (Exception e) {
- throw new MessagingException(e);
- }
- }
- int getCreditScore(String ssn) {
- //return ((int) (Math.random() * 600) + 300);
- return 1000;
- }
- int getCreditHistoryLength(String ssn) {
- //return ((int) (Math.random() * 19) + 1);
- return 10;
- }
-
- }
-
- protected static String textValueOfXPath(Node node, String xpath) throws TransformerException {
- CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
- NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
- Node root = iterator.nextNode();
- if (root instanceof Element) {
- Element element = (Element) root;
- if (element == null) {
- return "";
- }
- String text = DOMUtil.getElementText(element);
- return text;
- }
- else if (root != null) {
- return root.getNodeValue();
- } else {
- return null;
- }
- }
}
Added: incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPESpringComponentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPESpringComponentTest.java?rev=388165&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPESpringComponentTest.java (added)
+++ incubator/servicemix/trunk/servicemix-bpe/src/test/java/org/apache/servicemix/bpe/BPESpringComponentTest.java Thu Mar 23 05:13:37 2006
@@ -0,0 +1,40 @@
+package org.apache.servicemix.bpe;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class BPESpringComponentTest extends SpringTestSupport {
+
+ public void test() throws Exception {
+ ServiceMixClient client = new DefaultServiceMixClient(jbi);
+ MessageExchange me = client.createInOutExchange();
+ me.setService(new QName("urn:logicblaze:soa:loanbroker", "LoanBrokerService"));
+ me.setOperation(new QName("getLoanQuote"));
+ me.getMessage("in").setContent(new StringSource("<getLoanQuoteRequest xmlns=\"urn:logicblaze:soa:loanbroker\"><ssn>1234341</ssn><amount>100000.0</amount><duration>12</duration></getLoanQuoteRequest>"));
+ long t0 = System.currentTimeMillis();
+ client.sendSync(me);
+ long t1 = System.currentTimeMillis();
+ if (me.getError() != null) {
+ throw me.getError();
+ }
+ assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
+ String out = new SourceTransformer().contentToString(me.getMessage("out"));
+ System.err.println(out);
+ System.err.println("Time: " + (t1 - t0));
+ client.done(me);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/bpe/spring.xml");
+ }
+
+}
Added: incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/spring.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/spring.xml?rev=388165&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/spring.xml (added)
+++ incubator/servicemix/trunk/servicemix-bpe/src/test/resources/org/apache/servicemix/bpe/spring.xml Thu Mar 23 05:13:37 2006
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:bpe="http://servicemix.apache.org/bpe/1.0"
+ xmlns:ca="urn:logicblaze:soa:creditagency">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- output using a POJO -->
+ <sm:activationSpec>
+ <sm:component>
+ <bpe:component bpelResource="classpath:loanbroker/loanbroker.bpel" />
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec interfaceName="ca:CreditAgency">
+ <sm:component>
+ <bean class="loanbroker.CreditAgency" />
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec>
+ <sm:component>
+ <bean class="loanbroker.Bank">
+ <constructor-arg value="1" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec>
+ <sm:component>
+ <bean class="loanbroker.Bank">
+ <constructor-arg value="2" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+</beans>