Skip to content
Permalink
Browse files

actually getting the resource to work via upgraded grizzly and jersey…

… libs
  • Loading branch information...
barmintor committed Jun 10, 2013
1 parent 74794a1 commit 3613db34467ce1ccf78f83e445f44dbeafc5e02b
53 pom.xml
@@ -42,26 +42,22 @@
<type>test-jar</type>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-servlet-webserver</artifactId>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<scope>test</scope>
<version>2.2.21</version>
</dependency>
<dependency>
<groupId>com.sun.grizzly</groupId>
<artifactId>grizzly-http-servlet-deployer</artifactId>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-servlet</artifactId>
<scope>test</scope>
<version>1.9.57</version>
<version>2.2.21</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly</artifactId>
<artifactId>jersey-grizzly2</artifactId>
<scope>test</scope>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
@@ -91,7 +87,38 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>


<dependency>
<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-grizzly2</artifactId>
<version>1.17.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.14</version>
<scope>test</scope>
</dependency>
<!-- Playing with ordered loading for tests -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2-b04</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-servlet</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
@@ -5,7 +5,9 @@

public static final String OAUTH_WORKSPACE = "oauth";

public static final String CLIENT_PROPERTY = "oauth:client";
//TODO get namespaced properties to work
public static final String CLIENT_PROPERTY = "oauth-client";

public static final String PRINCIPAL_PROPERTY = "oauth:principal";
//TODO get namespaced properties to work
public static final String PRINCIPAL_PROPERTY = "oauth-principal";
}
@@ -25,6 +25,11 @@

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
init();
}

// used by Spring
public void init() {
LOGGER.debug("Initialized {}", this.getClass().getName());
}

@@ -4,13 +4,24 @@
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.Filter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

//import com.sun.grizzly.servlet.ServletRegistration;
//import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.servlet.FilterRegistration;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.jersey.grizzly2.servlet.GrizzlyWebContainerFactory;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
@@ -20,21 +31,22 @@
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;

import com.sun.grizzly.http.SelectorThread;
import com.sun.grizzly.http.servlet.ServletAdapter;
import com.sun.grizzly.http.servlet.ServletContextImpl;
import com.sun.grizzly.http.servlet.deployer.WebAppAdapter;
import com.sun.grizzly.http.webxml.WebappLoader;
import com.sun.grizzly.http.webxml.schema.ContextParam;
import com.sun.grizzly.http.webxml.schema.FilterMapping;
import com.sun.grizzly.http.webxml.schema.ServletMapping;
import com.sun.grizzly.http.webxml.schema.WebApp;
import com.sun.jersey.api.container.grizzly.GrizzlyServerFactory;
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory;
import com.sun.jersey.api.core.ClassNamesResourceConfig;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.api.core.ResourceConfig;
import com.sun.jersey.api.core.servlet.WebAppResourceConfig;
import com.sun.jersey.core.spi.component.ioc.IoCComponentProviderFactory;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import com.sun.jersey.spi.spring.container.SpringComponentProviderFactory;
import com.sun.jersey.spi.spring.container.servlet.SpringServlet;
import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;
import com.sun.jersey.test.framework.WebAppDescriptor.Builder;
import com.sun.jersey.test.framework.WebAppDescriptor.FilterDescriptor;
import com.sun.jersey.test.framework.spi.container.TestContainer;
import com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory;

