You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/03/12 18:17:18 UTC
[1/8] git commit: MARMOTTA-238: improved http error handling,
moving to the new jarx-rs + cdi infrastructure
Repository: marmotta
Updated Branches:
refs/heads/develop dd004d325 -> 2b732de37
MARMOTTA-238: improved http error handling, moving to the new jarx-rs + cdi infrastructure
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d297c0a2
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d297c0a2
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d297c0a2
Branch: refs/heads/develop
Commit: d297c0a2a2d9e1e95bf924af4a17239ef91dccef
Parents: 0a69f01
Author: Sergio Fernández <wi...@apache.org>
Authored: Sun Mar 2 20:46:45 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Sun Mar 2 20:46:45 2014 +0100
----------------------------------------------------------------------
.../core/exception/HttpErrorException.java | 107 +++++++
.../core/jaxrs/HttpErrorExceptionMapper.java | 91 ++++++
.../jaxrs/MarmottaImportExceptionMapper.java | 1 -
.../webservices/resource/ContentWebService.java | 83 +++---
.../webservices/resource/MetaWebService.java | 194 ++++++-------
.../resource/ResourceWebService.java | 282 +++++++++----------
.../resource/ResourceWebServiceHelper.java | 65 ++---
.../src/main/resources/templates/error.ftl | 83 ++++++
.../resources/web/public/style/blue/error.css | 43 +++
.../resources/web/public/style/white/error.css | 44 +++
10 files changed, 650 insertions(+), 343 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/exception/HttpErrorException.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/exception/HttpErrorException.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/exception/HttpErrorException.java
new file mode 100644
index 0000000..381e9da
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/exception/HttpErrorException.java
@@ -0,0 +1,107 @@
+/**
+ * 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.marmotta.platform.core.exception;
+
+import edu.emory.mathcs.backport.java.util.Collections;
+
+import javax.ws.rs.core.Response;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Resource Not Found Exception
+ *
+ * @author Sergio Fernández
+ */
+public class HttpErrorException extends Exception {
+
+ private final int status;
+ private final String reason;
+ private final String uri;
+
+ private final Map<String, String> headers;
+
+ /**
+ * Constructs an instance with the specified details
+ *
+ * @param status http status code
+ * @param reason reason phrase
+ * @param uri resource uri
+ * @param msg message
+ */
+ public HttpErrorException(int status, String reason, String uri, String msg) {
+ this(status, reason, uri, msg, new HashMap<String,String>());
+ }
+
+ /**
+ * Constructs an instance with the specified details
+ *
+ * @param status http status code
+ * @param uri resource uri
+ * @param msg message
+ */
+ public HttpErrorException(Response.Status status, String uri, String msg) {
+ this(status.getStatusCode(), status.getReasonPhrase(), uri, msg);
+ }
+
+ /**
+ * Constructs an instance with the specified details
+ *
+ * @param status http status code
+ * @param uri resource uri
+ * @param msg message
+ * @param headers custom headers
+ */
+ public HttpErrorException(Response.Status status, String uri, String msg, Map<String,String> headers) {
+ this(status.getStatusCode(), status.getReasonPhrase(), uri, msg, headers);
+ }
+
+ /**
+ * Constructs an instance with the specified details
+ *
+ * @param status http status code
+ * @param reason reason phrase
+ * @param uri resource uri
+ * @param msg message
+ * @param headers custom headers
+ */
+ public HttpErrorException(int status, String reason, String uri, String msg, Map<String,String> headers) {
+ super(msg);
+ this.status = status;
+ this.reason = reason;
+ this.uri = uri;
+ this.headers = new HashMap<String,String>(headers);
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public Map<String, String> getHeaders() {
+ return Collections.unmodifiableMap(headers);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/HttpErrorExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/HttpErrorExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/HttpErrorExceptionMapper.java
new file mode 100644
index 0000000..eb53cdb
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/HttpErrorExceptionMapper.java
@@ -0,0 +1,91 @@
+/*
+ * 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.marmotta.platform.core.jaxrs;
+
+import freemarker.template.TemplateException;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.api.templating.TemplatingService;
+import org.apache.marmotta.platform.core.exception.HttpErrorException;
+import org.slf4j.Logger;
+
+import javax.enterprise.context.Dependent;
+import javax.inject.Inject;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Map HttpErrorExceptionMapper to a internal server error and return the default error object
+ *
+ * @author Sergio Fernández
+ */
+@Provider
+@Dependent
+public class HttpErrorExceptionMapper implements CDIExceptionMapper<HttpErrorException> {
+
+ private final String TEMPLATE = "error.ftl";
+
+ @Inject
+ private Logger log;
+
+ @Inject
+ private ConfigurationService configurationService;
+
+ @Inject
+ private TemplatingService templatingService;
+
+ /**
+ * Map an exception to a {@link javax.ws.rs.core.Response}. Returning
+ * {@code null} results in a {@link javax.ws.rs.core.Response.Status#NO_CONTENT}
+ * response. Throwing a runtime exception results in a
+ * {@link javax.ws.rs.core.Response.Status#INTERNAL_SERVER_ERROR} response
+ *
+ * @param exception the exception to map to a response
+ * @return a response mapped from the supplied exception
+ */
+ @Override
+ public Response toResponse(HttpErrorException exception) {
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("status", exception.getStatus());
+ data.put("reason", exception.getReason());
+ data.put("uri", exception.getUri());
+ data.put("message", exception.getMessage());
+ try {
+ data.put("encoded_uri", URLEncoder.encode(exception.getUri(), "UTF-8"));
+ } catch (UnsupportedEncodingException uee) {
+ data.put("encoded_uri", exception.getUri());
+ }
+
+ Response.ResponseBuilder responseBuilder;
+ try {
+ responseBuilder = Response.status(exception.getStatus()).entity(templatingService.process(TEMPLATE, data));
+ } catch (IOException | TemplateException e) {
+ log.error("Error rendering template {}: {}", TEMPLATE, e.getMessage());
+ responseBuilder = Response.status(exception.getStatus()).entity(e.getMessage());
+ }
+ Response response = responseBuilder.build();
+ for (Map.Entry<String, String> entry : exception.getHeaders().entrySet()) {
+ response.getMetadata().add(entry.getKey(), entry.getValue());
+ }
+ return response;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java
index 9b67df1..1930b79 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java
@@ -19,7 +19,6 @@ package org.apache.marmotta.platform.core.jaxrs;
import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
-import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
index 7013767..b37fc3a 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ContentWebService.java
@@ -17,36 +17,14 @@
*/
package org.apache.marmotta.platform.core.webservices.resource;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.validation.constraints.NotNull;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
+import com.google.common.collect.ImmutableMap;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.api.content.ContentService;
import org.apache.marmotta.platform.core.api.io.MarmottaIOService;
import org.apache.marmotta.platform.core.api.templating.TemplatingService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
import org.apache.marmotta.platform.core.events.ContentCreatedEvent;
+import org.apache.marmotta.platform.core.exception.HttpErrorException;
import org.apache.marmotta.platform.core.exception.MarmottaException;
import org.apache.marmotta.platform.core.exception.WritingNotSupportedException;
import org.apache.marmotta.platform.core.qualifiers.event.ContentCreated;
@@ -55,6 +33,23 @@ import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Content Web Services
*
@@ -105,7 +100,7 @@ public class ContentWebService {
*/
@GET
@Path(ResourceWebService.MIME_PATTERN + ResourceWebService.UUID_PATTERN)
- public Response getContentLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @HeaderParam("Range") String range) throws UnsupportedEncodingException {
+ public Response getContentLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @HeaderParam("Range") String range) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return getContent(uri, mimetype, range);
}
@@ -131,7 +126,7 @@ public class ContentWebService {
*/
@GET
@Path(ResourceWebService.MIME_PATTERN)
- public Response getContentRemote(@QueryParam("uri") @NotNull String uri, @PathParam("mimetype") String mimetype, @HeaderParam("Range") String range) throws UnsupportedEncodingException {
+ public Response getContentRemote(@QueryParam("uri") @NotNull String uri, @PathParam("mimetype") String mimetype, @HeaderParam("Range") String range) throws UnsupportedEncodingException, HttpErrorException {
return getContent(URLDecoder.decode(uri, "utf-8"), mimetype, range);
}
@@ -215,7 +210,7 @@ public class ContentWebService {
*/
@PUT
@Path(ResourceWebService.MIME_PATTERN + ResourceWebService.UUID_PATTERN)
- public Response putContentLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request) {
+ public Response putContentLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request) throws HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return putContent(uri, mimetype, request);
}
@@ -239,7 +234,7 @@ public class ContentWebService {
@PUT
@Path(ResourceWebService.MIME_PATTERN)
public Response putContentRemote(@QueryParam("uri") @NotNull String uri, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request)
- throws UnsupportedEncodingException {
+ throws UnsupportedEncodingException, HttpErrorException {
return putContent(URLDecoder.decode(uri, "utf-8"), mimetype, request);
}
@@ -255,16 +250,18 @@ public class ContentWebService {
* @HTTP 404 resource or resource content not found
*/
@DELETE
- public Response deleteContentRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException {
+ public Response deleteContentRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException, HttpErrorException {
try {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
Resource resource = conn.getValueFactory().createURI(uri);
if (resource != null) {
- if (contentService.deleteContent(resource)) return Response.ok().build();
- else
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "no content found for this resource in LMF right now, but may be available again in the future", configurationService, templatingService);
+ if (contentService.deleteContent(resource)) {
+ return Response.ok().build();
+ } else {
+ throw new HttpErrorException(Response.Status.NOT_FOUND, uri, "no content found for this resource in Marmotta right now, but may be available again in the future");
+ }
}
return Response.status(Response.Status.NOT_FOUND).build();
} finally {
@@ -290,12 +287,12 @@ public class ContentWebService {
*/
@DELETE
@Path(ResourceWebService.UUID_PATTERN)
- public Response deleteContentLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException {
+ public Response deleteContentLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return deleteContentRemote(uri);
}
- private Response getContent(String uri, String mimetype, String range) throws UnsupportedEncodingException {
+ private Response getContent(String uri, String mimetype, String range) throws UnsupportedEncodingException, HttpErrorException {
try {
// FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
// "/" + uuid;
@@ -356,9 +353,8 @@ public class ContentWebService {
}
return response;
} else {
- Response response = ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.NOT_ACCEPTABLE, "no content for mimetype " + mimetype, configurationService, templatingService);
- ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendContentTypes(contentService.getContentType(resource)));
- return response;
+ ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", ResourceWebServiceHelper.appendContentTypes(contentService.getContentType(resource)));
+ throw new HttpErrorException(Status.NOT_ACCEPTABLE, resource.stringValue(), "no content for mimetype " + mimetype, headers);
}
} finally {
conn.close();
@@ -370,7 +366,7 @@ public class ContentWebService {
}
}
- public Response putContent(String uri, String mimetype, HttpServletRequest request) {
+ public Response putContent(String uri, String mimetype, HttpServletRequest request) throws HttpErrorException {
try {
final RepositoryConnection conn = sesameService.getConnection();
try {
@@ -386,19 +382,20 @@ public class ContentWebService {
}
}
- public Response putContent(URI resource, String mimetype, HttpServletRequest request) {
+ public Response putContent(URI resource, String mimetype, HttpServletRequest request) throws HttpErrorException {
try {
- if (request.getContentLength() == 0)
- return ResourceWebServiceHelper.buildErrorPage(resource.stringValue(), configurationService.getBaseUri(), Status.BAD_REQUEST, "content may not be empty for writting", configurationService, templatingService);
+ if (request.getContentLength() == 0) {
+ throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "content may not be empty for writing");
+ }
contentService.setContentStream(resource, request.getInputStream(), mimetype); // store content
if(configurationService.getBooleanConfiguration(ENHANCER_STANBOL_ENHANCER_ENABLED, false)) {
afterContentCreated.fire(new ContentCreatedEvent(resource)); //enhancer
}
return Response.ok().build();
} catch (IOException e) {
- return ResourceWebServiceHelper.buildErrorPage(resource.stringValue(), configurationService.getBaseUri(), Status.BAD_REQUEST, "could not read request body", configurationService, templatingService);
+ throw new HttpErrorException(Status.BAD_REQUEST, resource.stringValue(), "could not read request body");
} catch (WritingNotSupportedException e) {
- return ResourceWebServiceHelper.buildErrorPage(resource.stringValue(), configurationService.getBaseUri(), Status.FORBIDDEN, "writting this content is not supported", configurationService, templatingService);
+ throw new HttpErrorException(Status.FORBIDDEN, resource.stringValue(), "writting this content is not supported");
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
index cf43488..ae3fb48 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
@@ -17,30 +17,7 @@
*/
package org.apache.marmotta.platform.core.webservices.resource;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.validation.constraints.NotNull;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.StreamingOutput;
-
+import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.commons.collections.CollectionUtils;
import org.apache.marmotta.commons.http.ETagGenerator;
@@ -52,17 +29,31 @@ import org.apache.marmotta.platform.core.api.io.MarmottaIOService;
import org.apache.marmotta.platform.core.api.templating.TemplatingService;
import org.apache.marmotta.platform.core.api.triplestore.ContextService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
+import org.apache.marmotta.platform.core.exception.HttpErrorException;
import org.apache.marmotta.platform.core.services.sesame.ResourceSubjectMetadata;
import org.openrdf.model.Resource;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.event.InterceptingRepositoryConnection;
import org.openrdf.repository.event.base.InterceptingRepositoryConnectionWrapper;
-import org.openrdf.rio.RDFFormat;
-import org.openrdf.rio.RDFHandlerException;
-import org.openrdf.rio.RDFParseException;
-import org.openrdf.rio.RDFWriter;
-import org.openrdf.rio.Rio;
+import org.openrdf.rio.*;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.constraints.NotNull;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.StreamingOutput;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.LinkedList;
+import java.util.List;
/**
* Meta Web Services
@@ -76,10 +67,10 @@ public class MetaWebService {
@Inject
private ConfigurationService configurationService;
-
+
@Inject
private TemplatingService templatingService;
-
+
@Inject
private ContextService contextService;
@@ -96,54 +87,50 @@ public class MetaWebService {
* Returns remote resource metadata with the given uri and an accepted
* return type (mimetype)
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
- * triple store
- * @param mimetype
- * , accepted mimetype follows the pattern .+/.+
+ * @param uri , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @param mimetype , accepted mimetype follows the pattern .+/.+
* @return a remote resource's metadata (body is the resource data in
- * requested format)
+ * requested format)
* @HTTP 200 resource metadata found and returned
* @HTTP 400 bad request (maybe uri is not defined)
* @HTTP 404 resource cannot be found
* @HTTP 406 resource cannot be found in the given format
* @HTTP 500 Internal Error
* @ResponseHeader Content-Type (for HTTP 406) a list of available metadata
- * types
+ * types
*/
@GET
@Path(ResourceWebService.MIME_PATTERN)
- public Response getMetaRemote(@QueryParam("uri") String uri, @QueryParam("genid") String genid, @PathParam("mimetype") String mimetype) throws UnsupportedEncodingException {
- if (StringUtils.isNotBlank(uri)) {
- return getMeta(URLDecoder.decode(uri, "utf-8"), mimetype);
- } else if (StringUtils.isNotBlank(genid)) {
- return getMeta(URLDecoder.decode(genid, "utf-8"), mimetype);
- } else {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.BAD_REQUEST, "Invalid Request", configurationService, templatingService);
- }
+ public Response getMetaRemote(@QueryParam("uri") String uri, @QueryParam("genid") String genid, @PathParam("mimetype") String mimetype) throws UnsupportedEncodingException, HttpErrorException {
+ if (StringUtils.isNotBlank(uri)) {
+ return getMeta(URLDecoder.decode(uri, "utf-8"), mimetype);
+ } else if (StringUtils.isNotBlank(genid)) {
+ return getMeta(URLDecoder.decode(genid, "utf-8"), mimetype);
+ } else {
+ throw new HttpErrorException(Status.BAD_REQUEST, uri, "Invalid Request");
+ }
}
/**
* Returns local resource data with the given uuid and an accepted return
* type (mimetype)
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
- * @param mimetype
- * , accepted mimetype follows the pattern .+/.+
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @param mimetype , accepted mimetype follows the pattern .+/.+
* @return a local resource's metadata (body is the resource data in
- * requested format)
+ * requested format)
* @HTTP 200 resource data found and returned
* @HTTP 404 resource cannot be found
* @HTTP 406 resource cannot be found in the given format
* @HTTP 500 Internal Error
* @ResponseHeader Content-Type (for HTTP 406) a list of available metadata
- * types
+ * types
*/
@GET
@Path(ResourceWebService.MIME_PATTERN + ResourceWebService.UUID_PATTERN)
- public Response getMetaLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype) throws UnsupportedEncodingException {
+ public Response getMetaLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return getMeta(uri, mimetype);
}
@@ -151,11 +138,9 @@ public class MetaWebService {
/**
* Sets metadata to a given locale resource
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
- * @param mimetype
- * content-type of the body (metadata) follows the pattern .+/.+
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
+ * @param mimetype content-type of the body (metadata) follows the pattern .+/.+
* @return HTTP response (success or error)
* @HTTP 200 put was successful
* @HTTP 400 bad request (e.g. body is empty)
@@ -163,11 +148,11 @@ public class MetaWebService {
* @HTTP 415 Content-Type is not supported
* @HTTP 500 Internal Error
* @ResponseHeader Content-Type (for HTTP 415) a list of available types for
- * metadata
+ * metadata
*/
@PUT
@Path(ResourceWebService.MIME_PATTERN + ResourceWebService.UUID_PATTERN)
- public Response putMetaLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request) {
+ public Response putMetaLocal(@PathParam("uuid") String uuid, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request) throws HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return putMeta(uri, mimetype, request);
}
@@ -175,11 +160,9 @@ public class MetaWebService {
/**
* Sets metadata to a given locale resource
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
- * triple store
- * @param mimetype
- * content-type of the body (metadata) follows the pattern .+/.+
+ * @param uri , the fully-qualified URI of the resource to create in the
+ * triple store
+ * @param mimetype content-type of the body (metadata) follows the pattern .+/.+
* @return HTTP response (success or error)
* @HTTP 200 put was successful
* @HTTP 400 bad request (e.g. uri is null)
@@ -187,20 +170,19 @@ public class MetaWebService {
* @HTTP 415 Content-Type is not supported
* @HTTP 500 Internal Error
* @ResponseHeader Content-Type (for HTTP 415) a list of available types for
- * metadata
+ * metadata
*/
@PUT
@Path(ResourceWebService.MIME_PATTERN)
public Response putMetaRemote(@QueryParam("uri") @NotNull String uri, @PathParam("mimetype") String mimetype, @Context HttpServletRequest request)
- throws UnsupportedEncodingException {
+ throws UnsupportedEncodingException, HttpErrorException {
return putMeta(URLDecoder.decode(uri, "utf-8"), mimetype, request);
}
/**
* Delete metadata of remote resource with given uri
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
+ * @param uri , the fully-qualified URI of the resource to create in the
* triple store
* @return HTTP response (success or error)
* @HTTP 200 resource content deleted
@@ -208,7 +190,7 @@ public class MetaWebService {
* @HTTP 404 resource or resource metadata not found
*/
@DELETE
- public Response deleteMetaRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException {
+ public Response deleteMetaRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException, HttpErrorException {
try {
InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
connection.begin();
@@ -218,7 +200,7 @@ public class MetaWebService {
connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));
// delete all triples for given subject
- connection.remove(subject,null,null);
+ connection.remove(subject, null, null);
return Response.ok().build();
} finally {
@@ -227,7 +209,7 @@ public class MetaWebService {
}
} catch (RepositoryException e) {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
+ throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, e.getMessage());
}
}
@@ -242,35 +224,34 @@ public class MetaWebService {
*/
@DELETE
@Path(ResourceWebService.UUID_PATTERN)
- public Response deleteMetaLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException {
+ public Response deleteMetaLocal(@PathParam("uuid") String uuid) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
return deleteMetaRemote(uri);
}
- private Response getMeta(String resource, String mimetype) throws UnsupportedEncodingException {
+ private Response getMeta(String resource, String mimetype) throws UnsupportedEncodingException, HttpErrorException {
try {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
-
+
Resource r = null;
- if (UriUtil.validate(resource)) {
+ if (UriUtil.validate(resource)) {
r = ResourceUtils.getUriResource(conn, resource);
- } else {
- r = ResourceUtils.getAnonResource(conn, resource);
- }
-
+ } else {
+ r = ResourceUtils.getAnonResource(conn, resource);
+ }
+
if (r == null || !ResourceUtils.isUsed(conn, r)) {
- return ResourceWebServiceHelper.buildErrorPage(resource, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "the requested resource could not be found in Marmotta right now, but may be available again in the future", configurationService, templatingService);
+ throw new HttpErrorException(Response.Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future");
}
-
+
// create parser
final RDFFormat serializer = kiWiIOService.getSerializer(mimetype);
if (serializer == null) {
- Response response = Response.status(406).entity("mimetype can not be processed").build();
- ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
- return response;
+ ImmutableMap<String, String> headers = ImmutableMap.of("Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
+ throw new HttpErrorException(Status.NOT_ACCEPTABLE, resource, "mimetype can not be processed", headers);
}
final Resource subject = r;
@@ -279,12 +260,12 @@ public class MetaWebService {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
// FIXME: This method is executed AFTER the @Transactional!
- RDFWriter writer = Rio.createWriter(serializer,output);
+ RDFWriter writer = Rio.createWriter(serializer, output);
try {
RepositoryConnection connection = sesameService.getConnection();
try {
connection.begin();
- connection.exportStatements(subject,null,null,true,writer);
+ connection.exportStatements(subject, null, null, true, writer);
} finally {
connection.commit();
connection.close();
@@ -301,16 +282,16 @@ public class MetaWebService {
// build response
Response response = Response.ok(entity).lastModified(ResourceUtils.getLastModified(conn, r)).build();
response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
-
+
if (!mimetype.contains("html")) { // then create a proper filename
String[] components;
if (resource.contains("#")) {
- components = resource.split("#");
+ components = resource.split("#");
} else {
- components = resource.split("/");
+ components = resource.split("/");
}
- final String fileName = components[components.length-1] + "." + serializer.getDefaultFileExtension();
- response.getMetadata().add("Content-Disposition", "attachment; filename=\""+fileName+"\"");
+ final String fileName = components[components.length - 1] + "." + serializer.getDefaultFileExtension();
+ response.getMetadata().add("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
}
// create the Content-Type header for the response
@@ -325,7 +306,7 @@ public class MetaWebService {
// build the link to the human readable content of this resource (if it exists)
String contentLink = ResourceWebServiceHelper.buildContentLink(r, contentService.getContentType(r), configurationService);
- if(!"".equals(contentLink)) {
+ if (!"".equals(contentLink)) {
links.add(contentLink);
}
@@ -333,18 +314,18 @@ public class MetaWebService {
response.getMetadata().add("Link", CollectionUtils.fold(links, ", "));
}
return response;
- } finally {
+ } finally {
if (conn.isOpen()) {
conn.commit();
conn.close();
}
}
} catch (RepositoryException e) {
- return ResourceWebServiceHelper.buildErrorPage(resource, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
+ throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, resource, e.getMessage());
}
}
- public Response putMeta(String uri, String mimetype, HttpServletRequest request) {
+ public Response putMeta(String uri, String mimetype, HttpServletRequest request) throws HttpErrorException {
try {
// create parser
RDFFormat parser = kiWiIOService.getParser(mimetype);
@@ -353,8 +334,9 @@ public class MetaWebService {
ResourceWebServiceHelper.addHeader(response, "Content-Type", ResourceWebServiceHelper.appendMetaTypes(kiWiIOService.getProducedTypes()));
return response;
}
- if (request.getContentLength() == 0)
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.BAD_REQUEST, "content may not be empty in resource update", configurationService, templatingService);
+ if (request.getContentLength() == 0) {
+ throw new HttpErrorException(Status.BAD_REQUEST, uri, "content may not be empty in resource update");
+ }
// a intercepting connection that filters out all triples that have
// the wrong subject
@@ -367,23 +349,21 @@ public class MetaWebService {
connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));
// delete all triples for given subject
- connection.remove(subject, null, null, (Resource)null);
+ connection.remove(subject, null, null, (Resource) null);
// add RDF data from input to the suject
connection.add(request.getReader(), configurationService.getBaseUri(), parser, contextService.getDefaultContext());
- } finally {
+ } finally {
connection.commit();
connection.close();
}
return Response.ok().build();
} catch (URISyntaxException e) {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, "invalid target context", configurationService, templatingService);
+ throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, "invalid target context");
+ } catch (IOException | RDFParseException e) {
+ throw new HttpErrorException(Status.NOT_ACCEPTABLE, uri, "could not parse request body");
} catch (RepositoryException e) {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
- } catch (IOException e) {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, "could not read request body", configurationService, templatingService);
- } catch (RDFParseException e) {
- return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.UNSUPPORTED_MEDIA_TYPE, "could not parse request body", configurationService, templatingService);
+ throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, e.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
index 2373140..77456a1 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebService.java
@@ -17,32 +17,6 @@
*/
package org.apache.marmotta.platform.core.webservices.resource;
-import static javax.ws.rs.core.Response.status;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URISyntaxException;
-import java.net.URLDecoder;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Inject;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.OPTIONS;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.Response.Status;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.marmotta.commons.http.ContentType;
import org.apache.marmotta.commons.http.ETagGenerator;
@@ -54,12 +28,30 @@ import org.apache.marmotta.platform.core.api.content.ContentService;
import org.apache.marmotta.platform.core.api.io.MarmottaIOService;
import org.apache.marmotta.platform.core.api.templating.TemplatingService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
+import org.apache.marmotta.platform.core.exception.HttpErrorException;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.slf4j.Logger;
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
+import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import static javax.ws.rs.core.Response.status;
+
/**
* Resource Web Services
*
@@ -81,7 +73,7 @@ public class ResourceWebService {
@Inject
private ConfigurationService configurationService;
-
+
@Inject
private TemplatingService templatingService;
@@ -103,8 +95,7 @@ public class ResourceWebService {
/**
* Return the options that are available for a resource with the given URI.
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
+ * @param uri , the fully-qualified URI of the resource to create in the
* triple store
* @return HTTP response (empty body)
* @ResponseHeader Access-Control-Allow-Methods the HTTP methods that are allowable for the given resource
@@ -112,16 +103,16 @@ public class ResourceWebService {
*/
@OPTIONS
public Response optionsResourceRemote(@QueryParam("uri") String uri, @HeaderParam("Access-Control-Request-Headers") String reqHeaders) {
- if(reqHeaders == null) {
+ if (reqHeaders == null) {
reqHeaders = "Accept, Content-Type";
}
- if(uri == null)
+ if (uri == null)
return Response.ok()
.header("Allow", "POST")
- .header("Access-Control-Allow-Methods","POST")
+ .header("Access-Control-Allow-Methods", "POST")
.header("Access-Control-Allow-Headers", reqHeaders)
- .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
.build();
else {
try {
@@ -130,27 +121,27 @@ public class ResourceWebService {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
- URI resource = ResourceUtils.getUriResource(conn,uri);
+ URI resource = ResourceUtils.getUriResource(conn, uri);
conn.commit();
- if(resource != null) return Response.ok()
- .header("Allow","PUT, GET, DELETE")
- .header("Access-Control-Allow-Methods","PUT, GET, DELETE")
- .header("Access-Control-Allow-Headers",reqHeaders)
- .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ if (resource != null) return Response.ok()
+ .header("Allow", "PUT, GET, DELETE")
+ .header("Access-Control-Allow-Methods", "PUT, GET, DELETE")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
.build();
else
return Response.ok()
.header("Allow", "POST")
- .header("Access-Control-Allow-Methods","POST")
- .header("Access-Control-Allow-Headers",reqHeaders)
- .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .header("Access-Control-Allow-Methods", "POST")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
.build();
} finally {
conn.close();
}
- } catch(UnsupportedEncodingException ex) {
+ } catch (UnsupportedEncodingException ex) {
return Response.serverError().entity(ex.getMessage()).build();
} catch (RepositoryException ex) {
return Response.serverError().entity(ex.getMessage()).build();
@@ -162,9 +153,8 @@ public class ResourceWebService {
/**
* Return the options that are available for a resource with the given URI.
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
* @return HTTP response (empty body)
* @ResponseHeader Access-Control-Allow-Methods the HTTP methods that are allowable for the given resource
* @ResponseHeader Access-Control-Allow-Origin the origins that are allowable for cross-site scripting on this resource
@@ -174,11 +164,11 @@ public class ResourceWebService {
public Response optionsResourceLocal(@PathParam("uuid") String uuid, @HeaderParam("Access-Control-Request-Headers") String reqHeaders) {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
- if(reqHeaders == null) {
+ if (reqHeaders == null) {
reqHeaders = "Accept, Content-Type";
}
- if(uuid == null)
+ if (uuid == null)
return Response.status(Status.NOT_FOUND).build();
else {
try {
@@ -186,28 +176,28 @@ public class ResourceWebService {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
- URI resource = ResourceUtils.getUriResource(conn,uri);
+ URI resource = ResourceUtils.getUriResource(conn, uri);
conn.commit();
- if(resource != null) return Response.ok()
- .header("Allow","PUT, GET, DELETE")
- .header("Access-Control-Allow-Methods","PUT, GET, DELETE")
- .header("Access-Control-Allow-Headers",reqHeaders)
- .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ if (resource != null) return Response.ok()
+ .header("Allow", "PUT, GET, DELETE")
+ .header("Access-Control-Allow-Methods", "PUT, GET, DELETE")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
.build();
else
return Response.ok()
- .header("Allow","POST")
- .header("Access-Control-Allow-Methods","POST")
- .header("Access-Control-Allow-Headers",reqHeaders)
- .header("Access-Control-Allow-Origin",configurationService.getStringConfiguration("kiwi.allow_origin","*"))
+ .header("Allow", "POST")
+ .header("Access-Control-Allow-Methods", "POST")
+ .header("Access-Control-Allow-Headers", reqHeaders)
+ .header("Access-Control-Allow-Origin", configurationService.getStringConfiguration("kiwi.allow_origin", "*"))
.build();
} finally {
conn.close();
}
- } catch(UnsupportedEncodingException ex) {
+ } catch (UnsupportedEncodingException ex) {
return Response.serverError().entity(ex.getMessage()).build();
} catch (RepositoryException ex) {
return Response.serverError().entity(ex.getMessage()).build();
@@ -224,8 +214,7 @@ public class ResourceWebService {
* Creates new resource with given uri. If no uri is defined it creates a
* local uri with random uuid
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
+ * @param uri , the fully-qualified URI of the resource to create in the
* triple store
* @return HTTP response (body is a String message)
* @HTTP 201 new resource created
@@ -267,7 +256,7 @@ public class ResourceWebService {
conn.begin();
String location = remote ? configurationService.getServerUri() + ConfigurationService.RESOURCE_PATH + "?uri=" + uri : uri;
Response.Status status;
- if (ResourceUtils.getUriResource(conn,uri) != null) {
+ if (ResourceUtils.getUriResource(conn, uri) != null) {
status = Status.OK;
} else {
conn.getValueFactory().createURI(uri);
@@ -290,24 +279,23 @@ public class ResourceWebService {
* Returns a link to a local resource (data or content) with the given uuid
* and an accepted return type
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
* @return a link to a local resource's data or content
* @HTTP 303 resource can be found in the requested format under Location
* @HTTP 404 resource cannot be found
* @HTTP 406 resource cannot be found in the given format
* @HTTP 500 Internal Error
* @RequestHeader Accept accepted mimetypes; value must follow the pattern
- * (.+/.+(;rel=(content|meta))?,)+
+ * (.+/.+(;rel=(content|meta))?,)+
* @ResponseHeader Location (for HTTP 303) the url of the resource in the
- * requested format
+ * requested format
* @ResponseHeader Content-Type (for HTTP 406) a list of available types
- * (content and meta)
+ * (content and meta)
*/
@GET
@Path(UUID_PATTERN)
- public Response getLocal(@PathParam("uuid") String uuid, @HeaderParam("Accept") String types) throws UnsupportedEncodingException {
+ public Response getLocal(@PathParam("uuid") String uuid, @HeaderParam("Accept") String types) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
try {
return get(uri, types);
@@ -322,7 +310,7 @@ public class ResourceWebService {
* Returns a link to a remote resource (data or content) with the given uri
* and an accepted return type
*
- * @param uri the fully-qualified URI of the resource to create in the triple store
+ * @param uri the fully-qualified URI of the resource to create in the triple store
* @param format forces representation format (optional, normal content negotiation performed if empty)
* @HTTP 303 resource can be found in the requested format under Location
* @HTTP 400 bad request (maybe uri is not defined)
@@ -330,14 +318,14 @@ public class ResourceWebService {
* @HTTP 406 resource cannot be found in the given format
* @HTTP 500 Internal Error
* @RequestHeader Accept accepted mimetypes; value must follow the pattern
- * (.+/.+(;rel=(content|meta))?,)+
+ * (.+/.+(;rel=(content|meta))?,)+
* @ResponseHeader Location the url of the resource in the requested format
* @ResponseHeader Content-Type (for HTTP 406) a list of available types
- * (content and meta)
+ * (content and meta)
*/
@GET
public Response getRemote(@QueryParam("uri") String uri, @QueryParam("genid") String genid, @QueryParam("format") String format, @HeaderParam("Accept") String types)
- throws UnsupportedEncodingException {
+ throws UnsupportedEncodingException, HttpErrorException {
try {
if (StringUtils.isNotBlank(uri)) {
if (format != null && StringUtils.isNotBlank(format)) {
@@ -359,56 +347,58 @@ public class ResourceWebService {
}
}
- private Response get(String resource, String types) throws URISyntaxException, UnsupportedEncodingException {
+ private Response get(String resource, String types) throws URISyntaxException, UnsupportedEncodingException, HttpErrorException {
try {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
Resource r = null;
- if (UriUtil.validate(resource)) {
+ if (UriUtil.validate(resource)) {
try {
- if(ResourceUtils.isSubject(conn, resource)) { //tests if a resource is used as subject
+ if (ResourceUtils.isSubject(conn, resource)) { //tests if a resource is used as subject
r = ResourceUtils.getUriResource(conn, resource);
}
} catch (Exception e) {
- log.error("Error retrieving the resource <{}>: {}", resource, e.getMessage());
- log.debug("So redirecting directly to it...");
- return Response.seeOther(new java.net.URI(resource)).build();
+ log.error("Error retrieving the resource <{}>: {}", resource, e.getMessage());
+ log.debug("So redirecting directly to it...");
+ return Response.seeOther(new java.net.URI(resource)).build();
}
- } else {
- try {
- r = ResourceUtils.getAnonResource(conn, resource);
- } catch (Exception e) {
- log.error("Error retrieving the blank node <{}>: {}", resource, e.getMessage());
- return Response.status(Status.NOT_FOUND).entity("blank node id " + resource + " not found").build();
- }
- }
- if (r == null) return ResourceWebServiceHelper.buildErrorPage(resource, configurationService.getBaseUri(), Response.Status.NOT_FOUND, "the requested resource could not be found in Marmotta right now, but may be available again in the future", configurationService, templatingService);
+ } else {
+ try {
+ r = ResourceUtils.getAnonResource(conn, resource);
+ } catch (Exception e) {
+ log.error("Error retrieving the blank node <{}>: {}", resource, e.getMessage());
+ return Response.status(Status.NOT_FOUND).entity("blank node id " + resource + " not found").build();
+ }
+ }
+ if (r == null) {
+ throw new HttpErrorException(Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future");
+ }
// FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
// "/" + uuid;
- List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
- for(ContentType t : offeredTypes) {
- t.setParameter("rel", "meta");
+ List<ContentType> offeredTypes = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
+ for (ContentType t : offeredTypes) {
+ t.setParameter("rel", "meta");
}
String contentmime = contentService.getContentType(r);
- if(contentmime != null) {
- ContentType tContent = MarmottaHttpUtils.parseContentType(contentmime);
- tContent.setParameter("rel", "content");
- offeredTypes.add(0,tContent);
+ if (contentmime != null) {
+ ContentType tContent = MarmottaHttpUtils.parseContentType(contentmime);
+ tContent.setParameter("rel", "content");
+ offeredTypes.add(0, tContent);
}
-
+
if (types == null || types.equals("")) {
- return build406(Collections.<ContentType>emptyList(), offeredTypes);
+ return build406(Collections.<ContentType>emptyList(), offeredTypes);
}
List<ContentType> acceptedTypes = MarmottaHttpUtils.parseAcceptHeader(types);
- ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes,acceptedTypes);
+ ContentType bestType = MarmottaHttpUtils.bestContentType(offeredTypes, acceptedTypes);
- log.debug("identified best type: {}",bestType);
+ log.debug("identified best type: {}", bestType);
- if(bestType != null) {
+ if (bestType != null) {
Response response = buildGetResponse(r, bestType);
response.getMetadata().add("Last-Modified", ResourceUtils.getLastModified(conn, r));
response.getMetadata().add("ETag", "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
@@ -427,22 +417,20 @@ public class ResourceWebService {
}
}
- private Response build406(List<ContentType> acceptedTypes, List<ContentType> offeredTypes) {
- ResponseBuilder response = Response.status(Status.NOT_ACCEPTABLE);
- response.header("Content-Type", "text/plain; charset=UTF-8");
-
- StringBuilder entity = new StringBuilder();
- entity.append("Could not find matching type for "+acceptedTypes+"\n");
- entity.append("choose one of the following:");
- for (ContentType contentType : offeredTypes) {
- entity.append(" ").append(contentType).append("\n");
- }
- entity.append("\n");
- response.entity(entity.toString());
- return response.build();
- }
-
+ private Response build406(List<ContentType> acceptedTypes, List<ContentType> offeredTypes) {
+ ResponseBuilder response = Response.status(Status.NOT_ACCEPTABLE);
+ response.header("Content-Type", "text/plain; charset=UTF-8");
+ StringBuilder entity = new StringBuilder();
+ entity.append("Could not find matching type for " + acceptedTypes + "\n");
+ entity.append("choose one of the following:");
+ for (ContentType contentType : offeredTypes) {
+ entity.append(" ").append(contentType).append("\n");
+ }
+ entity.append("\n");
+ response.entity(entity.toString());
+ return response.build();
+ }
// ******************************************* P U T
@@ -453,24 +441,23 @@ public class ResourceWebService {
* Returns a Link where the given data (metadata or content) can be put to
* the local resource
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
* @return a link where the data can be put (depends on Content-Type)
* @HTTP 303 resource in given format can be put under Location
* @HTTP 404 resource cannot be found
* @HTTP 415 Content-Type is not supported
* @HTTP 500 Internal Error
* @RequestHeader Content-Type type of the body; value must follow the
- * pattern .+/.+(;rel=(content|meta))?
+ * pattern .+/.+(;rel=(content|meta))?
* @ResponseHeader Location (for HTTP 303) the url where data can be put
*/
@PUT
@Path(UUID_PATTERN)
- public Response putLocal(@PathParam("uuid") String uuid, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException {
+ public Response putLocal(@PathParam("uuid") String uuid, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
String uri = configurationService.getBaseUri() + "resource/" + uuid;
try {
- return put(uri, type, uuid,request);
+ return put(uri, type, uuid, request);
} catch (URISyntaxException e) {
return Response.serverError().entity(e.getMessage()).build();
}
@@ -482,8 +469,7 @@ public class ResourceWebService {
* Returns a Link where the given data (metadata or content) can be put to
* the remote resource
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
+ * @param uri , the fully-qualified URI of the resource to create in the
* triple store
* @return a link where the data can be put (depends on Content-Type)
* @HTTP 303 resource in given format can be put under Location
@@ -492,11 +478,11 @@ public class ResourceWebService {
* @HTTP 415 Content-Type is not supported
* @HTTP 500 Internal Error
* @RequestHeader Content-Type type of the body; value must follow the
- * pattern .+/.+(;rel=(content|meta))?
+ * pattern .+/.+(;rel=(content|meta))?
* @ResponseHeader Location (for HTTP 303) the url where data can be put
*/
@PUT
- public Response putRemote(@QueryParam("uri") String uri, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException {
+ public Response putRemote(@QueryParam("uri") String uri, @HeaderParam("Content-Type") String type, @Context HttpServletRequest request) throws UnsupportedEncodingException, HttpErrorException {
try {
if (uri != null) return put(URLDecoder.decode(uri, "utf-8"), type, null, request);
else
@@ -506,7 +492,7 @@ public class ResourceWebService {
}
}
- private Response put(String uri, String mimetype, String uuid, HttpServletRequest request) throws URISyntaxException, UnsupportedEncodingException {
+ private Response put(String uri, String mimetype, String uuid, HttpServletRequest request) throws URISyntaxException, UnsupportedEncodingException, HttpErrorException {
try {
// FIXME String appendix = uuid == null ? "?uri=" + URLEncoder.encode(uri, "utf-8") :
// "/" + uuid;
@@ -516,24 +502,24 @@ public class ResourceWebService {
// the offered types are those sent by the client in the Content-Type header; if the rel attribute is not
// given, we add the default rel value
List<ContentType> types = MarmottaHttpUtils.parseAcceptHeader(mimetype);
- for(ContentType type : types) {
- if(type.getParameter("rel") == null) {
- type.setParameter("rel",configurationService.getStringConfiguration("linkeddata.mime.rel.default", "meta"));
+ for (ContentType type : types) {
+ if (type.getParameter("rel") == null) {
+ type.setParameter("rel", configurationService.getStringConfiguration("linkeddata.mime.rel.default", "meta"));
}
}
// the acceptable types are all types for content and the meta types we have parsers for; we do not care so
// much about the order ...
List<ContentType> acceptable = MarmottaHttpUtils.parseStringList(kiWiIOService.getProducedTypes());
- for(ContentType a : acceptable) {
+ for (ContentType a : acceptable) {
a.setParameter("rel", "meta");
}
- ContentType allContent = new ContentType("*","*");
+ ContentType allContent = new ContentType("*", "*");
allContent.setParameter("rel", "content");
- acceptable.add(0,allContent);
+ acceptable.add(0, allContent);
// determine the best match between the offered types and the acceptable types
- ContentType bestType = MarmottaHttpUtils.bestContentType(types,acceptable);
+ ContentType bestType = MarmottaHttpUtils.bestContentType(types, acceptable);
if (bestType != null) {
if (configurationService.getBooleanConfiguration("linkeddata.redirect.put", true)) {
@@ -544,15 +530,15 @@ public class ResourceWebService {
con.commit();
return Response
.status(configurationService.getIntConfiguration("linkeddata.redirect.status", 303))
- // .location(new URI(configurationService.getBaseUri() +
- // bestType.getParameter("rel") + "/" + bestType.getMime() + appendix))
+ // .location(new URI(configurationService.getBaseUri() +
+ // bestType.getParameter("rel") + "/" + bestType.getMime() + appendix))
.location(new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource, bestType, configurationService)))
.build();
} finally {
con.close();
}
} else {
- if("content".equalsIgnoreCase(bestType.getParameter("rel")))
+ if ("content".equalsIgnoreCase(bestType.getParameter("rel")))
return contentWebService.putContent(uri, bestType.getMime(), request);
else if ("meta".equalsIgnoreCase(bestType.getParameter("rel")))
return metaWebService.putMeta(uri, bestType.getMime(), request);
@@ -576,8 +562,7 @@ public class ResourceWebService {
/**
* Delete remote resource with given uri
*
- * @param uri
- * , the fully-qualified URI of the resource to create in the
+ * @param uri , the fully-qualified URI of the resource to create in the
* triple store
* @return HTTP response (success or error)
* @HTTP 200 resource deleted
@@ -592,9 +577,9 @@ public class ResourceWebService {
RepositoryConnection conn = sesameService.getConnection();
try {
conn.begin();
- Resource resource = ResourceUtils.getUriResource(conn,URLDecoder.decode(uri, "utf-8"));
+ Resource resource = ResourceUtils.getUriResource(conn, URLDecoder.decode(uri, "utf-8"));
if (resource != null) {
- ResourceUtils.removeResource(conn,resource);
+ ResourceUtils.removeResource(conn, resource);
return Response.ok().build();
} else
return Response.status(Response.Status.NOT_FOUND).build();
@@ -612,9 +597,8 @@ public class ResourceWebService {
/**
* Delete local resource with given uuid
*
- * @param uuid
- * , a unique identifier (must not contain url specific
- * characters like /,# etc.)
+ * @param uuid , a unique identifier (must not contain url specific
+ * characters like /,# etc.)
* @return HTTP response (success or error)
* @HTTP 200 resource deleted
* @HTTP 404 resource not found
@@ -632,16 +616,16 @@ public class ResourceWebService {
return Response
.status(configurationService.getIntConfiguration(
"linkeddata.redirect.status", 303))
- .header("Vary", "Accept")
- .header("Content-Type", type.toString())
+ .header("Vary", "Accept")
+ .header("Content-Type", type.toString())
// .location(new URI(configurationService.getBaseUri() +
// type.getParameter("rel") + "/" + type.getType() + "/"
// +type.getSubtype() +
// appendix))
- .location(
- new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource,
- type.getParameter("rel"), type.getMime(), configurationService)))
- .build();
+ .location(
+ new java.net.URI(ResourceWebServiceHelper.buildResourceLink(resource,
+ type.getParameter("rel"), type.getMime(), configurationService)))
+ .build();
} catch (Exception e) {
return Response.serverError().build();
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
index 15abd70..55f54d8 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/ResourceWebServiceHelper.java
@@ -34,25 +34,24 @@ import java.util.Map;
/**
* Helper methods shared accross the difference resource web services
- *
- * @author Sergio Fernández
*
+ * @author Sergio Fernández
*/
public class ResourceWebServiceHelper {
-
+
private static final String TEMPLATE_404 = "404.ftl";
- public static void addHeader(Response response, String name, String value) {
+ public static void addHeader(Response response, String name, String value) {
response.getMetadata().add(name, value);
}
-
+
public static String appendTypes(List<String> datamimes, String mime) {
StringBuilder sb = new StringBuilder();
sb.append(appendContentTypes(mime));
sb.append(appendMetaTypes(datamimes));
return sb.toString();
- }
-
+ }
+
public static String appendMetaTypes(List<String> datamimes) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < datamimes.size(); i++) {
@@ -64,7 +63,7 @@ public class ResourceWebServiceHelper {
}
return sb.toString();
}
-
+
public static String appendContentTypes(String mime) {
if (mime != null) {
return mime + ";rel=content";
@@ -72,9 +71,9 @@ public class ResourceWebServiceHelper {
return "";
}
}
-
+
/**
- * @deprecated Use {@link #buildContentLink(URI,String,ConfigurationService)} instead
+ * @deprecated Use {@link #buildContentLink(URI, String, ConfigurationService)} instead
*/
public static String buildContentLink(URI resource, String uuid, String mime, ConfigurationService configurationService) {
return buildContentLink(resource, mime, configurationService);
@@ -94,10 +93,10 @@ public class ResourceWebServiceHelper {
b.append(";rel=content");
}
return b.toString();
- }
-
+ }
+
/**
- * @deprecated Use {@link #buildMetaLinks(URI,List<String>,ConfigurationService)} instead
+ * @deprecated Use {@link #buildMetaLinks(URI, List<String>,ConfigurationService)} instead
*/
public static String buildMetaLinks(URI resource, String uuid, List<String> datamimes, ConfigurationService configurationService) {
return buildMetaLinks(resource, datamimes, configurationService);
@@ -120,7 +119,7 @@ public class ResourceWebServiceHelper {
}
return b.toString();
}
-
+
public static String buildResourceLink(URI resource, ContentType cType, ConfigurationService configurationService) {
return buildResourceLink(resource, cType.getParameter("rel"),
cType.getMime(), configurationService);
@@ -134,36 +133,16 @@ public class ResourceWebServiceHelper {
uuid = resource.stringValue().substring((base + "resource/").length());
return String.format("%s%s/%s/%s", base, rel, mime, uuid);
} else {
- if (resource instanceof URI) {
- try {
- return String.format("%s%s/%s?uri=%s", src, rel, mime, URLEncoder.encode(resource.stringValue(), ResourceWebService.CHARSET));
- } catch (UnsupportedEncodingException e) {
- return String.format("%s%s/%s?uri=%s", src, rel, mime, resource.stringValue());
- }
- } else {
- return String.format("%s%s/%s?genid=%s", src, rel, mime, resource.stringValue());
- }
+ if (resource instanceof URI) {
+ try {
+ return String.format("%s%s/%s?uri=%s", src, rel, mime, URLEncoder.encode(resource.stringValue(), ResourceWebService.CHARSET));
+ } catch (UnsupportedEncodingException e) {
+ return String.format("%s%s/%s?uri=%s", src, rel, mime, resource.stringValue());
+ }
+ } else {
+ return String.format("%s%s/%s?genid=%s", src, rel, mime, resource.stringValue());
+ }
}
}
-
- public static Response buildErrorPage(String uri, String base, Status status, String message, ConfigurationService configurationService, TemplatingService templatingService) {
- Map<String, Object> data = new HashMap<String, Object>();
- data.put("uri", uri);
- data.put("message", message);
- try {
- data.put("encoded_uri", URLEncoder.encode(uri, "UTF-8"));
- } catch (UnsupportedEncodingException uee) {
- data.put("encoded_uri", uri);
- }
-
- try {
- return Response.status(status)
- .entity(templatingService.process(TEMPLATE_404, data))
- .build();
- } catch (Exception e) {
- return Response.status(Response.Status.NOT_FOUND)
- .entity("Not Found").build();
- }
- }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/resources/templates/error.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/error.ftl b/platform/marmotta-core/src/main/resources/templates/error.ftl
new file mode 100644
index 0000000..85f468d
--- /dev/null
+++ b/platform/marmotta-core/src/main/resources/templates/error.ftl
@@ -0,0 +1,83 @@
+<#--
+
+ 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.
+
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
+
+ <head>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <title>${status} ${phrase} - Marmotta Linked Data Explorer</title>
+ <script src="${SERVER_URL}webjars/jquery/1.8.2/jquery.min.js" type="text/javascript" ></script>
+ <link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" type="text/css" />
+ <link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" type="text/css" />
+ <link href="${SERVER_URL}${DEFAULT_STYLE}error.css" rel="stylesheet" type="text/css" />
+ </head>
+
+ <body>
+
+ <div id="wrapper">
+ <div id="header">
+ <a id="logo" href="${SERVER_URL}" title="${PROJECT}">
+ <img src="${SERVER_URL}${LOGO}" alt="${PROJECT} logo" />
+ </a>
+ <h1>Marmotta Linked Data Explorer</h1>
+ <div class="clean"></div>
+ </div>
+ <div class="clear"></div>
+ <div id="center">
+ <div id="content">
+
+ <h2>Error: ${status} ${phrase}</h2>
+
+ <p>
+ <strong><a href="${SERVER_URL}resource?uri=${encoded_uri}">${uri}</a></strong><a href="${uri}"><img src="${SERVER_URL}core/public/img/icon/link.png" alt="${uri}" title="go to ${uri} directly" /></a>
+ </p>
+
+ <p>
+ Sorry, but ${message}. Further details in the logs.
+ </p>
+
+ </div>
+
+ </div>
+
+ <div class="clear"></div>
+ <div id="footer">
+ <div id="footer_line">
+ <span>
+ ${FOOTER}
+ </span>
+ </div>
+ </div>
+
+ </div>
+
+ <script type="text/javascript">
+
+ $(document).ready(function() {
+
+ });
+
+ </script>
+
+ </body>
+
+</html>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css b/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
new file mode 100644
index 0000000..fc35268
--- /dev/null
+++ b/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
@@ -0,0 +1,43 @@
+/**
+ * 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.
+ */
+
+div#header h1, div#center {
+ width: auto;
+ min-height: 400px;
+ margin: 0;
+}
+
+div#center {
+ padding: 2em 30% 2em 30%;
+}
+
+div#center {
+ float: none;
+ vertical-align: middle;
+ padding: 2em 30% 5em 30%;
+}
+
+div#center > * {
+ margin-top: 2em;
+ font-size: 1.6em;
+}
+
+div#center > p > a > img {
+ vertical-align: text-top;
+ margin-left: 0.15em;
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/d297c0a2/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/web/public/style/white/error.css b/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
new file mode 100644
index 0000000..9d3b62a
--- /dev/null
+++ b/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+div#header h1, div#center {
+ width: auto;
+ min-height: 400px;
+ margin: 0;
+}
+
+div#center {
+ padding: 2em 30% 2em 30%;
+}
+
+div#center {
+ float: none;
+ vertical-align: middle;
+ padding: 2em 30% 5em 30%;
+}
+
+div#center > * {
+ margin-top: 2em;
+ font-size: 1.6em;
+}
+
+div#center > p > a > img {
+ vertical-align: text-top;
+ margin-left: 0.15em;
+}
+
[3/8] git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/marmotta into develop
Posted by wi...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/marmotta into develop
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/31d04b5a
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/31d04b5a
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/31d04b5a
Branch: refs/heads/develop
Commit: 31d04b5a139891962e9d5eda652315371487c189
Parents: edb5faf dd004d3
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Mar 10 11:20:50 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Mar 10 11:20:50 2014 +0100
----------------------------------------------------------------------
platform/backends/marmotta-backend-http/pom.xml | 2 +-
.../platform/core/servlet/MarmottaPreStartupListener.java | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
[6/8] git commit: more lmf cleanup
Posted by wi...@apache.org.
more lmf cleanup
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/1ca8577c
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/1ca8577c
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/1ca8577c
Branch: refs/heads/develop
Commit: 1ca8577c61d77a0c3cede911f7423a73bf277592
Parents: 0550b39
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Mar 12 16:56:15 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Mar 12 16:56:15 2014 +0100
----------------------------------------------------------------------
.../main/resources/config-defaults.properties | 26 +++++++++-----------
1 file changed, 11 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/1ca8577c/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-defaults.properties b/platform/marmotta-core/src/main/resources/config-defaults.properties
index ba80bbf..8d7ae29 100644
--- a/platform/marmotta-core/src/main/resources/config-defaults.properties
+++ b/platform/marmotta-core/src/main/resources/config-defaults.properties
@@ -17,7 +17,7 @@
#
###############################################################################
-# LMF core configuration
+# Core configuration
###############################################################################
# KiWi home directory (for configuration files etc)
@@ -32,16 +32,16 @@ kiwi.host = http://localhost:8080/
#the path of the KiWi installation, e.g. /, /marmotta, /LMF or /KiWi
kiwi.path = /
-# true if the LMF system host configuration has been set up, do not change
+# true if the system host configuration has been set up, do not change
kiwi.setup.host = false
-# true if the LMF system database configuration has been set up, do not change
+# true if the system database configuration has been set up, do not change
kiwi.setup.database = false
# kiwi startup page
kiwi.pages.startup = core/admin/about.html
-# lmf default style
+# default style
kiwi.pages.project = marmotta
# marmotta logo
@@ -50,10 +50,10 @@ kiwi.pages.project.marmotta.logo = core/public/img/logo/marmotta-logo.png
# marmotta footer
kiwi.pages.project.marmotta.footer = Copyright © 2013-2014 The Apache Software Foundation, Licensed under the <a href\="\#">Apache License, Version 2.0.</a><br>Apache, Marmotta, the Apache feather and Marmotta logos are trademarks of The Apache Software Foundation.
-# lmf logo
+# custom logo
kiwi.pages.project.custom.logo = core/public/img/logo/custom-logo.png
-# lmf footer
+# custom footer
kiwi.pages.project.custom.footer = Your Footer powered by <a href="http://marmotta.apache.org/">Apache Marmotta</a>.
# supported styles
@@ -66,17 +66,14 @@ debug.enabled = false
# according to HTTP
linkeddata.redirect.status = 303
-
# determines whether to issue a redirect for PUT requests; if set to true, the resource service will return
# a redirect to the actual content or metadata location for the resource, resulting in a second request to be issued
# by the browser; if set to false, the resource service directly processes the content/metadata upload
linkeddata.redirect.put = false
-
# default rel value for resource interaction with HTTP (MUST be 'meta' or 'content')
linkeddata.mime.rel.default = meta
-
# sort menu entries by weight instead of alphabet
templating.sort_by_weight = true
@@ -122,7 +119,6 @@ logging.file.debug.keep = 30
# Content Readers and Writers (in case a resource is requested with ;rel=content
###############################################################################
-
# a reader/writer for content stored in the file system; by default, this is applied to all resources that have
# a file:/ URI. It is disabled by default, because it potentially allows reading/writing all files in the file system
# to only enable reading but disable writing, remove the content.filesystem.writer property
@@ -131,12 +127,12 @@ content.filesystem.writer=org.apache.marmotta.platform.core.services.content.Fil
content.filesystem.pattern=(${marmotta.home}/resources|${kiwi.context}resource/|urn:).*
#content.filesystem.pattern=file:/tmp/.*
content.filesystem.enabled=true
-# if enabled allow only access to resources stored in the LMF work directory
+# if enabled allow only access to resources stored in the work directory
content.filesystem.secure=true
# a reader for content stored on a remote HTTP server; by default, this is applied to all resources that are not in
-# the context of the LMF web application; enabled by default, because it is a safe operation
+# the context of the web application; enabled by default, because it is a safe operation
content.http.reader=org.apache.marmotta.platform.core.services.content.HTTPContentReader
content.http.pattern=(?!${kiwi.context}resource)http://.*
content.http.enabled=false
@@ -157,7 +153,7 @@ resources.servercache.enabled = false
###############################################################################
-# LMF importer configuration
+# Importer configuration
###############################################################################
# generate KiWi title and text content for each imported resource in the RDF importer
@@ -167,14 +163,14 @@ importer.generate_descriptions = false
importer.batchsize = 50
###############################################################################
-# LMF Statistics Module
+# Statistics Module
###############################################################################
# whether collecting statistics about the execution should be enabled on start or not
statistics.enabled = true
###############################################################################
-# LMF Default Prefixes
+# Default Prefixes
###############################################################################
# prefixes mappings
[4/8] git commit: MARMOTTA-431: updated to jdeb 1.1.1 release for
building proper .changes file
Posted by wi...@apache.org.
MARMOTTA-431: updated to jdeb 1.1.1 release for building proper .changes file
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/f77b249b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/f77b249b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/f77b249b
Branch: refs/heads/develop
Commit: f77b249b3521fcb5b63379a3689ea4a1ca9c8bb1
Parents: 31d04b5
Author: Sergio Fernández <wi...@apache.org>
Authored: Tue Mar 11 08:46:14 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Tue Mar 11 08:46:14 2014 +0100
----------------------------------------------------------------------
launchers/marmotta-webapp/pom.xml | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/f77b249b/launchers/marmotta-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/launchers/marmotta-webapp/pom.xml b/launchers/marmotta-webapp/pom.xml
index bf7bf27..a2c435b 100644
--- a/launchers/marmotta-webapp/pom.xml
+++ b/launchers/marmotta-webapp/pom.xml
@@ -140,8 +140,7 @@
<plugin>
<artifactId>jdeb</artifactId>
<groupId>org.vafer</groupId>
- <!--required for generating proper .changes: <version>1.1-SNAPSHOT</version>-->
- <version>1.0.1</version>
+ <version>1.1.1</version>
<executions>
<execution>
<phase>package</phase>
[7/8] git commit: MARMOTTA-238: fixed error in the template
Posted by wi...@apache.org.
MARMOTTA-238: fixed error in the template
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/bb52d27b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/bb52d27b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/bb52d27b
Branch: refs/heads/develop
Commit: bb52d27bae31b1ce66fd2c480899411e0474183f
Parents: 1ca8577
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Mar 12 18:00:51 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Mar 12 18:00:51 2014 +0100
----------------------------------------------------------------------
platform/marmotta-core/src/main/resources/templates/error.ftl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bb52d27b/platform/marmotta-core/src/main/resources/templates/error.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/error.ftl b/platform/marmotta-core/src/main/resources/templates/error.ftl
index 85f468d..ef39fbb 100644
--- a/platform/marmotta-core/src/main/resources/templates/error.ftl
+++ b/platform/marmotta-core/src/main/resources/templates/error.ftl
@@ -24,7 +24,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>${status} ${phrase} - Marmotta Linked Data Explorer</title>
+ <title>${status} ${reason} - Linked Data Explorer - Apache Marmotta</title>
<script src="${SERVER_URL}webjars/jquery/1.8.2/jquery.min.js" type="text/javascript" ></script>
<link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" type="text/css" />
<link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" type="text/css" />
@@ -45,7 +45,7 @@
<div id="center">
<div id="content">
- <h2>Error: ${status} ${phrase}</h2>
+ <h2>Error: ${status} ${reason}</h2>
<p>
<strong><a href="${SERVER_URL}resource?uri=${encoded_uri}">${uri}</a></strong><a href="${uri}"><img src="${SERVER_URL}core/public/img/icon/link.png" alt="${uri}" title="go to ${uri} directly" /></a>
[8/8] git commit: MARMOTTA-182: added some minimum stule,
plus the image with the sad marmot created by Oliver
Posted by wi...@apache.org.
MARMOTTA-182: added some minimum stule, plus the image with the sad marmot created by Oliver
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/2b732de3
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/2b732de3
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/2b732de3
Branch: refs/heads/develop
Commit: 2b732de378389c2b9c22b0308945e2c074d388d7
Parents: bb52d27
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Mar 12 18:14:45 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Mar 12 18:14:45 2014 +0100
----------------------------------------------------------------------
.../src/main/resources/templates/error.ftl | 4 +--
.../web/public/img/logo/marmotta-sad.png | Bin 0 -> 37916 bytes
.../resources/web/public/style/blue/error.css | 28 +++++-------------
.../resources/web/public/style/white/error.css | 29 +++++--------------
4 files changed, 18 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2b732de3/platform/marmotta-core/src/main/resources/templates/error.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/error.ftl b/platform/marmotta-core/src/main/resources/templates/error.ftl
index ef39fbb..9e1f35d 100644
--- a/platform/marmotta-core/src/main/resources/templates/error.ftl
+++ b/platform/marmotta-core/src/main/resources/templates/error.ftl
@@ -24,7 +24,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <title>${status} ${reason} - Linked Data Explorer - Apache Marmotta</title>
+ <title>${status} ${reason} - Marmotta Error</title>
<script src="${SERVER_URL}webjars/jquery/1.8.2/jquery.min.js" type="text/javascript" ></script>
<link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" type="text/css" />
<link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" type="text/css" />
@@ -38,7 +38,7 @@
<a id="logo" href="${SERVER_URL}" title="${PROJECT}">
<img src="${SERVER_URL}${LOGO}" alt="${PROJECT} logo" />
</a>
- <h1>Marmotta Linked Data Explorer</h1>
+ <h1>Marmotta Error</h1>
<div class="clean"></div>
</div>
<div class="clear"></div>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2b732de3/platform/marmotta-core/src/main/resources/web/public/img/logo/marmotta-sad.png
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/web/public/img/logo/marmotta-sad.png b/platform/marmotta-core/src/main/resources/web/public/img/logo/marmotta-sad.png
new file mode 100644
index 0000000..cbd3b2e
Binary files /dev/null and b/platform/marmotta-core/src/main/resources/web/public/img/logo/marmotta-sad.png differ
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2b732de3/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css b/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
index fc35268..623acb4 100644
--- a/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
+++ b/platform/marmotta-core/src/main/resources/web/public/style/blue/error.css
@@ -16,28 +16,16 @@
* limitations under the License.
*/
-div#header h1, div#center {
- width: auto;
- min-height: 400px;
- margin: 0;
-}
-
div#center {
- padding: 2em 30% 2em 30%;
+ float: none;
+ width: 60%;
+ padding-left: 20%;
+ padding-bottom: 8em;
}
-div#center {
- float: none;
- vertical-align: middle;
- padding: 2em 30% 5em 30%;
-}
-
-div#center > * {
- margin-top: 2em;
+div#content {
+ min-height: 200px;
font-size: 1.6em;
-}
-
-div#center > p > a > img {
- vertical-align: text-top;
- margin-left: 0.15em;
+ background: #ffffff url('../../img/logo/marmotta-sad.png') no-repeat right top;
+ padding-right: 220px;
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/2b732de3/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/web/public/style/white/error.css b/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
index 9d3b62a..623acb4 100644
--- a/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
+++ b/platform/marmotta-core/src/main/resources/web/public/style/white/error.css
@@ -16,29 +16,16 @@
* limitations under the License.
*/
-div#header h1, div#center {
- width: auto;
- min-height: 400px;
- margin: 0;
-}
-
-div#center {
- padding: 2em 30% 2em 30%;
-}
-
div#center {
- float: none;
- vertical-align: middle;
- padding: 2em 30% 5em 30%;
+ float: none;
+ width: 60%;
+ padding-left: 20%;
+ padding-bottom: 8em;
}
-div#center > * {
- margin-top: 2em;
+div#content {
+ min-height: 200px;
font-size: 1.6em;
+ background: #ffffff url('../../img/logo/marmotta-sad.png') no-repeat right top;
+ padding-right: 220px;
}
-
-div#center > p > a > img {
- vertical-align: text-top;
- margin-left: 0.15em;
-}
-
[5/8] git commit: added schema.org prefix mapping by default
Posted by wi...@apache.org.
added schema.org prefix mapping by default
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/0550b39f
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/0550b39f
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/0550b39f
Branch: refs/heads/develop
Commit: 0550b39f78e59420a9ba16bcfd8c4232e6f4996f
Parents: f77b249
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Mar 12 16:54:13 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Mar 12 16:54:13 2014 +0100
----------------------------------------------------------------------
.../marmotta-core/src/main/resources/config-defaults.properties | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0550b39f/platform/marmotta-core/src/main/resources/config-defaults.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/config-defaults.properties b/platform/marmotta-core/src/main/resources/config-defaults.properties
index 4ac724d..ba80bbf 100644
--- a/platform/marmotta-core/src/main/resources/config-defaults.properties
+++ b/platform/marmotta-core/src/main/resources/config-defaults.properties
@@ -192,7 +192,7 @@ prefix.rdf = http://www.w3.org/1999/02/22-rdf-syntax-ns#
prefix.skos = http://www.w3.org/2004/02/skos/core#
prefix.ldp = http://www.w3.org/ns/ldp#
prefix.mao = http://www.w3.org/ns/ma-ont#
-
+prefix.schema = http://schema.org/
contexts.default = ${kiwi.context}context/default
contexts.inferred = ${kiwi.context}context/inferred
[2/8] git commit: Merge branch 'develop' of
https://git-wip-us.apache.org/repos/asf/marmotta into develop
Posted by wi...@apache.org.
Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/marmotta into develop
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/edb5fafc
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/edb5fafc
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/edb5fafc
Branch: refs/heads/develop
Commit: edb5fafc809d3628e408e77bec33188809ccf26f
Parents: d297c0a e2e23ef
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Mar 3 09:33:46 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Mar 3 09:33:46 2014 +0100
----------------------------------------------------------------------
.../marmotta/platform/core/startup/MarmottaStartupService.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------