Author: heiko.braun(a)jboss.com
Date: 2008-02-20 08:15:03 -0500 (Wed, 20 Feb 2008)
New Revision: 5752
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/InVMServlet.java
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/eventing/mgmt/DispatcherDelegate.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/EventingSupport.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/NotificationTestCase.java
stack/native/trunk/src/test/resources/jaxws/wseventing/WEB-INF/web.xml
Log:
JBWS-1912: WS-Eventing, Bypass RMIAdaptor when used locally
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/eventing/mgmt/DispatcherDelegate.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/eventing/mgmt/DispatcherDelegate.java 2008-02-20
13:14:01 UTC (rev 5751)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/eventing/mgmt/DispatcherDelegate.java 2008-02-20
13:15:03 UTC (rev 5752)
@@ -1,10 +1,9 @@
package org.jboss.ws.extensions.eventing.mgmt;
import java.net.URI;
+import java.util.Iterator;
-import javax.management.MBeanServerConnection;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.ObjectName;
+import javax.management.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Reference;
@@ -12,6 +11,7 @@
import javax.naming.StringRefAddr;
import org.jboss.ws.WSException;
+import org.jboss.logging.Logger;
import org.w3c.dom.Element;
/**
@@ -24,6 +24,8 @@
*/
public class DispatcherDelegate implements EventDispatcher, Referenceable
{
+ private static final Logger log = Logger.getLogger(DispatcherDelegate.class);
+
private String hostname;
public final static String MANAGER_HOSTNAME = "manager.hostname";
private SubscriptionManagerMBean subscriptionManager = null;
@@ -60,8 +62,12 @@
try
{
ObjectName objectName = SubscriptionManager.OBJECT_NAME;
- subscriptionManager =
(SubscriptionManagerMBean)MBeanServerInvocationHandler.newProxyInstance(getServer(),
objectName, SubscriptionManagerMBean.class,
- false);
+ subscriptionManager = (SubscriptionManagerMBean)
+ MBeanServerInvocationHandler.newProxyInstance(
+ getServer(),
+ objectName,
+ SubscriptionManagerMBean.class, false
+ );
}
catch (Exception e)
{
@@ -72,14 +78,49 @@
return subscriptionManager;
}
+ /**
+ *
http://wiki.jboss.org/wiki/Wiki.jsp?page=FindMBeanServer
+ *
+ * @return
+ * @throws NamingException
+ */
private MBeanServerConnection getServer() throws NamingException
{
- // todo: bypass rmi adapter when used locally
- InitialContext iniCtx = new InitialContext();
- MBeanServerConnection server =
(MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
+ // Local
+ MBeanServerConnection server = locateJBoss();
+
+ if(null==server)
+ {
+ // Remote
+ InitialContext iniCtx = new InitialContext();
+ server =
(MBeanServerConnection)iniCtx.lookup("jmx/invoker/RMIAdaptor");
+ log.debug("Using RMI invocation");
+ }
+ else
+ {
+ log.debug("Using in-VM invocation");
+ }
+
return server;
}
+ // avoid dependency on jboss-jmx.jar
+ public MBeanServerConnection locateJBoss()
+ {
+ MBeanServerConnection jboss = null;
+
+ for (Iterator i = MBeanServerFactory.findMBeanServer(null).iterator(); i.hasNext();
)
+ {
+ MBeanServer server = (MBeanServer) i.next();
+ if (server.getDefaultDomain().equals("jboss"))
+ {
+ jboss = server;
+ }
+ }
+
+ return jboss;
+ }
+
void setHostname(String hostname)
{
if (null == hostname)
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/EventingSupport.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/EventingSupport.java 2008-02-20
13:14:01 UTC (rev 5751)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/EventingSupport.java 2008-02-20
13:15:03 UTC (rev 5752)
@@ -80,8 +80,7 @@
" <Lat>2746</Lat>\n" +
" <Long>8270</Long>\n" +
" <Comments xml:lang='en-US' >\n" +
- " WINDS 55 WITH GUSTS TO 65. ROOF TORN OFF BOAT HOUSE. REPORTED\n"
+
- " BY STORM SPOTTER. (TBW)\n" +
+ " Should be a REMOTE notification\n" +
" </Comments>\n" +
"</WindReport>";
Added:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/InVMServlet.java
===================================================================
--- stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/InVMServlet.java
(rev 0)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/InVMServlet.java 2008-02-20
13:15:03 UTC (rev 5752)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.ws.jaxws.wseventing;
+
+import org.jboss.ws.extensions.eventing.mgmt.EventDispatcher;
+import org.jboss.ws.extensions.eventing.EventingConstants;
+import org.jboss.wsf.common.DOMUtils;
+import org.w3c.dom.Element;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * Test the in vm event dispatching
+ */
+public class InVMServlet extends HttpServlet
+{
+
+ private final static String notification =
+ "<WindReport type='critical'>\n" +
+ " <Date>030701</Date>\n" +
+ " <Time>0041</Time>\n" +
+ " <Speed>65</Speed>\n" +
+ " <Location>BRADENTON BEACH</Location>\n" +
+ " <County>MANATEE</County>\n" +
+ " <State>FL</State>\n" +
+ " <Lat>2746</Lat>\n" +
+ " <Long>8270</Long>\n" +
+ " <Comments xml:lang='en-US' >\n" +
+ " Should be a LOCAL invocation\n" +
+ " </Comments>\n" +
+ "</WindReport>";
+
+ protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse
httpServletResponse) throws ServletException, IOException
+ {
+ try
+ {
+ InitialContext iniCtx = new InitialContext();
+ EventDispatcher delegate = (EventDispatcher)
+ iniCtx.lookup(EventingConstants.DISPATCHER_JNDI_NAME);
+
+ Element payload = DOMUtils.parse(notification);
+ delegate.dispatch(new
URI("http://www.jboss.org/wind/Warnings"),
payload);
+
+ httpServletResponse.getWriter().print("Notification successful");
+ }
+ catch (Exception e)
+ {
+ throw new ServletException("Failed to do in VM dispatching", e);
+ }
+ }
+}
Property changes on:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/InVMServlet.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/NotificationTestCase.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/NotificationTestCase.java 2008-02-20
13:14:01 UTC (rev 5751)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wseventing/NotificationTestCase.java 2008-02-20
13:15:03 UTC (rev 5752)
@@ -34,6 +34,13 @@
import org.jboss.wsf.common.DOMUtils;
import org.w3c.dom.Element;
+import java.net.URL;
+import java.net.HttpURLConnection;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
/**
* Test the notification delivery.
*
@@ -66,4 +73,27 @@
}
}
+ public void testInVMNotification() throws Exception
+ {
+ URL u = new URL ( "http://localhost:8080/jaxws-wseventing/inVM" );
+ HttpURLConnection huc = (HttpURLConnection) u.openConnection();
+ huc.setRequestMethod("GET");
+ huc.connect();
+
+ StringBuffer sb = new StringBuffer();
+
+ int code = huc.getResponseCode();
+ if (code>=200 && code<300 )
+ {
+ InputStream in = huc.getInputStream();
+ BufferedReader input = new BufferedReader(new InputStreamReader(in));
+ String line = "";
+ while ((line = input.readLine()) != null)
+ sb.append(line);
+ }
+
+ assertEquals(sb.toString(), "Notification successful");
+ huc.disconnect();
+ }
+
}
Modified: stack/native/trunk/src/test/resources/jaxws/wseventing/WEB-INF/web.xml
===================================================================
--- stack/native/trunk/src/test/resources/jaxws/wseventing/WEB-INF/web.xml 2008-02-20
13:14:01 UTC (rev 5751)
+++ stack/native/trunk/src/test/resources/jaxws/wseventing/WEB-INF/web.xml 2008-02-20
13:15:03 UTC (rev 5752)
@@ -33,6 +33,17 @@
<url-pattern>/manage</url-pattern>
</servlet-mapping>
+ <servlet>
+ <servlet-name>inVM</servlet-name>
+
<servlet-class>org.jboss.test.ws.jaxws.wseventing.InVMServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>inVM</servlet-name>
+ <url-pattern>/inVM</url-pattern>
+ </servlet-mapping>
+
+
<session-config>
<session-timeout>54</session-timeout>
</session-config>