summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java8
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java22
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTCacheContext.java258
-rw-r--r--sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPCacheContext.java99
5 files changed, 67 insertions, 322 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
index 371645c2d4..20fb9309d5 100644
--- a/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-atom-runtime/src/main/java/org/apache/tuscany/sca/binding/atom/provider/AtomBindingListenerServlet.java
@@ -163,7 +163,7 @@ class AtomBindingListenerServlet extends HttpServlet {
// Test for any cache info in the request
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.getCacheContextFromRequest( request );
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest( request );
} catch ( java.text.ParseException e ) {
}
// System.out.println( "AtomBindingListener.doGet cache context=" + cacheContext );
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
index 22e1cb7349..0fe13337ef 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
@@ -91,7 +91,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -165,7 +165,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -231,7 +231,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -297,7 +297,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
index cb65d74293..b91c6d7f6d 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
@@ -34,7 +34,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tuscany.sca.assembly.Binding;
-import org.apache.tuscany.sca.binding.rest.RESTCacheContext;
+import org.apache.tuscany.sca.common.http.HTTPCacheContext;
import org.apache.tuscany.sca.common.http.HTTPContentTypeMapper;
import org.apache.tuscany.sca.common.http.HTTPContext;
import org.apache.tuscany.sca.invocation.Invoker;
@@ -148,9 +148,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
String id = path.substring(1);
Message responseMessage = null;
- RESTCacheContext cacheContext = null;
+ HTTPCacheContext cacheContext = null;
try {
- cacheContext = RESTCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -238,9 +238,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
String id = path.substring(1);
Message responseMessage = null;
- RESTCacheContext cacheContext = null;
+ HTTPCacheContext cacheContext = null;
try {
- cacheContext = RESTCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -304,9 +304,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
String id = path.substring(1);
Message responseMessage = null;
- RESTCacheContext cacheContext = null;
+ HTTPCacheContext cacheContext = null;
try {
- cacheContext = RESTCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -370,9 +370,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
// String id = path.substring(1);
Message responseMessage = null;
- RESTCacheContext cacheContext = null;
+ HTTPCacheContext cacheContext = null;
try {
- cacheContext = RESTCacheContext.getCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
@@ -408,9 +408,9 @@ public class RESTBindingListenerServlet extends HttpServlet {
// Test if the ETag and LastModified are returned as a cache context.
Object body = responseMessage.getBody();
- if ( body.getClass() == RESTCacheContext.class ) {
+ if ( body.getClass() == HTTPCacheContext.class ) {
// Transfer to header if so.
- RESTCacheContext cc = (RESTCacheContext)responseMessage.getBody();
+ HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody();
if (( cc != null ) && ( cc.isEnabled() )) {
String eTag = cc.getETag();
if ( eTag != null )
diff --git a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTCacheContext.java b/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTCacheContext.java
deleted file mode 100644
index a6acbaf48e..0000000000
--- a/sca-java-2.x/trunk/modules/binding-rest/src/main/java/org/apache/tuscany/sca/binding/rest/RESTCacheContext.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. 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.
- */
-
-package org.apache.tuscany.sca.binding.rest;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.servlet.http.HttpServletRequest;
-
-
-/**
- * A class to store cache settings for Atom and HTTP requests and responses.
- *
- * Predicates are statements that work in conjunction with
- * ETags and LastModified dates to determine if a precondition
- * or postcondition is satisfied.
- * See HTTP specification for how predicates wrk:
- * http://tools.ietf.org/html/rfc2616
- * Example predicates in HTTP include If-Match, If-None-Match,
- * If-Modified-Since, If-Unmodified-Since, If-Range.
-
- */
-public class RESTCacheContext {
- public static final SimpleDateFormat RFC822DateFormat = new SimpleDateFormat( "EEE, dd MMM yyyy HH:mm:ss Z" ); // RFC 822 date time
-
- public boolean enabled;
- public String eTag;
- public String lastModified;
- public Date lastModifiedDate;
- public boolean ifModifiedSince;
- public boolean ifUnmodifiedSince;
- public boolean ifMatch;
- public boolean ifNoneMatch;
- public boolean ifRange;
-
- /**
- * An ETag is a unique ID for an item. It changes when
- * a field in the item or the update date changes.
- * See HTTP specification for how ETags work:
- * http://tools.ietf.org/html/rfc2616
- * @return the eTag
- */
- public String getETag() {
- return eTag;
- }
- /**
- * @param tag the eTag to set
- */
- public void setETag(String tag) {
- eTag = tag;
- enabled = true;
- }
- /**
- * The LastModified date is the time the item was last
- * changed. See HTTP specification for how ETags work:
- * http://tools.ietf.org/html/rfc2616
- * @return the lastModified
- */
- public String getLastModified() {
- return lastModified;
- }
- /**
- * The LastModified date is the time the item was last
- * changed. See HTTP specification for how ETags work:
- * http://tools.ietf.org/html/rfc2616
- * @return the lastModified
- */
- public Date getLastModifiedAsDate() {
- return lastModifiedDate;
- }
- /**
- * @param lastModified the lastModified to set
- */
- public void setLastModified(String lastModified) throws java.text.ParseException {
- this.lastModified = lastModified;
- // Catch date formatting on input to help debugging.
- lastModifiedDate = RFC822DateFormat.parse( lastModified );
- enabled = true;
- }
-
- /**
- * @param lastModified the lastModified to set
- */
- public void setLastModified(Date updated) {
- this.lastModified = RFC822DateFormat.format( updated );
- lastModifiedDate = updated;
- enabled = true;
- }
-
- /**
- * @return the ifModifedSince
- */
- public boolean isIfModifiedSince() {
- return ifModifiedSince;
- }
- /**
- * @param ifModifedSince the ifModifedSince to set
- */
- public void setIfModifiedSince(boolean ifModifiedSince) {
- this.ifModifiedSince = ifModifiedSince;
- if ( ifModifiedSince )
- enabled = true;
- }
- /**
- * @return the ifUnModifiedSince
- */
- public boolean isIfUnmodifiedSince() {
- return ifUnmodifiedSince;
- }
- /**
- * @param ifUnModifiedSince the ifUnModifiedSince to set
- */
- public void setIfUnmodifiedSince(boolean ifUnmodifiedSince) {
- this.ifUnmodifiedSince = ifUnmodifiedSince;
- if ( ifUnmodifiedSince )
- enabled = true;
- }
- /**
- * @return the ifMatch
- */
- public boolean isIfMatch() {
- return ifMatch;
- }
- /**
- * @param ifMatch the ifMatch to set
- */
- public void setIfMatch(boolean ifMatch) {
- this.ifMatch = ifMatch;
- if ( ifMatch )
- enabled = true;
- }
- /**
- * @return the ifNoneMatch
- */
- public boolean isIfNoneMatch() {
- return ifNoneMatch;
- }
- /**
- * @param ifNoneMatch the ifNoneMatch to set
- */
- public void setIfNoneMatch(boolean ifNoneMatch) {
- this.ifNoneMatch = ifNoneMatch;
- if ( ifNoneMatch )
- enabled = true;
- }
- /**
- * @return the ifRange
- */
- public boolean isIfRange() {
- return ifRange;
- }
- /**
- * @param ifRange the ifRange to set
- */
- public void setIfRange(boolean ifRange) {
- this.ifRange = ifRange;
- if ( ifRange )
- enabled = true;
- }
-
- public String toString() {
- final String PREDPREFIX = ", predicates=";
- StringBuffer sb = new StringBuffer(PREDPREFIX);
- if ( ifMatch || ifNoneMatch || ifModifiedSince || ifUnmodifiedSince || ifRange ) {
- if ( ifMatch ) {
- if ( sb.length() > PREDPREFIX.length() ) sb.append( ", ");
- sb.append("If-Match");
- }
- if ( ifNoneMatch ) {
- if ( sb.length() > PREDPREFIX.length() ) sb.append( ", ");
- sb.append("If-None-Match");
- }
- if ( ifModifiedSince ) {
- if ( sb.length() > PREDPREFIX.length() ) sb.append( ", ");
- sb.append("If-Modified-Since");
- }
- if ( ifUnmodifiedSince ) {
- if ( sb.length() > PREDPREFIX.length() ) sb.append( ", ");
- sb.append("If-UnModified-Since");
- }
- if ( ifRange ) {
- if ( sb.length() > PREDPREFIX.length() ) sb.append( ", ");
- sb.append("If-Range");
- }
- } else {
- sb.append("null");
- }
-
- return "eTag=" + eTag + ", lastModified=" + lastModified
- + sb.toString();
- }
-
- /**
- * Gets the cache context information (ETag, LastModified, predicates) from the Http request.
- * @param request
- * @return
- */
- public static RESTCacheContext getCacheContextFromRequest( HttpServletRequest request ) throws java.text.ParseException {
- RESTCacheContext context = new RESTCacheContext();
-
- String eTag = request.getHeader( "If-Match" );
- if ( eTag != null ) {
- context.setETag( eTag );
- context.setIfMatch( true );
- }
- eTag = request.getHeader( "If-None-Match" );
- if ( eTag != null ) {
- context.setETag( eTag );
- context.setIfNoneMatch( true );
- }
- String lastModifiedString = request.getHeader( "If-Modified-Since" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfModifiedSince( true );
- }
- lastModifiedString = request.getHeader( "If-Unmodified-Since" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfUnmodifiedSince( true );
- }
- lastModifiedString = request.getHeader( "If-Range" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfRange( true );
- }
- return context;
- }
- /**
- * Enabled is true whenever ETag, LastModified, or predicate is set.
- * @return the enabled
- */
- public boolean isEnabled() {
- return enabled;
- }
- /**
- * @param enabled the enabled to set
- */
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-}
diff --git a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPCacheContext.java b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPCacheContext.java
index 6688fb8a94..7f8048098c 100644
--- a/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPCacheContext.java
+++ b/sca-java-2.x/trunk/modules/common-http/src/main/java/org/apache/tuscany/sca/common/http/HTTPCacheContext.java
@@ -50,6 +50,57 @@ public class HTTPCacheContext {
public boolean ifRange;
/**
+ * Gets the cache context information (ETag, LastModified, predicates) from the Http request.
+ * @param request
+ * @return
+ */
+ public static HTTPCacheContext createCacheContextFromRequest( HttpServletRequest request ) throws java.text.ParseException {
+ HTTPCacheContext context = new HTTPCacheContext();
+
+ String eTag = request.getHeader( "If-Match" );
+ if ( eTag != null ) {
+ context.setETag( eTag );
+ context.setIfMatch( true );
+ }
+ eTag = request.getHeader( "If-None-Match" );
+ if ( eTag != null ) {
+ context.setETag( eTag );
+ context.setIfNoneMatch( true );
+ }
+ String lastModifiedString = request.getHeader( "If-Modified-Since" );
+ if ( lastModifiedString != null ) {
+ context.setLastModified( lastModifiedString );
+ context.setIfModifiedSince( true );
+ }
+ lastModifiedString = request.getHeader( "If-Unmodified-Since" );
+ if ( lastModifiedString != null ) {
+ context.setLastModified( lastModifiedString );
+ context.setIfUnmodifiedSince( true );
+ }
+ lastModifiedString = request.getHeader( "If-Range" );
+ if ( lastModifiedString != null ) {
+ context.setLastModified( lastModifiedString );
+ context.setIfRange( true );
+ }
+ return context;
+ }
+
+ /**
+ * Enabled is true whenever ETag, LastModified, or predicate is set.
+ * @return the enabled
+ */
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ /**
+ * @param enabled the enabled to set
+ */
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ /**
* An ETag is a unique ID for an item. It changes when
* a field in the item or the update date changes.
* See HTTP specification for how ETags work:
@@ -206,52 +257,4 @@ public class HTTPCacheContext {
+ sb.toString();
}
- /**
- * Gets the cache context information (ETag, LastModified, predicates) from the Http request.
- * @param request
- * @return
- */
- public static HTTPCacheContext getCacheContextFromRequest( HttpServletRequest request ) throws java.text.ParseException {
- HTTPCacheContext context = new HTTPCacheContext();
-
- String eTag = request.getHeader( "If-Match" );
- if ( eTag != null ) {
- context.setETag( eTag );
- context.setIfMatch( true );
- }
- eTag = request.getHeader( "If-None-Match" );
- if ( eTag != null ) {
- context.setETag( eTag );
- context.setIfNoneMatch( true );
- }
- String lastModifiedString = request.getHeader( "If-Modified-Since" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfModifiedSince( true );
- }
- lastModifiedString = request.getHeader( "If-Unmodified-Since" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfUnmodifiedSince( true );
- }
- lastModifiedString = request.getHeader( "If-Range" );
- if ( lastModifiedString != null ) {
- context.setLastModified( lastModifiedString );
- context.setIfRange( true );
- }
- return context;
- }
- /**
- * Enabled is true whenever ETag, LastModified, or predicate is set.
- * @return the enabled
- */
- public boolean isEnabled() {
- return enabled;
- }
- /**
- * @param enabled the enabled to set
- */
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
}