Permalink
Browse files

Migrate to AS7 based HttpService

  • Loading branch information...
tdiesler committed Jul 23, 2012
1 parent 9277645 commit 6616b332aa58d0000cd3bac9278d1b991342be44
View
26 pom.xml
@@ -74,8 +74,6 @@
<version.jboss.spec.servlet30.api>1.0.2.Final</version.jboss.spec.servlet30.api>
<version.jboss.spec.transaction11.api>1.0.1.Final</version.jboss.spec.transaction11.api>
<version.junit>4.10</version.junit>
- <version.ops4j.paxlogging>1.6.4</version.ops4j.paxlogging>
- <version.ops4j.pax.web>2.0.2</version.ops4j.pax.web>
<version.osgi>4.2.0</version.osgi>
<version.slf4j>1.6.4</version.slf4j>
</properties>
@@ -265,30 +263,6 @@
<version>${version.apache.felix.scr}</version>
</dependency>
- <!-- Jetty -->
- <dependency>
- <groupId>org.eclipse.jetty.aggregate</groupId>
- <artifactId>jetty-all-server</artifactId>
- <version>${version.eclipse.jetty}</version>
- </dependency>
-
- <!-- OPS4J -->
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-jetty</artifactId>
- <version>${version.ops4j.pax.web}</version>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-runtime</artifactId>
- <version>${version.ops4j.pax.web}</version>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-spi</artifactId>
- <version>${version.ops4j.pax.web}</version>
- </dependency>
-
<!-- org.osgi -->
<dependency>
<groupId>org.osgi</groupId>
View
@@ -119,26 +119,6 @@
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.eclipse.jetty.aggregate</groupId>
- <artifactId>jetty-all-server</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-jetty</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-runtime</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.web</groupId>
- <artifactId>pax-web-spi</artifactId>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
@@ -1,55 +0,0 @@
-/*
- * 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.osgi;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.http.HttpService;
-
-
-/**
- * HTTP integration test support.
- *
- * @author thomas.diesler@jboss.com
- * @since 26-Jan-2012
- */
-public final class HttpServiceSupport extends RepositorySupport {
-
- public static final String OPS4J_PAXWEB_JETTY = "org.ops4j.pax.web:pax-web-jetty";
- public static final String OPS4J_PAXWEB_RUNTIME = "org.ops4j.pax.web:pax-web-runtime";
- public static final String OPS4J_PAXWEB_SPI = "org.ops4j.pax.web:pax-web-spi";
- public static final String ECLIPSE_JETTY_SERVER = "org.eclipse.jetty.aggregate:jetty-all-server";
-
- public static HttpService provideHttpService(BundleContext syscontext, Bundle bundle) throws BundleException {
- ServiceReference sref = syscontext.getServiceReference(HttpService.class.getName());
- if (sref == null) {
- installSupportBundle(syscontext, getCoordinates(bundle, ECLIPSE_JETTY_SERVER));
- installSupportBundle(syscontext, getCoordinates(bundle, OPS4J_PAXWEB_SPI));
- installSupportBundle(syscontext, getCoordinates(bundle, OPS4J_PAXWEB_RUNTIME)).start();
- installSupportBundle(syscontext, getCoordinates(bundle, OPS4J_PAXWEB_JETTY)).start();
- sref = syscontext.getServiceReference(HttpService.class.getName());
- }
- return (HttpService) syscontext.getService(sref);
- }
-}
@@ -6,11 +6,6 @@ org.apache.aries\:org.apache.aries.util=@version.apache.aries.util@
org.apache.felix\:org.apache.felix.configadmin=@version.apache.felix.configadmin@
org.apache.felix\:org.apache.felix.eventadmin=@version.apache.felix.eventadmin@
org.apache.felix\:org.apache.felix.scr=@version.apache.felix.scr@
-org.eclipse.jetty.aggregate\:jetty-all-server=@version.eclipse.jetty@
org.jboss.osgi.http\:jbosgi-http-api=@version.jboss.osgi.http@
org.jboss.osgi.jmx\:jbosgi-jmx=@version.jboss.osgi.jmx@
org.jboss.osgi.xerces\:jbosgi-xerces=@version.jboss.osgi.xerces@
-org.ops4j.pax.logging\:pax-logging-api=@version.ops4j.paxlogging@
-org.ops4j.pax.web\:pax-web-jetty=@version.ops4j.pax.web@
-org.ops4j.pax.web\:pax-web-runtime=@version.ops4j.pax.web@
-org.ops4j.pax.web\:pax-web-spi=@version.ops4j.pax.web@
@@ -1,128 +0,0 @@
-/*
- * 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.osgi.example.http;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.inject.Inject;
-import javax.servlet.Servlet;
-import javax.servlet.http.HttpServlet;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.osgi.repository.XRequirementBuilder;
-import org.jboss.osgi.resolver.XRequirement;
-import org.jboss.osgi.spi.OSGiManifestBuilder;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.Asset;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.test.osgi.HttpServiceSupport;
-import org.jboss.test.osgi.HttpSupport;
-import org.jboss.test.osgi.RepositorySupport;
-import org.jboss.test.osgi.example.http.bundle.EndpointServlet;
-import org.jboss.test.osgi.example.http.bundle.HttpExampleActivator;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.resource.Resource;
-import org.osgi.service.http.HttpService;
-import org.osgi.service.packageadmin.PackageAdmin;
-import org.osgi.service.repository.Repository;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * A test that deployes a bundle that containes a HttpServlet which is registered through the OSGi HttpService
- *
- * @author thomas.diesler@jboss.com
- * @since 23-Jan-2009
- */
-@RunWith(Arquillian.class)
-public class HttpServiceTestCase {
-
- @Inject
- public BundleContext context;
-
- @Inject
- public Bundle bundle;
-
- @Deployment
- public static JavaArchive createdeployment() {
- final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "example-http");
- archive.addClasses(HttpExampleActivator.class, EndpointServlet.class, RepositorySupport.class, HttpServiceSupport.class, HttpSupport.class);
- archive.addAsResource("http/message.txt", "res/message.txt");
- archive.addAsManifestResource(RepositorySupport.BUNDLE_VERSIONS_FILE);
- archive.setManifest(new Asset() {
- public InputStream openStream() {
- OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
- builder.addBundleSymbolicName(archive.getName());
- builder.addBundleManifestVersion(2);
- builder.addBundleActivator(HttpExampleActivator.class);
- builder.addImportPackages(BundleActivator.class, PackageAdmin.class, ServiceTracker.class);
- builder.addImportPackages(HttpService.class, HttpServlet.class, Servlet.class);
- builder.addImportPackages(XRequirementBuilder.class, XRequirement.class, Repository.class, Resource.class);
- return builder.openStream();
- }
- });
- return archive;
- }
-
- @Test
- public void testServletAccess() throws Exception {
- HttpServiceSupport.provideHttpService(context, bundle);
- bundle.start();
- String line = getHttpResponse("/example-http/servlet?test=plain", 5000);
- assertEquals("Hello from Servlet", line);
- }
-
- @Test
- public void testServletInitProps() throws Exception {
- HttpServiceSupport.provideHttpService(context, bundle);
- bundle.start();
- String line = getHttpResponse("/example-http/servlet?test=initProp", 5000);
- assertEquals("initProp=SomeValue", line);
- }
-
- @Test
- public void testServletBundleContext() throws Exception {
- HttpServiceSupport.provideHttpService(context, bundle);
- bundle.start();
- String line = getHttpResponse("/example-http/servlet?test=context", 5000);
- assertEquals("example-http", line);
- }
-
- @Test
- public void testResourceAccess() throws Exception {
- HttpServiceSupport.provideHttpService(context, bundle);
- bundle.start();
- String line = getHttpResponse("/example-http/file/message.txt", 5000);
- assertEquals("Hello from Resource", line);
- }
-
- private String getHttpResponse(String reqPath, int timeout) throws IOException {
- return HttpSupport.getHttpResponse("localhost", 8090, reqPath, timeout);
- }
-}
@@ -1,61 +0,0 @@
-/*
- * 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.osgi.example.http.bundle;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.osgi.framework.BundleContext;
-
-@SuppressWarnings("serial")
-public class EndpointServlet extends HttpServlet {
- private BundleContext context;
-
- // This hides the default ctor and verifies that this instance is used
- public EndpointServlet(BundleContext context) {
- this.context = context;
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
- PrintWriter out = res.getWriter();
-
- String testParam = req.getParameter("test");
- if ("plain".equals(testParam)) {
- out.println("Hello from Servlet");
- } else if ("initProp".equals(testParam)) {
- String value = getInitParameter(testParam);
- out.println(testParam + "=" + value);
- } else if ("context".equals(testParam)) {
- out.println(context.getBundle().getSymbolicName());
- } else {
- throw new IllegalArgumentException("Invalid 'test' parameter: " + testParam);
- }
-
- out.close();
- }
-}
Oops, something went wrong.

0 comments on commit 6616b33

Please sign in to comment.