alpha version of camel se

master
Vishnu 2013-07-18 14:58:38 +05:30
parent eb82310f5c
commit bbf4389520
54 changed files with 9499 additions and 0 deletions

View File

@ -219,6 +219,7 @@
<xpathmodel.artifact.version>${jbicomps.currentVersion}</xpathmodel.artifact.version>
<xsdmodel.artifact.version>${jbicomps.currentVersion}</xsdmodel.artifact.version>
<xsltse.artifact.version>${jbicomps.currentVersion}</xsltse.artifact.version>
<camelse.artifact.version>${jbicomps.currentVersion}</camelse.artifact.version>
<!-- contributed: -->
<screenscraperse.release.version>${ojc.default.release.version}</screenscraperse.release.version>
@ -952,6 +953,17 @@
<artifactId>restbc-installer</artifactId>
<version>${restbc.artifact.version}</version>
</dependency>
<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>camelseimpl</artifactId>
<version>${camelse.artifact.version}</version>
</dependency>
<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>camelse-installer</artifactId>
<version>${camelse.artifact.version}</version>
</dependency>
</dependencies>

View File

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>clean</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>clean</goal>
</goals>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</action>
<action>
<actionName>build</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>install</goal>
</goals>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</action>
<action>
<actionName>test</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>package</goal>
</goals>
<properties>
<maven.test.skip>false</maven.test.skip>
</properties>
</action>
<action>
<actionName>rebuild</actionName>
<packagings>
<packaging>*</packaging>
</packagings>
<goals>
<goal>clean</goal>
<goal>install</goal>
</goals>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</action>
<action>
<actionName>CUSTOM-testreport</actionName>
<displayName>testreport</displayName>
<goals>
<goal>surefire-report:report-only</goal>
</goals>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</action>
<action>
<actionName>CUSTOM-allreports</actionName>
<displayName>allreports</displayName>
<goals>
<goal>site</goal>
</goals>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
</action>
</actions>

View File

@ -0,0 +1,176 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<artifactId>build-common</artifactId>
<groupId>open-jbi-components</groupId>
<version>1.1</version>
<relativePath>../../build-common</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>open-jbi-components</groupId>
<artifactId>camelseimpl</artifactId>
<name>camelseimpl</name>
<version>${jbicomps.currentVersion}</version>
<description>camelseimpl description</description>
<properties>
<component.name>openesb-camel-se</component.name>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Component-Version>${camelse.artifact.version}</Component-Version>
<Component-Name>${component.name}</Component-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- camel dependencies -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.8.0</version>
</dependency>
<!-- camel dependencies -->
<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>componentsl</artifactId>
<scope>provided</scope>
</dependency>
<!--<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>encoder-fw</artifactId>
</dependency>
<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>qos</artifactId>
</dependency>
<dependency>
<groupId>open-jbi-components</groupId>
<artifactId>compositelock</artifactId>
</dependency>-->
<!-- TEST DEPENDENCIES-->
<!--<dependency>
<groupId>jbicompsplatform</groupId>
<artifactId>compileconf</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jmock</groupId>
<artifactId>jmock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jmock</groupId>
<artifactId>jmock-cglib</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.hulp.meas</groupId>
<artifactId>net.sf.hulp.meas.itf</artifactId>
<optional>true</optional>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.sf.hulp.meas</groupId>
<artifactId>net.sf.hulp.meas.impl</artifactId>
<optional>true</optional>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>open-esb</groupId>
<artifactId>jbi-admin-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>-->
</dependencies>
</project>

View File

@ -0,0 +1,18 @@
#
# 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.
#
class=org.openesb.components.camelse.camel.JBIBridgeComponent

View File

@ -0,0 +1,20 @@
#
# The logging properties used for eclipse testing, We want to see debug output on the console.
#
log4j.rootLogger=INFO, out
# uncomment the following line to turn on Camel debugging
#log4j.logger.org.apache.camel=DEBUG
# uncomment the following line to turn on ActiveMQ debugging
#log4j.logger.org.apache.activemq=DEBUG
log4j.logger.org.springframework=WARN
# CONSOLE appender not used by default
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

View File

