You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/11/06 09:59:44 UTC
svn commit: r592337 [7/7] - in /mina/sandbox/asyncweb:
core/src/main/java/org/safehaus/asyncweb/codec/
core/src/main/java/org/safehaus/asyncweb/codec/decoder/
core/src/main/java/org/safehaus/asyncweb/codec/decoder/support/
core/src/main/java/org/safeha...
Modified: mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/service/filter/resolver/SimplePrefixResolverTest.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/service/filter/resolver/SimplePrefixResolverTest.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/service/filter/resolver/SimplePrefixResolverTest.java (original)
+++ mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/service/filter/resolver/SimplePrefixResolverTest.java Tue Nov 6 00:59:36 2007
@@ -31,68 +31,71 @@
/**
* Tests <code>SimplePrefixResolver</code>
- *
+ *
* @author irvingd
*
*/
public class SimplePrefixResolverTest extends TestCase {
- private SimplePrefixResolver resolver;
-
- public SimplePrefixResolverTest(String name) {
- super (name);
- }
-
- protected void setUp() {
- resolver = new SimplePrefixResolver();
- }
-
- /**
- * Tests that if no prefix is configured, the request uri is
- * returned as the resolved service name
- */
- public void testNoPrefixPassThrough() throws Exception {
- assertResolvedValue("a", "a");
- assertResolvedValue("some/service/Name", "some/service/Name");
- assertResolvedValue("", "");
- assertResolvedValue(null, null);
- }
-
- /**
- * Tests that no resolution is made if a prefix is configured and the
- * request uri does not start with this prefix
- */
- public void testPrefixNoMatch() throws Exception {
- resolver.setUriPrefix("prefix/");
- assertResolvedValue("a", null);
- assertResolvedValue("/prefix/x", null);
- assertResolvedValue("", null);
- assertResolvedValue(null, null);
- }
-
- /**
- * Tests that a resolution is made if a prefix is configured, and the
- * request uri matches the prefix
- */
- public void testPrefixMatch() throws Exception {
- resolver.setUriPrefix("prefix/");
- assertResolvedValue("prefix/a", "a");
- assertResolvedValue("prefix/a/b", "a/b");
- assertResolvedValue("prefix/", "");
- }
-
- private void assertResolvedValue(String uri, String expected) throws Exception {
- HttpRequest request = createRequestForURI(uri);
- String resolved = resolver.resolveService(request);
- assertEquals("Unexpected service name", expected, resolved);
- }
-
- private HttpRequest createRequestForURI(String uri) throws URISyntaxException {
- MutableHttpRequest req = new DefaultHttpRequest();
- if (uri != null) {
- req.setRequestUri(new URI(uri));
- }
- return req;
- }
-
+ private SimplePrefixResolver resolver;
+
+ public SimplePrefixResolverTest(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() {
+ resolver = new SimplePrefixResolver();
+ }
+
+ /**
+ * Tests that if no prefix is configured, the request uri is
+ * returned as the resolved service name
+ */
+ public void testNoPrefixPassThrough() throws Exception {
+ assertResolvedValue("a", "a");
+ assertResolvedValue("some/service/Name", "some/service/Name");
+ assertResolvedValue("", "");
+ assertResolvedValue(null, null);
+ }
+
+ /**
+ * Tests that no resolution is made if a prefix is configured and the
+ * request uri does not start with this prefix
+ */
+ public void testPrefixNoMatch() throws Exception {
+ resolver.setUriPrefix("prefix/");
+ assertResolvedValue("a", null);
+ assertResolvedValue("/prefix/x", null);
+ assertResolvedValue("", null);
+ assertResolvedValue(null, null);
+ }
+
+ /**
+ * Tests that a resolution is made if a prefix is configured, and the
+ * request uri matches the prefix
+ */
+ public void testPrefixMatch() throws Exception {
+ resolver.setUriPrefix("prefix/");
+ assertResolvedValue("prefix/a", "a");
+ assertResolvedValue("prefix/a/b", "a/b");
+ assertResolvedValue("prefix/", "");
+ }
+
+ private void assertResolvedValue(String uri, String expected)
+ throws Exception {
+ HttpRequest request = createRequestForURI(uri);
+ String resolved = resolver.resolveService(request);
+ assertEquals("Unexpected service name", expected, resolved);
+ }
+
+ private HttpRequest createRequestForURI(String uri)
+ throws URISyntaxException {
+ MutableHttpRequest req = new DefaultHttpRequest();
+ if (uri != null) {
+ req.setRequestUri(new URI(uri));
+ }
+ return req;
+ }
+
}
Modified: mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/LinkedPermitIssuerTest.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/LinkedPermitIssuerTest.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/LinkedPermitIssuerTest.java (original)
+++ mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/LinkedPermitIssuerTest.java Tue Nov 6 00:59:36 2007
@@ -26,159 +26,163 @@
/**
* Tests <code>LinkedPermitIssuer</code>
- *
+ *
* @author irvingd
*
*/
public class LinkedPermitIssuerTest extends TestCase {
- private static final int LIFETIME = 100;
-
- private LinkedPermitIssuer issuer;
- private MockListener listener;
-
- protected void setUp() throws Exception {
- issuer = new LinkedPermitIssuer(LIFETIME);
- listener = new MockListener();
- }
-
- protected void tearDown() throws Exception {
- issuer.close();
- }
-
- /**
- * Tests that we can issue permits
- */
- public void testAddPermits() {
- TimedPermit permit1 = issuer.issuePermit("1");
- assertNotNull(permit1);
- TimedPermit permit2 = issuer.issuePermit("2");
- assertNotNull(permit2);
- assertNotSame(permit1, permit2);
- }
-
- /**
- * Tests that if we cancel a permit:
- * <ul>
- * <li>We are informed that the permit has been successfully cancelled on the
- * first cancellation</li>
- * <li>A subsequent attempt to cancel the permit indicates that no further
- * cancellation took place</li>
- * </ul>
- */
- public void testCancelPermit() {
- TimedPermit permit = issuer.issuePermit("permit");
- assertTrue("Expected cancellation", permit.cancel());
- assertFalse("Unexpected calcellation", permit.cancel());
- }
-
- /**
- * Tests that if we cancel a permit, no expiration notification is fired
- * for it
- */
- public void testCancelAbortsExpiry() {
- registerMockListener();
- TimedPermit permit = issuer.issuePermit("permit");
- assertTrue("Expected cancellation", permit.cancel());
- listener.validate(LIFETIME * 2);
- }
-
- /**
- * Tests that closing the issuer aborts expiry notifications
- */
- public void testCloseAbortsExpiry() {
- registerMockListener();
- issuer.issuePermit("permit");
- issuer.close();
- listener.validate(LIFETIME * 2);
- }
-
- /**
- * Tests that renewing a permit causes its lifetime to be extended
- */
- public void testRenewalSingle() {
- registerMockListener();
- TimedPermit permit = issuer.issuePermit("permit");
- listener.validate(LIFETIME / 2);
- permit.renew();
- listener.validate((3 * LIFETIME) / 4);
- listener.addExpectedExpiration("permit");
- listener.validate(LIFETIME / 2);
- }
-
- /**
- * Obtains multiple entries from the issuer.
- * One entry has its lifetime renewed.
- * We check that the entries expire when expected.
- */
- public void testRenewalMulti() {
- registerMockListener();
- issuer.issuePermit("permit1");
- TimedPermit permit2 = issuer.issuePermit("permit2");
- issuer.issuePermit("permit3");
- listener.validate(LIFETIME / 2);
- listener.addExpectedExpiration("permit1");
- listener.addExpectedExpiration("permit3");
- permit2.renew();
- listener.validate((3 * LIFETIME) / 4);
- listener.addExpectedExpiration("permit2");
- listener.validate(LIFETIME / 2);
- }
-
- /**
- * Tests that we can renew the head entry, and then subsequently renew
- * a following entry
- */
- public void testRenewHeadFirst() {
- TimedPermit permit1 = issuer.issuePermit("permit1");
- TimedPermit permit2 = issuer.issuePermit("permit2");
- permit1.renew();
- permit2.renew();
- }
-
- private void registerMockListener() {
- issuer.addPermitExpirationListener(listener);
- }
-
- /**
- * A mock <code>PermitExpirationListener</code>
- *
- * @author irvingd
- */
- private class MockListener implements PermitExpirationListener {
-
- private List<Object> expectedToExpire = new ArrayList<Object>();
- private List<Object> expired = new ArrayList<Object>();
-
- public void permitExpired(Object o) {
- expired.add(o);
- }
-
- void addExpectedExpiration(Object o) {
- expectedToExpire.add(o);
- }
-
- /**
- * Validates that exactly those entries expected to expire have expred.
- */
- void validate() {
- assertEquals(expectedToExpire, expired);
- }
-
- /**
- * Performs validation after a specified peroid
- *
- * @param delay The delay (in ms)
- */
- void validate(long delay) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- validate();
- }
-
- }
-
+ private static final int LIFETIME = 100;
+
+ private LinkedPermitIssuer issuer;
+
+ private MockListener listener;
+
+ @Override
+ protected void setUp() throws Exception {
+ issuer = new LinkedPermitIssuer(LIFETIME);
+ listener = new MockListener();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ issuer.close();
+ }
+
+ /**
+ * Tests that we can issue permits
+ */
+ public void testAddPermits() {
+ TimedPermit permit1 = issuer.issuePermit("1");
+ assertNotNull(permit1);
+ TimedPermit permit2 = issuer.issuePermit("2");
+ assertNotNull(permit2);
+ assertNotSame(permit1, permit2);
+ }
+
+ /**
+ * Tests that if we cancel a permit:
+ * <ul>
+ * <li>We are informed that the permit has been successfully cancelled on the
+ * first cancellation</li>
+ * <li>A subsequent attempt to cancel the permit indicates that no further
+ * cancellation took place</li>
+ * </ul>
+ */
+ public void testCancelPermit() {
+ TimedPermit permit = issuer.issuePermit("permit");
+ assertTrue("Expected cancellation", permit.cancel());
+ assertFalse("Unexpected calcellation", permit.cancel());
+ }
+
+ /**
+ * Tests that if we cancel a permit, no expiration notification is fired
+ * for it
+ */
+ public void testCancelAbortsExpiry() {
+ registerMockListener();
+ TimedPermit permit = issuer.issuePermit("permit");
+ assertTrue("Expected cancellation", permit.cancel());
+ listener.validate(LIFETIME * 2);
+ }
+
+ /**
+ * Tests that closing the issuer aborts expiry notifications
+ */
+ public void testCloseAbortsExpiry() {
+ registerMockListener();
+ issuer.issuePermit("permit");
+ issuer.close();
+ listener.validate(LIFETIME * 2);
+ }
+
+ /**
+ * Tests that renewing a permit causes its lifetime to be extended
+ */
+ public void testRenewalSingle() {
+ registerMockListener();
+ TimedPermit permit = issuer.issuePermit("permit");
+ listener.validate(LIFETIME / 2);
+ permit.renew();
+ listener.validate(3 * LIFETIME / 4);
+ listener.addExpectedExpiration("permit");
+ listener.validate(LIFETIME / 2);
+ }
+
+ /**
+ * Obtains multiple entries from the issuer.
+ * One entry has its lifetime renewed.
+ * We check that the entries expire when expected.
+ */
+ public void testRenewalMulti() {
+ registerMockListener();
+ issuer.issuePermit("permit1");
+ TimedPermit permit2 = issuer.issuePermit("permit2");
+ issuer.issuePermit("permit3");
+ listener.validate(LIFETIME / 2);
+ listener.addExpectedExpiration("permit1");
+ listener.addExpectedExpiration("permit3");
+ permit2.renew();
+ listener.validate(3 * LIFETIME / 4);
+ listener.addExpectedExpiration("permit2");
+ listener.validate(LIFETIME / 2);
+ }
+
+ /**
+ * Tests that we can renew the head entry, and then subsequently renew
+ * a following entry
+ */
+ public void testRenewHeadFirst() {
+ TimedPermit permit1 = issuer.issuePermit("permit1");
+ TimedPermit permit2 = issuer.issuePermit("permit2");
+ permit1.renew();
+ permit2.renew();
+ }
+
+ private void registerMockListener() {
+ issuer.addPermitExpirationListener(listener);
+ }
+
+ /**
+ * A mock <code>PermitExpirationListener</code>
+ *
+ * @author irvingd
+ */
+ private class MockListener implements PermitExpirationListener {
+
+ private List<Object> expectedToExpire = new ArrayList<Object>();
+
+ private List<Object> expired = new ArrayList<Object>();
+
+ public void permitExpired(Object o) {
+ expired.add(o);
+ }
+
+ void addExpectedExpiration(Object o) {
+ expectedToExpire.add(o);
+ }
+
+ /**
+ * Validates that exactly those entries expected to expire have expred.
+ */
+ void validate() {
+ assertEquals(expectedToExpire, expired);
+ }
+
+ /**
+ * Performs validation after a specified peroid
+ *
+ * @param delay The delay (in ms)
+ */
+ void validate(long delay) {
+ try {
+ Thread.sleep(delay);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ validate();
+ }
+
+ }
+
}
Modified: mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/MockNextFilter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/MockNextFilter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/MockNextFilter.java (original)
+++ mina/sandbox/asyncweb/core/src/test/java/org/safehaus/asyncweb/util/MockNextFilter.java Tue Nov 6 00:59:36 2007
@@ -26,30 +26,30 @@
/**
* A simple <code>InvocationChain</code> which counts the
* number of invocations made
- *
+ *
* @author irvingd
*
*/
public class MockNextFilter implements NextFilter {
- private int invokeCount;
-
- /**
- * Simply updates the invoke count for this chain
- */
- public void invoke() {
- ++invokeCount;
- }
-
- /**
- * Asserts that a specified number of invocations have
- * been made
- *
- * @param expected The expected invocation count
- */
- public void assertInvocationCount(int expected) {
- Assert.assertEquals("Unexpected invocation count",
- expected, invokeCount);
- }
+ private int invokeCount;
+
+ /**
+ * Simply updates the invoke count for this chain
+ */
+ public void invoke() {
+ ++invokeCount;
+ }
+
+ /**
+ * Asserts that a specified number of invocations have
+ * been made
+ *
+ * @param expected The expected invocation count
+ */
+ public void assertInvocationCount(int expected) {
+ Assert.assertEquals("Unexpected invocation count", expected,
+ invokeCount);
+ }
}
Modified: mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/cookie/CookieExample.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/cookie/CookieExample.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/cookie/CookieExample.java (original)
+++ mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/cookie/CookieExample.java Tue Nov 6 00:59:36 2007
@@ -35,86 +35,91 @@
public class CookieExample implements HttpService {
- private static final String ADD_COOKIE_NAME = "cookieName";
- private static final String ADD_COOKIE_VALUE = "cookieValue";
- private static final String ADD_COOKIE_PATH = "cookiePath";
- private static final String ADD_COOKIE_EXPIRY = "cookieExpiry";
-
- private String form;
-
- public void handleRequest(HttpServiceContext context) throws Exception {
- MutableHttpResponse response = new DefaultHttpResponse();
-
- StringWriter buf = new StringWriter();
- PrintWriter writer = new PrintWriter(buf);
- writer.println("<html><body>");
- writer.println(form);
- MutableCookie addedCookie = addCookieIfPresent(context, response);
- if (addedCookie != null) {
- writeAddedCookie(addedCookie, writer);
- }
- writer.println("</body></html>");
- writer.flush();
-
- IoBuffer bb = IoBuffer.allocate(1024);
- bb.setAutoExpand(true);
- bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
- bb.flip();
- response.setContent(new ByteBufferContent(bb));
-
- context.commitResponse(response);
- }
-
- /**
- * Sets the string containing our cookie form
- *
- * @param form The form string
- */
- public void setForm(String form) {
- this.form = form;
- }
-
- public void start() {
- // Dont care
- }
-
- public void stop() {
- // Dont care
- }
-
- private void writeAddedCookie(MutableCookie cookie, PrintWriter writer) {
- writer.println("<b><i>Cookie Added:</i></b>");
- writer.println(cookie);
- }
-
- private MutableCookie addCookieIfPresent(HttpServiceContext context, MutableHttpResponse response) {
- HttpRequest request = context.getRequest();
- String name = getParamValue(request, ADD_COOKIE_NAME);
- String value = getParamValue(request, ADD_COOKIE_VALUE);
- if (name == null || value == null) {
- return null;
- }
- MutableCookie cookie = new DefaultCookie(name);
- cookie.setValue(value);
-
- if (getParamValue(request, ADD_COOKIE_PATH) != null) {
- cookie.setPath(request.getParameter(ADD_COOKIE_PATH));
- }
- if (getParamValue(request, ADD_COOKIE_EXPIRY) != null) {
- try {
- int expiry = Integer.parseInt(request.getParameter(ADD_COOKIE_EXPIRY));
- cookie.setMaxAge(expiry);
- } catch (NumberFormatException e) {
- // ignore expiry
- }
- }
- response.addCookie(cookie);
- return cookie;
- }
-
- private static final String getParamValue(HttpRequest request, String name) {
- String value = request.getParameter(name);
- return value == null || "".equals(value )? null : value;
- }
-
+ private static final String ADD_COOKIE_NAME = "cookieName";
+
+ private static final String ADD_COOKIE_VALUE = "cookieValue";
+
+ private static final String ADD_COOKIE_PATH = "cookiePath";
+
+ private static final String ADD_COOKIE_EXPIRY = "cookieExpiry";
+
+ private String form;
+
+ public void handleRequest(HttpServiceContext context) throws Exception {
+ MutableHttpResponse response = new DefaultHttpResponse();
+
+ StringWriter buf = new StringWriter();
+ PrintWriter writer = new PrintWriter(buf);
+ writer.println("<html><body>");
+ writer.println(form);
+ MutableCookie addedCookie = addCookieIfPresent(context, response);
+ if (addedCookie != null) {
+ writeAddedCookie(addedCookie, writer);
+ }
+ writer.println("</body></html>");
+ writer.flush();
+
+ IoBuffer bb = IoBuffer.allocate(1024);
+ bb.setAutoExpand(true);
+ bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
+ bb.flip();
+ response.setContent(new ByteBufferContent(bb));
+
+ context.commitResponse(response);
+ }
+
+ /**
+ * Sets the string containing our cookie form
+ *
+ * @param form The form string
+ */
+ public void setForm(String form) {
+ this.form = form;
+ }
+
+ public void start() {
+ // Dont care
+ }
+
+ public void stop() {
+ // Dont care
+ }
+
+ private void writeAddedCookie(MutableCookie cookie, PrintWriter writer) {
+ writer.println("<b><i>Cookie Added:</i></b>");
+ writer.println(cookie);
+ }
+
+ private MutableCookie addCookieIfPresent(HttpServiceContext context,
+ MutableHttpResponse response) {
+ HttpRequest request = context.getRequest();
+ String name = getParamValue(request, ADD_COOKIE_NAME);
+ String value = getParamValue(request, ADD_COOKIE_VALUE);
+ if (name == null || value == null) {
+ return null;
+ }
+ MutableCookie cookie = new DefaultCookie(name);
+ cookie.setValue(value);
+
+ if (getParamValue(request, ADD_COOKIE_PATH) != null) {
+ cookie.setPath(request.getParameter(ADD_COOKIE_PATH));
+ }
+ if (getParamValue(request, ADD_COOKIE_EXPIRY) != null) {
+ try {
+ int expiry = Integer.parseInt(request
+ .getParameter(ADD_COOKIE_EXPIRY));
+ cookie.setMaxAge(expiry);
+ } catch (NumberFormatException e) {
+ // ignore expiry
+ }
+ }
+ response.addCookie(cookie);
+ return cookie;
+ }
+
+ private static final String getParamValue(HttpRequest request, String name) {
+ String value = request.getParameter(name);
+ return value == null || "".equals(value) ? null : value;
+ }
+
}
Modified: mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/helloworld/HelloWorldHttpService.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/helloworld/HelloWorldHttpService.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/helloworld/HelloWorldHttpService.java (original)
+++ mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/helloworld/HelloWorldHttpService.java Tue Nov 6 00:59:36 2007
@@ -37,130 +37,133 @@
import org.safehaus.asyncweb.service.HttpService;
import org.safehaus.asyncweb.service.HttpServiceContext;
-
/**
* A simple <code>HttpService</code> which sends "hello world"
* responses to every request.
- *
+ *
* Note that normally we wouldn't be generating html directly in a service :o)
- *
+ *
* @author irvingd
*
*/
public class HelloWorldHttpService implements HttpService {
- private String message = "Hello from AsyncWeb!!";
-
- /**
- * Sends the configured message as an HTTP response
- */
- public void handleRequest(HttpServiceContext context) throws Exception {
- MutableHttpResponse response = new DefaultHttpResponse();
-
- StringWriter buf = new StringWriter();
- PrintWriter writer = new PrintWriter(buf);
- writer.println("<html><body><b>Your message of the day:</b><br/><br/>");
- writer.println("<h2><i>" + message + "</h2></i><br/><br/>");
- writeHeaders(context.getRequest(), writer);
- writer.println("<br/>");
- writeParameters(context.getRequest(), writer);
- writer.println("<br/>");
- writeCookies(context.getRequest(), writer);
- writer.flush();
-
- IoBuffer bb = IoBuffer.allocate(1024);
- bb.setAutoExpand(true);
- bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
- bb.flip();
- response.setContent(new ByteBufferContent(bb));
-
- response.setHeader("Pragma", "no-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setStatus(HttpResponseStatus.OK);
-
-
- context.commitResponse(response);
- }
-
- /**
- * Sets the message to return in responses.
- * This is called for you by the framework!
- *
- * @param message The message
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /**
- * Writes headers from the request to the specified writer
- *
- * @param request The request
- * @param writer The writer
- */
- private void writeHeaders(HttpRequest request, PrintWriter writer) {
- writer.println("You sent these headers with your request:<br/>");
- writer.println("<ul>");
- for (String headerName: request.getHeaders().keySet()) {
- String headerValue = request.getHeader(headerName);
- writer.print("<li>" + headerName + " = " + headerValue + "</li>");
- }
- writer.println("</ul>");
- }
-
- /**
- * Writes cookies from the request to the specified writer
- *
- * @param request The request
- * @param writer The writer
- */
- private void writeCookies(HttpRequest request, PrintWriter writer) {
- Collection<Cookie> cookies = request.getCookies();
- if (!cookies.isEmpty()) {
- writer.println("You sent these cookies with your request:<br/>");
- writer.println("<ul>");
- for (Cookie cookie: cookies) {
- writer.println("<li>Name = " + cookie.getName() + " Value = " + cookie.getValue());
- writer.println(" Path = " + cookie.getPath() + " Version = " + cookie.getVersion() + "</li>");
- }
- writer.println("</ul>");
- }
- }
-
- /**
- * Writes request parameters to the specified writer
- *
- * @param request The request
- * @param writer The writer
- */
- private void writeParameters(HttpRequest request, PrintWriter writer) {
- if (request.getParameters().size() > 0) {
- writer.println("You sent these parameters with your request:<br/><br/>");
- writer.println("<ul>");
-
- for (Map.Entry<String, List<String>> entry: request.getParameters().entrySet()) {
- writer.println("<li>");
- writer.print("'" + entry.getKey() + "' = ");
- for (Iterator<String> i = entry.getValue().iterator(); i.hasNext();) {
- String value = i.next();
- writer.print("'" + value + "'");
- if (i.hasNext()) {
- writer.print(", ");
- }
- }
- writer.println("</li/>");
- }
-
- writer.println("</ul>");
- }
- }
-
- public void start() {
- // Dont care
- }
-
- public void stop() {
- // Dont care
- }
+ private String message = "Hello from AsyncWeb!!";
+
+ /**
+ * Sends the configured message as an HTTP response
+ */
+ public void handleRequest(HttpServiceContext context) throws Exception {
+ MutableHttpResponse response = new DefaultHttpResponse();
+
+ StringWriter buf = new StringWriter();
+ PrintWriter writer = new PrintWriter(buf);
+ writer.println("<html><body><b>Your message of the day:</b><br/><br/>");
+ writer.println("<h2><i>" + message + "</h2></i><br/><br/>");
+ writeHeaders(context.getRequest(), writer);
+ writer.println("<br/>");
+ writeParameters(context.getRequest(), writer);
+ writer.println("<br/>");
+ writeCookies(context.getRequest(), writer);
+ writer.flush();
+
+ IoBuffer bb = IoBuffer.allocate(1024);
+ bb.setAutoExpand(true);
+ bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
+ bb.flip();
+ response.setContent(new ByteBufferContent(bb));
+
+ response.setHeader("Pragma", "no-cache");
+ response.setHeader("Cache-Control", "no-cache");
+ response.setStatus(HttpResponseStatus.OK);
+
+ context.commitResponse(response);
+ }
+
+ /**
+ * Sets the message to return in responses.
+ * This is called for you by the framework!
+ *
+ * @param message The message
+ */
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ /**
+ * Writes headers from the request to the specified writer
+ *
+ * @param request The request
+ * @param writer The writer
+ */
+ private void writeHeaders(HttpRequest request, PrintWriter writer) {
+ writer.println("You sent these headers with your request:<br/>");
+ writer.println("<ul>");
+ for (String headerName : request.getHeaders().keySet()) {
+ String headerValue = request.getHeader(headerName);
+ writer.print("<li>" + headerName + " = " + headerValue + "</li>");
+ }
+ writer.println("</ul>");
+ }
+
+ /**
+ * Writes cookies from the request to the specified writer
+ *
+ * @param request The request
+ * @param writer The writer
+ */
+ private void writeCookies(HttpRequest request, PrintWriter writer) {
+ Collection<Cookie> cookies = request.getCookies();
+ if (!cookies.isEmpty()) {
+ writer.println("You sent these cookies with your request:<br/>");
+ writer.println("<ul>");
+ for (Cookie cookie : cookies) {
+ writer.println("<li>Name = " + cookie.getName() + " Value = "
+ + cookie.getValue());
+ writer.println(" Path = " + cookie.getPath() + " Version = "
+ + cookie.getVersion() + "</li>");
+ }
+ writer.println("</ul>");
+ }
+ }
+
+ /**
+ * Writes request parameters to the specified writer
+ *
+ * @param request The request
+ * @param writer The writer
+ */
+ private void writeParameters(HttpRequest request, PrintWriter writer) {
+ if (request.getParameters().size() > 0) {
+ writer
+ .println("You sent these parameters with your request:<br/><br/>");
+ writer.println("<ul>");
+
+ for (Map.Entry<String, List<String>> entry : request
+ .getParameters().entrySet()) {
+ writer.println("<li>");
+ writer.print("'" + entry.getKey() + "' = ");
+ for (Iterator<String> i = entry.getValue().iterator(); i
+ .hasNext();) {
+ String value = i.next();
+ writer.print("'" + value + "'");
+ if (i.hasNext()) {
+ writer.print(", ");
+ }
+ }
+ writer.println("</li/>");
+ }
+
+ writer.println("</ul>");
+ }
+ }
+
+ public void start() {
+ // Dont care
+ }
+
+ public void stop() {
+ // Dont care
+ }
}
Modified: mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/HttpProtocolHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/HttpProtocolHandler.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/HttpProtocolHandler.java (original)
+++ mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/HttpProtocolHandler.java Tue Nov 6 00:59:36 2007
@@ -40,105 +40,106 @@
import org.safehaus.asyncweb.util.HttpHeaderConstants;
public class HttpProtocolHandler implements IoHandler {
- private static final int CONTENT_PADDING = 0; // 101
+ private static final int CONTENT_PADDING = 0; // 101
- private final Map<Integer, IoBuffer> buffers = new ConcurrentHashMap<Integer, IoBuffer>();
+ private final Map<Integer, IoBuffer> buffers = new ConcurrentHashMap<Integer, IoBuffer>();
- private final Timer timer;
+ private final Timer timer;
- public HttpProtocolHandler() {
- timer = new Timer(true);
- }
-
- public void exceptionCaught(IoSession session, Throwable cause)
- throws Exception {
- if (!(cause instanceof IOException)) {
- IoSessionLogger.getLogger(session).warn(cause);
- }
- session.close();
- }
-
- public void messageReceived(IoSession session, Object message)
- throws Exception {
- HttpRequest req = (HttpRequest) message;
- String path = req.getRequestUri().getPath();
-
- MutableHttpResponse res;
- if (path.startsWith("/size/")) {
- doDataResponse(session, req);
- } else if (path.startsWith("/delay/")) {
- doAsynchronousDelayedResponse(session, req);
- } else if (path.startsWith("/adelay/")) {
- doAsynchronousDelayedResponse(session, req);
- } else {
- res = new DefaultHttpResponse();
- res.setStatus(HttpResponseStatus.OK);
- writeResponse(session, req, res);
- }
- }
-
- private void writeResponse(IoSession session, HttpRequest req,
- MutableHttpResponse res) {
- res.normalize(req);
- WriteFuture future = session.write(res);
- if (!HttpHeaderConstants.VALUE_KEEP_ALIVE.equalsIgnoreCase(res
- .getHeader(HttpHeaderConstants.KEY_CONNECTION))) {
- future.addListener(IoFutureListener.CLOSE);
- }
- }
-
- private void doDataResponse(IoSession session, HttpRequest req) {
- String path = req.getRequestUri().getPath();
- int size = Integer.parseInt(path.substring(path.lastIndexOf('/') + 1)) + CONTENT_PADDING;
-
- MutableHttpResponse res = new DefaultHttpResponse();
- res.setStatus(HttpResponseStatus.OK);
- res.setHeader("ETag", "W/\"" + size + "-1164091960000\"");
- res.setHeader("Last-Modified", "Tue, 31 Nov 2006 06:52:40 GMT");
-
- IoBuffer buf = buffers.get(size);
- if (buf == null) {
- buf = IoBuffer.allocate(size);
- buffers.put(size, buf);
- }
-
- res.setContent(new ByteBufferContent(buf.duplicate()));
- writeResponse(session, req, res);
- }
-
- private void doAsynchronousDelayedResponse(final IoSession session,
- final HttpRequest req) {
- String path = req.getRequestUri().getPath();
- int delay = Integer.parseInt(path.substring(path.lastIndexOf('/') + 1));
-
- final MutableHttpResponse res = new DefaultHttpResponse();
- res.setStatus(HttpResponseStatus.OK);
- res.setHeader("ETag", "W/\"0-1164091960000\"");
- res.setHeader("Last-Modified", "Tue, 31 Nov 2006 06:52:40 GMT");
-
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
+ public HttpProtocolHandler() {
+ timer = new Timer(true);
+ }
+
+ public void exceptionCaught(IoSession session, Throwable cause)
+ throws Exception {
+ if (!(cause instanceof IOException)) {
+ IoSessionLogger.getLogger(session).warn(cause);
+ }
+ session.close();
+ }
+
+ public void messageReceived(IoSession session, Object message)
+ throws Exception {
+ HttpRequest req = (HttpRequest) message;
+ String path = req.getRequestUri().getPath();
+
+ MutableHttpResponse res;
+ if (path.startsWith("/size/")) {
+ doDataResponse(session, req);
+ } else if (path.startsWith("/delay/")) {
+ doAsynchronousDelayedResponse(session, req);
+ } else if (path.startsWith("/adelay/")) {
+ doAsynchronousDelayedResponse(session, req);
+ } else {
+ res = new DefaultHttpResponse();
+ res.setStatus(HttpResponseStatus.OK);
+ writeResponse(session, req, res);
+ }
+ }
+
+ private void writeResponse(IoSession session, HttpRequest req,
+ MutableHttpResponse res) {
+ res.normalize(req);
+ WriteFuture future = session.write(res);
+ if (!HttpHeaderConstants.VALUE_KEEP_ALIVE.equalsIgnoreCase(res
+ .getHeader(HttpHeaderConstants.KEY_CONNECTION))) {
+ future.addListener(IoFutureListener.CLOSE);
+ }
+ }
+
+ private void doDataResponse(IoSession session, HttpRequest req) {
+ String path = req.getRequestUri().getPath();
+ int size = Integer.parseInt(path.substring(path.lastIndexOf('/') + 1))
+ + CONTENT_PADDING;
+
+ MutableHttpResponse res = new DefaultHttpResponse();
+ res.setStatus(HttpResponseStatus.OK);
+ res.setHeader("ETag", "W/\"" + size + "-1164091960000\"");
+ res.setHeader("Last-Modified", "Tue, 31 Nov 2006 06:52:40 GMT");
+
+ IoBuffer buf = buffers.get(size);
+ if (buf == null) {
+ buf = IoBuffer.allocate(size);
+ buffers.put(size, buf);
+ }
+
+ res.setContent(new ByteBufferContent(buf.duplicate()));
writeResponse(session, req, res);
- }
- }, delay);
- }
-
- public void messageSent(IoSession session, Object message) throws Exception {
- }
-
- public void sessionClosed(IoSession session) throws Exception {
- }
-
- public void sessionCreated(IoSession session) throws Exception {
- }
-
- public void sessionIdle(IoSession session, IdleStatus status)
- throws Exception {
- session.close();
- }
-
- public void sessionOpened(IoSession session) throws Exception {
- session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
- }
+ }
+
+ private void doAsynchronousDelayedResponse(final IoSession session,
+ final HttpRequest req) {
+ String path = req.getRequestUri().getPath();
+ int delay = Integer.parseInt(path.substring(path.lastIndexOf('/') + 1));
+
+ final MutableHttpResponse res = new DefaultHttpResponse();
+ res.setStatus(HttpResponseStatus.OK);
+ res.setHeader("ETag", "W/\"0-1164091960000\"");
+ res.setHeader("Last-Modified", "Tue, 31 Nov 2006 06:52:40 GMT");
+
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ writeResponse(session, req, res);
+ }
+ }, delay);
+ }
+
+ public void messageSent(IoSession session, Object message) throws Exception {
+ }
+
+ public void sessionClosed(IoSession session) throws Exception {
+ }
+
+ public void sessionCreated(IoSession session) throws Exception {
+ }
+
+ public void sessionIdle(IoSession session, IdleStatus status)
+ throws Exception {
+ session.close();
+ }
+
+ public void sessionOpened(IoSession session) throws Exception {
+ session.getConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
+ }
}
Modified: mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/Main.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/Main.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/Main.java (original)
+++ mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/lightweight/Main.java Tue Nov 6 00:59:36 2007
@@ -29,27 +29,25 @@
import org.safehaus.asyncweb.codec.HttpServerCodecFactory;
public class Main {
- public static void main(String[] args) throws Exception {
- Executor threadPool = Executors.newCachedThreadPool();
- SocketAcceptor acceptor = new NioSocketAcceptor(
- Runtime.getRuntime().availableProcessors() + 1,
- threadPool);
+ public static void main(String[] args) throws Exception {
+ Executor threadPool = Executors.newCachedThreadPool();
+ SocketAcceptor acceptor = new NioSocketAcceptor(Runtime.getRuntime()
+ .availableProcessors() + 1, threadPool);
- acceptor.getFilterChain().addLast(
- "codec",
- new ProtocolCodecFilter(new HttpServerCodecFactory()));
+ acceptor.getFilterChain().addLast("codec",
+ new ProtocolCodecFilter(new HttpServerCodecFactory()));
- acceptor.setReuseAddress(true);
- acceptor.getSessionConfig().setReuseAddress(true);
- acceptor.getSessionConfig().setReceiveBufferSize(1024);
- acceptor.getSessionConfig().setSendBufferSize(1024);
- acceptor.getSessionConfig().setTcpNoDelay(true);
- acceptor.getSessionConfig().setSoLinger(-1);
- acceptor.setBacklog(10240);
-
- acceptor.setLocalAddress(new InetSocketAddress(9012));
- acceptor.setHandler(new HttpProtocolHandler());
-
- acceptor.bind();
- }
+ acceptor.setReuseAddress(true);
+ acceptor.getSessionConfig().setReuseAddress(true);
+ acceptor.getSessionConfig().setReceiveBufferSize(1024);
+ acceptor.getSessionConfig().setSendBufferSize(1024);
+ acceptor.getSessionConfig().setTcpNoDelay(true);
+ acceptor.getSessionConfig().setSoLinger(-1);
+ acceptor.setBacklog(10240);
+
+ acceptor.setLocalAddress(new InetSocketAddress(9012));
+ acceptor.setHandler(new HttpProtocolHandler());
+
+ acceptor.bind();
+ }
}
Modified: mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/session/SessionExample.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/session/SessionExample.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/session/SessionExample.java (original)
+++ mina/sandbox/asyncweb/example/src/main/java/org/safehaus/asyncweb/example/session/SessionExample.java Tue Nov 6 00:59:36 2007
@@ -33,92 +33,102 @@
/**
* A very simple example which demonstrates session usage
- *
+ *
* @author irvingd
*
*/
public class SessionExample implements HttpService {
- private static final String COUNT_PROPERTY = "accessCount";
- private static final String DESTROY_PARAM = "destroySession";
-
- /**
- * Provides a response showing some session details for the current request.
- * If no session is assocaited with the request, a new session is created.
- */
- public void handleRequest(HttpServiceContext context) throws Exception {
- MutableHttpResponse response = new DefaultHttpResponse();
- response.setHeader("Pragma", "no-cache");
- response.setHeader("Cache-Control", "no-cache");
-
- StringWriter buf = new StringWriter();
- PrintWriter writer = new PrintWriter(buf);
- writer.println("<html><body>");
- if (!checkDestroy(context, writer)) {
- showSessionDetails(context, writer);
- createNewSessionIfRequired(context, writer);
- }
- writer.println("</body></html>");
- writer.flush();
-
- IoBuffer bb = IoBuffer.allocate(1024);
- bb.setAutoExpand(true);
- bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
- bb.flip();
- response.setContent(new ByteBufferContent(bb));
-
- context.commitResponse(response);
- }
-
- private void showSessionDetails(HttpServiceContext context, PrintWriter writer) {
- HttpSession session = context.getSession(false);
- if (session != null) {
- writer.println("<ul>");
- writer.println("<li>A session was retrieved for your request</li>");
- writer.println("<li>Is session attached? " + session.isAttached() + "</li>");
- writer.println("<li>Is session valid? " + session.isValid() + "</li>");
- Integer count = (Integer) session.getValue(COUNT_PROPERTY);
- int newAccessCount;
- if (count == null) {
- writer.println("<li>This is the first time the new session has been accessed</li>");
- newAccessCount = 1;
- } else {
- newAccessCount = count.intValue() + 1;
- writer.println("<li>The session has been accessed " + newAccessCount + " times</li>");
- }
- session.setValue(COUNT_PROPERTY, new Integer(newAccessCount));
- }
- }
-
- private void createNewSessionIfRequired(HttpServiceContext context, PrintWriter writer) {
- HttpSession session = context.getSession(false);
- if (session == null) {
- session = context.getSession(true);
- writer.println("<i>No current session was located. A new session has been created</i>");
- }
- }
-
- private boolean checkDestroy(HttpServiceContext context, PrintWriter writer) {
- boolean foundParam = false;
- if (context.getRequest().containsParameter(DESTROY_PARAM)) {
- foundParam = true;
- HttpSession session = context.getSession(false);
- if (session == null) {
- writer.println("<i>There is no current session to destroy!</li>");
- } else {
- session.destroy();
- writer.println("<i>The current session has been destroyed</li>");
- }
- }
- return foundParam;
- }
-
- public void start() {
- // Dont care
- }
-
- public void stop() {
- // Dont care
- }
+ private static final String COUNT_PROPERTY = "accessCount";
+
+ private static final String DESTROY_PARAM = "destroySession";
+
+ /**
+ * Provides a response showing some session details for the current request.
+ * If no session is assocaited with the request, a new session is created.
+ */
+ public void handleRequest(HttpServiceContext context) throws Exception {
+ MutableHttpResponse response = new DefaultHttpResponse();
+ response.setHeader("Pragma", "no-cache");
+ response.setHeader("Cache-Control", "no-cache");
+
+ StringWriter buf = new StringWriter();
+ PrintWriter writer = new PrintWriter(buf);
+ writer.println("<html><body>");
+ if (!checkDestroy(context, writer)) {
+ showSessionDetails(context, writer);
+ createNewSessionIfRequired(context, writer);
+ }
+ writer.println("</body></html>");
+ writer.flush();
+
+ IoBuffer bb = IoBuffer.allocate(1024);
+ bb.setAutoExpand(true);
+ bb.putString(buf.toString(), Charset.forName("UTF-8").newEncoder());
+ bb.flip();
+ response.setContent(new ByteBufferContent(bb));
+
+ context.commitResponse(response);
+ }
+
+ private void showSessionDetails(HttpServiceContext context,
+ PrintWriter writer) {
+ HttpSession session = context.getSession(false);
+ if (session != null) {
+ writer.println("<ul>");
+ writer.println("<li>A session was retrieved for your request</li>");
+ writer.println("<li>Is session attached? " + session.isAttached()
+ + "</li>");
+ writer.println("<li>Is session valid? " + session.isValid()
+ + "</li>");
+ Integer count = (Integer) session.getValue(COUNT_PROPERTY);
+ int newAccessCount;
+ if (count == null) {
+ writer
+ .println("<li>This is the first time the new session has been accessed</li>");
+ newAccessCount = 1;
+ } else {
+ newAccessCount = count.intValue() + 1;
+ writer.println("<li>The session has been accessed "
+ + newAccessCount + " times</li>");
+ }
+ session.setValue(COUNT_PROPERTY, new Integer(newAccessCount));
+ }
+ }
+
+ private void createNewSessionIfRequired(HttpServiceContext context,
+ PrintWriter writer) {
+ HttpSession session = context.getSession(false);
+ if (session == null) {
+ session = context.getSession(true);
+ writer
+ .println("<i>No current session was located. A new session has been created</i>");
+ }
+ }
+
+ private boolean checkDestroy(HttpServiceContext context, PrintWriter writer) {
+ boolean foundParam = false;
+ if (context.getRequest().containsParameter(DESTROY_PARAM)) {
+ foundParam = true;
+ HttpSession session = context.getSession(false);
+ if (session == null) {
+ writer
+ .println("<i>There is no current session to destroy!</li>");
+ } else {
+ session.destroy();
+ writer
+ .println("<i>The current session has been destroyed</li>");
+ }
+ }
+ return foundParam;
+ }
+
+ public void start() {
+ // Dont care
+ }
+
+ public void stop() {
+ // Dont care
+ }
}
Modified: mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/HttpServiceLoader.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/HttpServiceLoader.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/HttpServiceLoader.java (original)
+++ mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/HttpServiceLoader.java Tue Nov 6 00:59:36 2007
@@ -27,30 +27,30 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
-
/**
* Loads all <code>HttpService</code>s defined in an
- * <code>ApplicationContext</code> to an associated
+ * <code>ApplicationContext</code> to an associated
* <code>HttpServiceHandler</code>
- *
+ *
* @author irvingd
*/
public class HttpServiceLoader implements ApplicationContextAware {
- private HttpServiceHandler handler;
-
- public void setHandler(HttpServiceHandler httpServiceHandler) {
- this.handler = httpServiceHandler;
- }
-
- public void setApplicationContext(ApplicationContext context) {
- Map services = context.getBeansOfType(HttpService.class);
- for (Iterator iter=services.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry entry = (Map.Entry) iter.next();
- String serviceName = (String) entry.getKey();
- HttpService service = (HttpService) entry.getValue();
- handler.addHttpService(serviceName, service);
+ private HttpServiceHandler handler;
+
+ public void setHandler(HttpServiceHandler httpServiceHandler) {
+ this.handler = httpServiceHandler;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void setApplicationContext(ApplicationContext context) {
+ Map<String, HttpService> services = context.getBeansOfType(HttpService.class);
+ for (Iterator<Map.Entry<String, HttpService>> iter = services.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry<String, HttpService> entry = iter.next();
+ String serviceName = entry.getKey();
+ HttpService service = entry.getValue();
+ handler.addHttpService(serviceName, service);
+ }
}
- }
}
Modified: mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/Main.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/Main.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/Main.java (original)
+++ mina/sandbox/asyncweb/springframework/src/main/java/org/safehaus/asyncweb/integration/spring/Main.java Tue Nov 6 00:59:36 2007
@@ -28,72 +28,75 @@
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
-
/**
* Simple stand-alone server which loads configuration using Spring
- *
+ *
* @author irvingd
*
*/
public class Main {
-
- private static final Log LOG = LogFactory.getLog(Main.class);
-
- private static final String CONFIG_PROPERTY = "asyncWeb.config";
- private static final String SERVICE_CONFIG_PROPERTY = "asyncWeb.config.services";
- private static final String DEFAULT_SERVICE_CONFIG = "httpServiceDefinitions";
-
- private String configDir;
- private String serviceConfigName;
-
- /**
- * @param asyncWebDir The async web base directory
- */
- public Main(File asyncWebDir) {
- this(asyncWebDir, DEFAULT_SERVICE_CONFIG);
- }
-
- /**
- * @param asyncWebDir The async web configuration directory - containing the
- * <code>AsyncWeb.xml</code> configuration file
- * @param serviceConfigName The name of the directory within <code>configDir</code>
- * containing service definitions
- */
- public Main(File asyncWebDir, String serviceConfigName) {
- if (!asyncWebDir.isDirectory()) {
- throw new IllegalArgumentException("Could not find asyncWeb directory: " + asyncWebDir);
+
+ private static final Log LOG = LogFactory.getLog(Main.class);
+
+ private static final String CONFIG_PROPERTY = "asyncWeb.config";
+
+ private static final String SERVICE_CONFIG_PROPERTY = "asyncWeb.config.services";
+
+ private static final String DEFAULT_SERVICE_CONFIG = "httpServiceDefinitions";
+
+ private String configDir;
+
+ private String serviceConfigName;
+
+ /**
+ * @param asyncWebDir The async web base directory
+ */
+ public Main(File asyncWebDir) {
+ this(asyncWebDir, DEFAULT_SERVICE_CONFIG);
+ }
+
+ /**
+ * @param asyncWebDir The async web configuration directory - containing the
+ * <code>AsyncWeb.xml</code> configuration file
+ * @param serviceConfigName The name of the directory within <code>configDir</code>
+ * containing service definitions
+ */
+ public Main(File asyncWebDir, String serviceConfigName) {
+ if (!asyncWebDir.isDirectory()) {
+ throw new IllegalArgumentException(
+ "Could not find asyncWeb directory: " + asyncWebDir);
+ }
+ this.configDir = asyncWebDir.getAbsolutePath() + "/";
+ this.serviceConfigName = serviceConfigName;
+ }
+
+ /**
+ * Uses system properties to determine the asyncWeb configuration directory,
+ * and (optionally) the service configuration directory contained within
+ */
+ Main() {
+ configDir = System.getProperty(CONFIG_PROPERTY);
+ configDir = configDir == null ? "AsyncWeb/" : configDir + "/";
+ serviceConfigName = System.getProperty(SERVICE_CONFIG_PROPERTY,
+ DEFAULT_SERVICE_CONFIG);
+ }
+
+ public void start() {
+ String[] configs = new String[] { configDir + "conf/AsyncWeb.xml",
+ configDir + "conf/" + serviceConfigName + "/*.xml" };
+ ApplicationContext ctx = new FileSystemXmlApplicationContext(configs);
+ ServiceContainer container = (ServiceContainer) ctx
+ .getBean("container");
+ try {
+ container.start();
+ } catch (ContainerLifecycleException e) {
+ LOG.error("Failed to start container", e);
+ System.exit(1);
+ }
+ LOG.info("AsyncWeb server started");
}
- this.configDir = asyncWebDir.getAbsolutePath() + "/";
- this.serviceConfigName = serviceConfigName;
- }
-
- /**
- * Uses system properties to determine the asyncWeb configuration directory,
- * and (optionally) the service configuration directory contained within
- */
- Main() {
- configDir = System.getProperty(CONFIG_PROPERTY);
- configDir = configDir == null ? "AsyncWeb/" : (configDir + "/");
- serviceConfigName = System.getProperty(SERVICE_CONFIG_PROPERTY,
- DEFAULT_SERVICE_CONFIG);
- }
-
- public void start() {
- String[] configs = new String[] { configDir + "conf/AsyncWeb.xml", configDir +
- "conf/" + serviceConfigName + "/*.xml"};
- ApplicationContext ctx = new FileSystemXmlApplicationContext(configs);
- ServiceContainer container = (ServiceContainer) ctx.getBean("container");
- try {
- container.start();
- } catch (ContainerLifecycleException e) {
- LOG.error("Failed to start container", e);
- System.exit(1);
+
+ public static void main(String[] args) throws Exception {
+ new Main().start();
}
- LOG.info("AsyncWeb server started");
- }
-
-
- public static void main(String[] args) throws Exception {
- new Main().start();
- }
}