You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/08/29 08:59:58 UTC
svn commit: r690130 - in
/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi: api/
exception/ helper/ jaxp/ listener/ marshaler/ transformer/
Author: gertv
Date: Thu Aug 28 23:59:57 2008
New Revision: 690130
URL: http://svn.apache.org/viewvc?rev=690130&view=rev
Log:
SM-1455: Moving shared code from servicemix-core to servicemix-utils
Added:
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/Message.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/FaultException.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoFaultAvailableException.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoInMessageAvailableException.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoOutMessageAvailableException.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/MessageHelper.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DefaultNamespaceContext.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/JavaSource.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/MessageExchangeListener.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/DefaultMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/PojoMarshaler.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/CopyTransformer.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/MessageTransformer.java
servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/Message.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/Message.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/Message.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/api/Message.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.api;
+
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.jbi.marshaler.PojoMarshaler;
+
+/**
+ * An extension of the standard {@link NormalizedMessage} which allows you to
+ * work directly with message bodies as POJOs ignoring the XML stuff or passing a binary
+ * message around as a ByteBuffer or byte[]
+ *
+ * @version $Revision: 359151 $
+ */
+public interface Message extends NormalizedMessage {
+
+ /**
+ * Returns the body as a POJO. Depending on the implementation this could be
+ * a Java POJO, a DOM tree or a byte[]
+ */
+ Object getBody() throws MessagingException;
+
+ /**
+ * Returns the body as a POJO. Depending on the implementation this could be
+ * a Java POJO, a DOM tree or a byte[]
+ *
+ * @param marshaler marshaler to be used for conversion
+ */
+ Object getBody(PojoMarshaler marshaler) throws MessagingException;
+
+ /**
+ * Sets the body as a POJO
+ */
+ void setBody(Object body) throws MessagingException;
+
+ /**
+ * Returns the message exchange
+ */
+ MessageExchange getExchange();
+
+ /**
+ * Helper method to create a new fault for this message exchange
+ */
+ Fault createFault() throws MessagingException;
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/FaultException.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/FaultException.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/FaultException.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/FaultException.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.exception;
+
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * An exception which is thrown if a fault occurs in some JBI client invocation.
+ *
+ * @version $Revision: 564374 $
+ */
+public class FaultException extends MessagingException {
+
+ private final MessageExchange exchange;
+ private final Fault fault;
+
+ public FaultException(String text, MessageExchange exchange, Fault fault) {
+ super(text);
+ this.exchange = exchange;
+ this.fault = fault;
+ }
+
+ public static FaultException newInstance(MessageExchange exchange) throws NoFaultAvailableException {
+ Fault fault = exchange.getFault();
+ if (fault == null) {
+ throw new NoFaultAvailableException(exchange);
+ } else {
+ return new FaultException("Fault occurred invoking server: " + fault, exchange, fault);
+ }
+ }
+
+ public MessageExchange getExchange() {
+ return exchange;
+ }
+
+ public Fault getFault() {
+ return fault;
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoFaultAvailableException.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoFaultAvailableException.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoFaultAvailableException.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoFaultAvailableException.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.exception;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * An exception thrown if a component cannot find an expected {@link Fault}
+ *
+ * @version $Revision: 564607 $
+ */
+public class NoFaultAvailableException extends MessagingException {
+
+ private final MessageExchange messageExchange;
+
+ public NoFaultAvailableException(MessageExchange messageExchange) {
+ super("No Fault available for message exchange: " + messageExchange);
+ this.messageExchange = messageExchange;
+ }
+
+ /**
+ * The message exchange on which the problem occurred
+ */
+ public MessageExchange getMessageExchange() {
+ return messageExchange;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoInMessageAvailableException.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoInMessageAvailableException.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoInMessageAvailableException.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoInMessageAvailableException.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.exception;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * An exception thrown if a component cannot find an expected in message.
+ *
+ * @version $Revision: 564374 $
+ */
+public class NoInMessageAvailableException extends MessagingException {
+
+ private final MessageExchange messageExchange;
+
+ public NoInMessageAvailableException(MessageExchange messageExchange) {
+ super("No in message available for message exchange: " + messageExchange);
+ this.messageExchange = messageExchange;
+ }
+
+ /**
+ * The message exchange on which the problem occurred
+ */
+ public MessageExchange getMessageExchange() {
+ return messageExchange;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoOutMessageAvailableException.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoOutMessageAvailableException.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoOutMessageAvailableException.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/exception/NoOutMessageAvailableException.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.exception;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * An exception thrown if a component cannot find an expected output message.
+ *
+ * @version $Revision: 564374 $
+ */
+public class NoOutMessageAvailableException extends MessagingException {
+
+ private final MessageExchange messageExchange;
+
+ public NoOutMessageAvailableException(MessageExchange messageExchange) {
+ super("No out message available for message exchange: " + messageExchange);
+ this.messageExchange = messageExchange;
+ }
+
+ /**
+ * The message exchange on which the problem occurred
+ */
+ public MessageExchange getMessageExchange() {
+ return messageExchange;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/MessageHelper.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/MessageHelper.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/MessageHelper.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/helper/MessageHelper.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.helper;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.api.Message;
+import org.apache.servicemix.jbi.jaxp.JavaSource;
+import org.apache.servicemix.jbi.marshaler.PojoMarshaler;
+
+/**
+ * Some helper methods for working with messages
+ *
+ * @version $Revision: $
+ */
+public final class MessageHelper {
+
+ private MessageHelper() {
+ }
+
+ /**
+ * A helper method to return the body of the message as a POJO which could be a
+ * bean or some DOMish model of the body.
+ *
+ * @param message the message on which to extract the body
+ * @return the body of the message as a POJO or DOM object
+ * @throws javax.jbi.messaging.MessagingException
+ *
+ */
+ public static Object getBody(NormalizedMessage message) throws MessagingException {
+ Source content = message.getContent();
+ if (content instanceof JavaSource) {
+ JavaSource source = (JavaSource) content;
+ return source.getObject();
+ }
+ if (message instanceof Message) {
+ return ((Message) message).getBody();
+ }
+ return message.getProperty(PojoMarshaler.BODY);
+ }
+
+ /**
+ * A helper method to return the body of the message as a POJO which could be a
+ * bean or some DOMish model of the body.
+ *
+ * @param message the message on which to extract the body
+ * @param marshaller the marshaller used to map from the XML representation to the POJO
+ * @return the body of the message as a POJO or DOM object
+ * @throws javax.jbi.messaging.MessagingException
+ *
+ */
+ public static Object getBody(NormalizedMessage message, PojoMarshaler marshaller) throws MessagingException {
+ Source content = message.getContent();
+ if (content instanceof JavaSource) {
+ JavaSource source = (JavaSource) content;
+ return source.getObject();
+ }
+ if (message instanceof Message) {
+ return ((Message) message).getBody(marshaller);
+ }
+ return message.getProperty(PojoMarshaler.BODY);
+ }
+
+ /**
+ * Sets the body of the message as a POJO
+ *
+ * @param message the message on which to set the body
+ * @param body the POJO or DOMish model to set
+ * @throws MessagingException
+ */
+ public static void setBody(NormalizedMessage message, Object body) throws MessagingException {
+ Source content = message.getContent();
+ if (content instanceof JavaSource) {
+ JavaSource source = (JavaSource) content;
+ source.setObject(body);
+ } else if (message instanceof Message) {
+ ((Message) message).setBody(body);
+ } else {
+ message.setProperty(PojoMarshaler.BODY, body);
+ }
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DefaultNamespaceContext.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DefaultNamespaceContext.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DefaultNamespaceContext.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/DefaultNamespaceContext.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.jaxp;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPathFactory;
+
+/**
+ * An implementation of {@link NamespaceContext} which uses a simple Map where
+ * the keys are the prefixes and the values are the URIs
+ *
+ * @version $Revision: $
+ */
+public class DefaultNamespaceContext implements NamespaceContext {
+
+ private final Map map;
+ private final NamespaceContext parent;
+
+ public DefaultNamespaceContext() {
+ this.map = new HashMap();
+ XPathFactory factory = XPathFactory.newInstance();
+ this.parent = factory.newXPath().getNamespaceContext();
+ }
+
+ public DefaultNamespaceContext(NamespaceContext parent, Map map) {
+ this.parent = parent;
+ this.map = map;
+ }
+
+ /**
+ * A helper method to make it easy to create newly populated instances
+ */
+ public DefaultNamespaceContext add(String prefix, String uri) {
+ map.put(prefix, uri);
+ return this;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ String answer = (String) map.get(prefix);
+ if (answer == null && parent != null) {
+ return parent.getNamespaceURI(prefix);
+ }
+ return answer;
+ }
+
+ public String getPrefix(String namespaceURI) {
+ for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (namespaceURI.equals(entry.getValue())) {
+ return (String) entry.getKey();
+ }
+ }
+ if (parent != null) {
+ return parent.getPrefix(namespaceURI);
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String namespaceURI) {
+ Set set = new HashSet();
+ for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ if (namespaceURI.equals(entry.getValue())) {
+ set.add(entry.getKey());
+ }
+ }
+ if (parent != null) {
+ Iterator iter = parent.getPrefixes(namespaceURI);
+ while (iter.hasNext()) {
+ set.add(iter.next());
+ }
+ }
+ return set.iterator();
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/JavaSource.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/JavaSource.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/JavaSource.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/jaxp/JavaSource.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.jaxp;
+
+import javax.xml.transform.Source;
+
+/**
+ * Represents an API to a JAXP {@link Source} which is capable of holding on to a POJO
+ *
+ * @version $Revision: 564374 $
+ */
+public interface JavaSource extends Source {
+
+ /**
+ * Returns the POJO equivalent of the Source
+ */
+ Object getObject();
+
+ /**
+ * Sets the POJO equivalent of the Source
+ */
+ void setObject(Object object);
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/MessageExchangeListener.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/MessageExchangeListener.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/MessageExchangeListener.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/listener/MessageExchangeListener.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.listener;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * Interface to be notified when a {@link MessagingException} is received
+ *
+ * @version $Revision: 564607 $
+ */
+public interface MessageExchangeListener {
+
+ /**
+ * MessageExchange passed directly to the listener
+ *
+ * @param exchange
+ * @throws MessagingException
+ */
+ void onMessageExchange(MessageExchange exchange) throws MessagingException;
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/DefaultMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/DefaultMarshaler.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/DefaultMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/DefaultMarshaler.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.marshaler;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.w3c.dom.Node;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * Default implementation of {@link PojoMarshaler} which will pass through
+ * String objects as XML content, DOM objects or Stream objects, otherwise the
+ * payload is stored in a message property.
+ *
+ * @version $Revision: 564607 $
+ */
+public class DefaultMarshaler implements PojoMarshaler {
+
+ private PojoMarshaler parent;
+
+ public DefaultMarshaler() {
+ }
+
+ public DefaultMarshaler(PojoMarshaler parent) {
+ this.parent = parent;
+ }
+
+ public PojoMarshaler getParent() {
+ return parent;
+ }
+
+ public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException {
+ if (body instanceof Source) {
+ message.setContent((Source) body);
+ } else {
+ message.setProperty(BODY, body);
+ Source content = asContent(message, body);
+ message.setContent(content);
+ }
+ }
+
+ public Object unmarshal(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ Object answer = message.getProperty(BODY);
+ if (answer == null) {
+ if (parent != null) {
+ answer = parent.unmarshal(exchange, message);
+ }
+ if (answer == null) {
+ answer = defaultUnmarshal(exchange, message);
+ }
+ }
+ return answer;
+ }
+
+ protected Object defaultUnmarshal(MessageExchange exchange, NormalizedMessage message) {
+ Source content = message.getContent();
+ if (content instanceof DOMSource) {
+ DOMSource source = (DOMSource) content;
+ return source.getNode();
+ }
+ return content;
+ }
+
+ protected Source asContent(NormalizedMessage message, Object body) {
+ if (body instanceof Source) {
+ return (Source) body;
+ } else if (body instanceof String) {
+ // lets assume String is the XML to send
+ return new StringSource((String) body);
+ } else if (body instanceof Node) {
+ return new DOMSource((Node) body);
+ }
+ return null;
+ }
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/PojoMarshaler.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/PojoMarshaler.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/PojoMarshaler.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/marshaler/PojoMarshaler.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.marshaler;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * A plugin strategy which marshals an Object into and out of a JBI message.
+ * This interface is used by the ServiceMixClient to marshal POJOs into and out
+ * of JBI messages.
+ *
+ * @version $Revision: 564607 $
+ */
+public interface PojoMarshaler {
+
+ /**
+ * The key on the message to store the message body which cannot be
+ * marshaled into or out of XML easily or to provide a cache of the object
+ * representation of the object.
+ */
+ String BODY = "org.apache.servicemix.body";
+
+ /**
+ * Marshals the payload into the normalized message, typically as the
+ * content property.
+ *
+ * @param exchange
+ * the message exchange in which to marshal
+ * @param message
+ * the message in which to marshal
+ * @param body
+ * the body of the message as a POJO
+ */
+ void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException;
+
+ /**
+ * Unmarshals the response out of the normalized message.
+ *
+ * @param exchange
+ * the message exchange, which is an {@link InOut} or
+ * {@link InOptionalOut}
+ * @param message
+ * the output message
+ * @return the unmarshaled body object, extracted from the message
+ * @throws MessagingException
+ */
+ Object unmarshal(MessageExchange exchange, NormalizedMessage message) throws MessagingException;
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/CopyTransformer.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/CopyTransformer.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/CopyTransformer.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/CopyTransformer.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,192 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.transformer;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+
+import org.xml.sax.SAXException;
+
+import org.apache.servicemix.jbi.jaxp.BytesSource;
+import org.apache.servicemix.jbi.jaxp.ResourceSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.marshaler.PojoMarshaler;
+
+/**
+ * A simple transformer which copies the properties and content from the source message to the destination message.
+ *
+ * @version $Revision: 564374 $
+ */
+public class CopyTransformer implements MessageTransformer {
+
+ private static final CopyTransformer INSTANCE = new CopyTransformer();
+
+ private SourceTransformer sourceTransformer = new SourceTransformer();
+
+ private boolean copyProperties = true;
+
+ private boolean copyAttachments = true;
+
+ private boolean copySecuritySubject = true;
+
+ /**
+ * @return the copyAttachments
+ */
+ public boolean isCopyAttachments() {
+ return copyAttachments;
+ }
+
+ /**
+ * @param copyAttachments the copyAttachments to set
+ */
+ public void setCopyAttachments(boolean copyAttachments) {
+ this.copyAttachments = copyAttachments;
+ }
+
+ /**
+ * @return the copyProperties
+ */
+ public boolean isCopyProperties() {
+ return copyProperties;
+ }
+
+ /**
+ * @param copyProperties the copyProperties to set
+ */
+ public void setCopyProperties(boolean copyProperties) {
+ this.copyProperties = copyProperties;
+ }
+
+ /**
+ * @return the copySecuritySubject
+ */
+ public boolean isCopySecuritySubject() {
+ return copySecuritySubject;
+ }
+
+ /**
+ * @param copySecuritySubject the copySecuritySubject to set
+ */
+ public void setCopySecuritySubject(boolean copySecuritySubject) {
+ this.copySecuritySubject = copySecuritySubject;
+ }
+
+ /**
+ * Returns the singleton instance
+ *
+ * @return the singleton instance
+ */
+ public static CopyTransformer getInstance() {
+ return INSTANCE;
+ }
+
+ public boolean transform(MessageExchange exchange, NormalizedMessage from,
+ NormalizedMessage to) throws MessagingException {
+ if (copyProperties) {
+ copyProperties(from, to);
+ }
+
+ Source content = from.getContent();
+ if ((content instanceof StreamSource || content instanceof SAXSource)
+ && !(content instanceof StringSource)
+ && !(content instanceof BytesSource)
+ && !(content instanceof ResourceSource)) {
+ // lets avoid stream open exceptions by using a temporary format
+ try {
+ content = sourceTransformer.toDOMSource(from);
+ } catch (TransformerException e) {
+ throw new MessagingException(e);
+ } catch (ParserConfigurationException e) {
+ throw new MessagingException(e);
+ } catch (IOException e) {
+ throw new MessagingException(e);
+ } catch (SAXException e) {
+ throw new MessagingException(e);
+ }
+ }
+ to.setContent(content);
+
+ if (copyAttachments) {
+ copyAttachments(from, to);
+ }
+
+ if (copySecuritySubject) {
+ copySecuritySubject(from, to);
+ }
+
+ return true;
+ }
+
+ /**
+ * Copies all of the properties from one message to another
+ *
+ * @param from the message containing the properties
+ * @param to the destination messages where the properties are set
+ */
+ public static void copyProperties(NormalizedMessage from,
+ NormalizedMessage to) {
+ for (Iterator iter = from.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ // Do not copy transient properties
+ if (!PojoMarshaler.BODY.equals(name)) {
+ Object value = from.getProperty(name);
+ to.setProperty(name, value);
+ }
+ }
+ }
+
+ /**
+ * Copies the attachments from a message to another message
+ *
+ * @param from the message with the attachments
+ * @param to the message to which attachments are added
+ * @throws MessagingException if an attachment could not be added
+ */
+ public static void copyAttachments(NormalizedMessage from,
+ NormalizedMessage to) throws MessagingException {
+ for (Iterator iter = from.getAttachmentNames().iterator(); iter
+ .hasNext();) {
+ String name = (String) iter.next();
+ DataHandler value = from.getAttachment(name);
+ to.addAttachment(name, value);
+ }
+ }
+
+ /**
+ * Copies the subject from a message to another message
+ *
+ * @param from the message with the subject
+ * @param to the message to which the subject is added
+ * @throws MessagingException if an attachment could not be added
+ */
+ public static void copySecuritySubject(NormalizedMessage from,
+ NormalizedMessage to) throws MessagingException {
+ to.setSecuritySubject(from.getSecuritySubject());
+ }
+
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/MessageTransformer.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/MessageTransformer.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/MessageTransformer.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/MessageTransformer.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.transformer;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * Represents a transformer of an input message into an output message
+ *
+ * @version $Revision: 426415 $
+ */
+public interface MessageTransformer {
+
+ /**
+ * Transfers the state in the input message into the output message
+ * @param exchange the exchange on which the messages are flowing
+ * @param in the input message
+ * @param out an empty out message ready to contain the result of the transformation
+ */
+ boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException;
+}
Added: servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java
URL: http://svn.apache.org/viewvc/servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java?rev=690130&view=auto
==============================================================================
--- servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java (added)
+++ servicemix/utils/trunk/src/main/java/org/apache/servicemix/jbi/transformer/PropertyAddTransformer.java Thu Aug 28 23:59:57 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.jbi.transformer;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+public class PropertyAddTransformer extends CopyTransformer {
+
+ String name;
+ String value;
+
+ public boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ super.transform(exchange, in, out);
+ out.setProperty(name, value);
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
\ No newline at end of file