Author: andy
Date: Wed Nov 13 21:36:21 2013
New Revision: 1541735
URL: http://svn.apache.org/r1541735
Log:
QueryValidator generating JSON response
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ActionErrorException.java
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
URL:
http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java?rev=1541735&r1=1541734&r2=1541735&view=diff
==============================================================================
---
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
(original)
+++
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/server/SPARQLServer.java
Wed Nov 13 21:36:21 2013
@@ -36,7 +36,7 @@ import org.apache.jena.fuseki.mgt.PageNa
import org.apache.jena.fuseki.servlets.* ;
import org.apache.jena.fuseki.validation.DataValidator ;
import org.apache.jena.fuseki.validation.IRIValidator ;
-import org.apache.jena.fuseki.validation.QueryValidator ;
+import org.apache.jena.fuseki.validation2.QueryValidator ;
import org.apache.jena.fuseki.validation.UpdateValidator ;
import org.apache.jena.riot.WebContent ;
import org.eclipse.jetty.http.MimeTypes ;
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ActionErrorException.java
URL:
http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ActionErrorException.java?rev=1541735&r1=1541734&r2=1541735&view=diff
==============================================================================
---
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ActionErrorException.java
(original)
+++
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ActionErrorException.java
Wed Nov 13 21:36:21 2013
@@ -18,12 +18,12 @@
package org.apache.jena.fuseki.servlets;
-class ActionErrorException extends RuntimeException
+public class ActionErrorException extends RuntimeException
{
- final Throwable exception ;
- final String message ;
- final int rc ;
- ActionErrorException(Throwable ex, String message, int rc)
+ public final Throwable exception ;
+ public final String message ;
+ public final int rc ;
+ public ActionErrorException(Throwable ex, String message, int rc)
{
this.exception = ex ;
this.message = message ;
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
URL:
http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java?rev=1541735&r1=1541734&r2=1541735&view=diff
==============================================================================
---
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
(original)
+++
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/servlets/ServletBase.java
Wed Nov 13 21:36:21 2013
@@ -16,7 +16,7 @@
* limitations under the License.
*/
-package org.apache.jena.fuseki.servlets;
+package org.apache.jena.fuseki.servlets ;
import java.io.IOException ;
import java.io.PrintWriter ;
@@ -32,100 +32,100 @@ import org.apache.jena.fuseki.HttpNames
import org.apache.jena.web.HttpSC ;
import org.slf4j.Logger ;
-public abstract class ServletBase extends HttpServlet
-{
- protected static final Logger log = Fuseki.requestLog ;
- public final boolean verboseLogging = Fuseki.verboseLogging ;
- private static AtomicLong requestIdAlloc = new AtomicLong(0) ;
+public abstract class ServletBase extends HttpServlet {
+ protected static final Logger log = Fuseki.requestLog ;
+ public final boolean verboseLogging = Fuseki.verboseLogging ;
+ private static AtomicLong requestIdAlloc = new AtomicLong(0) ;
+
+ protected ServletBase() {}
- protected ServletBase() { }
-
/**
- * Helper method which gets a unique request ID and appends it as a header
to the response
- * @param request HTTP Request
- * @param response HTTP Response
+ * Helper method which gets a unique request ID and appends it as a header
+ * to the response
+ *
+ * @param request
+ * HTTP Request
+ * @param response
+ * HTTP Response
* @return Request ID
*/
protected long allocRequestId(HttpServletRequest request,
HttpServletResponse response) {
- long id = requestIdAlloc.incrementAndGet();
- addRequestId(response, id);
- return id;
+ long id = requestIdAlloc.incrementAndGet() ;
+ addRequestId(response, id) ;
+ return id ;
}
-
+
/**
* Helper method for attaching a request ID to a response as a header
- * @param response Response
- * @param id Request ID
+ *
+ * @param response
+ * Response
+ * @param id
+ * Request ID
*/
protected void addRequestId(HttpServletResponse response, long id) {
- response.addHeader("Fuseki-Request-ID", Long.toString(id));
+ response.addHeader("Fuseki-Request-ID", Long.toString(id)) ;
}
-
- protected void responseSendError(HttpServletResponse response, int
statusCode, String message)
- {
- try { response.sendError(statusCode, message) ; }
- catch (IOException ex) { errorOccurred(ex) ; }
- catch (IllegalStateException ex) { }
- }
-
- protected void responseSendError(HttpServletResponse response, int
statusCode)
- {
- try { response.sendError(statusCode) ; }
- catch (IOException ex) { errorOccurred(ex) ; }
+
+ protected void responseSendError(HttpServletResponse response, int
statusCode, String message) {
+ try {
+ response.sendError(statusCode, message) ;
+ } catch (IOException ex) {
+ errorOccurred(ex) ;
+ } catch (IllegalStateException ex) {}
}
- protected static String wholeRequestURL(HttpServletRequest request)
- {
+ protected void responseSendError(HttpServletResponse response, int
statusCode) {
+ try {
+ response.sendError(statusCode) ;
+ } catch (IOException ex) {
+ errorOccurred(ex) ;
+ }
+ }
+
+ protected static String wholeRequestURL(HttpServletRequest request) {
StringBuffer sb = request.getRequestURL() ;
String queryString = request.getQueryString() ;
- if ( queryString != null )
- {
+ if ( queryString != null ) {
sb.append("?") ;
sb.append(queryString) ;
}
return sb.toString() ;
}
-
- protected static void successNoContent(HttpAction action)
- {
- success(action, HttpSC.NO_CONTENT_204);
- }
-
- protected static void success(HttpAction action)
- {
- success(action, HttpSC.OK_200);
- }
-
- protected static void successCreated(HttpAction action)
- {
- success(action, HttpSC.CREATED_201);
+
+ protected static void successNoContent(HttpAction action) {
+ success(action, HttpSC.NO_CONTENT_204) ;
+ }
+
+ protected static void success(HttpAction action) {
+ success(action, HttpSC.OK_200) ;
+ }
+
+ protected static void successCreated(HttpAction action) {
+ success(action, HttpSC.CREATED_201) ;
}
-
+
// When 404 is no big deal e.g. HEAD
- protected static void successNotFound(HttpAction action)
- {
+ protected static void successNotFound(HttpAction action) {
success(action, HttpSC.NOT_FOUND_404) ;
}
//
- protected static void success(HttpAction action, int httpStatusCode)
- {
- action.response.setStatus(httpStatusCode);
- }
-
- protected static void successPage(HttpAction action, String message)
- {
+ protected static void success(HttpAction action, int httpStatusCode) {
+ action.response.setStatus(httpStatusCode) ;
+ }
+
+ protected static void successPage(HttpAction action, String message) {
try {
- action.response.setContentType("text/html");
- action.response.setStatus(HttpSC.OK_200);
+ action.response.setContentType("text/html") ;
+ action.response.setStatus(HttpSC.OK_200) ;
PrintWriter out = action.response.getWriter() ;
out.println("<html>") ;
out.println("<head>") ;
out.println("</head>") ;
out.println("<body>") ;
- out.println("<h1>Success</h1>");
- if ( message != null )
- {
+ out.println("<h1>Success</h1>") ;
+ if ( message != null ) {
out.println("<p>") ;
out.println(message) ;
out.println("</p>") ;
@@ -133,94 +133,76 @@ public abstract class ServletBase extend
out.println("</body>") ;
out.println("</html>") ;
out.flush() ;
- } catch (IOException ex) { errorOccurred(ex) ; }
+ } catch (IOException ex) {
+ errorOccurred(ex) ;
+ }
}
-
- protected static void warning(String string)
- {
+
+ protected static void warning(String string) {
log.warn(string) ;
}
-
- protected static void warning(String string, Throwable thorwable)
- {
+
+ protected static void warning(String string, Throwable thorwable) {
log.warn(string, thorwable) ;
}
-
- protected static void errorBadRequest(String string)
- {
+
+ protected static void errorBadRequest(String string) {
error(HttpSC.BAD_REQUEST_400, string) ;
}
- protected static void errorNotFound(String string)
- {
+ protected static void errorNotFound(String string) {
error(HttpSC.NOT_FOUND_404, string) ;
}
- protected static void errorNotImplemented(String msg)
- {
+ protected static void errorNotImplemented(String msg) {
error(HttpSC.NOT_IMPLEMENTED_501, msg) ;
}
-
- protected static void errorMethodNotAllowed(String method)
- {
- error(HttpSC.METHOD_NOT_ALLOWED_405, "HTTP method not allowed:
"+method) ;
+
+ protected static void errorMethodNotAllowed(String method) {
+ error(HttpSC.METHOD_NOT_ALLOWED_405, "HTTP method not allowed: " +
method) ;
}
- protected static void errorForbidden(String msg)
- {
+ protected static void errorForbidden(String msg) {
if ( msg != null )
error(HttpSC.FORBIDDEN_403, msg) ;
else
error(HttpSC.FORBIDDEN_403, "Forbidden") ;
}
-
- protected static void error(int statusCode)
- {
+
+ protected static void error(int statusCode) {
throw new ActionErrorException(null, null, statusCode) ;
}
-
- protected static void error(int statusCode, String string)
- {
+ protected static void error(int statusCode, String string) {
throw new ActionErrorException(null, string, statusCode) ;
}
-
- protected static void errorOccurred(String message)
- {
+
+ protected static void errorOccurred(String message) {
errorOccurred(message, null) ;
}
- protected static void errorOccurred(Throwable ex)
- {
+ protected static void errorOccurred(Throwable ex) {
errorOccurred(null, ex) ;
}
- protected static void errorOccurred(String message, Throwable ex)
- {
+ protected static void errorOccurred(String message, Throwable ex) {
throw new ActionErrorException(ex, message,
HttpSC.INTERNAL_SERVER_ERROR_500) ;
}
-
- protected static String formatForLog(String string)
- {
+
+ protected static String formatForLog(String string) {
string = string.replace('\n', ' ') ;
string = string.replace('\r', ' ') ;
- return string ;
+ return string ;
}
- static String varyHeaderSetting =
- StrUtils.strjoin(",",
- HttpNames.hAccept,
- HttpNames.hAcceptEncoding,
- HttpNames.hAcceptCharset ) ;
-
- public static void setVaryHeader(HttpServletResponse httpResponse)
- {
+ static String varyHeaderSetting = StrUtils.strjoin(",", HttpNames.hAccept,
HttpNames.hAcceptEncoding,
+
HttpNames.hAcceptCharset) ;
+
+ public static void setVaryHeader(HttpServletResponse httpResponse) {
httpResponse.setHeader(HttpNames.hVary, varyHeaderSetting) ;
}
-
- public static void setCommonHeaders(HttpServletResponse httpResponse)
- {
+ public static void setCommonHeaders(HttpServletResponse httpResponse) {
httpResponse.setHeader(HttpNames.hAccessControlAllowOrigin, "*") ;
httpResponse.setHeader(HttpNames.hServer, Fuseki.serverHttpName) ;
}
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java
URL:
http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java?rev=1541735&r1=1541734&r2=1541735&view=diff
==============================================================================
---
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java
(original)
+++
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/validation/QueryValidator.java
Wed Nov 13 21:36:21 2013
@@ -37,7 +37,7 @@ import com.hp.hpl.jena.sparql.serializer
public class QueryValidator extends ValidatorBase
{
- public QueryValidator()
+ private QueryValidator()
{ }
static final String paramLineNumbers = "linenumbers" ;