Author: richard.opalka(a)jboss.com
Date: 2008-11-28 09:32:57 -0500 (Fri, 28 Nov 2008)
New Revision: 8819
Added:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointImpl.java
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointInterface.java
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/JBWS2268TestCase.java
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/WEB-INF/
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/WEB-INF/web.xml
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java
stack/native/trunk/modules/testsuite/native-tests/scripts/build-jars-jaxws.xml
Log:
[JBWS-2268] refactoring javax.annotation support to stack specific endpoint servlet +
providing issue test
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java 2008-11-28
14:32:23 UTC (rev 8818)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java 2008-11-28
14:32:57 UTC (rev 8819)
@@ -21,7 +21,14 @@
*/
package org.jboss.wsf.stack.jbws;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.management.EndpointResolver;
+import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
+import org.jboss.wsf.common.javax.PreDestroyHolder;
import org.jboss.wsf.common.servlet.AbstractEndpointServlet;
import javax.servlet.ServletConfig;
@@ -35,6 +42,11 @@
public final class EndpointServlet extends AbstractEndpointServlet
{
+ // provide logging
+ protected static final Logger log = Logger.getLogger(EndpointServlet.class);
+
+ private List<PreDestroyHolder> preDestroyRegistry = new
LinkedList<PreDestroyHolder>();
+
/**
* Provides Native specific endpoint resolver
* @param servletContext servlet context
@@ -56,5 +68,49 @@
{
ServletConfigHelper.initEndpointConfig(servletConfig, endpoint);
}
+
+ @Override
+ protected final void postService()
+ {
+ registerForPreDestroy(endpoint);
+ }
+ @Override
+ public final void destroy()
+ {
+ synchronized(this.preDestroyRegistry)
+ {
+ for (PreDestroyHolder holder : this.preDestroyRegistry)
+ {
+ try
+ {
+ JavaxAnnotationHelper.callPreDestroyMethod(holder.getObject());
+ }
+ catch (Exception exception)
+ {
+ log.error(exception.getMessage(), exception);
+ }
+ }
+ this.preDestroyRegistry.clear();
+ this.preDestroyRegistry = null;
+ }
+ super.destroy();
+ }
+
+ private void registerForPreDestroy(Endpoint ep)
+ {
+ PreDestroyHolder holder =
(PreDestroyHolder)ep.getAttachment(PreDestroyHolder.class);
+ if (holder != null)
+ {
+ synchronized(this.preDestroyRegistry)
+ {
+ if (!this.preDestroyRegistry.contains(holder))
+ {
+ this.preDestroyRegistry.add(holder);
+ }
+ }
+ ep.removeAttachment(PreDestroyHolder.class);
+ }
+ }
+
}
Modified: stack/native/trunk/modules/testsuite/native-tests/scripts/build-jars-jaxws.xml
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/scripts/build-jars-jaxws.xml 2008-11-28
14:32:23 UTC (rev 8818)
+++
stack/native/trunk/modules/testsuite/native-tests/scripts/build-jars-jaxws.xml 2008-11-28
14:32:57 UTC (rev 8819)
@@ -382,6 +382,14 @@
</webinf>
</war>
+ <!-- jaxws-jbws2268 -->
+ <war warfile="${tests.output.dir}/test-libs/jaxws-jbws2268.war"
webxml="${tests.output.dir}/test-resources/jaxws/jbws2268/WEB-INF/web.xml">
+ <classes dir="${tests.output.dir}/test-classes">
+ <include name="org/jboss/test/ws/jaxws/jbws2268/*.class"/>
+ <exclude
name="org/jboss/test/ws/jaxws/jbws2268/*TestCase.class"/>
+ </classes>
+ </war>
+
<!-- jaxws-jbws2285 -->
<war warfile="${tests.output.dir}/test-libs/jaxws-jbws2285.war"
webxml="${tests.output.dir}/test-resources/jaxws/jbws2285/WEB-INF/web.xml">
<classes dir="${tests.output.dir}/test-classes">
Added:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointImpl.java
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointImpl.java
(rev 0)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointImpl.java 2008-11-28
14:32:57 UTC (rev 8819)
@@ -0,0 +1,86 @@
+/*
+ * 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.jbws2268;
+
+import java.io.File;
+import java.io.FileWriter;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+/**
+ * Endpoint Implementation
+ * @author richard.opalka(a)jboss.com
+ */
+@WebService(
+ serviceName = "EndpointService",
+ targetNamespace = "http://www.jboss.org/test/ws/jaxws/jbws2268",
+ endpointInterface="org.jboss.test.ws.jaxws.jbws2268.EndpointInterface"
+)
+public final class EndpointImpl
+{
+
+ private StringBuilder builder = new StringBuilder();
+ private File file;
+
+ public EndpointImpl()
+ {
+ super();
+ }
+
+ @PostConstruct
+ protected void init()
+ {
+ this.builder.append("init() ");
+ }
+
+ @WebMethod
+ public boolean setFile(String targetFile)
+ {
+ this.file = new File(targetFile);
+ return this.file.exists();
+ }
+
+ @PreDestroy
+ private void destroy()
+ {
+ this.builder.append("destroy()");
+ this.writeTestLog();
+ }
+
+ private void writeTestLog()
+ {
+ try
+ {
+ FileWriter fw = new FileWriter(this.file);
+ fw.write(this.builder.toString());
+ fw.close();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+}
Added:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointInterface.java
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointInterface.java
(rev 0)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/EndpointInterface.java 2008-11-28
14:32:57 UTC (rev 8819)
@@ -0,0 +1,34 @@
+/*
+ * 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.jbws2268;
+
+import javax.jws.WebService;
+
+/**
+ * Endpoint Interface
+ * @author richard.opalka(a)jboss.com
+ */
+@WebService(targetNamespace = "http://www.jboss.org/test/ws/jaxws/jbws2268")
+public interface EndpointInterface
+{
+ boolean setFile(String targetFile);
+}
Added:
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/JBWS2268TestCase.java
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/JBWS2268TestCase.java
(rev 0)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws2268/JBWS2268TestCase.java 2008-11-28
14:32:57 UTC (rev 8819)
@@ -0,0 +1,93 @@
+/*
+ * 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.jbws2268;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Service;
+
+import junit.framework.Test;
+
+import org.jboss.wsf.common.IOUtils;
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+
+/**
+ * [JBWS-2268] Implement @PostConstruct and @Predestroy annotations support for POJO
based endpoints
+ * @author richard.opalka(a)jboss.com
+ */
+public final class JBWS2268TestCase extends JBossWSTest
+{
+
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(JBWS2268TestCase.class, "");
+ }
+
+ private EndpointInterface getProxy() throws Exception
+ {
+ QName serviceName = new
QName("http://www.jboss.org/test/ws/jaxws/jbws2268",
"EndpointService");
+ URL wsdlURL = new URL("http://" + getServerHost() +
":8080/jaxws-jbws2268?wsdl");
+
+ Service service = Service.create(wsdlURL, serviceName);
+ return (EndpointInterface)service.getPort(EndpointInterface.class);
+ }
+
+ private File createLogFile() throws Exception
+ {
+ File workDir = getResourceFile("target");
+ assertTrue("Work dir doesn't exist", workDir.exists());
+ String fileName = System.identityHashCode(this) + ".log";
+ File retVal = new File(workDir, fileName);
+ retVal.createNewFile();
+ return retVal;
+ }
+
+ public void testJavaxAnnotationsSupport() throws Exception
+ {
+ File logFile = createLogFile();
+
+ deploy("jaxws-jbws2268.war");
+ try
+ {
+ assertTrue(getProxy().setFile(logFile.getAbsolutePath()));
+ }
+ finally
+ {
+ undeploy("jaxws-jbws2268.war");
+ assertPostConstructAndPreDestroyLogs(logFile);
+ }
+ }
+
+ private void assertPostConstructAndPreDestroyLogs(File logFile) throws Exception
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ IOUtils.copyStream(baos, new FileInputStream(logFile));
+ assertEquals(baos.toString().trim(), "init() destroy()");
+ logFile.delete();
+ }
+
+}
Added:
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/WEB-INF/web.xml
===================================================================
---
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/WEB-INF/web.xml
(rev 0)
+++
stack/native/trunk/modules/testsuite/native-tests/src/test/resources/jaxws/jbws2268/WEB-INF/web.xml 2008-11-28
14:32:57 UTC (rev 8819)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <servlet>
+ <servlet-name>EndpointImpl</servlet-name>
+
<servlet-class>org.jboss.test.ws.jaxws.jbws2268.EndpointImpl</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>EndpointImpl</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
\ No newline at end of file