You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2014/03/17 17:51:23 UTC
git commit: MARMOTTA-409: Added jsonp support for web-services
Repository: marmotta
Updated Branches:
refs/heads/develop 5d383da4c -> eddba62be
MARMOTTA-409: Added jsonp support for web-services
It is now possible to auto-register additional jax-rs "Interceptors" by implementing the new CDIInterceptor interface.
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/eddba62b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/eddba62b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/eddba62b
Branch: refs/heads/develop
Commit: eddba62bee738421fbb4a54f34a3e5d323e81204
Parents: 5d383da
Author: Jakob Frank <ja...@apache.org>
Authored: Mon Mar 17 17:30:08 2014 +0100
Committer: Jakob Frank <ja...@apache.org>
Committed: Mon Mar 17 17:32:08 2014 +0100
----------------------------------------------------------------------
.../backend/kiwi/DatabaseWebService.java | 2 +-
.../core/api/jaxrs/InterceptorService.java | 31 +++++
.../platform/core/jaxrs/CDIExceptionMapper.java | 28 -----
.../platform/core/jaxrs/ErrorResponse.java | 126 -------------------
.../core/jaxrs/HttpErrorExceptionMapper.java | 91 --------------
.../core/jaxrs/IllegalStateExceptionMapper.java | 47 -------
.../core/jaxrs/MarmottaExceptionMapper.java | 49 --------
.../jaxrs/MarmottaImportExceptionMapper.java | 48 -------
.../core/jaxrs/RepositoryExceptionMapper.java | 50 --------
.../core/jaxrs/URISyntaxExceptionMapper.java | 47 -------
.../UnsupportedOperationExceptionMapper.java | 47 -------
.../exceptionmappers/CDIExceptionMapper.java | 28 +++++
.../jaxrs/exceptionmappers/ErrorResponse.java | 126 +++++++++++++++++++
.../HttpErrorExceptionMapper.java | 91 ++++++++++++++
.../IllegalStateExceptionMapper.java | 46 +++++++
.../MarmottaExceptionMapper.java | 48 +++++++
.../MarmottaImportExceptionMapper.java | 48 +++++++
.../RepositoryExceptionMapper.java | 49 ++++++++
.../URISyntaxExceptionMapper.java | 47 +++++++
.../UnsupportedOperationExceptionMapper.java | 46 +++++++
.../core/jaxrs/interceptors/CDIInterceptor.java | 30 +++++
.../jaxrs/interceptors/JsonPInterceptor.java | 45 +++++++
.../jaxrs/ExceptionMapperServiceImpl.java | 2 +-
.../services/jaxrs/InterceptorServiceImpl.java | 73 +++++++++++
.../webservices/system/SystemWebService.java | 2 +-
.../platform/core/test/base/JettyMarmotta.java | 12 +-
26 files changed, 722 insertions(+), 537 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/DatabaseWebService.java
----------------------------------------------------------------------
diff --git a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/DatabaseWebService.java b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/DatabaseWebService.java
index 8c68a96..9e8b4ba 100644
--- a/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/DatabaseWebService.java
+++ b/platform/backends/marmotta-backend-kiwi/src/main/java/org/apache/marmotta/platform/backend/kiwi/DatabaseWebService.java
@@ -19,7 +19,7 @@ package org.apache.marmotta.platform.backend.kiwi;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
-import org.apache.marmotta.platform.core.jaxrs.ErrorResponse;
+import org.apache.marmotta.platform.core.jaxrs.exceptionmappers.ErrorResponse;
import org.slf4j.Logger;
import javax.enterprise.context.ApplicationScoped;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/jaxrs/InterceptorService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/jaxrs/InterceptorService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/jaxrs/InterceptorService.java
new file mode 100644
index 0000000..5cb6c74
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/api/jaxrs/InterceptorService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.api.jaxrs;
+
+/**
+ * This service auto-registers JAX-RS interceptors implementing the CDIInterceptor interface and
+ * registers them with RESTEasy. This allows applications based on Marmotta to easily implement and register their
+ * own Interceptors without needing to go into RESTEasy.
+ * <p/>
+ * Note that Interceptors that are injected via CDI need to be annotated with @Dependent, or otherwise
+ * they will be proxied by the CDI implementation and then the generic type cannot be determined.
+ *
+ * @author Jakob Frank (jakob@apache.org)
+ */
+public interface InterceptorService {
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/CDIExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/CDIExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/CDIExceptionMapper.java
deleted file mode 100644
index c2eba6e..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/CDIExceptionMapper.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import javax.ws.rs.ext.ExceptionMapper;
-
-/**
- * A marker-interface to allow CDI injection of ExceptionMappers implementing this interface by the ExceptionMapperService.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-public interface CDIExceptionMapper<E extends Throwable> extends ExceptionMapper<E> {
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorResponse.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorResponse.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorResponse.java
deleted file mode 100644
index 38ff150..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorResponse.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import javax.ws.rs.core.Response;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-/**
- * Represents a uniform error response for REST service requests.
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@XmlRootElement(name = "Error")
-public class ErrorResponse {
-
- private int code;
-
- private String message;
-
- private String stackTrace;
-
- public ErrorResponse() {
- }
-
- public ErrorResponse(int code, String message) {
- this.code = code;
- this.message = message;
- }
-
- public ErrorResponse(int code, String message, String stackTrace) {
- this.code = code;
- this.message = message;
- this.stackTrace = stackTrace;
- }
-
- public ErrorResponse(int code, Exception ex) {
- this(code, ex.getMessage(), ex);
- }
-
- public ErrorResponse(int code, String message, Exception ex) {
- this.code = code;
- this.message = message;
-
- StringWriter writer = new StringWriter();
- ex.printStackTrace(new PrintWriter(writer));
-
- this.stackTrace = writer.toString();
- }
-
- @XmlElement(name = "code", required = true)
- public int getCode() {
- return code;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- @XmlElement(name = "message", required = true)
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- @XmlElement(name = "stackTrace", required = false)
- public String getStackTrace() {
- return stackTrace;
- }
-
- public void setStackTrace(String stackTrace) {
- this.stackTrace = stackTrace;
- }
-
- public static Response errorResponse(Response.Status status, String message) {
- ErrorResponse entity = new ErrorResponse(status.getStatusCode(), message);
- return Response.status(status).entity(entity).build();
- }
-
- public static Response errorResponse(Response.Status status, Exception ex) {
- ErrorResponse entity = new ErrorResponse(status.getStatusCode(), ex);
- return Response.status(status).entity(entity).build();
- }
-
- public static Response errorResponse(Response.Status status, String message, Exception ex) {
- ErrorResponse entity = new ErrorResponse(status.getStatusCode(), message);
-
- return Response.status(status).entity(entity).build();
- }
-
-
- public String toString() {
- StringBuffer b = new StringBuffer();
- b.append("Code: ");
- b.append(code);
- b.append(System.getProperty("line.separator"));
- b.append("Message: ");
- b.append(message);
- if(stackTrace != null) {
- b.append(System.getProperty("line.separator"));
- b.append("StackTrace: ");
- b.append(stackTrace);
- }
- return b.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/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
deleted file mode 100644
index eb53cdb..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/HttpErrorExceptionMapper.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.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/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/IllegalStateExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/IllegalStateExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/IllegalStateExceptionMapper.java
deleted file mode 100644
index 9dfe1c6..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/IllegalStateExceptionMapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Map MarmottaExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class IllegalStateExceptionMapper implements CDIExceptionMapper<IllegalStateException> {
-
- /**
- * 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(IllegalStateException exception) {
- return ErrorResponse.errorResponse(Response.Status.SERVICE_UNAVAILABLE, exception.getMessage());
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaExceptionMapper.java
deleted file mode 100644
index 51b3d88..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaExceptionMapper.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import org.apache.marmotta.platform.core.exception.MarmottaException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Map MarmottaExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class MarmottaExceptionMapper implements CDIExceptionMapper<MarmottaException> {
-
- /**
- * 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(MarmottaException exception) {
- return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/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
deleted file mode 100644
index 1930b79..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/MarmottaImportExceptionMapper.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
-
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Map MarmottaExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class MarmottaImportExceptionMapper implements CDIExceptionMapper<MarmottaImportException> {
-
- /**
- * 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(MarmottaImportException exception) {
- return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/RepositoryExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/RepositoryExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/RepositoryExceptionMapper.java
deleted file mode 100644
index 42ddb08..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/RepositoryExceptionMapper.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import org.openrdf.repository.RepositoryException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Map RepositoryExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class RepositoryExceptionMapper implements CDIExceptionMapper<RepositoryException> {
-
-
- /**
- * 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(RepositoryException exception) {
- return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/URISyntaxExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/URISyntaxExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/URISyntaxExceptionMapper.java
deleted file mode 100644
index ffbc66f..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/URISyntaxExceptionMapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-import java.net.URISyntaxException;
-
-/**
- * Map MarmottaExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class URISyntaxExceptionMapper implements CDIExceptionMapper<URISyntaxException> {
-
- /**
- * 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(URISyntaxException exception) {
- return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/UnsupportedOperationExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/UnsupportedOperationExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/UnsupportedOperationExceptionMapper.java
deleted file mode 100644
index 1a0f65e..0000000
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/UnsupportedOperationExceptionMapper.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.core.jaxrs;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.Dependent;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.Provider;
-
-/**
- * Map MarmottaExceptions to a internal server error and return the default error object
- *
- * @author Sebastian Schaffert (sschaffert@apache.org)
- */
-@Provider
-@Dependent
-public class UnsupportedOperationExceptionMapper implements CDIExceptionMapper<UnsupportedOperationException> {
-
- /**
- * 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(UnsupportedOperationException exception) {
- return ErrorResponse.errorResponse(Response.Status.fromStatusCode(501), exception.getMessage());
- }
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/CDIExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/CDIExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/CDIExceptionMapper.java
new file mode 100644
index 0000000..84d9295
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/CDIExceptionMapper.java
@@ -0,0 +1,28 @@
+/*
+ * 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.exceptionmappers;
+
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * A marker-interface to allow CDI injection of ExceptionMappers implementing this interface by the ExceptionMapperService.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface CDIExceptionMapper<E extends Throwable> extends ExceptionMapper<E> {
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/ErrorResponse.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/ErrorResponse.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/ErrorResponse.java
new file mode 100644
index 0000000..878be4f
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/ErrorResponse.java
@@ -0,0 +1,126 @@
+/*
+ * 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.exceptionmappers;
+
+import javax.ws.rs.core.Response;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Represents a uniform error response for REST service requests.
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@XmlRootElement(name = "Error")
+public class ErrorResponse {
+
+ private int code;
+
+ private String message;
+
+ private String stackTrace;
+
+ public ErrorResponse() {
+ }
+
+ public ErrorResponse(int code, String message) {
+ this.code = code;
+ this.message = message;
+ }
+
+ public ErrorResponse(int code, String message, String stackTrace) {
+ this.code = code;
+ this.message = message;
+ this.stackTrace = stackTrace;
+ }
+
+ public ErrorResponse(int code, Exception ex) {
+ this(code, ex.getMessage(), ex);
+ }
+
+ public ErrorResponse(int code, String message, Exception ex) {
+ this.code = code;
+ this.message = message;
+
+ StringWriter writer = new StringWriter();
+ ex.printStackTrace(new PrintWriter(writer));
+
+ this.stackTrace = writer.toString();
+ }
+
+ @XmlElement(name = "code", required = true)
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ @XmlElement(name = "message", required = true)
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ @XmlElement(name = "stackTrace", required = false)
+ public String getStackTrace() {
+ return stackTrace;
+ }
+
+ public void setStackTrace(String stackTrace) {
+ this.stackTrace = stackTrace;
+ }
+
+ public static Response errorResponse(Response.Status status, String message) {
+ ErrorResponse entity = new ErrorResponse(status.getStatusCode(), message);
+ return Response.status(status).entity(entity).build();
+ }
+
+ public static Response errorResponse(Response.Status status, Exception ex) {
+ ErrorResponse entity = new ErrorResponse(status.getStatusCode(), ex);
+ return Response.status(status).entity(entity).build();
+ }
+
+ public static Response errorResponse(Response.Status status, String message, Exception ex) {
+ ErrorResponse entity = new ErrorResponse(status.getStatusCode(), message);
+
+ return Response.status(status).entity(entity).build();
+ }
+
+
+ public String toString() {
+ StringBuffer b = new StringBuffer();
+ b.append("Code: ");
+ b.append(code);
+ b.append(System.getProperty("line.separator"));
+ b.append("Message: ");
+ b.append(message);
+ if(stackTrace != null) {
+ b.append(System.getProperty("line.separator"));
+ b.append("StackTrace: ");
+ b.append(stackTrace);
+ }
+ return b.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/HttpErrorExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/HttpErrorExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/HttpErrorExceptionMapper.java
new file mode 100644
index 0000000..86f680d
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/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.exceptionmappers;
+
+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/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/IllegalStateExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/IllegalStateExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/IllegalStateExceptionMapper.java
new file mode 100644
index 0000000..72e6c08
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/IllegalStateExceptionMapper.java
@@ -0,0 +1,46 @@
+/*
+ * 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.exceptionmappers;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map MarmottaExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class IllegalStateExceptionMapper implements CDIExceptionMapper<IllegalStateException> {
+
+ /**
+ * 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(IllegalStateException exception) {
+ return ErrorResponse.errorResponse(Response.Status.SERVICE_UNAVAILABLE, exception.getMessage());
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaExceptionMapper.java
new file mode 100644
index 0000000..2aa283b
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaExceptionMapper.java
@@ -0,0 +1,48 @@
+/*
+ * 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.exceptionmappers;
+
+import org.apache.marmotta.platform.core.exception.MarmottaException;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map MarmottaExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class MarmottaExceptionMapper implements CDIExceptionMapper<MarmottaException> {
+
+ /**
+ * 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(MarmottaException exception) {
+ return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaImportExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaImportExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaImportExceptionMapper.java
new file mode 100644
index 0000000..fcb0fa6
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/MarmottaImportExceptionMapper.java
@@ -0,0 +1,48 @@
+/*
+ * 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.exceptionmappers;
+
+import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map MarmottaExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class MarmottaImportExceptionMapper implements CDIExceptionMapper<MarmottaImportException> {
+
+ /**
+ * 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(MarmottaImportException exception) {
+ return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/RepositoryExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/RepositoryExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/RepositoryExceptionMapper.java
new file mode 100644
index 0000000..e7d9fb3
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/RepositoryExceptionMapper.java
@@ -0,0 +1,49 @@
+/*
+ * 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.exceptionmappers;
+
+import org.openrdf.repository.RepositoryException;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map RepositoryExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class RepositoryExceptionMapper implements CDIExceptionMapper<RepositoryException> {
+
+
+ /**
+ * 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(RepositoryException exception) {
+ return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/URISyntaxExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/URISyntaxExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/URISyntaxExceptionMapper.java
new file mode 100644
index 0000000..2434a63
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/URISyntaxExceptionMapper.java
@@ -0,0 +1,47 @@
+/*
+ * 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.exceptionmappers;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+import java.net.URISyntaxException;
+
+/**
+ * Map MarmottaExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class URISyntaxExceptionMapper implements CDIExceptionMapper<URISyntaxException> {
+
+ /**
+ * 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(URISyntaxException exception) {
+ return ErrorResponse.errorResponse(Response.Status.INTERNAL_SERVER_ERROR, exception);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/UnsupportedOperationExceptionMapper.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/UnsupportedOperationExceptionMapper.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/UnsupportedOperationExceptionMapper.java
new file mode 100644
index 0000000..b149f0d
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/exceptionmappers/UnsupportedOperationExceptionMapper.java
@@ -0,0 +1,46 @@
+/*
+ * 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.exceptionmappers;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map MarmottaExceptions to a internal server error and return the default error object
+ *
+ * @author Sebastian Schaffert (sschaffert@apache.org)
+ */
+@Provider
+@Dependent
+public class UnsupportedOperationExceptionMapper implements CDIExceptionMapper<UnsupportedOperationException> {
+
+ /**
+ * 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(UnsupportedOperationException exception) {
+ return ErrorResponse.errorResponse(Response.Status.fromStatusCode(501), exception.getMessage());
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/CDIInterceptor.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/CDIInterceptor.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/CDIInterceptor.java
new file mode 100644
index 0000000..fc37f53
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/CDIInterceptor.java
@@ -0,0 +1,30 @@
+/*
+ * 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.interceptors;
+
+import javax.ws.rs.ext.WriterInterceptor;
+
+/**
+ * A marker-interface to allow CDI injection of Interceptors implementing this interface by the InterceptorService.
+ *
+ * @author Jakob Frank (jakob@apache.org)
+ * @see org.apache.marmotta.platform.core.api.jaxrs.InterceptorService
+ */
+public interface CDIInterceptor extends WriterInterceptor {
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/JsonPInterceptor.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/JsonPInterceptor.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/JsonPInterceptor.java
new file mode 100644
index 0000000..0ec113b
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/interceptors/JsonPInterceptor.java
@@ -0,0 +1,45 @@
+/*
+ * 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.interceptors;
+
+import org.jboss.resteasy.plugins.providers.jackson.Jackson2JsonpInterceptor;
+
+import javax.enterprise.context.Dependent;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * <p>
+ * JSONP is an alternative to normal AJAX requests. Instead of using a XMLHttpRequest a script tag is added to the DOM.
+ * The browser will call the corresponding URL and download the JavaScript. The server creates a response which looks like a
+ * method call. The parameter is the body of the request. The name of the method to call is normally passed as query parameter.
+ * The method has to be present in the current JavaScript environment.
+ * </p>
+ * <p>
+ * Jackson JSON processor can produce such an response. This interceptor checks if the media type is a JavaScript one if there is a query
+ * parameter with the method name. The default name of this query parameter is "callback". So this interceptor is compatible with
+ * <a href="http://api.jquery.com/jQuery.ajax/">jQuery</a>.
+ * </p>
+
+ * @see org.jboss.resteasy.plugins.providers.jackson.Jackson2JsonpInterceptor
+ * @see org.apache.marmotta.platform.core.jaxrs.interceptors.CDIInterceptor
+ */
+@Provider
+@Dependent
+public class JsonPInterceptor extends Jackson2JsonpInterceptor implements CDIInterceptor {
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/ExceptionMapperServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/ExceptionMapperServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/ExceptionMapperServiceImpl.java
index ca06ed6..918bd86 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/ExceptionMapperServiceImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/ExceptionMapperServiceImpl.java
@@ -19,7 +19,7 @@ package org.apache.marmotta.platform.core.services.jaxrs;
import org.apache.marmotta.platform.core.api.jaxrs.ExceptionMapperService;
import org.apache.marmotta.platform.core.events.SystemStartupEvent;
-import org.apache.marmotta.platform.core.jaxrs.CDIExceptionMapper;
+import org.apache.marmotta.platform.core.jaxrs.exceptionmappers.CDIExceptionMapper;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.slf4j.Logger;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/InterceptorServiceImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/InterceptorServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/InterceptorServiceImpl.java
new file mode 100644
index 0000000..a9f71bf
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/jaxrs/InterceptorServiceImpl.java
@@ -0,0 +1,73 @@
+/*
+ * 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.services.jaxrs;
+
+import org.apache.marmotta.platform.core.api.jaxrs.InterceptorService;
+import org.apache.marmotta.platform.core.events.SystemStartupEvent;
+import org.apache.marmotta.platform.core.jaxrs.interceptors.CDIInterceptor;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+/**
+ * This service auto-registers JAX-RS interceptors implementing the CDIInterceptor interface and
+ * registers them with RESTEasy. This allows applications based on Marmotta to easily implement and register their
+ * own Interceptors without needing to go into RESTEasy.
+ * <p/>
+ * Note that Interceptors that are injected via CDI need to be annotated with @Dependent, or otherwise
+ * they will be proxied by the CDI implementation and then the generic type cannot be determined.
+ *
+ * @author Jakob Frank (jakob@apache.org)
+ */
+@ApplicationScoped
+public class InterceptorServiceImpl implements InterceptorService {
+
+ private Logger log = LoggerFactory.getLogger(InterceptorServiceImpl.class);
+
+ @Inject
+ private Instance<CDIInterceptor> interceptors;
+
+ @PostConstruct
+ protected void initialize() {
+ ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
+
+ register(factory);
+ }
+
+ public void register(ResteasyProviderFactory factory) {
+ log.info("initialising JAX-RS interceptors");
+
+ for(CDIInterceptor interceptor : interceptors) {
+ log.debug("registering interceptor: {}", interceptor.getClass().getName());
+
+ factory.registerProviderInstance(interceptor);
+ }
+ }
+
+ // trigger startup once configuration service is finished with initialisation
+ protected void initEvent(@Observes SystemStartupEvent e) {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
index 08c669e..b4ca6af 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/system/SystemWebService.java
@@ -18,7 +18,7 @@
package org.apache.marmotta.platform.core.webservices.system;
import org.apache.marmotta.platform.core.api.triplestore.SesameService;
-import org.apache.marmotta.platform.core.jaxrs.ErrorResponse;
+import org.apache.marmotta.platform.core.jaxrs.exceptionmappers.ErrorResponse;
import org.slf4j.Logger;
import javax.enterprise.context.ApplicationScoped;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/eddba62b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
index 29640f9..8b43be2 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/JettyMarmotta.java
@@ -18,6 +18,7 @@
package org.apache.marmotta.platform.core.test.base;
import org.apache.marmotta.platform.core.services.jaxrs.ExceptionMapperServiceImpl;
+import org.apache.marmotta.platform.core.services.jaxrs.InterceptorServiceImpl;
import org.apache.marmotta.platform.core.servlet.MarmottaResourceFilter;
import org.apache.marmotta.platform.core.test.base.jetty.TestApplication;
import org.apache.marmotta.platform.core.test.base.jetty.TestInjectorFactory;
@@ -135,13 +136,22 @@ public class JettyMarmotta extends AbstractMarmotta {
log.error("could not start up embedded jetty server", e);
}
- // make sure exception mappers are loaded and registered before jetty starts up
+ // make sure exception mappers are loaded and registered
ExceptionMapperServiceImpl mapperService = CDIContext.getInstance(ExceptionMapperServiceImpl.class);
try {
mapperService.register(((HttpServletDispatcher) restEasyFilter.getServlet()).getDispatcher().getProviderFactory());
} catch (ServletException e) {
log.warn("could not register exception mappers");
}
+
+ // make sure interceptors are loaded and registered
+ InterceptorServiceImpl interceptorService = CDIContext.getInstance(InterceptorServiceImpl.class);
+ try {
+ interceptorService.register(((HttpServletDispatcher) restEasyFilter.getServlet()).getDispatcher().getProviderFactory());
+ } catch (ServletException e) {
+ log.warn("could not register interceptors");
+ }
+
}
@Override