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/11/05 15:31:01 UTC
[1/4] git commit: MARMOTTA-562: more debugging to see why the the
excepetion mappers get registered twice
Repository: marmotta
Updated Branches:
refs/heads/develop 9dfc605bd -> bc25e3265
MARMOTTA-562: more debugging to see why the the excepetion mappers get registered twice
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/bc25e326
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/bc25e326
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/bc25e326
Branch: refs/heads/develop
Commit: bc25e32651e0021f90e057a73b44c0156342d51d
Parents: 41842d0
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Nov 5 15:30:41 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Nov 5 15:30:50 2014 +0100
----------------------------------------------------------------------
.../core/jndi/MarmottaInitialContextFactoryBuilder.java | 2 +-
.../core/services/jaxrs/ExceptionMapperServiceImpl.java | 7 +------
.../platform/core/test/base/AbstractMarmotta.java | 11 ++++++-----
.../marmotta/platform/core/test/base/JettyMarmotta.java | 1 +
.../platform/core/test/base/TestStoreProvider.java | 2 +-
.../platform/core/test/base/jetty/TestApplication.java | 1 -
.../core/test/base/jetty/TestInjectorFactory.java | 3 +--
.../platform/core/test/jaxrs/ExceptionHandlingTest.java | 4 +---
8 files changed, 12 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jndi/MarmottaInitialContextFactoryBuilder.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jndi/MarmottaInitialContextFactoryBuilder.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jndi/MarmottaInitialContextFactoryBuilder.java
index fbd988b..0178204 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jndi/MarmottaInitialContextFactoryBuilder.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jndi/MarmottaInitialContextFactoryBuilder.java
@@ -35,7 +35,7 @@ public class MarmottaInitialContextFactoryBuilder implements InitialContextFacto
@Override
public InitialContextFactory createInitialContextFactory(Hashtable<?, ?> hashtable) throws NamingException {
- // check if we are inside the LMF or outside; inside the LMF we return our own context factory,
+ // check if we are inside the Marmotta or outside; inside the Marmotta we return our own context factory,
// outside the system default
try {
return (InitialContextFactory) Thread.currentThread().getContextClassLoader().loadClass(MarmottaContextFactory.class.getName()).getMethod("getInstance").invoke(null);
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/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 918bd86..0c69b54 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
@@ -53,19 +53,15 @@ public class ExceptionMapperServiceImpl implements ExceptionMapperService {
*/
@PostConstruct
public void initialise() {
-
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
-
register(factory);
}
-
public void register(ResteasyProviderFactory factory) {
log.info("initialising JAX-RS exception mappers");
for(CDIExceptionMapper<?> mapper : mappers) {
- log.debug("registering exception mapper: {}", mapper.getClass().getName());
-
+ log.info("registering exception mapper: {}", mapper.getClass().getName());
factory.registerProviderInstance(mapper);
}
}
@@ -75,5 +71,4 @@ public class ExceptionMapperServiceImpl implements ExceptionMapperService {
}
-
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
index 51ca188..c54cbc7 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/AbstractMarmotta.java
@@ -70,12 +70,12 @@ public abstract class AbstractMarmotta {
// put bean manager into JNDI
try {
- new InitialContext().bind("java:comp/BeanManager",container.getBeanManager());
+ new InitialContext().bind("java:comp/BeanManager", container.getBeanManager());
} catch (NamingException e) {
- log.error("error adding bean manager to JNDI",e);
+ log.error("error adding bean manager to JNDI", e);
}
- // create temporary LMF home directory
+ // create temporary marmotta home directory
home = Files.createTempDir();
// create a temporary configuration with an in-memory database URL for H2
@@ -84,7 +84,7 @@ public abstract class AbstractMarmotta {
override.setProperty("logging.template", "/logback-testing.xml");
override.setProperty("testing.enabled", true);
- // initialise LMF using a temporary directory
+ // initialise marmotta using a temporary directory
startupService = getService(MarmottaStartupService.class);
}
@@ -106,16 +106,17 @@ public abstract class AbstractMarmotta {
}
}
-
private void cleanJNDI() {
try {
new InitialContext().unbind("java:comp/env/BeanManager");
} catch (NamingException e) {
}
+
try {
new InitialContext().unbind("java:comp/BeanManager");
} catch (NamingException e) {
}
+
try {
new InitialContext().unbind("java:app/BeanManager");
} catch (NamingException e) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/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 97a7ef1..b4de8b3 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
@@ -32,6 +32,7 @@ import org.eclipse.jetty.servlet.FilterMapping;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/TestStoreProvider.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/TestStoreProvider.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/TestStoreProvider.java
index 5c96803..0f47c7c 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/TestStoreProvider.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/TestStoreProvider.java
@@ -41,7 +41,6 @@ public class TestStoreProvider implements StoreProvider {
private static Logger log = LoggerFactory.getLogger(TestStoreProvider.class);
-
/**
* Create the repository using the sail given as argument. This method is needed because some backends
* use custom implementations of SailRepository.
@@ -84,4 +83,5 @@ public class TestStoreProvider implements StoreProvider {
public boolean isEnabled() {
return true;
}
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestApplication.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestApplication.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestApplication.java
index 8e73fa4..cf51cbf 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestApplication.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestApplication.java
@@ -30,7 +30,6 @@ public class TestApplication extends Application {
// this is a hack, since there is no other way to inject a service class into a JAX-RS application
private static Set<Class<?>> testedWebService;
-
@Override
public Set<Class<?>> getClasses() {
return testedWebService;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
index a322573..e25c965 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
@@ -123,8 +123,7 @@ public class TestInjectorFactory implements InjectorFactory {
*
* @return ResteasyCdiExtension instance
*/
- private ResteasyCdiExtension lookupResteasyCdiExtension()
- {
+ private ResteasyCdiExtension lookupResteasyCdiExtension() {
Set<Bean<?>> beans = manager.getBeans(ResteasyCdiExtension.class);
Bean<?> bean = manager.resolve(beans);
if (bean == null) throw new IllegalStateException("Unable to obtain ResteasyCdiExtension instance.");
http://git-wip-us.apache.org/repos/asf/marmotta/blob/bc25e326/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
index 127d937..d50f3d1 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
@@ -2,7 +2,6 @@ package org.apache.marmotta.platform.core.test.jaxrs;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.ResponseBody;
-import org.apache.commons.io.IOUtils;
import org.apache.marmotta.platform.core.api.config.ConfigurationService;
import org.apache.marmotta.platform.core.exception.MarmottaException;
import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
@@ -55,7 +54,6 @@ public class ExceptionHandlingTest {
getBody();
response.print();
- /*
final ResponseBody responseJson = expect().
log().ifError().
statusCode(404).
@@ -68,7 +66,7 @@ public class ExceptionHandlingTest {
responseJson.print();
Assert.assertEquals(404, responseJson.jsonPath().get("status"));
Assert.assertEquals("Not Found", responseJson.jsonPath().get("reason"));
- */
+
}
}
[2/4] git commit: MARMOTTA-562: impemented basic json message for
http errors
Posted by wi...@apache.org.
MARMOTTA-562: impemented basic json message for http errors
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/3ecce046
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/3ecce046
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/3ecce046
Branch: refs/heads/develop
Commit: 3ecce0469f88e48ae0e0649f6e866323f33a48f1
Parents: 0965f73
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Nov 5 14:29:43 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Nov 5 15:30:50 2014 +0100
----------------------------------------------------------------------
.../commons/http/MarmottaHttpUtils.java | 2 +
.../core/exception/HttpErrorException.java | 6 +-
.../platform/core/jaxrs/ErrorMessage.java | 50 ++++++++++++++
.../HttpErrorExceptionMapper.java | 69 ++++++++++++------
.../core/test/jaxrs/ExceptionHandlingTest.java | 73 ++++++++++++++++++++
5 files changed, 176 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/3ecce046/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
index d1e070c..c0d7ce4 100644
--- a/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
+++ b/commons/marmotta-commons/src/main/java/org/apache/marmotta/commons/http/MarmottaHttpUtils.java
@@ -23,6 +23,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.openrdf.query.resultio.QueryResultFormat;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/3ecce046/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
index 381e9da..aba26cd 100644
--- 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
@@ -24,14 +24,16 @@ import java.util.HashMap;
import java.util.Map;
/**
- * Resource Not Found Exception
+ * HTTP Error 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;
@@ -80,7 +82,7 @@ public class HttpErrorException extends Exception {
* @param msg message
* @param headers custom headers
*/
- public HttpErrorException(int status, String reason, String uri, String msg, Map<String,String> headers) {
+ public HttpErrorException(int status, String reason, String uri, String msg, Map<String, String> headers) {
super(msg);
this.status = status;
this.reason = reason;
http://git-wip-us.apache.org/repos/asf/marmotta/blob/3ecce046/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorMessage.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorMessage.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorMessage.java
new file mode 100644
index 0000000..b80560f
--- /dev/null
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/jaxrs/ErrorMessage.java
@@ -0,0 +1,50 @@
+/**
+ * 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.HttpErrorException;
+
+/**
+ * Error Message for serialization purposes
+ *
+ * @author Sergio Fernández
+ */
+public class ErrorMessage {
+
+ public String uri;
+
+ public int status;
+
+ public String reason;
+
+ public String message;
+
+ public ErrorMessage(String uri, int status, String reason, String message) {
+ this.status = status;
+ this.reason = reason;
+ this.message = message;
+ }
+
+ public ErrorMessage(HttpErrorException exception) {
+ this.uri = exception.getUri();
+ this.status = exception.getStatus();
+ this.reason = exception.getReason();
+ this.message = exception.getMessage();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/3ecce046/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
index 69aabfe..d91cc43 100644
--- 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
@@ -18,9 +18,12 @@ package org.apache.marmotta.platform.core.jaxrs.exceptionmappers;
import freemarker.template.TemplateException;
import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.http.ContentType;
+import org.apache.marmotta.commons.http.MarmottaHttpUtils;
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.apache.marmotta.platform.core.jaxrs.ErrorMessage;
import org.slf4j.Logger;
import javax.enterprise.context.Dependent;
@@ -30,6 +33,7 @@ import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -64,34 +68,55 @@ public class HttpErrorExceptionMapper implements CDIExceptionMapper<HttpErrorExc
*/
@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("message", exception.getMessage());
- if (StringUtils.isNotBlank(exception.getUri())) {
- data.put("uri", exception.getUri());
- try {
- data.put("encoded_uri", URLEncoder.encode(exception.getUri(), "UTF-8"));
- } catch (UnsupportedEncodingException uee) {
- data.put("encoded_uri", exception.getUri());
+ final Map<String, String> exceptionHeaders = exception.getHeaders();
+
+ boolean htmlError = true; //HTML still by default
+ if (exceptionHeaders.containsKey("Accept")) {
+ final String acceptHeader = exceptionHeaders.get("Accept");
+ final ContentType bestContentType = MarmottaHttpUtils.bestContentType(Arrays.asList(MarmottaHttpUtils.parseContentType("text/html"), MarmottaHttpUtils.parseContentType("application/json")),
+ Arrays.asList(MarmottaHttpUtils.parseContentType(acceptHeader)));
+ if (bestContentType.matches(MarmottaHttpUtils.parseContentType("application/json"))) {
+ htmlError = false;
}
- } else {
- data.put("uri", "");
- data.put("encoded_uri", "");
}
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());
+ if (htmlError) {
+ //html rendering
+ Map<String, Object> data = new HashMap<>();
+ data.put("status", exception.getStatus());
+ data.put("reason", exception.getReason());
+
+ data.put("message", exception.getMessage());
+ if (StringUtils.isNotBlank(exception.getUri())) {
+ data.put("uri", exception.getUri());
+ try {
+ data.put("encoded_uri", URLEncoder.encode(exception.getUri(), "UTF-8"));
+ } catch (UnsupportedEncodingException uee) {
+ data.put("encoded_uri", exception.getUri());
+ }
+ } else {
+ data.put("uri", "");
+ data.put("encoded_uri", "");
+ }
+
+ try {
+ responseBuilder = Response.status(exception.getStatus()).entity(templatingService.process(TEMPLATE, data));
+ } catch (IOException | TemplateException e) {
+ log.error("Error rendering html error template {}: {}", TEMPLATE, e.getMessage());
+ responseBuilder = Response.status(exception.getStatus()).entity(e.getMessage());
+ }
+ } else {
+ //simple json error message
+ responseBuilder = Response.status(exception.getStatus()).entity(new ErrorMessage(exception));
}
- Response response = responseBuilder.build();
- for (Map.Entry<String, String> entry : exception.getHeaders().entrySet()) {
- response.getMetadata().add(entry.getKey(), entry.getValue());
+
+ //forward headers
+ for (Map.Entry<String, String> entry : exceptionHeaders.entrySet()) {
+ responseBuilder.header(entry.getKey(), entry.getValue());
}
- return response;
+
+ return responseBuilder.build();
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/3ecce046/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
new file mode 100644
index 0000000..61677c0
--- /dev/null
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
@@ -0,0 +1,73 @@
+package org.apache.marmotta.platform.core.test.jaxrs;
+
+import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.response.ResponseBody;
+import org.apache.commons.io.IOUtils;
+import org.apache.marmotta.platform.core.api.config.ConfigurationService;
+import org.apache.marmotta.platform.core.exception.MarmottaException;
+import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
+import org.apache.marmotta.platform.core.webservices.resource.ResourceWebService;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.rio.RDFParseException;
+
+import java.io.IOException;
+
+import static com.jayway.restassured.RestAssured.expect;
+
+/**
+ * Test for exceptions handling
+ *
+ * @author Sergio Fernández
+ */
+public class ExceptionHandlingTest {
+
+ private static JettyMarmotta marmotta;
+
+ @BeforeClass
+ public static void setUp() throws RepositoryException, IOException, RDFParseException {
+ marmotta = new JettyMarmotta("/marmotta", ResourceWebService.class);
+
+ RestAssured.baseURI = "http://localhost";
+ RestAssured.port = marmotta.getPort();
+ RestAssured.basePath = marmotta.getContext();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ marmotta.shutdown();
+ }
+
+ @Test
+ public void testNotFound() throws MarmottaException, IOException {
+
+ final ResponseBody response = expect().
+ log().ifError().
+ statusCode(404).
+ contentType("text/html").
+ given().
+ header("Accept", "text/html").
+ when().
+ get(ConfigurationService.RESOURCE_PATH + "/foo").
+ getBody();
+ response.print();
+
+ final ResponseBody responseJson = expect().
+ log().ifError().
+ statusCode(404).
+ contentType("application/json").
+ given().
+ header("Accept", "application/json").
+ when().
+ get(ConfigurationService.RESOURCE_PATH + "/foo").
+ getBody();
+ responseJson.print();
+ Assert.assertEquals(404, responseJson.jsonPath().get("status"));
+ Assert.assertEquals("Not Found", responseJson.jsonPath().get("reason"));
+
+ }
+
+}
[4/4] git commit: MARMOTTA-562: fixed potential npe rendering
exceptions
Posted by wi...@apache.org.
MARMOTTA-562: fixed potential npe rendering exceptions
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/0965f73f
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/0965f73f
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/0965f73f
Branch: refs/heads/develop
Commit: 0965f73f27e49efc67fde688f81895cc14cadf04
Parents: 9dfc605
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Nov 5 11:47:35 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Nov 5 15:30:50 2014 +0100
----------------------------------------------------------------------
.../exceptionmappers/HttpErrorExceptionMapper.java | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/0965f73f/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
index 99adeba..69aabfe 100644
--- 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
@@ -17,6 +17,7 @@
package org.apache.marmotta.platform.core.jaxrs.exceptionmappers;
import freemarker.template.TemplateException;
+import org.apache.commons.lang3.StringUtils;
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;
@@ -66,12 +67,18 @@ public class HttpErrorExceptionMapper implements CDIExceptionMapper<HttpErrorExc
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());
+ if (StringUtils.isNotBlank(exception.getUri())) {
+ data.put("uri", exception.getUri());
+ try {
+ data.put("encoded_uri", URLEncoder.encode(exception.getUri(), "UTF-8"));
+ } catch (UnsupportedEncodingException uee) {
+ data.put("encoded_uri", exception.getUri());
+ }
+ } else {
+ data.put("uri", "");
+ data.put("encoded_uri", "");
}
Response.ResponseBuilder responseBuilder;
[3/4] git commit: MARMOTTA-562: fixed lmf label
Posted by wi...@apache.org.
MARMOTTA-562: fixed lmf label
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/41842d07
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/41842d07
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/41842d07
Branch: refs/heads/develop
Commit: 41842d07e575a0063aeb980aa794cb08631d986e
Parents: 3ecce04
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Nov 5 14:32:09 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Nov 5 15:30:50 2014 +0100
----------------------------------------------------------------------
.../platform/core/test/base/jetty/TestInjectorFactory.java | 2 +-
.../marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/41842d07/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
index b712f35..a322573 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/base/jetty/TestInjectorFactory.java
@@ -61,7 +61,7 @@ public class TestInjectorFactory implements InjectorFactory {
this.delegate = ResteasyProviderFactory.getInstance().getInjectorFactory();
this.extension = lookupResteasyCdiExtension();
- log.info("creating new RestEasy Injector Factory for LMF Test Environment");
+ log.info("creating new RestEasy Injector Factory for Marmotta Test Environment");
}
public static void setManager(BeanManager manager) {
http://git-wip-us.apache.org/repos/asf/marmotta/blob/41842d07/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
index 61677c0..127d937 100644
--- a/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
+++ b/platform/marmotta-core/src/test/java/org/apache/marmotta/platform/core/test/jaxrs/ExceptionHandlingTest.java
@@ -55,6 +55,7 @@ public class ExceptionHandlingTest {
getBody();
response.print();
+ /*
final ResponseBody responseJson = expect().
log().ifError().
statusCode(404).
@@ -67,7 +68,7 @@ public class ExceptionHandlingTest {
responseJson.print();
Assert.assertEquals(404, responseJson.jsonPath().get("status"));
Assert.assertEquals("Not Found", responseJson.jsonPath().get("reason"));
-
+ */
}
}