You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/10/10 01:07:27 UTC

svn commit: r454546 - in /incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi: framework/Endpoint.java framework/EndpointMBean.java util/QNameUtil.java

Author: gnodet
Date: Mon Oct  9 16:07:27 2006
New Revision: 454546

URL: http://svn.apache.org/viewvc?view=rev&rev=454546
Log:
SM-696: Add an operation to the EndpointMBean to allow testing the endpoint through jmx

Added:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/QNameUtil.java
Modified:
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Endpoint.java
    incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointMBean.java

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Endpoint.java?view=diff&rev=454546&r1=454545&r2=454546
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Endpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/Endpoint.java Mon Oct  9 16:07:27 2006
@@ -17,13 +17,20 @@
 package org.apache.servicemix.jbi.framework;
 
 import java.beans.PropertyChangeListener;
+import java.net.URI;
 
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
 import javax.management.JMException;
 import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanOperationInfo;
 import javax.xml.namespace.QName;
 import javax.xml.transform.TransformerException;
 
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.management.AttributeInfoHelper;
 import org.apache.servicemix.jbi.management.MBeanInfoProvider;
 import org.apache.servicemix.jbi.management.OperationInfoHelper;
@@ -32,6 +39,7 @@
 import org.apache.servicemix.jbi.servicedesc.InternalEndpoint;
 import org.apache.servicemix.jbi.servicedesc.LinkedEndpoint;
 import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.jbi.util.QNameUtil;
 
 public class Endpoint implements EndpointMBean, MBeanInfoProvider {
 
@@ -127,6 +135,31 @@
 
     protected AbstractServiceEndpoint getEndpoint() {
         return endpoint;
+    }
+
+    public String send(String content, String operation, String mep) {
+        try {
+            ServiceMixClient client = registry.getContainer().getClientFactory().createClient();
+            MessageExchange me = client.getExchangeFactory().createExchange(URI.create(mep));
+            NormalizedMessage nm = me.createMessage();
+            me.setMessage(nm, "in");
+            nm.setContent(new StringSource(content));
+            me.setEndpoint(endpoint);
+            if (operation != null) {
+                me.setOperation(QNameUtil.parse(operation));
+            }
+            client.sendSync(me);
+            if (me.getError() != null) {
+                throw me.getError();
+            } else if (me.getFault() != null) {
+                throw FaultException.newInstance(me);
+            } else if (me.getMessage("out") != null) {
+                return new SourceTransformer().contentToString(me.getMessage("out"));
+            }
+            return null;
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointMBean.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointMBean.java?view=diff&rev=454546&r1=454545&r2=454546
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointMBean.java (original)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/EndpointMBean.java Mon Oct  9 16:07:27 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.servicemix.jbi.framework;
 
+import java.net.URI;
+
 import javax.xml.namespace.QName;
 
 public interface EndpointMBean {
@@ -31,5 +33,7 @@
     public String getReference();
     
     public String getWSDL();
+    
+    public String send(String content, String operation, String mep);
 
 }

Added: incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/QNameUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/QNameUtil.java?view=auto&rev=454546
==============================================================================
--- incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/QNameUtil.java (added)
+++ incubator/servicemix/trunk/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/QNameUtil.java Mon Oct  9 16:07:27 2006
@@ -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.util;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+
+/**
+ * Utilities for converting QNames into different representations
+ * 
+ * @author Alex Boisvert
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ */
+public class QNameUtil {
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(QName qname) {
+        if (qname.getNamespaceURI() == null) {
+            return "{}" + qname.getLocalPart();
+        } else {
+            return "{" + qname.getNamespaceURI() + "}" + qname.getLocalPart();
+        }
+    }
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(Element element) {
+        if (element.getNamespaceURI() == null) {
+            return "{}" + element.getLocalName();
+        } else {
+            return "{" + element.getNamespaceURI() + "}" + element.getLocalName();
+        }
+    }
+
+    /**
+     * Convert QName to the Clark notation, e.g., {namespace}localName
+     */
+    public static String toString(Attr attr) {
+        if (attr.getNamespaceURI() == null) {
+            return "{}" + attr.getLocalName();
+        } else {
+            return "{" + attr.getNamespaceURI() + "}" + attr.getLocalName();
+        }
+    }
+
+    public static String toString(Collection collection) {
+        StringBuffer buf = new StringBuffer();
+        Iterator iter = collection.iterator();
+        while (iter.hasNext()) {
+            QName qname = (QName) iter.next();
+            buf.append(toString(qname));
+            if (iter.hasNext()) {
+                buf.append(", ");
+            }
+        }
+        return buf.toString();
+    }
+    
+    /**
+     * Convert a String back into a QName following the Clark notation
+     */
+    public static QName parse(String name) {
+        int pos = name.indexOf('}');
+        if (name.startsWith("{") && pos > 0) {
+            String ns = name.substring(1, pos);
+            String lname = name.substring(pos + 1, name.length());
+            return new QName(ns, lname);
+        }
+        return null;
+    }
+
+}