public class ContainerWrapper implements ApplicationContextAware {

@@ -44,7 +56,7 @@

private int port;

private SelectorThread server;
private HttpServer server;

private String packagesToScan = null;

@@ -66,48 +78,57 @@ public void setPort(final int port) {

public void start() throws Exception {

WebApp webApp = new WebApp();
JerseyTest jt;

WebAppAdapter waa = new WebAppAdapter("target", "test", webApp, getClass().getClassLoader(), null);

final URI uri = URI.create("http://localhost:" + port + "/");
final ServletAdapter adapter = waa.newServletAdapter(new SpringServlet());
if (packagesToScan != null) {
adapter.addInitParameter("com.sun.jersey.config.property.packages",
packagesToScan);
}
adapter.addInitParameter("com.sun.jersey.api.json.POJOMappingFeature",
"true");

if (contextConfigLocation != null) {
adapter.addContextParameter("contextConfigLocation",
contextConfigLocation);
}

Map<String,String> initParams = new HashMap<String, String>();

DelegatingFilterProxy filter = new DelegatingFilterProxy();
filter.setTargetBeanName("oauthFilter");
adapter.addFilter(filter, filter.getClass().getName() + "-" +
filter.hashCode(), null);
server = GrizzlyWebContainerFactory.create(uri, initParams);

filter = new DelegatingFilterProxy();
filter.setTargetBeanName("authNFilter");
adapter.addFilter(filter, filter.getClass().getName() + "-" +
filter.hashCode(), null);

adapter.addServletListener("org.springframework.web.context.ContextLoaderListener");

adapter.setContextPath(uri.getPath());
adapter.setProperty("load-on-startup", 1);

server = GrizzlyServerFactory.create(uri, waa);
WebappContext wac = new WebappContext("test", "");

wac.addContextInitParameter("contextConfigLocation",
"classpath:spring-test/master.xml");

wac.addListener("org.springframework.web.context.ContextLoaderListener");
wac.addListener("org.springframework.web.context.request.RequestContextListener");

ServletRegistration servlet = wac.addServlet("jersey-servlet", SpringServlet.class);

servlet.addMapping("/*");

// servlet.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS,
// PackagesResourceConfig.class.getName());

servlet.setInitParameter("com.sun.jersey.config.property.packages", "org.fcrepo");

servlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
//
// FilterRegistration filter = wac.addFilter("delegating-2", DelegatingFilterProxy.class);
//
// filter.setInitParameter("targetBeanName", "oauthFilter");
//
// filter.addMappingForUrlPatterns(null, "/authorization");
//
// filter = wac.addFilter("delegating-1", DelegatingFilterProxy.class);
//
// filter.setInitParameter("targetBeanName", "authNFilter");
//
// filter.addMappingForUrlPatterns(null, "/token");

wac.deploy(server);

URL webXml = this.getClass().getResource("/web.xml");
logger.error(webXml.toString());

logger.debug("started grizzly webserver endpoint at " +
server.getPort());
server.getHttpHandler().getName());
}

public void stop() throws Exception {
server.stopEndpoint();
server.stop();
}

public void setFilters(final List<Filter> filters) {
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-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-3.0.xsd">

<!-- Master context for the test application. -->

<import resource="classpath:/spring-test/repo.xml"/>
<import resource="classpath:/spring-test/rest.xml"/>
<import resource="classpath:/spring-test/security.xml"/>

</beans>
@@ -23,6 +23,6 @@
<bean class="org.fcrepo.services.NodeService"/>
<bean class="org.fcrepo.binary.PolicyDecisionPoint" />
<!-- mints JCR Sessions -->
<bean class="org.fcrepo.session.SessionFactory"/>
<bean class="org.fcrepo.session.SessionFactory" id="org.fcrepo.session.SessionFactory" />

</beans>
@@ -16,7 +16,7 @@
<bean class="org.fcrepo.auth.oauth.DefaultOAuthResourceProvider">
<property name="sessionFactory">
<!-- mints JCR Sessions : needs to reappear here because it can't be autowired from the enclosed contexts-->
<bean class="org.fcrepo.session.SessionFactory"/>
<ref bean="org.fcrepo.session.SessionFactory"/>
</property>
</bean>
</property>
@@ -29,6 +29,6 @@
</property>
</bean>

<bean name="authNFilter" class="org.fcrepo.auth.oauth.filter.RestrictToAuthNFilter"/>
<bean name="authNFilter" class="org.fcrepo.auth.oauth.filter.RestrictToAuthNFilter" init-method="init" />

</beans>
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" metadata-complete="false">

<display-name>Fedora-on-ModeShape</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-test/rest.xml; classpath:spring-test/repo.xml; classpath:spring-test/security.xml</param-value>
</context-param>


<!-- engaging the ModeShape REST API -->

<context-param>
<param-name>org.modeshape.jcr.RepositoryName</param-name>
<param-value>repo</param-value>
</context-param>
<context-param>
<param-name>org.modeshape.jcr.URL</param-name>
<param-value>WEB-INF/classes/config/repository.json</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Required parameter for ModeShape REST - should not be modified -->
<listener>
<listener-class>org.modeshape.web.jcr.ModeShapeJcrDeployer</listener-class>
</listener>

<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.fcrepo</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<filter>
<filter-name>delegating-1</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>oauthFilter</param-value>
</init-param>
</filter>
<filter>
<filter-name>delegating-2</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetBeanName</param-name>
<param-value>authNFilter</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>delegating-1</filter-name>
<url-pattern>/token</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>delegating-2</filter-name>
<url-pattern>/authorization</url-pattern>
</filter-mapping>

<!-- BASIC security parameters -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>fcrepo</realm-name>
</login-config>

<security-role>
<role-name>admin</role-name>
</security-role>

</web-app>

0 comments on commit 3613db3

Please sign in to comment.
You can’t perform that action at this time.