abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r414975 - in /incubator/abdera/java/branches/snell_sandbox/server: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/abdera/ src/main/java/org/apache/abdera/server/ src/main/java/org/apac...
Date Sat, 17 Jun 2006 00:56:24 GMT
Author: jmsnell
Date: Fri Jun 16 17:56:23 2006
New Revision: 414975

URL: http://svn.apache.org/viewvc?rev=414975&view=rev
Log:
Initial checkin of my server api sandbox

Added:
    incubator/abdera/java/branches/snell_sandbox/server/README
    incubator/abdera/java/branches/snell_sandbox/server/src/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/AbderaServerException.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/CachePolicy.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestContext.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandler.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/ResponseContext.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
    incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
Modified:
    incubator/abdera/java/branches/snell_sandbox/server/   (props changed)

Propchange: incubator/abdera/java/branches/snell_sandbox/server/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jun 16 17:56:23 2006
@@ -0,0 +1,4 @@
+
+bin
+.classpath
+.project

Added: incubator/abdera/java/branches/snell_sandbox/server/README
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/README?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/README (added)
+++ incubator/abdera/java/branches/snell_sandbox/server/README Fri Jun 16 17:56:23 2006
@@ -0,0 +1,4 @@
+This is a first pass at an abstraction of the server api from a couple of
+APP server implementations.  Elias is also working on an alternative set of 
+interfaces and an implementation.  This will continue to evolve over the 
+next week or so.
\ No newline at end of file

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/AbderaServerException.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/AbderaServerException.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/AbderaServerException.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/AbderaServerException.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,74 @@
+package org.apache.abdera.server;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+@SuppressWarnings("serial")
+// TODO: need to finish this
+public class AbderaServerException 
+  extends Exception 
+  implements ResponseContext {
+
+  private int status = 0;
+  private String statusText = null;
+  private Date lastModified = null;
+  private String etag = null;
+  private String language = null;
+  private URI contentLocation = null;
+  private MimeType contentType = null;
+  private URI location = null;
+  
+  public AbderaServerException(int status, String text) {
+    this.status = status;
+    this.statusText = text;
+  }
+  
+  public int getStatus() {
+    return status;
+  }
+
+  public String getStatusText() {
+    return statusText;
+  }
+
+  public Date getLastModified() {
+    return lastModified;
+  }
+
+  public String getEntityTag() {
+    return etag;
+  }
+
+  public String getContentLanguage() {
+    return language;
+  }
+
+  public URI getContentLocation() {
+    return contentLocation;
+  }
+
+  public MimeType getContentType() {
+    return contentType;
+  }
+
+  public URI getLocation() {
+    return location;
+  }
+
+  public void writeTo(OutputStream out) throws IOException {
+    // TODO
+  }
+
+  public CachePolicy getCachePolicy() {
+    return null;
+  }
+
+  public boolean hasEntity() {
+    return false;
+  }
+
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/CachePolicy.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/CachePolicy.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/CachePolicy.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/CachePolicy.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,25 @@
+package org.apache.abdera.server;
+
+import java.util.Date;
+
+public interface CachePolicy {
+
+  boolean isPublic();
+  
+  boolean isCacheable();
+  
+  boolean isStorable();
+  
+  boolean isTransformable();
+  
+  boolean mustRevalidate();
+  
+  boolean proxyMustRevalidate();
+  
+  int getMaxAge();
+  
+  int getSharedMaxAge();
+  
+  Date getExpires();
+  
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestContext.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestContext.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestContext.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,17 @@
+package org.apache.abdera.server;
+
+import java.net.URI;
+
+public interface RequestContext {
+
+  public static enum Method {
+    GET, POST, PUT, DELETE, OPTIONS, HEAD
+  }
+  
+  Method getMethod();
+  
+  URI getRequestUri();
+  
+  //TODO: finish
+  
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandler.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandler.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandler.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandler.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,9 @@
+package org.apache.abdera.server;
+
+public interface RequestHandler {
+
+  ResponseContext invoke(
+    RequestContext requestContext) 
+      throws AbderaServerException;
+  
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/RequestHandlerFactory.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,11 @@
+package org.apache.abdera.server;
+
+public interface RequestHandlerFactory {
+  
+  public static final RequestHandlerFactory INSTANCE = null;
+  
+  RequestHandler newRequestHandler(
+    RequestContext requestContext) 
+      throws AbderaServerException;
+  
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/ResponseContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/ResponseContext.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/ResponseContext.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/ResponseContext.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,34 @@
+package org.apache.abdera.server;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+public interface ResponseContext {
+
+  int getStatus();
+  
+  String getStatusText();
+  
+  Date getLastModified();
+  
+  String getEntityTag();
+  
+  String getContentLanguage();
+  
+  URI getContentLocation();
+   
+  MimeType getContentType();
+  
+  URI getLocation();
+  
+  CachePolicy getCachePolicy();
+  
+  boolean hasEntity();
+  
+  void writeTo(OutputStream out) throws IOException;
+  
+}
\ No newline at end of file

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,18 @@
+package org.apache.abdera.server.exceptions;
+
+import org.apache.abdera.server.AbderaServerException;
+
+public class MethodNotAllowed 
+  extends AbderaServerException {
+
+  private static final long serialVersionUID = -633052744794889086L;
+
+  public MethodNotAllowed() {
+    super(405, null);
+  }
+
+  public MethodNotAllowed(String text) {
+    super(405, text);
+  }
+  
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,82 @@
+package org.apache.abdera.server.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.abdera.server.AbderaServerException;
+import org.apache.abdera.server.CachePolicy;
+import org.apache.abdera.server.RequestContext;
+import org.apache.abdera.server.RequestHandler;
+import org.apache.abdera.server.RequestHandlerFactory;
+import org.apache.abdera.server.ResponseContext;
+import org.apache.abdera.server.exceptions.MethodNotAllowed;
+
+public class AbderaServlet 
+  extends HttpServlet {
+
+  private static final long serialVersionUID = -4273782501412352619L;
+
+  @Override
+  protected void service(
+    HttpServletRequest request, 
+    HttpServletResponse response) 
+      throws ServletException, IOException {
+    RequestContext requestContext = new ServletRequestContext(request);
+    ResponseContext responseContext = null;
+    RequestHandler handler = null;
+    try {
+      RequestHandlerFactory factory = RequestHandlerFactory.INSTANCE;            // TODO:
improve this
+      if (factory != null)
+        handler = factory.newRequestHandler(requestContext);
+      if (handler != null) {
+        responseContext = handler.invoke(requestContext);
+      } else {
+        throw new MethodNotAllowed(request.getMethod());
+      }
+    } catch (AbderaServerException exception) {
+      responseContext = exception;
+    }
+    doOutput(response, responseContext); 
+  }
+
+  private void doOutput(
+    HttpServletResponse response, 
+    ResponseContext context) 
+      throws IOException, ServletException {
+    if (context != null) {
+      if (context.getStatusText() != null)
+        response.sendError(context.getStatus(), context.getStatusText());
+      else 
+        response.setStatus(context.getStatus());
+      if (context.getLastModified() != null)
+        response.setDateHeader("Last-Modified", context.getLastModified().getTime());
+      if (context.getContentLanguage() != null)
+        response.setHeader("Content-Language", context.getContentLanguage());
+      if (context.getContentLocation() != null)
+        response.setHeader("Content-Location", context.getContentLocation().toString());
+      if (context.getContentType() != null)
+        response.setContentType(context.getContentType().toString());
+      if (context.getEntityTag() != null)
+        response.setHeader("ETag", context.getEntityTag());
+      if (context.getLocation() != null)
+        response.setHeader("Location", context.getLocation().toString());
+      handleCachePolicy(response, context.getCachePolicy());
+      if (context.hasEntity())
+        context.writeTo(response.getOutputStream());
+    } else {
+      response.sendError(
+        HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+    }
+  }
+  
+  private void handleCachePolicy(
+    HttpServletResponse response, 
+    CachePolicy cachePolicy) {
+      if (cachePolicy == null) return;
+      //TODO
+  }
+}

Added: incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java?rev=414975&view=auto
==============================================================================
--- incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
(added)
+++ incubator/abdera/java/branches/snell_sandbox/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
Fri Jun 16 17:56:23 2006
@@ -0,0 +1,36 @@
+package org.apache.abdera.server.servlet;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.abdera.server.RequestContext;
+
+public class ServletRequestContext 
+  implements RequestContext {
+
+  private HttpServletRequest servletRequest = null;
+  
+  public ServletRequestContext(HttpServletRequest request) {
+    this.servletRequest = request;
+  }
+  
+  public Method getMethod() {
+    return Method.valueOf(servletRequest.getMethod());
+  }
+
+  public URI getRequestUri() {
+    URI uri = null;
+    try {
+      StringBuffer buf = 
+        new StringBuffer(
+          servletRequest.getRequestURI());
+      if (servletRequest.getQueryString() != null)
+        buf.append("?" + servletRequest.getQueryString());
+      uri = new URI(buf.toString());
+    } catch (URISyntaxException e) {}
+    return uri;
+  }
+
+}



Mime
View raw message