@ -0,0 +1,132 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
/*
* CamelSEComponentLifeCycle.java
*/
package org.openesb.components.camelse;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jbi.component.ComponentContext;
import javax.jbi.management.MBeanNames;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.StandardMBean;
import org.openesb.components.camelse.CamelSEConfigMBean.CamelSEConfigMBeanImpl;
import org.openesb.components.camelse.common.BasicComponentLifeCycle;
import org.openesb.components.camelse.common.DefaultMessageExchangeReceiver;
import org.openesb.components.camelse.common.MessageExchangeReceiver;
import javax.jbi.JBIException;
import javax.jbi.component.Component;
/**
* This class extends the basic ComponentLifeCycle implementation to provide component
* specific implementation of the ComponentLifeCycle.
*
* @see javax.jbi.ComponentLifeCycle
* @see com.sun.jbi.sample.component.common.BasicComponentLifeCycle
* @author chikkala
*/
public class CamelSEComponentLifeCycle extends BasicComponentLifeCycle {
private CamelSEConfigMBeanImpl mConfigImpl;
/** constructor */
public CamelSEComponentLifeCycle(Component compRuntime) {
super(compRuntime);
}
/**
* creates DefaultMessageExchangeReceiver to handles receiving and processing
* the message exchanges from the delivery channel.
*/
@Override
protected MessageExchangeReceiver createMessageExchangeReceiver() {
return new DefaultMessageExchangeReceiver();
}
/**
* chance to extended classes to do the component specific init
* @throws javax.jbi.JBIException
*/
@Override
protected void doInit() throws JBIException {
super.doInit();
//TODO: create and register addtional mbeans if needed();
}
@Override
protected void doShutDown() throws JBIException {
super.doShutDown();
//TODO: unregister addtional mbeans created and clean the resources if needed.
}
@Override
protected void doStart() throws JBIException {
super.doStart();
}
@Override
protected void doStop() throws JBIException {
super.doStop();
}
@Override
protected StandardMBean createExtensionMBean() {
try {
ComponentContext ctx = this.getComponentContext();
if ( this.mConfigImpl == null ) {
this.mConfigImpl = new CamelSEConfigMBeanImpl(ctx.getInstallRoot(), ctx.getWorkspaceRoot());
}
StandardMBean configBean = new StandardMBean(this.mConfigImpl, CamelSEConfigMBean.class);
return configBean;
} catch (NotCompliantMBeanException ex) {
Logger.getLogger(CamelSEComponentLifeCycle.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
@Override
protected ObjectName createExtensionMBeanName() {
MBeanNames mbeanNames = this.getComponentContext().getMBeanNames();
// return mbeanNames.createCustomComponentMBeanName(mbeanNames.COMPONENT_LIFE_CYCLE_EXTENSION);
// return the configuration mbean as the extension mbean for now.
//TODO: change this to return null and manage add/remove configuration mbean
// as additional mbeans in doInit and doShutDown methods?
return mbeanNames.createCustomComponentMBeanName("Configuration");
}
protected CamelSEConfigMBean getConfigMBeanImpl() {
return this.mConfigImpl;
}
}

View File

@ -0,0 +1,194 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.openesb.components.camelse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author chikkala
*/
public interface CamelSEConfigMBean {
public void setCamelHome(String camelHome);
public String getCamelHome();
public void setIncludeCamelLibs(String includeLibs);
public String getIncludeCamelLibs();
public void setExcludeCamelLibs(String excludeLibs);
public String getExcludeCamelLibs();
public static class CamelSEConfigMBeanImpl implements CamelSEConfigMBean {
/** relative path in both installPath and workPath*/
private static final String CONFIG_FILE_PATH = "config.properties";
private static final String PROP_CAMEL_HOME = "camel.home";
private static final String PROP_EXCLUDE_CAMEL_LIBS = "exclude.camel.libs";
private static final String PROP_INCLUDE_CAMEL_LIBS = "include.camel.libs";
private File mConfigFile;
private Properties mConfigProps;
public CamelSEConfigMBeanImpl(String installPath) {
this(installPath, null);
}
/**
* if workPath is null, properties are loaded
* @param installPath
* @param workPath
*/
public CamelSEConfigMBeanImpl(String installPath, String workPath) {
this.mConfigProps = new Properties();
if (workPath == null) {
this.mConfigFile = createConfigFile(installPath);
loadProperties(this.mConfigProps, this.mConfigFile);
} else {
this.mConfigFile = createConfigFile(workPath);
Properties installProps = new Properties();
File installFile = findConfigFile(installPath);
if (installFile != null) {
loadProperties(installProps, installFile);
}
this.mConfigProps.putAll(installProps);
loadProperties(this.mConfigProps, this.mConfigFile);
}
}
private File createConfigFile(String configRootPath) {
File confFile = new File(configRootPath, CONFIG_FILE_PATH);
if (!confFile.exists()) {
try {
File confParent = confFile.getParentFile();
confParent.mkdirs();
FileWriter writer = new FileWriter(confFile);
writer.append("# CamelSe Configuration parameters");
writer.close();
} catch (Exception ex) {
//TODO: log.
ex.printStackTrace();
}
}
if (confFile.exists()) {
return confFile;
} else {
return null;
}
}
private File findConfigFile(String configRootPath) {
File confFile = new File(configRootPath, CONFIG_FILE_PATH);
if (confFile.exists()) {
return confFile;
} else {
return null;
}
}
private void saveProperties(File propFile, Properties props) {
FileOutputStream outS = null;
try {
outS = new FileOutputStream(propFile);
props.store(outS, "# CamelSe Configuration parameters");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (outS != null) {
try {
outS.close();
} catch (IOException ex) {
Logger.getLogger(CamelSEConfigMBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void loadProperties(Properties props, File propFile) {
FileInputStream inS = null;
try {
inS = new FileInputStream(propFile);
props.load(inS);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (inS != null) {
try {
inS.close();
} catch (IOException ex) {
Logger.getLogger(CamelSEConfigMBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private StringBuffer readResourceAsString(String resourcePath) {
StringWriter writer = new StringWriter();
InputStream inS = null;
try {
inS = this.getClass().getResourceAsStream(resourcePath);
InputStreamReader reader = new InputStreamReader(inS);
char[] buff = new char[1024];
int size = 0;
while ((size = reader.read(buff)) != -1) {
writer.write(buff, 0, size);
}
} catch (Exception ex) {
Logger.getLogger(CamelSEConfigMBean.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if ( inS != null ) {
try {
inS.close();
} catch (IOException ex) {
Logger.getLogger(CamelSEConfigMBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return writer.getBuffer();
}
public void setCamelHome(String camelHome) {
this.mConfigProps.setProperty(PROP_CAMEL_HOME, camelHome);
this.saveProperties(mConfigFile, mConfigProps);
}
public String getCamelHome() {
return this.mConfigProps.getProperty(PROP_CAMEL_HOME, "");
}
public void setIncludeCamelLibs(String includeLibs) {
this.mConfigProps.setProperty(PROP_INCLUDE_CAMEL_LIBS, includeLibs);
this.saveProperties(mConfigFile, mConfigProps);
}
public String getIncludeCamelLibs() {
return this.mConfigProps.getProperty(PROP_INCLUDE_CAMEL_LIBS, "");
}
public void setExcludeCamelLibs(String excludeLibs) {
this.mConfigProps.setProperty(PROP_EXCLUDE_CAMEL_LIBS, excludeLibs);
this.saveProperties(mConfigFile, mConfigProps);
}
public String getExcludeCamelLibs() {
return this.mConfigProps.getProperty(PROP_EXCLUDE_CAMEL_LIBS, "");
}
}
}

View File

@ -0,0 +1,303 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.openesb.components.camelse;
import java.util.ArrayList;
import java.util.List;
import javax.jbi.JBIException;
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.Fault;
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.wsdl.Definition;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.OperationType;
import javax.wsdl.Output;
import javax.wsdl.Part;
import javax.wsdl.PortType;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import org.openesb.components.camelse.JBIWrapperUtil;
import org.openesb.components.camelse.common.RuntimeHelper;
import org.openesb.components.camelse.common.deployment.ConsumerEndpoint;
import org.openesb.components.camelse.common.deployment.SUDescriptor;
import org.openesb.components.camelse.common.deployment.ServiceUnit;
import org.openesb.components.camelse.common.wsdl.WSDL11JBIWrapper;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
* @author chikkala
*/
public class CamelSEConsumerEndpoint extends ConsumerEndpoint {
private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
private static final long SEND_SYNC_TIMEOUT = 60000; // 1 minute
/** Creates a new instance of CamelSEConsumerEndpoint */
public CamelSEConsumerEndpoint(SUDescriptor.Consumes consumes, Definition wsdlDef, ServiceUnit su) {
super(consumes, wsdlDef, su);
}
@Override
protected void doInit() throws JBIException {
RuntimeHelper.getLogger().fine("CamelSEConsumerEndpoint(Consumer): init called");
this.initCamelEndpoint();
}
@Override
protected void doActivate() throws JBIException {
RuntimeHelper.getLogger().fine("CamelSEConsumerEndpoint(Consumer): activate called");
this.activateCamelEndpoint();
}
@Override
protected void doDeactivate() throws JBIException {
RuntimeHelper.getLogger().fine("CamelSEConsumerEndpoint(Consumer): deactivate called");
this.deactivateCamelEndpoint();
}
@Override
protected void doClean() throws JBIException {
RuntimeHelper.getLogger().fine("CamelSEConsumerEndpoint(Consumer): clean called");
this.cleanCamelEndpoint();
}
private void activateCamelEndpoint() {
//NOOP
}
private void cleanCamelEndpoint() {
//NOOP
}
private void deactivateCamelEndpoint() {
//NOOP
}
private void initCamelEndpoint() {
//NOOP
}
// /**
// * initiate exchange with a sepcified operation.
// * @param operation operation local name or qname as string. Assumes the service endpoint's
// * interface ns for operations ns
// * @param inSource
// * @return
// * @throws javax.jbi.JBIException
// */
// public Source initiateMessageExchange(String operation, Source inSource) throws JBIException {
// QName opQName = null;
// if (operation != null && operation.trim().length() > 0) {
// QName qn = QName.valueOf(operation);
// if (qn.getNamespaceURI().trim().length() > 0) {
// opQName = qn;
// } else {
// opQName = this.getOperationQName(operation);
// }
// }
// return initiateMessageExchange(opQName, inSource); // with default operation.
// }
/**
*
* @param operation openration name. can be null for default operation.
* @param inSource
* @return outSource if any. else null.
* @throws javax.jbi.JBIException on exception
*/
public Source initiateMessageExchange(QName operation, Source inSource) throws JBIException {
// 1. Decide what type of message exchange needed for this operation.
Source outSource = null;
try {
Operation wsdlOp = this.getWSDLOperation(operation);
if ( wsdlOp == null ) {
String msg = "Cannot find the wsdl operation " + operation + " on the jbi consumer endpoint " + this.getID();
this.getLogger().fine(msg);
throw new JBIException(msg);
}
QName wsdlOpQName = this.getOperationQName(wsdlOp.getName());
if ( OperationType.REQUEST_RESPONSE.equals(wsdlOp.getStyle()) ) {
outSource = doInOutMessageExchange(wsdlOpQName, inSource);
} else if ( OperationType.ONE_WAY.equals(wsdlOp.getStyle()) ) {
doInOnlyMessageExchange(wsdlOpQName, inSource);
} else {
throw new JBIException("Unsupported MEP " + wsdlOp.getStyle() +
"for operation " + operation);
}
return outSource;
} catch (Exception ex) {
ex.printStackTrace();
throw new JBIException(ex);
}
}
/**
* invokes the service provider with in-only message exchange sent to delivery channel
* by the consumer.
* //TODO: pass message headers, attachments and other normalized message settings.
* @param operation operation name on a service
* @param inSource input xml document for the InOut operation
* @throws java.lang.Exception if any error occurs in invoking the operation on the service.
* @return output xml document as a Source object received from InOut operation of the
* service invoked.
*/
private void doInOnlyMessageExchange(QName operation, Source inSource)
throws Exception {
// 2. normalized the message.
// 3. locate service endpoint
// 4. create message exchange according to the Opeations MEP
// get the component context and the delivery channel for preparing to send message
ComponentContext compContext = this.getComponentContext();
DeliveryChannel channel = this.getDeliveryChannel();
// create INOUT Message Exchange
InOnly inOnlyME = this.createInOnlyMessageExchange(operation);
// set the content of the IN normalized message ( Normalize the message )
NormalizedMessage inMsg = inOnlyME.getInMessage();
Operation wsdlOperation = this.getWSDLOperation(inOnlyME.getOperation());
JBIWrapperUtil.addJBIWrapperToInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource));
//// System.out.println("#### CamelSE ConsumerEndpont.doInOnlyMx : In Message Content for InOnly ");
//// System.out.println(RuntimeHelper.readFromSource(inMsg.getContent()));
// send the message exchange and wait for response
boolean isSent = channel.sendSync(inOnlyME, SEND_SYNC_TIMEOUT);
if ( !isSent ) {
throw new Exception("JMXBinding:Timeout occured in sending the message to provider");
}
// check if you got a done message or error ( done or error are only allowed in in-only)
// process the Message Exchange to check for done or error message and
// complete InOut message exchange with provider
//TODO: put this below code in processInOnlyMessageExchangeOnConsumer()
ExchangeStatus status = inOnlyME.getStatus();
this.getLogger().fine("Consumer:InOnly:Processing Message Exchange with status " + status);
if (ExchangeStatus.DONE.equals(status) ) {
this.getLogger().fine("Consumer: Completed the INONLY MessageExchange");
return;
} else if (ExchangeStatus.ERROR.equals(status) ) {
// error can occur any time. so just return the error back to client.
Exception serverSideEx = inOnlyME.getError();
StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx);
throw new Exception("Consumer:INONLY Message Exchange status ERROR.\n" + exMsgBuff);
} else {
// any other status is error.
throw new Exception("Consumer:INONLY Message Exchange error. status: " + status);
}
}
/**
* invokes service provider with in-out message exchange sent to delivery channel
* by the consumer
* @param operation operation name on a service
* @param inSource input xml document for the InOut operation
* @throws java.lang.Exception if any error occurs in invoking the operation on the service.
* @return output xml document as a Source object received from InOut operation of the
* service invoked.
*/
private Source doInOutMessageExchange(QName operation, Source inSource)
throws Exception {
// 2. normalized the message.
// 3. locate service endpoint
// 4. create message exchange according to the Opeations MEP
// get the component context and the delivery channel for preparing to send message
ComponentContext compContext = this.getComponentContext();
DeliveryChannel channel = this.getDeliveryChannel();
// create INOUT Message Exchange
InOut inOutME = this.createInOutMessageExchange(operation);
// set the content of the IN normalized message ( Normalize the message )
NormalizedMessage inMsg = inOutME.getInMessage();
Operation wsdlOperation = this.getWSDLOperation(inOutME.getOperation());
JBIWrapperUtil.addJBIWrapperToInput(wsdlOperation, inMsg, RuntimeHelper.sourceToDOMSource(inSource));
// send the message exchange and wait for response
boolean isSent = channel.sendSync(inOutME, SEND_SYNC_TIMEOUT);
if ( !isSent ) {
throw new Exception("CamelSE:Timeout occured in sending the message to provider");
}
// check if you got a out message or fault or error
// process the Message Exchange to get the output message and
// complete InOut message exchange with provider
NormalizedMessage outMsg = processInOutMessageExchangeOnConsumer(inOutME);
Source outSource = JBIWrapperUtil.removeJBIWrapperFromOutput(wsdlOperation, outMsg);
return outSource;
}
/**
* takes the InOut message exchange received from sendSync call and processes it further
* to complete InOut message exchange with provider and returns the out message or throws
* exception in case of error or faults.
*/
private NormalizedMessage processInOutMessageExchangeOnConsumer(InOut inoutExchange)
throws Exception {
// InOut MessageExchange processing on consumer side
// 1. ACTIVE status receives a fault or out message,
// send the done status to complete message exchange
// return the fault/out message to external consumer
// 2. can not receive DONE status
// 3. when received ERROR status, return the error to consumer.
// process the message exchange based on its state.
ExchangeStatus status = inoutExchange.getStatus();
this.getLogger().fine("Consumer:Processing Message Exchange with status " + status);
if (ExchangeStatus.ACTIVE.equals(status) ) {
Fault fault = inoutExchange.getFault();
NormalizedMessage outMsg = inoutExchange.getOutMessage();
// send done to complete message exchange.
DeliveryChannel channel = this.getDeliveryChannel();
inoutExchange.setStatus(ExchangeStatus.DONE);
channel.send(inoutExchange);
this.getLogger().fine("Consumer: Completed the INOUT MessageExchange");
// process fault or out message
if ( fault != null ) {
// throw an exception if there is a fault message.
Source faultContent = fault.getContent();
StringBuffer faultContentBuff = null;
if ( faultContent != null ) {
faultContentBuff = RuntimeHelper.readFromSource(faultContent);
}
throw new Exception("Consumer:INOUT message exchange Fault \n" +
faultContentBuff);
}
// return the outMessage for processing
if ( outMsg != null ) {
return outMsg;
} else {
throw new Exception("Consumer: Null Out message in INOUT message exchange. ");
}
} else if (ExchangeStatus.DONE.equals(status) ) {
// can not get DONE on Consumer side in INOUT message exchange.
throw new Exception("Consumer: Illegal status DONE on INOUT message exchange");
} else if (ExchangeStatus.ERROR.equals(status) ) {
// error can occur any time. so just return the error back to client.
Exception serverSideEx = inoutExchange.getError();
StringBuffer exMsgBuff = RuntimeHelper.getExceptionStackTrace(serverSideEx);
throw new Exception("Consumer:INOUT Message Exchange status ERROR.\n" + exMsgBuff);
} else {
throw new Exception("Consumer:INOUT Message Exchange error. status: " + status);
}
}
}

View File

@ -0,0 +1,97 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
/*
* CamelSEInstaller.java
*/
package org.openesb.components.camelse;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jbi.management.MBeanNames;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.StandardMBean;
import org.openesb.components.camelse.CamelSEConfigMBean.CamelSEConfigMBeanImpl;
import org.openesb.components.camelse.common.ComponentInstaller;
import javax.jbi.JBIException;
import javax.jbi.component.InstallationContext;
/**
* This class extends the ComponentInstaller that implements the
* javax.jbi.component.Bootstrap for a component installation contract.
*
* If the default implemenation of the javax.jbi.component.Bootstrap
* in com.sun.jbi.sample.component.common.ComponentInstaller is not sufficient
* for this components install, uninstall and upgrade requirements, override the
* default implementation here to add component specific installation and upgrade
* tasks such as initializing configuration mbean and creating resources specific
* to component or upgrade workspace and service units during upgrading the component.
*
* @see javax.jbi.Bootstrap
* @see com.sun.jbi.sample.component.common.ComponentInstaller
* @author chikkala
*/
public class CamelSEInstaller extends ComponentInstaller {
/** Constructor to create the MyEngineInstaller. */
public CamelSEInstaller() {
}
@Override
protected void doInit() throws JBIException {
super.doInit();
//// InstallationContext ctx = this.getInstallationContext();
//// List classPaths = ctx.getClassPathElements();
//// System.out.println("***** BEGIN CAMEL SE CLASS PATH ELEMENTS ******");
//// for ( Object path : classPaths ) {
//// System.out.println("CAMEL SE:ClassPathEl: " + path);
//// }
//// System.out.println("***** END CAMEL SE CLASS PATH ELEMENTS ******");
}
@Override
protected StandardMBean createExtensionMBean() {
try {
InstallationContext ctx = this.getInstallationContext();
CamelSEConfigMBeanImpl impl = new CamelSEConfigMBeanImpl(ctx.getInstallRoot());
StandardMBean configBean = new StandardMBean(impl, CamelSEConfigMBean.class);
return configBean;
} catch (NotCompliantMBeanException ex) {
Logger.getLogger(CamelSEInstaller.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
@Override
protected ObjectName createExtensionMBeanName() {
MBeanNames mbeanNames = this.getInstallationContext().getContext().getMBeanNames();
return mbeanNames.createCustomComponentMBeanName(mbeanNames.COMPONENT_LIFE_CYCLE_EXTENSION);
}
}

View File

@ -0,0 +1,105 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
/*
* CamelSEProviderEndpoint.java
*/
package org.openesb.components.camelse;
import org.openesb.components.camelse.camel.JBIBridgeEndpoint;
import org.openesb.components.camelse.common.MessageExchangeHandler;
import org.openesb.components.camelse.common.RuntimeHelper;
import org.openesb.components.camelse.common.MessageExchangeListener;
import org.openesb.components.camelse.common.deployment.ProviderEndpoint;
import org.openesb.components.camelse.common.deployment.SUDescriptor;
import javax.jbi.JBIException;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.wsdl.Definition;
/**
* This class extends the ProviderEndpoint to implement component specific endpoint configuration.
* It implements the MessageExchangeListener to receive message exchange notifications from the
* MessageExchangeSupport fired by MessageExchangeReceiver and process it using a message exchange
* handler.
*
* This endpoint is configured for a service provided by this component which can receive a xml
* document and apply xslt transformation and send the results back in a InOut message exchange
* to complete a service invocation on this endpoint.
*
* @author chikkala
*/
public class CamelSEProviderEndpoint extends ProviderEndpoint implements MessageExchangeListener {
/** Creates a new instance of XSLTProviderEndpoint */
public CamelSEProviderEndpoint(SUDescriptor.Provides provides, Definition wsdlDef, CamelSEServiceUnit su) {
super(provides, wsdlDef, su);
}
public JBIBridgeEndpoint getCamelEndpoint(MessageExchange me) {
CamelSEServiceUnit su = (CamelSEServiceUnit)this.getServiceUnit();
return su.getCamelEndpoint(me);
}
@Override
public void doInit() throws JBIException {
RuntimeHelper.getLogger().info("ProviderSEEndpoint:doInit called");
CamelSEServiceUnit su = (CamelSEServiceUnit) this.getServiceUnit();
//TODO: do any service impl specific initiaization
}
/**
* creates the message exchange handler that will be used to process the message exchange
* received for this endpoint.
*/
@Override
public MessageExchangeHandler createMessageExchangeHandler() {
return new CamelSEProviderMessageExchangeHandler(this);
}
/**
* returns the implementation of the message exchange listener which the
* MessageExchangeSupport invokes when a message exchange is received from delivery
* channel by MessageExchangeReceiver.
*/
@Override
protected MessageExchangeListener createMessageExchangeListener() {
return this;
}
/**
* implementation of the message exchange received method of the listener.
*/
public void messageExchangeReceived(ExchangeStatus status, MessageExchange me) {
try {
RuntimeHelper.getLogger().fine("MXListener.MessageExchangeReceived: with Status: " + status);
processMessageExchangeWithHandler(status, me);
// processMessageExchange(me);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

View File

@ -0,0 +1,192 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
* @(#)CamelSEProviderMessageExchangeHandler.java
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
package org.openesb.components.camelse;
import java.util.ArrayList;
import java.util.List;
import javax.wsdl.Input;
import javax.wsdl.Message;
import javax.wsdl.Operation;
import javax.wsdl.Part;
import javax.xml.transform.dom.DOMSource;
import org.openesb.components.camelse.common.AbstractMessageExchangeHandler;
import org.openesb.components.camelse.common.RuntimeHelper;
import org.openesb.components.camelse.common.wsdl.WSDL11JBIWrapper;
import org.openesb.components.camelse.camel.JBIBridgeEndpoint;
import java.io.StringReader;
import java.util.logging.Logger;
import javax.jbi.JBIException;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.Fault;
import javax.jbi.messaging.InOnly;
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.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* This class extends the AbstractMessageExchangeHandler to implement the component specific
* message exchange processing on the provider side in a service engine.
*
* @author chikkala
*/
public class CamelSEProviderMessageExchangeHandler extends AbstractMessageExchangeHandler {
private static final String XMLNS_NS = "http://www.w3.org/2000/xmlns/";
private CamelSEProviderEndpoint mEndpoint;
/** Creates a new instance of ProviderSEMXHandler */
public CamelSEProviderMessageExchangeHandler(CamelSEProviderEndpoint endpoint) {
this.mEndpoint = endpoint;
}
protected Logger getLogger() {
return this.mEndpoint.getLogger();
}
protected DeliveryChannel getDeliveryChannel() {
return this.mEndpoint.getDeliveryChannel();
}
protected void validateMessageExchange() throws MessagingException {
MessageExchange msgExchange = this.getMessageExchange();
if (this.getMessageExchange() == null) {
throw new MessagingException("MessageExchange Object is null in MessageExchageHandler");
}
if (MessageExchange.Role.CONSUMER.equals(msgExchange.getRole())) {
throw new MessagingException("Provider Message Exchange Handler can not have MessageExchange with CONSUMER Role");
}
}
protected void processError(Exception ex) {
MessageExchange msgExchange = this.getMessageExchange();
Exception errEx = msgExchange.getError(); // get the error and print
RuntimeHelper.getLogger().info(
" Message Exchange Provider received Error: " + errEx.getMessage());
msgExchange.getError().printStackTrace();
}
protected void processDone() {
MessageExchange msgExchange = this.getMessageExchange();
RuntimeHelper.getLogger().info(" Message Exchange Provider received DONE :" +
" END of service invocation");
}
protected void processFault(Fault fault) {
MessageExchange msgExchange = this.getMessageExchange();
RuntimeHelper.logError(" Message Exchange Provider Handler can not receive Fault on Provider side");
}
protected void processMessage() {
try {
MessageExchange me = this.getMessageExchange();
if (me instanceof InOnly) {
processMessageOnProvider((InOnly) me);
} else if (me instanceof InOut) {
processMessageOnProvider((InOut) me);
} else {
throw new JBIException("Unsupported message exchage " + me);
}
// processInMessageOnProvider((InOut)this.getMessageExchange());
// processInOnlyMessageOnProvider((InOnly)this.getMessageExchange());
} catch (JBIException ex) {
ex.printStackTrace();
}
}
/**
* synchronous processing of the inonly message exchange.
* @param inOnlyExchange
* @throws javax.jbi.JBIException
*/
protected void processMessageOnProvider(InOnly inOnlyExchange) throws JBIException {
RuntimeHelper.getLogger().fine("Processing inonly message exchange" + inOnlyExchange);
JBIBridgeEndpoint ep = this.mEndpoint.getCamelEndpoint(inOnlyExchange);
if (ep == null) {
throw new JBIException("Can not find Camel Endpoint for " + inOnlyExchange);
}
QName operationQName = inOnlyExchange.getOperation();
Operation wsdlOperation = this.mEndpoint.getWSDLOperation(operationQName);
JBIWrapperUtil.removeJBIWrapperFromInMessage(wsdlOperation, inOnlyExchange.getInMessage());
ep.getConsumer().processJBIMessageExchange(inOnlyExchange);
this.sendDone();
}
/**
* synchronour processing of the inout message exchange.
* @param inOutExchange
* @throws javax.jbi.JBIException
*/
protected void processMessageOnProvider(InOut inOutExchange) throws JBIException {
RuntimeHelper.getLogger().fine("Processing In Message on Provider side " + inOutExchange);
// invoke the service operation
try {
QName opName = inOutExchange.getOperation();
QName svcName = inOutExchange.getEndpoint().getServiceName();
// process
JBIBridgeEndpoint ep = this.mEndpoint.getCamelEndpoint(inOutExchange);
if (ep == null) {
throw new JBIException("Can not find Camel Endpoint for " + inOutExchange);
}
QName operationQName = inOutExchange.getOperation();
Operation wsdlOperation = this.mEndpoint.getWSDLOperation(operationQName);
JBIWrapperUtil.removeJBIWrapperFromInMessage(wsdlOperation, inOutExchange.getInMessage());
WSDL11JBIWrapper outWrapper = WSDL11JBIWrapper.createOutputWrapper(wsdlOperation);
ep.getConsumer().processJBIMessageExchange(inOutExchange, outWrapper);
} catch (Exception ex) {
// exception invoking the operation. so, set exception text as fault content.
ex.printStackTrace();
String faultText = RuntimeHelper.getExceptionAsXmlText(ex);
Source faultContent = RuntimeHelper.createDOMSource(new StringReader(faultText));
Fault fault = inOutExchange.createFault();
inOutExchange.setFault(fault);
fault.setContent(faultContent); // may need to normalize the content.
}
// send out or fault message.
// this.getDeliveryChannel().sendSync(inOutExchange, SEND_SYNC_TIMEOUT);
this.send();
}
}

View File

@ -0,0 +1,77 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
* @(#)CamelSERuntime.java
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
package org.openesb.components.camelse;
import org.openesb.components.camelse.common.ComponentRuntime;
import javax.jbi.component.ComponentLifeCycle;
import javax.jbi.component.ServiceUnitManager;
/**
* This class extends the ComponentRuntime that implements javax.jbi.component.Component
* interface required for the component contract at runtime.
*
* This class provides the component specific ComponentLifeCycle implementation
* as well as the component specific ServiceUnitManager implementation.
*
* Add any additional component runtime specific functionality here.
*
* @see javax.jbi.component.Component
* @see com.sun.jbi.sample.component.common.ComponentRuntime
* @see com.sun.jbi.sample.component.common.BasicComponentLifecycle
* @see com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager
* @author chikkala
*/
public class CamelSERuntime extends ComponentRuntime {
/** Creates a new instance of MyEngineRuntime */
public CamelSERuntime() {
super();
}
/**
* overriding the parent's createComponentLifeCycle to create
* component specific component lifecycle implementation.
*/
@Override
protected ComponentLifeCycle createComponentLifeCycle() {
return new CamelSEComponentLifeCycle(this);
}
/**
* overrides the parent's createServiceUnitManager to create component
* specific service unit manager
*/
@Override
protected ServiceUnitManager createServiceUnitManager() {
return new CamelSESUManager(this);
}
}

View File

@ -0,0 +1,68 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.
* If applicable add the following below this CDDL HEADER,
* with the fields enclosed by brackets "[]" replaced with
* your own identifying information: Portions Copyright
* [year] [name of copyright owner]
*/
/*
* @(#)CamelSESUManager.java
*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* END_HEADER - DO NOT EDIT
*/
package org.openesb.components.camelse;
import org.openesb.components.camelse.common.RuntimeHelper;
import org.openesb.components.camelse.common.deployment.AbstractServiceUnitManager;
import org.openesb.components.camelse.common.deployment.ServiceUnit;
import java.util.logging.Logger;
import javax.jbi.management.DeploymentException;
/**
* This class extends the AbstractServiceUnitManager to implement component specific
* service unit manager by creating the component specific ServiceUnit implementation.
* @see com.sun.jbi.sample.component.common.deployment.AbstractServiceUnitManager
* @see com.sun.jbi.sample.component.common.deployment.ServiceUnit
* @author chikkala
*/
public class CamelSESUManager extends AbstractServiceUnitManager {
private CamelSERuntime mRuntime;
/** Creates a new instance of CamelSESUManager */
public CamelSESUManager(CamelSERuntime compRuntime) {
super();
this.mRuntime = compRuntime;
}
protected Logger getLogger() {
return RuntimeHelper.getLogger();
}
protected String getComponentName() {
return RuntimeHelper.getComponentName();
}
//TODO implement CamelSEServiceUnit
protected ServiceUnit createServiceUnit(String suName, String suRootPath) throws DeploymentException {
return new CamelSEServiceUnit(suName, suRootPath, this.mRuntime);
}
}

View File

@ -0,0 +1,310 @@
/*
* BEGIN_HEADER - DO NOT EDIT
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* https://open-esb.dev.java.net/public/CDDLv1.0.html.