abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eli...@apache.org
Subject svn commit: r415753 - in /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server: exceptions/ exceptions/MethodNotAllowed.java servlet/ servlet/AbderaServlet.java servlet/ServletRequestContext.java
Date Tue, 20 Jun 2006 18:13:00 GMT
Author: eliast
Date: Tue Jun 20 11:12:59 2006
New Revision: 415753

URL: http://svn.apache.org/viewvc?rev=415753&view=rev
Log:
moved from branch/snell_sandbox

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
  (with props)
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
  (with props)
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
  (with props)

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java?rev=415753&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
Tue Jun 20 11:12:59 2006
@@ -0,0 +1,35 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+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);
+  }
+  
+}

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/exceptions/MethodNotAllowed.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java?rev=415753&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
Tue Jun 20 11:12:59 2006
@@ -0,0 +1,99 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+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
+  }
+}

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/AbderaServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java?rev=415753&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
Tue Jun 20 11:12:59 2006
@@ -0,0 +1,115 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.server.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+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;
+  }
+  
+  public URI getBaseUri() {
+	// TODO: this should be done from properties
+	StringBuffer buffer = new StringBuffer("http://");
+	buffer.append(servletRequest.getServerName());
+	if (servletRequest.getLocalPort() != 80) {
+		buffer.append(":");
+		buffer.append(servletRequest.getLocalPort());
+	}
+	buffer.append(servletRequest.getServletPath());
+	try {
+		return new URI(buffer.toString());
+	} catch (URISyntaxException e) {
+		throw new RuntimeException(e);
+	}
+  }
+  
+  public String getHeader(String name) {
+	  return servletRequest.getHeader(name);
+  }
+
+  public List<String> getHeaders(String name) {
+	  return Collections.list(servletRequest.getHeaders(name));
+  }
+  
+  public List<String> getHeaderNames() {
+	  return Collections.list(servletRequest.getHeaderNames());
+  }
+  
+  public URI getPathInfo() {
+	try {
+		String pathInfo = servletRequest.getPathInfo();
+		if(pathInfo == null) {
+			pathInfo = "";
+		}
+		return new URI(pathInfo);
+	} catch (URISyntaxException e) {
+		throw new RuntimeException(e);
+	}
+  }
+  
+  public String getParameter(String name) {
+	  return servletRequest.getParameter(name);
+  }
+  
+  public List<String> getParameters(String name) {
+	  return Arrays.asList(servletRequest.getParameterValues(name)); 
+  }
+  
+  public List<String> getParameterNames() {
+	  return Collections.list(servletRequest.getParameterNames());
+  }
+    
+  public InputStream getInputStream() throws IOException {
+	  return servletRequest.getInputStream();
+  }
+
+}

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/server/servlet/ServletRequestContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message