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/07/06 22:32:58 UTC
svn commit: r1143548 - in
/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki:
server/ servlets/
Author: andy
Date: Wed Jul 6 20:32:57 2011
New Revision: 1143548
URL: http://svn.apache.org/viewvc?rev=1143548&view=rev
Log:
Jetty's BlockingChannelConnector is a better choice than SelectChannelConnector
Added:
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java (with props)
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java (with props)
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseResultSet.java (contents, props changed)
- copied, changed from r1143025, incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java
Removed:
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java
Modified:
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/server/SPARQLServer.java
incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/SPARQL_Query.java
Modified: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/server/SPARQLServer.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/server/SPARQLServer.java?rev=1143548&r1=1143547&r2=1143548&view=diff
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/server/SPARQLServer.java (original)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/server/SPARQLServer.java Wed Jul 6 20:32:57 2011
@@ -26,7 +26,7 @@ import javax.servlet.http.HttpServlet ;
import org.eclipse.jetty.http.MimeTypes ;
import org.eclipse.jetty.server.Connector ;
import org.eclipse.jetty.server.Server ;
-import org.eclipse.jetty.server.nio.SelectChannelConnector ;
+import org.eclipse.jetty.server.nio.BlockingChannelConnector ;
import org.eclipse.jetty.servlet.DefaultServlet ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.servlet.ServletHolder ;
@@ -126,13 +126,11 @@ public class SPARQLServer
// Using "= new SelectChannelConnector() ;" on Darwin (OS/X) causes problems
// with initialization not seen (thread scheduling?) in Joseki.
- Connector connector = new SelectChannelConnector() ;
- /* The BlockingChannelConnector seems to not interact with thread management,
- * at least in the way I expect.
- */
-// BlockingChannelConnector connector = new BlockingChannelConnector() ;
-// connector.setThreadPool(new QueuedThreadPool(ThreadPoolSize));
+ // BlockingChannelConnector is better for pumping large responses back.
+ //Connector connector = new SelectChannelConnector() ;
+
+ Connector connector = new BlockingChannelConnector() ;
// Ignore. If set, then if this goes off, it keeps going off.
connector.setMaxIdleTime(0) ; // Jetty outputs a lot of messages if this goes off.
Added: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java?rev=1143548&view=auto
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java (added)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java Wed Jul 6 20:32:57 2011
@@ -0,0 +1,94 @@
+/**
+ * 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.openjena.fuseki.servlets;
+
+import javax.servlet.http.HttpServletRequest ;
+import javax.servlet.http.HttpServletResponse ;
+
+import org.openjena.fuseki.DEF ;
+import org.openjena.fuseki.Fuseki ;
+import org.openjena.fuseki.FusekiLib ;
+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 ;
+
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.xmloutput.RDFXMLWriterI ;
+
+public class ResponseModel
+{
+
+ public static void doResponseModel(Model model, HttpServletRequest request, HttpServletResponse response)
+ {
+ String mimeType = null ; // Header request type
+
+ // TODO Use MediaType throughout.
+ MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML) ;
+ if ( i != null )
+ mimeType = i.getContentType() ;
+
+ String writerMimeType = mimeType ;
+
+ if ( mimeType == null )
+ {
+ Fuseki.requestLog.warn("Can't find MIME type for response") ;
+ String x = WebLib.getAccept(request) ;
+ String msg ;
+ if ( x == null )
+ msg = "No Accept: header" ;
+ else
+ msg = "Accept: "+x+" : Not understood" ;
+ SPARQL_ServletBase.error(HttpSC.NOT_ACCEPTABLE_406, msg) ;
+ }
+
+ TypedInputStream ts = new TypedInputStream(null, mimeType, WebContent.charsetUTF8) ;
+ Lang lang = FusekiLib.langFromContentType(ts.getMediaType()) ;
+ RDFWriter rdfw = FusekiLib.chooseWriter(lang) ;
+
+ if ( rdfw instanceof RDFXMLWriterI )
+ rdfw.setProperty("showXmlDeclaration", "true") ;
+
+ // // Write locally to check it's possible.
+ // // Time/space tradeoff.
+ // try {
+ // OutputStream out = new NullOutputStream() ;
+ // rdfw.write(model, out, null) ;
+ // IO.flush(out) ;
+ // } catch (JenaException ex)
+ // {
+ // SPARQL_ServletBase.errorOccurred(ex) ;
+ // }
+
+ // Managed to write it locally
+ try {
+ ResponseResultSet.setHttpResponse(request, response, ts.getMediaType(), ts.getCharset()) ;
+ response.setStatus(HttpSC.OK_200) ;
+ rdfw.write(model, response.getOutputStream(), null) ;
+ response.getOutputStream().flush() ;
+ }
+ catch (Exception ex) { SPARQL_ServletBase.errorOccurred(ex) ; }
+ }
+
+}
+
Propchange: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseModel.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java?rev=1143548&view=auto
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java (added)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java Wed Jul 6 20:32:57 2011
@@ -0,0 +1,115 @@
+/**
+ * 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.openjena.fuseki.servlets;
+
+import java.io.IOException ;
+
+import javax.servlet.http.HttpServletRequest ;
+
+import org.openjena.fuseki.HttpNames ;
+import org.openjena.fuseki.conneg.WebLib ;
+import org.openjena.riot.WebContent ;
+
+public class ResponseOps
+{
+
+ public static boolean isEOFexception(IOException ioEx)
+ {
+ if ( ioEx.getClass().getName().equals("org.mortbay.jetty.EofException eofEx") )
+ return true ;
+ if ( ioEx instanceof java.io.EOFException )
+ return true ;
+ return false ;
+ }
+
+ public static String paramForceAccept(HttpServletRequest request)
+ {
+ String x = fetchParam(request, HttpNames.paramForceAccept) ;
+ return expandShortName(x) ;
+ }
+
+ public static String paramStylesheet(HttpServletRequest request)
+ { return fetchParam(request, HttpNames.paramStyleSheet) ; }
+
+ public static String paramOutput(HttpServletRequest request)
+ {
+ // Two names.
+ String x = fetchParam(request, HttpNames.paramOutput1) ;
+ if ( x == null )
+ x = fetchParam(request, HttpNames.paramOutput2) ;
+ return expandShortName(x) ;
+ }
+
+ public static String paramAcceptField(HttpServletRequest request)
+ {
+ String acceptField = WebLib.getAccept(request) ;
+ String acceptParam = fetchParam(request, HttpNames.paramAccept) ;
+
+ if ( acceptParam != null )
+ acceptField = acceptParam ;
+ if ( acceptField == null )
+ return null ;
+ return expandShortName(acceptField) ;
+ }
+
+ public static String expandShortName(String str)
+ {
+ if ( str == null )
+ return null ;
+ // Some short names.
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputJSON) )
+ return WebContent.contentTypeResultsJSON ;
+
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputSPARQL) )
+ return WebContent.contentTypeResultsXML ;
+
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputXML) )
+ return WebContent.contentTypeResultsXML ;
+
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputText) )
+ return WebContent.contentTypeTextPlain ;
+
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputCSV) )
+ return WebContent.contentTypeTextCSV ;
+
+ if ( str.equalsIgnoreCase(ResponseResultSet.contentOutputTSV) )
+ return WebContent.contentTypeTextTSV ;
+
+ return str ;
+ }
+
+ public static String paramCallback(HttpServletRequest request)
+ {
+ return fetchParam(request, HttpNames.paramCallback) ;
+ }
+
+ public static String fetchParam(HttpServletRequest request, String parameterName)
+ {
+ String value = request.getParameter(parameterName) ;
+ if ( value != null )
+ {
+ value = value.trim() ;
+ if ( value.length() == 0 )
+ value = null ;
+ }
+ return value ;
+ }
+
+}
+
Propchange: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseOps.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseResultSet.java (from r1143025, 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/ResponseResultSet.java?p2=incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseResultSet.java&p1=incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseQuery.java&r1=1143025&r2=1143548&rev=1143548&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/ResponseResultSet.java Wed Jul 6 20:32:57 2011
@@ -25,88 +25,28 @@ import javax.servlet.http.HttpServletReq
import javax.servlet.http.HttpServletResponse ;
import org.openjena.fuseki.DEF ;
-import org.openjena.fuseki.Fuseki ;
import org.openjena.fuseki.FusekiException ;
-import org.openjena.fuseki.FusekiLib ;
-import org.openjena.fuseki.HttpNames ;
import org.openjena.fuseki.conneg.AcceptList ;
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 ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import com.hp.hpl.jena.query.ResultSet ;
import com.hp.hpl.jena.query.ResultSetFormatter ;
-import com.hp.hpl.jena.rdf.model.Model ;
-import com.hp.hpl.jena.rdf.model.RDFWriter ;
-import com.hp.hpl.jena.xmloutput.RDFXMLWriterI ;
/** This is the content negotiation for each kind of SPARQL query result */
-public class ResponseQuery
+public class ResponseResultSet
{
- private static Logger log = LoggerFactory.getLogger(ResponseQuery.class) ;
+ private static Logger log = LoggerFactory.getLogger(ResponseResultSet.class) ;
interface OutputContent { void output(ServletOutputStream out) ; }
static AcceptList prefContentTypeResultSet = DEF.rsOffer ;
static AcceptList prefContentTypeRDF = DEF.rdfOffer ;
- public static void doResponseModel(Model model, HttpServletRequest request, HttpServletResponse response)
- {
- String mimeType = null ; // Header request type
-
- // TODO Use MediaType throughout.
- MediaType i = ConNeg.chooseContentType(request, DEF.rdfOffer, DEF.acceptRDFXML) ;
- if ( i != null )
- mimeType = i.getContentType() ;
-
- String writerMimeType = mimeType ;
-
- if ( mimeType == null )
- {
- Fuseki.requestLog.warn("Can't find MIME type for response") ;
- String x = WebLib.getAccept(request) ;
- String msg ;
- if ( x == null )
- msg = "No Accept: header" ;
- else
- msg = "Accept: "+x+" : Not understood" ;
- SPARQL_ServletBase.error(HttpSC.NOT_ACCEPTABLE_406, msg) ;
- }
-
- TypedInputStream ts = new TypedInputStream(null, mimeType, WebContent.charsetUTF8) ;
- Lang lang = FusekiLib.langFromContentType(ts.getMediaType()) ;
- RDFWriter rdfw = FusekiLib.chooseWriter(lang) ;
-
- if ( rdfw instanceof RDFXMLWriterI )
- rdfw.setProperty("showXmlDeclaration", "true") ;
-
-// // Write locally to check it's possible.
-// // Time/space tradeoff.
-// try {
-// OutputStream out = new NullOutputStream() ;
-// rdfw.write(model, out, null) ;
-// IO.flush(out) ;
-// } catch (JenaException ex)
-// {
-// SPARQL_ServletBase.errorOccurred(ex) ;
-// }
-
- // Managed to write it locally
- try {
- setHttpResponse(request, response, ts.getMediaType(), ts.getCharset()) ;
- response.setStatus(HttpSC.OK_200) ;
- rdfw.write(model, response.getOutputStream(), null) ;
- response.getOutputStream().flush() ;
- }
- catch (Exception ex) { SPARQL_ServletBase.errorOccurred(ex) ; }
- }
-
// One or the other argument must be null
public static void doResponseResultSet(final ResultSet resultSet, final Boolean booleanResult, HttpServletRequest request, HttpServletResponse response)
{
@@ -131,7 +71,7 @@ public class ResponseQuery
// Override content type
// Does &output= override?
// Requested output type by the web form or &output= in the request.
- String outputField = paramOutput(request) ; // Expands short names
+ String outputField = ResponseOps.paramOutput(request) ; // Expands short names
if ( outputField != null )
mimeType = outputField ;
@@ -139,12 +79,12 @@ public class ResponseQuery
String contentType = mimeType ; // Set the HTTP respose header to this.
// Stylesheet - change to application/xml.
- final String stylesheetURL = paramStylesheet(request) ;
+ final String stylesheetURL = ResponseOps.paramStylesheet(request) ;
if ( stylesheetURL != null && serializationType.equals(WebContent.contentTypeResultsXML))
contentType = WebContent.contentTypeXML ;
// Force to text/plain?
- String forceAccept = paramForceAccept(request) ;
+ String forceAccept = ResponseOps.paramForceAccept(request) ;
if ( forceAccept != null )
contentType = forceAccept ;
@@ -265,15 +205,6 @@ public class ResponseQuery
}
- private static boolean isEOFexception(IOException ioEx)
- {
- if ( ioEx.getClass().getName().equals("org.mortbay.jetty.EofException eofEx") )
- return true ;
- if ( ioEx instanceof java.io.EOFException )
- return true ;
- return false ;
- }
-
private static void output(String contentType, String charset, OutputContent proc,
HttpServletRequest httpRequest, HttpServletResponse httpResponse)
{
@@ -319,8 +250,8 @@ public class ResponseQuery
HttpServletRequest httpRequest, HttpServletResponse httpResponse)
{
try {
- String callback = paramCallback(httpRequest) ;
- String outputField = paramOutput(httpRequest) ;
+ String callback = ResponseOps.paramCallback(httpRequest) ;
+ String outputField = ResponseOps.paramOutput(httpRequest) ;
ServletOutputStream out = httpResponse.getOutputStream() ;
if ( callback != null )
@@ -353,36 +284,6 @@ public class ResponseQuery
} catch (IOException ex) { SPARQL_ServletBase.errorOccurred(ex) ; }
}
- private static String paramForceAccept(HttpServletRequest request)
- {
- String x = fetchParam(request, HttpNames.paramForceAccept) ;
- return expandShortName(x) ;
- }
-
- private static String paramStylesheet(HttpServletRequest request)
- { return fetchParam(request, HttpNames.paramStyleSheet) ; }
-
- private static String paramOutput(HttpServletRequest request)
- {
- // Two names.
- String x = fetchParam(request, HttpNames.paramOutput1) ;
- if ( x == null )
- x = fetchParam(request, HttpNames.paramOutput2) ;
- return expandShortName(x) ;
- }
-
- private static String paramAcceptField(HttpServletRequest request)
- {
- String acceptField = WebLib.getAccept(request) ;
- String acceptParam = fetchParam(request, HttpNames.paramAccept) ;
-
- if ( acceptParam != null )
- acceptField = acceptParam ;
- if ( acceptField == null )
- return null ;
- return expandShortName(acceptField) ;
- }
-
// Short names for "output="
// TODO Map !
public static final String contentOutputJSON = "json" ;
@@ -391,45 +292,5 @@ public class ResponseQuery
public static final String contentOutputText = "text" ;
public static final String contentOutputCSV = "csv" ;
public static final String contentOutputTSV = "tsv" ;
-
- private static String expandShortName(String str)
- {
- if ( str == null )
- return null ;
- // Some short names.
- if ( str.equalsIgnoreCase(contentOutputJSON) )
- return WebContent.contentTypeResultsJSON ;
-
- if ( str.equalsIgnoreCase(contentOutputSPARQL) )
- return WebContent.contentTypeResultsXML ;
-
- if ( str.equalsIgnoreCase(contentOutputXML) )
- return WebContent.contentTypeResultsXML ;
-
- if ( str.equalsIgnoreCase(contentOutputText) )
- return WebContent.contentTypeTextPlain ;
-
- if ( str.equalsIgnoreCase(contentOutputCSV) )
- return WebContent.contentTypeTextCSV ;
-
- if ( str.equalsIgnoreCase(contentOutputTSV) )
- return WebContent.contentTypeTextTSV ;
-
- return str ;
- }
-
- private static String paramCallback(HttpServletRequest request) { return fetchParam(request, HttpNames.paramCallback) ; }
-
- private static String fetchParam(HttpServletRequest request, String parameterName)
- {
- String value = request.getParameter(parameterName) ;
- if ( value != null )
- {
- value = value.trim() ;
- if ( value.length() == 0 )
- value = null ;
- }
- return value ;
- }
}
Propchange: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/ResponseResultSet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/SPARQL_Query.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/SPARQL_Query.java?rev=1143548&r1=1143547&r2=1143548&view=diff
==============================================================================
--- incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/SPARQL_Query.java (original)
+++ incubator/jena/Jena2/Fuseki/trunk/src/main/java/org/openjena/fuseki/servlets/SPARQL_Query.java Wed Jul 6 20:32:57 2011
@@ -308,12 +308,12 @@ public abstract class SPARQL_Query exten
protected void sendResults(HttpActionQuery action, SPARQLResult result)
{
if ( result.isResultSet() )
- ResponseQuery.doResponseResultSet(result.getResultSet(), null, action.request, action.response) ;
+ ResponseResultSet.doResponseResultSet(result.getResultSet(), null, action.request, action.response) ;
else if ( result.isGraph() )
- ResponseQuery.doResponseModel(result.getModel(), action.request, action.response) ;
+ ResponseModel.doResponseModel(result.getModel(), action.request, action.response) ;
else if ( result.isBoolean() )
// Make different?
- ResponseQuery.doResponseResultSet(null, result.getBooleanResult(), action.request, action.response) ;
+ ResponseResultSet.doResponseResultSet(null, result.getBooleanResult(), action.request, action.response) ;
else
errorOccurred("Unknown or invalid result type") ;
}