| CODENOTIFIER | HelpYou are not signed inSign in |
Project: PEtALS
Revision: 8838
Author: mcarpentier
Date: 06 Aug 2008 12:40:49
Changes:Added petals-bc-channelclient, a component made for test purposes which give a JMX access to the petals channel
Files:| ... | ...@@ -0,0 +1,71 @@ | |
| 1 | <project xmlns="http://maven.apache.org/POM/4.0.0" | |
| 2 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 3 | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| 4 | <modelVersion>4.0.0</modelVersion> | |
| 5 | ||
| 6 | <!-- ============== --> | |
| 7 | <!-- Identification --> | |
| 8 | <!-- ============== --> | |
| 9 | ||
| 10 | <parent> | |
| 11 | <artifactId>petals-tools</artifactId> | |
| 12 | <groupId>org.ow2.petals</groupId> | |
| 13 | <version>9-SNAPSHOT</version> | |
| 14 | </parent> | |
| 15 | ||
| 16 | <name>Petals Binding Component :: Channel Client</name> | |
| 17 | <artifactId>petals-bc-channelclient</artifactId> | |
| 18 | <groupId>org.ow2.petals</groupId> | |
| 19 | <version>1.0-SNAPSHOT</version> | |
| 20 | <packaging>jbi-component</packaging> | |
| 21 | ||
| 22 | <properties> | |
| 23 | <topDirectoryLocation>.</topDirectoryLocation> | |
| 24 | </properties> | |
| 25 | ||
| 26 | <dependencies> | |
| 27 | <dependency> | |
| 28 | <groupId>org.ow2.petals</groupId> | |
| 29 | <artifactId>petals-cdk-core</artifactId> | |
| 30 | <version>3.0</version> | |
| 31 | </dependency> | |
| 32 | ||
| 33 | <dependency> | |
| 34 | <groupId>org.ow2.petals</groupId> | |
| 35 | <artifactId>petals-jmx-api</artifactId> | |
| 36 | <version>1.3-SNAPSHOT</version> | |
| 37 | </dependency> | |
| 38 | ||
| 39 | </dependencies> | |
| 40 | ||
| 41 | <build> | |
| 42 | <plugins> | |
| 43 | <plugin> | |
| 44 | <groupId>org.objectweb.petals</groupId> | |
| 45 | <artifactId>maven-petals-plugin</artifactId> | |
| 46 | <extensions>true</extensions> | |
| 47 | </plugin> | |
| 48 | ||
| 49 | ||
| 50 | ||
| 51 | <plugin> | |
| 52 | <groupId>org.codehaus.mojo</groupId> | |
| 53 | <artifactId>netbeans-freeform-maven-plugin</artifactId> | |
| 54 | <configuration> | |
| 55 | <additionalGoals> | |
| 56 | plugin:xdoc site:site, | |
| 57 | projecthelp:active-profiles | |
| 58 | </additionalGoals> | |
| 59 | <additionalFiles> | |
| 60 | src/main/mdo/FreeformProject.mdo | |
| 61 | </additionalFiles> | |
| 62 | <additionalFolders> | |
| 63 | src/main/resources, src/test/projects, src/site, | |
| 64 | target | |
| 65 | </additionalFolders> | |
| 66 | </configuration> | |
| 67 | </plugin> | |
| 68 | </plugins> | |
| 69 | </build> | |
| 70 | ||
| 71 | </project> | |
| 0 | 72 | \ No newline at end of file |
| ... | ...@@ -0,0 +1,70 @@ | |
| 1 | /** | |
| 2 | * PETALS - PETALS Services Platform. | |
| 3 | * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/ | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | * ------------------------------------------------------------------------- | |
| 19 | * $Id$ | |
| 20 | * ------------------------------------------------------------------------- | |
| 21 | */ | |
| 22 | ||
| 23 | package org.ow2.petals.bc.channelclient.listener; | |
| 24 | ||
| 25 | import java.util.logging.Level; | |
| 26 | ||
| 27 | import org.ow2.petals.bc.channelclient.ChannelClientComponent; | |
| 28 | import org.ow2.petals.component.framework.listener.AbstractJBIListener; | |
| 29 | import org.ow2.petals.component.framework.util.Exchange; | |
| 30 | ||
| 31 | /** | |
| 32 | * This class implements the JBI listener | |
| 33 | * | |
| 34 | * @author mcarpentier - eBMWebSourcing | |
| 35 | * | |
| 36 | */ | |
| 37 | public final class JBIListener extends AbstractJBIListener { | |
| 38 | ||
| 39 | /** | |
| 40 | * The default constructor | |
| 41 | */ | |
| 42 | public JBIListener() { | |
| 43 | super(); | |
| 44 | } | |
| 45 | ||
| 46 | /** | |
| 47 | * (non-Javadoc) | |
| 48 | * | |
| 49 | * @see org.ow2.petals.component.common.listener.AbstractListener#init() | |
| 50 | */ | |
| 51 | @Override | |
| 52 | protected void init() { | |
| 53 | ||
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * (non-Javadoc) | |
| 58 | * | |
| 59 | * @param exchange | |
| 60 | * the exchange | |
| 61 | * @see org.ow2.petals.component.common.listener.AbstractJBIListener#processMessage(org.ow2.petals.component.common.util.MessageExchangeWrapper) | |
| 62 | */ | |
| 63 | @Override | |
| 64 | public void onJBIMessage(final Exchange exchange) { | |
| 65 | this.getLogger().log(Level.INFO, | |
| 66 | "ChannelClient received a message : " + exchange.getExchangeId()); | |
| 67 | ((ChannelClientComponent) this.getComponent()).getChannelClientBean().emitReceivedMessage( | |
| 68 | exchange); | |
| 69 | } | |
| 70 | } |
| ... | ...@@ -0,0 +1,232 @@ | |
| 1 | /** | |
| 2 | * PETALS - PETALS Services Platform. | |
| 3 | * Copyright (c) 2008 EBM Websourcing, http://www.ebmwebsourcing.com/ | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | * ------------------------------------------------------------------------- | |
| 19 | * $Id: ExchangeManager.java mcarpentier$ | |
| 20 | * ------------------------------------------------------------------------- | |
| 21 | */ | |
| 22 | ||
| 23 | package org.ow2.petals.bc.channelclient.listener; | |
| 24 | ||
| 25 | import java.io.File; | |
| 26 | import java.util.List; | |
| 27 | import java.util.Map; | |
| 28 | import java.util.Map.Entry; | |
| 29 | import java.util.logging.Logger; | |
| 30 | ||
| 31 | import javax.activation.DataHandler; | |
| 32 | import javax.activation.FileDataSource; | |
| 33 | import javax.jbi.JBIException; | |
| 34 | import javax.jbi.component.ComponentContext; | |
| 35 | import javax.jbi.messaging.DeliveryChannel; | |
| 36 | import javax.jbi.messaging.MessageExchange; | |
| 37 | import javax.jbi.messaging.MessagingException; | |
| 38 | import javax.jbi.servicedesc.ServiceEndpoint; | |
| 39 | import javax.security.auth.Subject; | |
| 40 | import javax.xml.namespace.QName; | |
| 41 | ||
| 42 | import org.ow2.petals.component.framework.Constants.MEPConstants; | |
| 43 | import org.ow2.petals.component.framework.util.Exchange; | |
| 44 | import org.ow2.petals.component.framework.util.ExchangeImpl; | |
| 45 | import org.ow2.petals.component.framework.util.StringHelper; | |
| 46 | import org.w3c.dom.Document; | |
| 47 | ||
| 48 | /** | |
| 49 | * | |
| 50 | * @author mcarpentier, nsalatge - eBM WebSourcing | |
| 51 | * | |
| 52 | */ | |
| 53 | public class ExchangeManager { | |
| 54 | ||
| 55 | /** | |
| 56 | * Send style | |
| 57 | * | |
| 58 | */ | |
| 59 | public static enum SendStyle { | |
| 60 | ASYNCHRONOUS_SEND, SYNCHRONOUS_SEND | |
| 61 | }; | |
| 62 | ||
| 63 | private final DeliveryChannel dc; | |
| 64 | ||
| 65 | private final ComponentContext cc; | |
| 66 | ||
| 67 | private Logger logger; | |
| 68 | ||
| 69 | /** | |
| 70 | * Default constructor | |
| 71 | * | |
| 72 | * @throws MessagingException | |
| 73 | */ | |
| 74 | public ExchangeManager(final ComponentContext cc, final DeliveryChannel dc, final Logger logger) | |
| 75 | throws MessagingException { | |
| 76 | this.dc = dc; | |
| 77 | this.cc = cc; | |
| 78 | this.logger = logger; | |
| 79 | ||
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Create a JBI message exchange | |
| 84 | * | |
| 85 | * @param itf | |
| 86 | * the QName | |
| 87 | * @param operation | |
| 88 | * the operation name | |
| 89 | * @param content | |
| 90 | * the content of the operation | |
| 91 | * @param attachmentFiles | |
| 92 | * the list of attachments | |
| 93 | * @param listener | |
| 94 | * the listener | |
| 95 | * @param properties | |
| 96 | * the properties | |
| 97 | * @param subject | |
| 98 | * the orchestra subject | |
| 99 | * @return the exchange. May be null | |
| 100 | * @throws MessagingException | |
| 101 | */ | |
| 102 | public Exchange createMsg(final String interfaceName, final String serviceName, | |
| 103 | final String operationName, final String endpointName, final MEPConstants mep, | |
| 104 | final Document content, final List<File> attachmentFiles, | |
| 105 | final Map<String, String> properties, final Subject subject) throws JBIException { | |
| 106 | ||
| 107 | if (mep == null) { | |
| 108 | throw new JBIException("the mep is null"); | |
| 109 | } | |
| 110 | ||
| 111 | MessageExchange msg = null; | |
| 112 | if (mep.equals(MEPConstants.IN_ONLY_PATTERN)) { | |
| 113 | msg = this.dc.createExchangeFactory().createInOnlyExchange(); | |
| 114 | } else if (mep.equals(MEPConstants.IN_OUT_PATTERN)) { | |
| 115 | msg = this.dc.createExchangeFactory().createInOutExchange(); | |
| 116 | } else if (mep.equals(MEPConstants.IN_OPTIONAL_OUT_PATTERN)) { | |
| 117 | msg = this.dc.createExchangeFactory().createInOptionalOutExchange(); | |
| 118 | } else if (mep.equals(MEPConstants.ROBUST_IN_ONLY_PATTERN)) { | |
| 119 | msg = this.dc.createExchangeFactory().createRobustInOnlyExchange(); | |
| 120 | } | |
| 121 | ||
| 122 | final Exchange me = new ExchangeImpl(msg); | |
| 123 | ||
| 124 | // Set Endpoint value on the exchange | |
| 125 | if (!StringHelper.isNullOrEmpty(endpointName)) { | |
| 126 | // test if the endpoint is activated | |
| 127 | final ServiceEndpoint svcEndpoint = this.cc.getEndpoint(QName.valueOf(serviceName), | |
| 128 | endpointName); | |
| 129 | me.setEndpoint(svcEndpoint); | |
| 130 | } | |
| 131 | // Set Service on the exchange | |
| 132 | if (!StringHelper.isNullOrEmpty(serviceName)) { | |
| 133 | me.setService(QName.valueOf(serviceName)); | |
| 134 | } | |
| 135 | // Set Interface on the exchange | |
| 136 | if (!StringHelper.isNullOrEmpty(interfaceName)) { | |
| 137 | me.setInterfaceName(QName.valueOf(interfaceName)); | |
| 138 | } | |
| 139 | // set the operation | |
| 140 | if (operationName == null) { | |
| 141 | throw new JBIException("operation cannot be null"); | |
| 142 | } | |
| 143 | me.setOperation(QName.valueOf(operationName)); | |
| 144 | ||
| 145 | // Create in msg | |
| 146 | me.setInMessageContent(content); | |
| 147 | ||
| 148 | // set properties | |
| 149 | if (properties != null) { | |
| 150 | for (final Entry<String, String> entry : properties.entrySet()) { | |
| 151 | me.setProperty(entry.getKey().trim(), entry.getValue().trim()); | |
| 152 | } | |
| 153 | } | |
| 154 | ||
| 155 | // setting attachments if any | |
| 156 | if (attachmentFiles != null) { | |
| 157 | for (final File attachmentFile : attachmentFiles) { | |
| 158 | try { | |
| 159 | me.getInMessage().addAttachment(attachmentFile.getName(), | |
| 160 | new DataHandler(new FileDataSource(attachmentFile))); | |
| 161 | } catch (final MessagingException e) { | |
| 162 | throw new JBIException("Error when attaching file " + attachmentFile.getName()); | |
| 163 | } | |
| 164 | } | |
| 165 | } | |
| 166 | ||
| 167 | // add authentification subject | |
| 168 | if (subject != null) { | |
| 169 | me.getInMessage().setSecuritySubject(subject); | |
| 170 | } | |
| 171 | ||
| 172 | // add authentificaiton context | |
| 173 | if (subject != null) { | |
| 174 | me.getInMessage().setSecuritySubject(subject); | |
| 175 | } | |
| 176 | ||
| 177 | return me; | |
| 178 | } | |
| 179 | ||
| 180 | public DeliveryChannel getDeliveryChannel() { | |
| 181 | return this.dc; | |
| 182 | } | |
| 183 | ||
| 184 | public Logger getLogger() { | |
| 185 | return this.logger; | |
| 186 | } | |
| 187 | ||
| 188 | /** | |
| 189 | * Call a jbi service | |
| 190 | * | |
| 191 | * @param partner | |
| 192 | * the partner to invoke. May be null | |
| 193 | * @param msgIn | |
| 194 | * the exchange | |
| 195 | * @param syncTime | |
| 196 | * the time if it a send synchrone type | |
| 197 | * @return the exchange | |
| 198 | * @throws MessagingException | |
| 199 | * impossible to send exchange | |
| 200 | */ | |
| 201 | public Exchange send(final SendStyle sendStyle, final Exchange msgIn, final Long syncTime) | |
| 202 | throws MessagingException { | |
| 203 | this.getLogger().finest("Entering in send method"); | |
| 204 | ||
| 205 | if (sendStyle == SendStyle.ASYNCHRONOUS_SEND) { | |
| 206 | this.dc.send(((ExchangeImpl) msgIn).getMessageExchange()); | |
| 207 | } else if (sendStyle == SendStyle.SYNCHRONOUS_SEND) { | |
| 208 | if (syncTime > 0) { | |
| 209 | this.dc.sendSync(((ExchangeImpl) msgIn).getMessageExchange(), syncTime); | |
| 210 | } else { | |
| 211 | this.dc.sendSync(((ExchangeImpl) msgIn).getMessageExchange()); | |
| 212 | } | |
| 213 | } else { | |
| 214 | throw new MessagingException("this type of message (" + sendStyle + ") is unknown"); | |
| 215 | } | |
| 216 | ||
| 217 | // if ((msgIn.getFault() != null)||(msgIn.getError() != null)) { | |
| 218 | // String msg = "Error from the provider " | |
| 219 | // + msgIn.getEndpoint().getEndpointName() + ": "; | |
| 220 | // if(msgIn.getFault() != null) { | |
| 221 | // msg = msg + msgIn.getFault(); | |
| 222 | // } | |
| 223 | // throw new MessagingException(msg, msgIn.getError()); | |
| 224 | // } | |
| 225 | this.getLogger().finest("Exit to the send method"); | |
| 226 | return msgIn; | |
| 227 | } | |
| 228 | ||
| 229 | public void setLogger(final Logger logger) { | |
| 230 | this.logger = logger; | |
| 231 | } | |
| 232 | } |
| ... | ...@@ -0,0 +1,48 @@ | |
| 1 | /** | |
| 2 | * PETALS - PETALS Services Platform. | |
| 3 | * Copyright (c) 2007 EBM Websourcing, http://www.ebmwebsourcing.com/ | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | * ------------------------------------------------------------------------- | |
| 19 | * $Id: EjbBCException.java ofabre$ | |
| 20 | * ------------------------------------------------------------------------- | |
| 21 | */ | |
| 22 | ||
| 23 | package org.ow2.petals.bc.channelclient; | |
| 24 | ||
| 25 | /** | |
| 26 | * | |
| 27 | * @author mcarpentier | |
| 28 | */ | |
| 29 | public class ChannelClientComponentException extends Exception { | |
| 30 | ||
| 31 | /** | |
| 32 | * | |
| 33 | */ | |
| 34 | private static final long serialVersionUID = 6475194290779742238L; | |
| 35 | ||
| 36 | public ChannelClientComponentException(final String message) { | |
| 37 | super(message); | |
| 38 | } | |
| 39 | ||
| 40 | public ChannelClientComponentException(final String message, final Throwable cause) { | |
| 41 | super(message, cause); | |
| 42 | } | |
| 43 | ||
| 44 | public ChannelClientComponentException(final Throwable cause) { | |
| 45 | super(cause); | |
| 46 | } | |
| 47 | ||
| 48 | } |
| ... | ...@@ -0,0 +1,104 @@ | |
| 1 | /** | |
| 2 | * PETALS - PETALS Services Platform. | |
| 3 | * Copyright (c) 2008 EBM Websourcing, http://www.ebmwebsourcing.com/ | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | * ------------------------------------------------------------------------- | |
| 19 | * $Id$ | |
| 20 | * ------------------------------------------------------------------------- | |
| 21 | */ | |
| 22 | ||
| 23 | package org.ow2.petals.bc.channelclient.jmx; | |
| 24 | ||
| 25 | import java.io.IOException; | |
| 26 | ||
| 27 | import javax.management.InstanceAlreadyExistsException; | |
| 28 | import javax.management.InstanceNotFoundException; | |
| 29 | import javax.management.MBeanRegistrationException; | |
| 30 | import javax.management.MBeanServer; | |
| 31 | import javax.management.MalformedObjectNameException; | |
| 32 | import javax.management.NotCompliantMBeanException; | |
| 33 | import javax.management.ObjectName; | |
| 34 | ||
| 35 | import org.ow2.petals.bc.channelclient.ChannelClientComponentException; | |
| 36 | import org.ow2.petals.bc.channelclient.jmx.mbean.ChannelClient; | |
| 37 | import org.ow2.petals.bc.channelclient.listener.ExchangeManager; | |
| 38 | ||
| 39 | /** | |
| 40 | * This class helps to register MBean | |
| 41 | * | |
| 42 | * @author mcarpentier | |
| 43 | * | |
| 44 | */ | |
| 45 | public class MBeanHelper { | |
| 46 | ||
| 47 | public static final String DOMAIN = "Petals"; | |
| 48 | ||
| 49 | public static final String CHANNELCLIENT_MBEAN = "ChannelClient"; | |
| 50 | ||
| 51 | /** | |
| 52 | * The singleton internal instance | |
| 53 | */ | |
| 54 | private static MBeanHelper mbeanHelper = null; | |
| 55 | ||
| 56 | static { | |
| 57 | mbeanHelper = new MBeanHelper(); | |
| 58 | } | |
| 59 | ||
| 60 | public static MBeanHelper getInstance() { | |
| 61 | return mbeanHelper; | |
| 62 | } | |
| 63 | ||
| 64 | private MBeanHelper() { | |
| 65 | } | |
| 66 | ||
| 67 | public ChannelClient registerChannelClientMBean(final MBeanServer mbeanServer, | |
| 68 | final ExchangeManager exchangeManager) throws ChannelClientComponentException { | |
| 69 | try { | |
| 70 | // register ChannelClientService | |
| 71 | final ChannelClient client = new ChannelClient(exchangeManager); | |
| 72 | final ObjectName testName = new ObjectName(DOMAIN + ":name=" + CHANNELCLIENT_MBEAN | |
| 73 | + ",type=service"); | |
| 74 | mbeanServer.registerMBean(client, testName); | |
| 75 | return client; | |
| 76 | } catch (MalformedObjectNameException e) { | |
| 77 | throw new ChannelClientComponentException(e); | |
| 78 | } catch (InstanceAlreadyExistsException e) { | |
| 79 | throw new ChannelClientComponentException(e); | |
| 80 | } catch (MBeanRegistrationException e) { | |
| 81 | throw new ChannelClientComponentException(e); | |
| 82 | } catch (NotCompliantMBeanException e) { | |
| 83 | throw new ChannelClientComponentException(e); | |
| 84 | } | |
| 85 | ||
| 86 | } | |
| 87 | ||
| 88 | public void unregisterChannelClientMBean(final MBeanServer mbeanServer) | |
| 89 | throws ChannelClientComponentException { | |
| 90 | try { | |
| 91 | // unregister ChannelClientService | |
| 92 | final ObjectName testName = new ObjectName(DOMAIN + ":name=" + CHANNELCLIENT_MBEAN | |
| 93 | + ",type=service"); | |
| 94 | mbeanServer.unregisterMBean(testName); | |
| 95 | } catch (MalformedObjectNameException e) { | |
| 96 | throw new ChannelClientComponentException(e); | |
| 97 | } catch (MBeanRegistrationException e) { | |
| 98 | throw new ChannelClientComponentException(e); | |
| 99 | } catch (InstanceNotFoundException e) { | |
| 100 | throw new ChannelClientComponentException(e); | |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | } |
| ... | ...@@ -0,0 +1,30 @@ | |
| 1 | <jbi:jbi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 2 | xmlns:petals="http://petals.ow2.org/extensions" | |
| 3 | xmlns:jbi="http://java.sun.com/xml/ns/jbi" version="1.0"> | |
| 4 | <jbi:component xmlns="http://java.sun.com/xml/ns/jbi" | |
| 5 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 6 | type="binding-component"> | |
| 7 | <jbi:identification> | |
| 8 | <jbi:name>petals-bc-channelclient</jbi:name> | |
| 9 | <jbi:description> | |
| 10 | A JBI Channel Client Component | |
| 11 | </jbi:description> | |
| 12 | </jbi:identification> | |
| 13 | <jbi:component-class-name description="Channel Client Component class"> | |
| 14 | org.ow2.petals.bc.channelclient.ChannelClientComponent | |
| 15 | </jbi:component-class-name> | |
| 16 | <jbi:component-class-path></jbi:component-class-path> | |
| 17 | <jbi:bootstrap-class-name> | |
| 18 | org.ow2.petals.component.framework.DefaultBootstrap | |
| 19 | </jbi:bootstrap-class-name> | |
| 20 | <jbi:bootstrap-class-path></jbi:bootstrap-class-path> | |
| 21 | ||
| 22 | <petals:jbi-listener-class-name> | |
| 23 | org.ow2.petals.bc.channelclient.listener.JBIListener | |
| 24 | </petals:jbi-listener-class-name> | |
| 25 | <petals:external-listener-class-name></petals:external-listener-class-name> | |
| 26 | ||
| 27 | <petals:component-interceptors></petals:component-interceptors> | |
| 28 | <petals:params></petals:params> | |
| 29 | </jbi:component> | |
| 30 | </jbi:jbi> |
| ... | ...@@ -0,0 +1 @@ | |
| 0 | -make the jmx server port configurable | |
| 0 | 1 | \ No newline at end of file |
| ... | ...@@ -0,0 +1,315 @@ | |
| 1 | /** | |
| 2 | * PETALS - PETALS Services Platform. | |
| 3 | * Copyright (c) 2008 EBM Websourcing, http://www.ebmwebsourcing.com/ | |
| 4 | * | |
| 5 | * This library is free software; you can redistribute it and/or | |
| 6 | * modify it under the terms of the GNU Lesser General Public | |
| 7 | * License as published by the Free Software Foundation; either | |
| 8 | * version 2.1 of the License, or (at your option) any later version. | |
| 9 | * This library is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | * Lesser General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Lesser General Public | |
| 15 | * License along with this library; if not, write to the Free Software | |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 | * | |
| 18 | * ------------------------------------------------------------------------- | |
| 19 | * $Id | |
| 20 | * ------------------------------------------------------------------------- | |
| 21 | */ | |
| 22 | ||
| 23 | package org.ow2.petals.bc.channelclient.jmx.mbean; | |
| 24 | ||
| 25 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.CONTENT; | |
| 26 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.ENDPOINT; | |
| 27 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.ID; | |
| 28 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.INTERFACE; | |
| 29 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.MESSAGE_TYPE; | |
| 30 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.ChannelClientReportKeyNames.SERVICE; | |
| 31 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.MessageType.DONE; | |
| 32 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.MessageType.ERROR; | |
| 33 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.MessageType.FAULT; | |
| 34 | import static org.ow2.petals.jmx.api.IPetalsMonitoringService.MessageType.OUT; | |
| 35 | ||
| 36 | import java.io.File; | |
| 37 | import java.util.HashMap; | |
| 38 | import java.util.List; | |
| 39 | import java.util.Map; | |
| 40 | import java.util.logging.Level; | |
| 41 | import java.util.logging.Logger; | |
| 42 | ||
| 43 | import javax.jbi.JBIException; | |
| 44 | import javax.jbi.messaging.ExchangeStatus; | |
| 45 | import javax.jbi.messaging.MessagingException; | |
| 46 | import javax.management.ListenerNotFoundException; | |
| 47 | import javax.management.MBeanNotificationInfo; | |
| 48 | import javax.management.MalformedObjectNameException; | |
| 49 | import javax.management.Notification; | |
| 50 | import javax.management.NotificationBroadcasterSupport; | |
| 51 | import javax.management.NotificationEmitter; | |
| 52 | import javax.management.NotificationFilter; | |
| 53 | import javax.management.NotificationListener; | |
| 54 | import javax.management.ObjectName; | |
| 55 | import javax.security.auth.Subject; | |
| 56 | import javax.xml.transform.TransformerException; | |
| 57 | ||
| 58 | import org.ow2.petals.bc.channelclient.ChannelClientComponentException; | |
| 59 | import org.ow2.petals.bc.channelclient.jmx.MBeanHelper; | |
| 60 | import org.ow2.petals.bc.channelclient.listener.ExchangeManager; | |
| 61 | import org.ow2.petals.component.framework.Constants.MEPConstants; | |
| 62 | import org.ow2.petals.component.framework.exception.PEtALSCDKException; | |
| 63 | import org.ow2.petals.component.framework.util.Exchange; | |
| 64 | import org.ow2.petals.component.framework.util.SourceHelper; | |
| 65 | import org.ow2.petals.component.framework.util.StringHelper; | |
| 66 | import org.ow2.petals.component.framework.util.XMLUtil; | |
| 67 | import org.w3c.dom.Document; | |
| 68 | ||
| 69 | /** | |
| 70 | * This class is used by JMX to send messages synchronously and asynchronously | |
| 71 | * | |
| 72 | * @author mcarpentier | |
| 73 | * | |
| 74 | */ | |
| 75 | public class ChannelClient implements ChannelClientMBean, NotificationEmitter { | |
| 76 | ||
| 77 | private final static String CHANNELCLIENT_NOTIFTYPE = "ChannelClient.notif"; | |
| 78 | ||
| 79 | private ExchangeManager exchangeManager; | |
| 80 | ||
| 81 | private Logger log; | |
| 82 | ||
| 83 | private NotificationBroadcasterSupport notifBroadcaster; | |
| 84 | ||
| 85 | public ChannelClient(ExchangeManager exchangeManager) { | |
| 86 | super(); | |
| 87 | this.exchangeManager = exchangeManager; | |
| 88 | this.log = exchangeManager.getLogger(); | |
| 89 | this.notifBroadcaster = new NotificationBroadcasterSupport(); | |
| 90 | } | |
| 91 | ||
| 92 | /* | |
| 93 | * (non-Javadoc) | |
| 94 | * | |
| 95 | * @see org.ow2.petals.bc.channelclient.jmx.mbean.ChannelClientMBean#sendSync(java.lang.String, | |
| 96 | * java.lang.String, java.lang.String, java.lang.String, | |
| 97 | * java.lang.String, java.lang.String, java.util.List, java.util.Map, | |
| 98 | * javax.security.auth.Subject) | |
| 99 | */ | |
| 100 | public HashMap<String, Object> sendSync(String interfaceName, String serviceName, | |
| 101 | String operationName, String endpointName, String mep, String content, | |
| 102 | List<File> attachmentFiles, Map<String, String> properties, Subject subject) | |
| 103 | throws Exception { | |
| 104 | try { | |
| 105 | MEPConstants mepConstant = mepCheck(mep); | |
| 106 | Document doc = XMLUtil.createDocumentFromString(content); | |
| 107 | Exchange ex = this.exchangeManager.createMsg(interfaceName, serviceName, operationName, | |
| 108 | endpointName, mepConstant, doc, attachmentFiles, properties, subject); | |
| 109 | ||
| 110 | this.exchangeManager.send(ExchangeManager.SendStyle.SYNCHRONOUS_SEND, ex, 0L); | |
| 111 | ||
| 112 | this.exchangeManager.getLogger().log(Level.INFO, | |
| 113 | "Message sync received - content: \n" + ex.getExchangeId()); | |
| 114 | return createResponseMap(ex); | |
| 115 | ||
| 116 | } catch (JBIException e) { | |
| 117 | // we have to log in PEtALS, then throw the exception to JMX | |
| 118 | log.log(Level.SEVERE, "Failed to send Message", e); | |
| 119 | throw new Exception(e); | |
| 120 | } | |
| 121 | ||
| 122 | } | |
| 123 | ||
| 124 | /* | |
| 125 | * (non-Javadoc) | |
| 126 | * | |
| 127 | * @see org.ow2.petals.bc.channelclient.jmx.mbean.ChannelClientMBean#sendASync(java.lang.String, | |
| 128 | * java.lang.String, java.lang.String, java.lang.String, | |
| 129 | * java.lang.String, java.lang.String, java.util.List, java.util.Map, | |
| 130 | * javax.security.auth.Subject) | |
| 131 | */ | |
| 132 | public String sendASync(String interfaceName, String serviceName, String operationName, | |
| 133 | String endpointName, String mep, String content, List<File> attachmentFiles, | |
| 134 | Map<String, String> properties, Subject subject) throws Exception { | |
| 135 | try { | |
| 136 | MEPConstants mepConstant = mepCheck(mep); | |
| 137 | Document doc = XMLUtil.createDocumentFromString(content); | |
| 138 | ||
| 139 | Exchange ex = this.exchangeManager.createMsg(interfaceName, serviceName, operationName, | |
| 140 | endpointName, mepConstant, doc, attachmentFiles, properties, subject); | |
| 141 | this.exchangeManager.send(ExchangeManager.SendStyle.ASYNCHRONOUS_SEND, ex, 0L); | |
| 142 | return ex.getExchangeId(); | |
| 143 | ||
| 144 | } catch (JBIException e) { | |
| 145 | // log in PEtALS, then throw the exception to JMX | |
| 146 | log.log(Level.SEVERE, "Failed to send Message", e); | |
| 147 | throw new Exception(e); | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * Emit the message through JMX notification system | |
| 153 | * | |
| 154 | * @param exchange | |
| 155 | * @throws MessagingException | |
| 156 | */ | |
| 157 | public void emitReceivedMessage(Exchange exchange) { | |
| 158 | log.log(Level.FINE, "Channel client emitting received message " + exchange.getExchangeId()); | |
| 159 | try { | |
| 160 | Notification n = new Notification(CHANNELCLIENT_NOTIFTYPE, new ObjectName("Petals:name=" | |
| 161 | + MBeanHelper.CHANNELCLIENT_MBEAN + ",type=service"), 1L); | |
| 162 | n.setUserData(createResponseMap(exchange)); | |
| 163 | this.notifBroadcaster.sendNotification(n); | |
| 164 | } catch (MessagingException e) { | |
| 165 | log.log(Level.SEVERE, "Can't create notification message", e); | |
| 166 | } catch (MalformedObjectNameException e) { | |
| 167 | log.log(Level.SEVERE, "Can't create notification message", e); | |
| 168 | } catch (NullPointerException e) { | |
| 169 | log.log(Level.SEVERE, "Can't create notification message", e); | |
| 170 | } | |
| 171 | } | |
| 172 | ||
| 173 | /** | |
| 174 | * Check mep validity | |
| 175 | * | |
| 176 | * @param mep | |
| 177 | * @return | |
| 178 | * @throws ChannelClientComponentException | |
| 179 | */ | |
| 180 | private MEPConstants mepCheck(String mep) throws ChannelClientComponentException { | |
| 181 | MEPConstants mepConstant = null; | |
| 182 | // TODO: do comparaison in a proper way | |
| 183 | if ("InOnly".equalsIgnoreCase(mep)) { | |
| 184 | mepConstant = MEPConstants.IN_ONLY_PATTERN; | |
| 185 | } else if ("InOut".equalsIgnoreCase(mep)) { | |
| 186 | mepConstant = MEPConstants.IN_OUT_PATTERN; | |
| 187 | } else if ("RobustInOnly".equalsIgnoreCase(mep)) { | |
| 188 | mepConstant = MEPConstants.ROBUST_IN_ONLY_PATTERN; | |
| 189 | } else if ("InOptionalOut".equalsIgnoreCase(mep)) { | |
| 190 | mepConstant = MEPConstants.IN_OPTIONAL_OUT_PATTERN; | |
| 191 | } else { | |
| 192 | throw new ChannelClientComponentException("Cant sendSync, bad mep paramater : " + mep); | |
| 193 | } | |
| 194 | return mepConstant; | |
| 195 | } | |
| 196 | ||
| 197 | /* | |
| 198 | * (non-Javadoc) | |
| 199 | * | |
| 200 | * @see javax.management.NotificationEmitter#removeNotificationListener(javax.management.NotificationListener, | |
| 201 | * javax.management.NotificationFilter, java.lang.Object) | |
| 202 | */ | |
| 203 | public void removeNotificationListener(NotificationListener listener, | |
| 204 | NotificationFilter filter, Object handback) throws ListenerNotFoundException { | |
| 205 | this.notifBroadcaster.removeNotificationListener(listener, filter, handback); | |
| 206 | } | |
| 207 | ||
| 208 | /* | |
| 209 | * (non-Javadoc) | |
| 210 | * | |
| 211 | * @see javax.management.NotificationBroadcaster#addNotificationListener(javax.management.NotificationListener, | |
| 212 | * javax.management.NotificationFilter, java.lang.Object) | |
| 213 | */ | |
| 214 | public void addNotificationListener(NotificationListener listener, NotificationFilter filter, | |
| 215 | Object handback) throws IllegalArgumentException { | |
| 216 | this.notifBroadcaster.addNotificationListener(listener, filter, handback); | |
| 217 | } | |
| 218 | ||
| 219 | /* | |
| 220 | * (non-Javadoc) | |
| 221 | * | |
| 222 | * @see javax.management.NotificationBroadcaster#getNotificationInfo() | |
| 223 | */ | |
| 224 | public MBeanNotificationInfo[] getNotificationInfo() { | |
| 225 | String[] types = new String[] { CHANNELCLIENT_NOTIFTYPE }; | |
| 226 | String name = Notification.class.getName(); | |
| 227 | String description = "Notification containing a message : " | |
| 228 | + "HashMap{(String) id, (Document) content}"; | |
| 229 | MBeanNotificationInfo info = new MBeanNotificationInfo(types, name, description); | |
| 230 | return new MBeanNotificationInfo[] { info }; | |
| 231 | } | |
| 232 | ||
| 233 | /* | |
| 234 | * (non-Javadoc) | |
| 235 | * | |
| 236 | * @see javax.management.NotificationBroadcaster#removeNotificationListener(javax.management.NotificationListener) | |
| 237 | */ | |
| 238 | public void removeNotificationListener(NotificationListener listener) | |
| 239 | throws ListenerNotFoundException { | |
| 240 | this.notifBroadcaster.removeNotificationListener(listener); | |
| 241 | } | |
| 242 | ||
| 243 | /** | |
| 244 | * Create an HashMap representation of a Message Exchange See | |
| 245 | * {@link ChannelClientReportKeyNames} for map constants | |
| 246 | * | |
| 247 | * @param ex | |
| 248 | * @return | |
| 249 | * @throws MessagingException | |
| 250 | */ | |
| 251 | private HashMap<String, Object> createResponseMap(Exchange ex) throws MessagingException { | |
| 252 | String meId = ex.getExchangeId(); | |