Author: heiko.braun(a)jboss.com
Date: 2007-11-11 05:33:55 -0500 (Sun, 11 Nov 2007)
New Revision: 5027
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/ResourceRegistryFactory.java
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/DescriptorDeploymentAspect.java
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ModelDeploymentAspect.java
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
stack/native/branches/rest/src/main/java/org/jboss/rs/model/OperationBinding.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/DefaultInvocationHandler.java
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DeploymentTestCase.java
stack/native/branches/rest/src/test/resources/rs/
stack/native/branches/rest/src/test/resources/rs/deployment/
stack/native/branches/rest/src/test/resources/rs/deployment/jbossrs.xml
stack/native/branches/rest/src/test/resources/rs/deployment/web.xml
Modified:
stack/native/branches/rest/ant-import-tests/build-jars-jaxws.xml
stack/native/branches/rest/ant-import/macros-deploy-native.xml
stack/native/branches/rest/build.xml
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
stack/native/branches/rest/src/main/resources/jbossws-native-config.xml
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DescriptorParserTestCase.java
Log:
Servlet invocation, first cut
Modified: stack/native/branches/rest/ant-import/macros-deploy-native.xml
===================================================================
--- stack/native/branches/rest/ant-import/macros-deploy-native.xml 2007-11-09 23:20:34 UTC
(rev 5026)
+++ stack/native/branches/rest/ant-import/macros-deploy-native.xml 2007-11-11 10:33:55 UTC
(rev 5027)
@@ -453,6 +453,9 @@
<include name="jboss-jaxws-ext.jar"/>
<include name="jboss-saaj.jar"/>
</fileset>
+ <fileset dir="@{thirdpartylibs}">
+ <include name="jsr311-api.jar"/>
+ </fileset>
</copy>
<mkdir
dir="${jboss500.home}/server/${jboss.server.instance}/deploy/jbossws.sar"/>
Modified: stack/native/branches/rest/ant-import-tests/build-jars-jaxws.xml
===================================================================
--- stack/native/branches/rest/ant-import-tests/build-jars-jaxws.xml 2007-11-09 23:20:34
UTC (rev 5026)
+++ stack/native/branches/rest/ant-import-tests/build-jars-jaxws.xml 2007-11-11 10:33:55
UTC (rev 5027)
@@ -649,7 +649,20 @@
<include name="wsdl/**"/>
</webinf>
</war>
-
+
+ <!-- RS stuff -->
+
+ <war warfile="${tests.output.dir}/libs/jbossrs-deployment.war"
webxml="${tests.output.dir}/resources/rs/deployment/web.xml">
+ <classes dir="${tests.output.dir}/classes">
+ <include name="org/jboss/test/rs/WidgetList.class"/>
+ <include name="org/jboss/test/rs/Widget.class"/>
+ <include name="org/jboss/test/rs/Specification.class"/>
+ </classes>
+ <webinf dir="${tests.output.dir}/resources/rs/deployment">
+ <include name="jbossrs.xml"/>
+ </webinf>
+ </war>
+
<!-- Please add alphabetically -->
<antcall target="build-interop-jars"/>
Modified: stack/native/branches/rest/build.xml
===================================================================
--- stack/native/branches/rest/build.xml 2007-11-09 23:20:34 UTC (rev 5026)
+++ stack/native/branches/rest/build.xml 2007-11-11 10:33:55 UTC (rev 5027)
@@ -291,7 +291,7 @@
<include name="wsdl4j.jar"/>
<include name="xmlsec.jar"/>
<include name="wstx.jar"/>
- <include name="jboss-jaxb-intros.jar"/>
+ <include name="jboss-jaxb-intros.jar"/>
</fileset>
<metainf dir="${core.dir}/src/main/resources/standard-config">
<include name="standard-*-config.xml"/>
Added: stack/native/branches/rest/src/main/java/org/jboss/rs/ResourceRegistryFactory.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/ResourceRegistryFactory.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/ResourceRegistryFactory.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs;
+
+import org.jboss.wsf.common.KernelAwareSPIFactory;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class ResourceRegistryFactory
+{
+ public final static String BEAN_NAME = "RS_RESOURCE_REGISTRY";
+
+ public static ResourceRegistryFactory newInstance()
+ {
+ return new ResourceRegistryFactory();
+ }
+
+ public ResourceRegistry createResourceRegistry()
+ {
+ return new KernelAwareSPIFactory().getKernelProvidedSPI(
+ BEAN_NAME, ResourceRegistry.class
+ );
+
+ }
+
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/ResourceRegistryFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/DescriptorDeploymentAspect.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/DescriptorDeploymentAspect.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/DescriptorDeploymentAspect.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.deployment;
+
+import org.jboss.rs.model.dd.DeploymentDescriptorParser;
+import org.jboss.rs.model.dd.JbossrsType;
+import org.jboss.rs.model.dd.ResourceType;
+import org.jboss.rs.ResourceRegistry;
+import org.jboss.wsf.spi.SPIProvider;
+import org.jboss.wsf.spi.SPIProviderResolver;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.DeploymentAspect;
+import org.jboss.wsf.spi.deployment.DeploymentModelFactory;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.deployment.Service;
+import org.jboss.wsf.spi.deployment.UnifiedVirtualFile;
+
+import java.io.IOException;
+
+/**
+ * Parses the jbossrs descriptor and turns it into a
+ * SPI structure for further consumption.
+ *
+ * @see org.jboss.rs.model.dd.DeploymentDescriptorParser
+ *
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class DescriptorDeploymentAspect extends DeploymentAspect
+{
+
+ public void create(Deployment deployment)
+ {
+ try
+ {
+ UnifiedVirtualFile vf = getJBossRSDescriptor(deployment);
+ JbossrsType dd = DeploymentDescriptorParser.read(vf.toURL().openStream());
+
+ // keep the DD model
+ deployment.addAttachment(JbossrsType.class, dd);
+
+ Service service = deployment.getService();
+
+ for(ResourceType resourceDesc : dd.getResource())
+ {
+ String name = resourceDesc.getName() != null ? resourceDesc.getName() :
"";
+ String impl = resourceDesc.getImplementation();
+
+ Endpoint ep = newEndpoint(impl);
+ ep.setShortName(name);
+ service.addEndpoint(ep);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to parse JBossRS descriptor", e);
+ }
+
+ }
+
+ private UnifiedVirtualFile getJBossRSDescriptor(Deployment deployment)
+ {
+ return (UnifiedVirtualFile)deployment.getProperty("jbossrs.dd.pointer");
+ }
+
+ private Endpoint newEndpoint(String impl)
+ {
+ SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
+ DeploymentModelFactory deploymentModelFactory =
spiProvider.getSPI(DeploymentModelFactory.class);
+ return deploymentModelFactory.newEndpoint(impl);
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/DescriptorDeploymentAspect.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ModelDeploymentAspect.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ModelDeploymentAspect.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ModelDeploymentAspect.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.deployment;
+
+import org.jboss.wsf.spi.deployment.DeploymentAspect;
+import org.jboss.wsf.spi.deployment.Deployment;
+import org.jboss.wsf.spi.deployment.Service;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.rs.model.ResourceModelParser;
+import org.jboss.rs.model.ResourceModel;
+import org.jboss.rs.ResourceRegistry;
+import org.jboss.rs.ResourceRegistryFactory;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class ModelDeploymentAspect extends DeploymentAspect
+{
+
+ public void create(Deployment deployment)
+ {
+
+ Service service = deployment.getService();
+ String contextRoot = service.getContextRoot();
+
+ if(null == contextRoot)
+ throw new IllegalArgumentException("Null context root");
+
+ ResourceRegistry registry =
ResourceRegistryFactory.newInstance().createResourceRegistry();
+
+ ResourceModelParser parser = ResourceModelParser.newInstance();
+ ClassLoader runtimeLoader = deployment.getRuntimeClassLoader();
+
+ for(Endpoint ep : service.getEndpoints())
+ {
+ try
+ {
+ Class c = runtimeLoader.loadClass(ep.getTargetBeanName());
+ ResourceModel rootResource = parser.parse(c);
+ registry.addResourceModelForContext(contextRoot, rootResource);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to load " +
ep.getTargetBeanName(), e);
+ }
+
+ }
+
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ModelDeploymentAspect.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,156 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.deployment;
+
+import org.jboss.rs.MethodHTTP;
+import org.jboss.rs.ResourceError;
+import org.jboss.rs.ResourceRegistry;
+import org.jboss.rs.ResourceRegistryFactory;
+import org.jboss.rs.model.ResourceMethod;
+import org.jboss.rs.model.ResourceModel;
+import org.jboss.rs.model.ResourceResolver;
+import org.jboss.rs.runtime.DefaultInvocationBuilder;
+import org.jboss.rs.runtime.DefaultInvocationHandler;
+import org.jboss.rs.runtime.Invocation;
+import org.jboss.rs.runtime.InvocationBuilder;
+import org.jboss.rs.runtime.RuntimeContext;
+import org.jboss.rs.runtime.InvocationHandler;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class ResourceServlet extends HttpServlet
+{
+
+ private List<ResourceModel> rootResources = new
ArrayList<ResourceModel>();
+
+ public void init(ServletConfig servletConfig) throws ServletException
+ {
+ ResourceRegistry reg =
ResourceRegistryFactory.newInstance().createResourceRegistry();
+ String webContext = servletConfig.getServletContext().getContextPath();
+ List<ResourceModel> models = reg.getResourceModelsForContext(webContext);
+
+ if(models.isEmpty())
+ throw new IllegalArgumentException("No root resources for context " +
webContext);
+ else
+ rootResources.addAll(models);
+
+ }
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ invokeFrom(MethodHTTP.GET, req, res);
+ }
+
+ protected void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ invokeFrom(MethodHTTP.POST, req, res);
+ }
+
+ protected void doPut(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ invokeFrom(MethodHTTP.PUT, req, res);
+ }
+
+ protected void doDelete(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
+ {
+ invokeFrom(MethodHTTP.DELETE, req, res);
+ }
+
+ private void invokeFrom(MethodHTTP method, HttpServletRequest req, HttpServletResponse
res)
+ throws ServletException
+ {
+ try
+ {
+ // construct a runtime context
+ URI uri = new URI(req.getRequestURI());
+ RuntimeContext rt = new RuntimeContext(method, uri, rootResources);
+
+ // TODO: impement accept header parsing
+ rt.parseAcceptHeader("text/plain, text/html");
+
+ // locate the resource to be invoked
+ ResourceResolver resolver = ResourceResolver.newInstance(rt);
+ ResourceMethod resourceMethod = resolver.resolve();
+
+ // create an Invocation instance
+ InvocationBuilder builder = new DefaultInvocationBuilder();
+ builder.addInvocationModel( resourceMethod.getParameterBinding() );
+ builder.addInvocationModel( resourceMethod.getOperationBinding() );
+ Invocation invocation = builder.build(rt);
+
+ // invoke it
+ InvocationHandler invoker = new DefaultInvocationHandler();
+ Object result = invoker.invoke(invocation);
+
+ if(result instanceof String)
+ {
+ res.setContentType("text/plain");
+ PrintWriter writer = res.getWriter();
+ writer.write(result.toString());
+ writer.flush();
+ writer.close();
+ }
+ else
+ {
+ serverError(405, "Cannot marshall " + result.getClass(), res);
+ }
+
+ }
+ catch(ResourceError resourceError)
+ {
+ serverError(resourceError.status, resourceError.getMessage(), res);
+ }
+ catch (Throwable e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+ private void serverError(int status, String message, HttpServletResponse res)
+ {
+ try
+ {
+ res.setStatus(status);
+ PrintWriter out = res.getWriter();
+ out.write(message);
+ out.flush();
+ out.close();
+ }
+ catch (IOException e)
+ {
+ System.out.println("Failed to write response:" + e.getMessage());
+ }
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/deployment/ResourceServlet.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: stack/native/branches/rest/src/main/java/org/jboss/rs/model/OperationBinding.java
===================================================================
--- stack/native/branches/rest/src/main/java/org/jboss/rs/model/OperationBinding.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/OperationBinding.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.model;
+
+import org.jboss.rs.runtime.InvocationModel;
+import org.jboss.rs.runtime.Invocation;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class OperationBinding implements InvocationModel
+{
+ private Method invocationTarget;
+
+ public OperationBinding(Method targetMethod)
+ {
+ this.invocationTarget = targetMethod;
+ }
+
+ public void accept(Invocation invocation)
+ {
+ try
+ {
+ Class<?> targetBean = invocationTarget.getDeclaringClass();
+ invocation.setTargetMethod(invocationTarget);
+ invocation.setTargetBean(targetBean);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to build invocation", e);
+ }
+
+
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/model/OperationBinding.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java 2007-11-09
23:20:34 UTC (rev 5026)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/model/ResourceMethod.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -96,6 +96,11 @@
return parameterBinding;
}
+ public OperationBinding getOperationBinding()
+ {
+ return new OperationBinding(this.invocationTarget);
+ }
+
void freeze()
{
// We need to know which param belongs to what regex group
Added:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/DefaultInvocationHandler.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/DefaultInvocationHandler.java
(rev 0)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/DefaultInvocationHandler.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.runtime;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class DefaultInvocationHandler implements InvocationHandler
+{
+
+ public Object invoke(Invocation invocation)
+ {
+ try
+ {
+ Object targetInstance = invocation.getTargetBean().newInstance();
+
+ Object result;
+
+ if(invocation.getParameterInstances().isEmpty())
+ {
+ result = invocation.getTargetMethod().invoke(targetInstance);
+ }
+ else
+ {
+ result = invocation.getTargetMethod().invoke(
+ targetInstance, invocation.getParameterInstances().toArray()
+ );
+ }
+ return result;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Invocation failed", e);
+ }
+ }
+}
Property changes on:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/DefaultInvocationHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java 2007-11-09
23:20:34 UTC (rev 5026)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/Invocation.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.LinkedList;
+import java.lang.reflect.Method;
/**
* The visitor part of the pattern.
@@ -36,7 +37,14 @@
{
private RuntimeContext context;
- List parameterInstances = new LinkedList();
+ // Actual paramter instances
+ private List parameterInstances = new LinkedList();
+
+ // invocation metadata about the method
+ private Method targetMethod;
+
+ // invocation metadata about the bean
+ private Class targetBean;
public Invocation(RuntimeContext context)
{
@@ -69,4 +77,24 @@
{
return parameterInstances;
}
+
+ public void setTargetMethod(Method targetMethod)
+ {
+ this.targetMethod = targetMethod;
+ }
+
+ public void setTargetBean(Class targetBean)
+ {
+ this.targetBean = targetBean;
+ }
+
+ public Method getTargetMethod()
+ {
+ return targetMethod;
+ }
+
+ public Class getTargetBean()
+ {
+ return targetBean;
+ }
}
Modified:
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java
===================================================================
---
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-09
23:20:34 UTC (rev 5026)
+++
stack/native/branches/rest/src/main/java/org/jboss/rs/runtime/RuntimeContext.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -28,6 +28,7 @@
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -43,6 +44,10 @@
// Request URI
private URI uri;
+ private String path;
+
+ private String webcontext;
+
// Accepted response body mime types
private List<MimeType> consumeMimeTypes = new ArrayList<MimeType>();
@@ -57,8 +62,33 @@
this.requestMethod = requestMethod;
this.rootResources = rootResources;
this.uri = uri;
+
+ tokenizeUri(this.uri);
}
+ private void tokenizeUri(URI uri)
+ {
+ try
+ {
+ // path without web context
+ String tmpPath = uri.toString();
+ if(tmpPath.startsWith("/"))
+ tmpPath = tmpPath.substring(1);
+ int i = tmpPath.indexOf("/");
+
+ this.path = tmpPath.substring(i);
+ if(path.startsWith("/"))
+ path = path.substring(1);
+
+ this.webcontext = tmpPath.substring(0, i+1);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+
+ }
+
public MethodHTTP getRequestMethod()
{
return requestMethod;
@@ -103,14 +133,18 @@
return provideMimeType;
}
+ public String getWebcontext()
+ {
+ return webcontext;
+ }
+
/**
* @return the path info of the associated URI.
*/
public String getPath()
{
- String path = uri.getPath();
- if(path.startsWith("/"))
- path = path.substring(1);
return path;
}
+
+
}
Modified: stack/native/branches/rest/src/main/resources/jbossws-native-config.xml
===================================================================
--- stack/native/branches/rest/src/main/resources/jbossws-native-config.xml 2007-11-09
23:20:34 UTC (rev 5026)
+++ stack/native/branches/rest/src/main/resources/jbossws-native-config.xml 2007-11-11
10:33:55 UTC (rev 5027)
@@ -28,6 +28,11 @@
<bean name="WSEndpointRegistry"
class="org.jboss.wsf.framework.management.ManagedEndpointRegistry">
<property name="mbeanServer"><inject
bean="WSMBeanServerLocator"
property="mbeanServer"/></property>
</bean>
+
+ <!-- The registry for REST resources -->
+ <bean name="RS_RESOURCE_REGISTRY"
class="org.jboss.rs.ResourceRegistry">
+ <!--property name="mbeanServer"><inject
bean="WSMBeanServerLocator"
property="mbeanServer"/></property-->
+ </bean>
<!-- A subscription manager for WS-Eventing -->
<bean name="WSSubscriptionManager"
class="org.jboss.ws.extensions.eventing.mgmt.SubscriptionManager">
@@ -78,6 +83,15 @@
<property name="provides">JAXBIntros</property>
</bean>
+ <bean name="RSDescriptorDeploymentAspect"
class="org.jboss.rs.deployment.DescriptorDeploymentAspect">
+ <property name="provides">ContainerMetaData</property>
+ </bean>
+
+ <bean name="RSModelDeploymentAspect"
class="org.jboss.rs.deployment.ModelDeploymentAspect">
+ <property name="requires">RuntimeLoader</property>
+ <property name="provides">ResourceModel</property>
+ </bean>
+
<!-- Deployment aspect installers -->
<!-- Phase 1 -->
<bean name="WSNativeDeploymentAspectInstallerPreJSE"
class="org.jboss.wsf.framework.deployment.DeploymentAspectInstaller">
@@ -143,4 +157,16 @@
</property>
<depends>WSDeploymentAspectInstallerEndpointAPI</depends>
</bean>
-
\ No newline at end of file
+
+
+ <bean name="WSNativeDeploymentAspectInstallerREST"
class="org.jboss.wsf.framework.deployment.DeploymentAspectInstaller">
+ <property name="manager"><inject
bean="WSDeploymentAspectManagerREST"/></property>
+ <property name="sortAspectsOnCreate">true</property>
+ <property name="aspects">
+ <set class="java.util.HashSet"
elementClass="org.jboss.wsf.spi.deployment.DeploymentAspect">
+ <inject bean="RSDescriptorDeploymentAspect"/>
+ <inject bean="RSModelDeploymentAspect"/>
+ </set>
+ </property>
+ </bean>
+
Added:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DeploymentTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DeploymentTestCase.java
(rev 0)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DeploymentTestCase.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.rs.deployment;
+
+import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestSetup;
+import junit.framework.Test;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.OutputStreamWriter;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/**
+ * @author Heiko.Braun(a)jboss.com
+ * @version $Revision$
+ */
+public class DeploymentTestCase extends JBossWSTest
+{
+ public static Test suite()
+ {
+ return new JBossWSTestSetup(DeploymentTestCase.class,
"jbossrs-deployment.war");
+ }
+
+
+ public void testRequest1() throws Exception
+ {
+ URL url = new URL("http://localhost:8080/jbossrs-deployment/widgets");
+ String response = doTextPlainRequest(url, null);
+ assertNotNull(response);
+ assertEquals("A widgetlist", response);
+ }
+
+ private String doTextPlainRequest(URL url, String data) throws Exception
+ {
+ URLConnection conn = url.openConnection();
+ conn.setDoOutput( data!=null );
+
+ if(data !=null)
+ {
+ OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
+
+ wr.write(data);
+ wr.flush();
+ wr.close();
+ }
+
+ // Get the response
+ BufferedReader rd = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
+ String line;
+ StringBuffer sb = new StringBuffer();
+ while ((line = rd.readLine()) != null)
+ {
+ sb.append(line);
+ }
+ rd.close();
+
+ return sb.toString();
+ }
+}
Property changes on:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DeploymentTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DescriptorParserTestCase.java
===================================================================
---
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DescriptorParserTestCase.java 2007-11-09
23:20:34 UTC (rev 5026)
+++
stack/native/branches/rest/src/test/java/org/jboss/test/rs/deployment/DescriptorParserTestCase.java 2007-11-11
10:33:55 UTC (rev 5027)
@@ -29,6 +29,8 @@
import java.io.ByteArrayInputStream;
/**
+ * Test the deployment descriptor parser.
+ *
* @author Heiko.Braun(a)jboss.com
* @version $Revision$
*/
Added: stack/native/branches/rest/src/test/resources/rs/deployment/jbossrs.xml
===================================================================
--- stack/native/branches/rest/src/test/resources/rs/deployment/jbossrs.xml
(rev 0)
+++ stack/native/branches/rest/src/test/resources/rs/deployment/jbossrs.xml 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+
+<jbossrs xmlns="http://org.jboss.rs/">
+ <resource>
+ <name>Widget</name>
+ <implementation>org.jboss.test.rs.WidgetList</implementation>
+ </resource>
+</jbossrs>
Property changes on:
stack/native/branches/rest/src/test/resources/rs/deployment/jbossrs.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: stack/native/branches/rest/src/test/resources/rs/deployment/web.xml
===================================================================
--- stack/native/branches/rest/src/test/resources/rs/deployment/web.xml
(rev 0)
+++ stack/native/branches/rest/src/test/resources/rs/deployment/web.xml 2007-11-11
10:33:55 UTC (rev 5027)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<web-app
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"
+ version="2.4">
+
+ <servlet>
+ <servlet-name>JBossRS</servlet-name>
+ <servlet-class>org.jboss.rs.deployment.ResourceServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JBossRS</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
+
Property changes on: stack/native/branches/rest/src/test/resources/rs/deployment/web.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF