Skip to content
This repository has been archived by the owner on May 28, 2018. It is now read-only.

Spring osgi pax web hack #3768

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions examples/osgi-http-service/bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand All @@ -58,6 +59,10 @@

<description>OSGi HttpService example bundle</description>

<properties>
<spring4.version>4.3.5.RELEASE_1</spring4.version>
</properties>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
Expand All @@ -77,6 +82,42 @@
<artifactId>org.apache.felix.eventadmin</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-beans</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-core</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-web</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-aop</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-context</artifactId>
<version>${spring4.version}</version>
</dependency>

<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.spring-expression</artifactId>
<version>${spring4.version}</version>
</dependency>
</dependencies>

<build>
Expand All @@ -87,8 +128,22 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.glassfish.jersey.examples.osgihttpservice</Export-Package>
<Import-Package>javax.servlet.*;version="[2.4,5.0)",*</Import-Package>
<Export-Package>
org.glassfish.jersey.examples.osgihttpservice,
org.glassfish.jersey.examples.osgihttpservice.spring
</Export-Package>
<Import-Package>
javax.servlet.*;version="[3.0,5.0)",
org.springframework.expression,
org.springframework.beans.factory,
org.springframework.beans.factory.xml,
org.springframework.cglib.core,
org.springframework.cglib.proxy,
org.springframework.beans,
org.springframework.context,
org.springframework.context.config,
*
</Import-Package>
<Bundle-Activator>org.glassfish.jersey.examples.osgihttpservice.Activator</Bundle-Activator>
<Implementation-Title>jersey-osgi-http-service-bundle</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,7 @@

package org.glassfish.jersey.examples.osgihttpservice;

import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.logging.Logger;

import javax.servlet.ServletException;

import org.glassfish.jersey.servlet.ServletContainer;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
Expand All @@ -58,6 +50,10 @@
import org.osgi.service.http.NamespaceException;
import org.osgi.util.tracker.ServiceTracker;

import javax.servlet.ServletException;
import java.util.HashMap;
import java.util.logging.Logger;

public class Activator implements BundleActivator {

private BundleContext bc;
Expand Down Expand Up @@ -119,7 +115,8 @@ private void rawRegisterServlets() throws ServletException, NamespaceException,
ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(myClassLoader);
httpService.registerServlet("/jersey-http-service", new ServletContainer(), getJerseyServletParams(), null);
ServletContainer servletToRegister = new ServletContainer(new JerseyApplication());
httpService.registerServlet("/jersey-http-service", servletToRegister, null, null);
} finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
Expand Down Expand Up @@ -150,11 +147,4 @@ private void unregisterServlets() {
logger.info("JERSEY BUNDLE: SERVLETS UNREGISTERED");
}
}

@SuppressWarnings("UseOfObsoleteCollectionType")
private Dictionary<String, String> getJerseyServletParams() {
Dictionary<String, String> jerseyServletParams = new Hashtable<>();
jerseyServletParams.put("javax.ws.rs.Application", JerseyApplication.class.getName());
return jerseyServletParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@

package org.glassfish.jersey.examples.osgihttpservice;

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JerseyApplication extends Application {
public class JerseyApplication extends ResourceConfig {

@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> result = new HashSet<Class<?>>();
result.add(StatusResource.class);
return result;
}
public JerseyApplication() {
property("contextConfig", new ClassPathXmlApplicationContext(
"org/glassfish/jersey/examples/osgihttpservice/spring/spring-context.xml"));

packages(false, "org.glassfish.jersey.examples.osgihttpservice.spring");
register(StatusResource.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.glassfish.jersey.examples.osgihttpservice.spring;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("status2")
@Named
public class SpringResource {

@Inject
private StatusGenerator statusGenerator;

@GET
@Produces("text/plain")
public String getStatus() {
return statusGenerator.status();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.glassfish.jersey.examples.osgihttpservice.spring;

public interface StatusGenerator {

String status();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.glassfish.jersey.examples.osgihttpservice.spring.impl;

import org.glassfish.jersey.examples.osgihttpservice.spring.StatusGenerator;

public class DefaultStatusGenerator implements StatusGenerator {

@Override
public String status() {
return "status from generator";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="statusGenerator"
class="org.glassfish.jersey.examples.osgihttpservice.spring.impl.DefaultStatusGenerator"/>
</beans>
60 changes: 57 additions & 3 deletions examples/osgi-http-service/functional-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -91,27 +92,32 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.framework</artifactId>
<version>5.6.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.eventadmin</artifactId>
<version>1.4.10</version>
<scope>test</scope>
</dependency>

<!-- Pax-Exam and JUnit dependencies -->
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-junit4</artifactId>
<version>4.11.0</version>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-forked</artifactId>
<version>4.11.0</version>
</dependency>

<dependency>
Expand All @@ -122,11 +128,49 @@
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-jetty-bundle</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-extender-war</artifactId>
<artifactId>pax-web-api</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.web</groupId>
<artifactId>pax-web-spi</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-finder</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-bundleutils</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-tree</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -159,6 +203,16 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet3.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -247,7 +301,7 @@
<configuration>
<!-- disable JaCoCo listener because it's not working with <forkMode>always</fork> (<reuseForks>false</reuseForks> respectively)
https://jira.sonarsource.com/browse/SONARJAVA-728 (https://github.com/SonarSource/sonar-java/pull/324) -->
<properties combine.self="override" />
<properties combine.self="override"/>
</configuration>
</plugin>
</plugins>
Expand Down
Loading