You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/06/29 21:34:34 UTC
svn commit: r1141212 - in /incubator/jena/Jena2/Fuseki/trunk: src-dev/dev/
src/main/java/org/openjena/fuseki/conneg/
src/main/java/org/openjena/fuseki/servlets/
Author: andy
Date: Wed Jun 29 19:34:34 2011
New Revision: 1141212
URL: http://svn.apache.org/viewvc?rev=1141212&view=rev
Log:
Add handling of unusual multiple Accept headers
Added:
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java (with props)
Modified:
incubator/jena/Jena2/Fuseki/trunk/src-dev/dev/DevFuseki.java
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/ConNeg.java
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java
Modified: incubator/jena/Jena2/Fuseki/trunk/src-dev/dev/DevFuseki.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src-dev/dev/DevFuseki.java?rev=1141212&r1=1141211&r2=1141212&view=diff
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src-dev/dev/DevFuseki.java (original)
+++ incubator/jena/Jena2/Fuseki/trunk/src-dev/dev/DevFuseki.java Wed Jun 29 19:34:34 2011
@@ -2,6 +2,10 @@ package dev;
public class DevFuseki
{
+ // Flint?
+ // Pages for publish mode.
+
+ // Multiple Accept headers
// WebContent and ContentType clean up.
// SOH defualt to not needing 'default'
Modified: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/ConNeg.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/ConNeg.java?rev=1141212&r1=1141211&r2=1141212&view=diff
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/ConNeg.java (original)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/ConNeg.java Wed Jun 29 19:34:34 2011
@@ -8,6 +8,7 @@ package org.openjena.fuseki.conneg;
import static org.openjena.fuseki.HttpNames.hAcceptCharset ;
+
import javax.servlet.http.HttpServletRequest ;
import org.slf4j.Logger ;
@@ -73,7 +74,7 @@ public class ConNeg
AcceptList myPrefs,
MediaType defaultMediaType)
{
- String a = httpRequest.getHeader("Accept") ;
+ String a = WebLib.getAccept(httpRequest) ;
if ( log.isDebugEnabled() )
log.debug("Accept request: "+a) ;
Added: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java?rev=1141212&view=auto
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java (added)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java Wed Jun 29 19:34:34 2011
@@ -0,0 +1,76 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package org.openjena.fuseki.conneg;
+
+import java.util.Enumeration ;
+
+import javax.servlet.http.HttpServletRequest ;
+
+import org.openjena.fuseki.HttpNames ;
+
+public class WebLib
+{
+ /** Split a string, removing whitespace around the split string.
+ * e.g. Use in splittign HTTP accept/content-type headers.
+ */
+ public static String[] split(String s, String splitStr)
+ {
+ String[] x = s.split(splitStr,2) ;
+ for ( int i = 0 ; i < x.length ; i++ )
+ {
+ x[i] = x[i].trim() ;
+ }
+ return x ;
+ }
+
+ /** Migrate to WebLib */
+ public static String getAccept(HttpServletRequest httpRequest)
+ {
+ // There can be multiple accept headers -- note many tools don't allow these to be this way (e.g. wget, curl)
+ @SuppressWarnings("unchecked")
+ Enumeration<String> en = httpRequest.getHeaders(HttpNames.hAccept) ;
+ if ( ! en.hasMoreElements() )
+ return null ;
+ StringBuilder sb = new StringBuilder() ;
+ String sep = "" ;
+ for ( ; en.hasMoreElements() ; )
+ {
+ String x = en.nextElement() ;
+ sb.append(sep) ;
+ sep = ", " ;
+ sb.append(x) ;
+ }
+ return sb.toString() ;
+ }
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
Propchange: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/conneg/WebLib.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java?rev=1141212&r1=1141211&r2=1141212&view=diff
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java (original)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java Wed Jun 29 19:34:34 2011
@@ -21,6 +21,7 @@ import org.openjena.fuseki.conneg.Accept
import org.openjena.fuseki.conneg.ConNeg ;
import org.openjena.fuseki.conneg.MediaType ;
import org.openjena.fuseki.conneg.TypedInputStream ;
+import org.openjena.fuseki.conneg.WebLib ;
import org.openjena.fuseki.http.HttpSC ;
import org.openjena.riot.Lang ;
import org.openjena.riot.WebContent ;
@@ -57,7 +58,7 @@ public class ResponseQuery
if ( mimeType == null )
{
Fuseki.requestLog.warn("Can't find MIME type for response") ;
- String x = request.getHeader("Accept") ;
+ String x = WebLib.getAccept(request) ;
String msg ;
if ( x == null )
msg = "No Accept: header" ;
@@ -360,7 +361,7 @@ public class ResponseQuery
private static String paramAcceptField(HttpServletRequest request)
{
- String acceptField = request.getHeader(HttpNames.hAccept) ;
+ String acceptField = WebLib.getAccept(request) ;
String acceptParam = fetchParam(request, HttpNames.paramAccept) ;
if ( acceptParam != null )