Skip to content

Commit

Permalink
latest changes for a possible running Servlet 3.0, this pretty much d…
Browse files Browse the repository at this point in the history
…oes the job. Only finetuning left
  • Loading branch information
ANierbeck committed Aug 26, 2011
1 parent e1a9535 commit 4ee7d41
Show file tree
Hide file tree
Showing 29 changed files with 756 additions and 344 deletions.
2 changes: 1 addition & 1 deletion itest/src/test/java/org/ops4j/pax/web/itest/ITestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Option[] configure() {
configProfile(),
compendiumProfile(),
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level")
.value("INFO"),
.value("DEBUG"),
systemProperty("org.osgi.service.http.hostname").value(
"127.0.0.1"),
systemProperty("org.osgi.service.http.port")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package org.ops4j.pax.web.itest;

import static org.junit.Assert.fail;

import java.util.Dictionary;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.ops4j.pax.web.service.spi.WebEvent;
import org.ops4j.pax.web.service.spi.WebListener;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;


/**
* @author Achim Nierbeck
*/
@RunWith(JUnit4TestRunner.class)
public class Servlet3WarIntegrationTest extends ITestBase {

Logger LOG = LoggerFactory.getLogger(Servlet3WarIntegrationTest.class);

private Bundle installWarBundle;

private WebListener webListener;



@Before
public void setUp() throws BundleException, InterruptedException {
LOG.info("Setting up test");
webListener = new WebListenerImpl();
bundleContext.registerService(WebListener.class.getName(), webListener,
null);
String bundlePath = WEB_BUNDLE
+ "mvn:org.ops4j.pax.web.samples/helloworld-servlet3/2.0.0-SNAPSHOT/war?"
+ WEB_CONTEXT_PATH + "=/servlet3";
installWarBundle = bundleContext.installBundle(bundlePath);
installWarBundle.start();

int count = 0;
while (!((WebListenerImpl) webListener).gotEvent() && count < 50) {
synchronized (this) {
this.wait(100);
count++;
}
}
}

@After
public void tearDown() throws BundleException {
if (installWarBundle != null) {
installWarBundle.stop();
installWarBundle.uninstall();
}
}

/**
* You will get a list of bundles installed by default plus your testcase,
* wrapped into a bundle called pax-exam-probe
*/
@Test
public void listBundles() {
for (Bundle b : bundleContext.getBundles()) {
if (b.getState() != Bundle.ACTIVE)
fail("Bundle should be active: " + b);

Dictionary headers = b.getHeaders();
String ctxtPath = (String) headers.get(WEB_CONTEXT_PATH);
if (ctxtPath != null)
System.out.println("Bundle " + b.getBundleId() + " : "
+ b.getSymbolicName() + " : " + ctxtPath);
else
System.out.println("Bundle " + b.getBundleId() + " : "
+ b.getSymbolicName());
}

}

@Test
public void testWC() throws Exception {

testWebPath("http://127.0.0.1:8181/servlet3", "<h1>Hello World</h1>");

}

@Test
public void testSlash() throws Exception {


testWebPath("http://127.0.0.1:8181/servlet3/", "<h1>Hello World</h1>");

}


private class WebListenerImpl implements WebListener {

private boolean event = false;

public void webEvent(WebEvent event) {
LOG.info("Got event: " + event);
if (event.getType() == 2)
this.event = true;
}

public boolean gotEvent() {
return event;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletException;

import org.osgi.service.http.HttpContext;
Expand Down Expand Up @@ -280,8 +281,22 @@ void registerFilter( Filter filter,
* @param httpContext
*/
void unregisterConstraintMapping(HttpContext httpContext);


/**
* Register ServletContainerInitializer....
*
* @param servletContainerInitializer
* @param classes
* @param m_httpContext
*/
void registerServletContainerInitializer(
ServletContainerInitializer servletContainerInitializer,
Class[] classes, HttpContext m_httpContext);

SharedWebContainerContext getDefaultSharedHttpContext();

void unregisterServletContainerInitializer(HttpContext m_httpContext);


}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.ops4j.pax.web.extender.war.internal.model.WebAppListener;
import org.ops4j.pax.web.extender.war.internal.model.WebAppLoginConfig;
import org.ops4j.pax.web.extender.war.internal.model.WebAppServlet;
import org.ops4j.pax.web.extender.war.internal.model.WebAppServletContainerInitializer;

/**
* A visitor that registers a web application using a standard http service.
Expand Down Expand Up @@ -185,7 +186,7 @@ public void visit( final WebAppErrorPage webAppErrorPage )
* @see WebAppVisitor#visit(WebAppListener)
*/
public void visit(WebAppLoginConfig loginConfig) {
LOG.info( "Pax Web not available. Skipping listener registration for [" + loginConfig + "]" );
LOG.info( "Pax Web not available. Skipping login config registration for [" + loginConfig + "]" );
}

/**
Expand All @@ -194,9 +195,15 @@ public void visit(WebAppLoginConfig loginConfig) {
* @see WebAppVisitor#visit(WebAppListener)
*/
public void visit(WebAppConstraintMapping constraintMapping) {
LOG.info( "Pax Web not available. Skipping listener registration for [" + constraintMapping + "]" );
LOG.info( "Pax Web not available. Skipping constraint mapping registration for [" + constraintMapping + "]" );
}


public void visit(
WebAppServletContainerInitializer servletContainerInitializer) {
LOG.info( "Pax Web not available. Skipping container initializer registration for [" +servletContainerInitializer + "]");
}

/**
* Creates an instance of a class from class name.
*
Expand Down
Loading

0 comments on commit 4ee7d41

Please sign in to comment.