You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by am...@apache.org on 2017/07/06 00:54:47 UTC
incubator-unomi git commit: UNOMI-101 : Add Exception mapper for
error handling
Repository: incubator-unomi
Updated Branches:
refs/heads/master 8f6f2472d -> be379f8ec
UNOMI-101 : Add Exception mapper for error handling
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/be379f8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/be379f8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/be379f8e
Branch: refs/heads/master
Commit: be379f8eca0a6f804b89d380c5c938dd684bf234
Parents: 8f6f247
Author: Abdelkader Midani <am...@apache.org>
Authored: Thu Jul 6 02:54:45 2017 +0200
Committer: Abdelkader Midani <am...@apache.org>
Committed: Thu Jul 6 02:54:45 2017 +0200
----------------------------------------------------------------------
.../router/rest/ConfigRestExceptionMapper.java | 33 +++++++++
.../ExportConfigurationServiceEndPoint.java | 17 +++--
.../ImportConfigurationServiceEndPoint.java | 11 ++-
.../router/rest/PartialContentException.java | 74 ++++++++++++++++++++
.../resources/OSGI-INF/blueprint/blueprint.xml | 4 ++
5 files changed, 131 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/be379f8e/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ConfigRestExceptionMapper.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ConfigRestExceptionMapper.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ConfigRestExceptionMapper.java
new file mode 100644
index 0000000..179f3d4
--- /dev/null
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ConfigRestExceptionMapper.java
@@ -0,0 +1,33 @@
+/*
+ * 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.unomi.router.rest;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
+/**
+ * Created by amidani on 06/07/2017.
+ */
+public class ConfigRestExceptionMapper implements ExceptionMapper<PartialContentException> {
+
+ @Override
+ public Response toResponse(PartialContentException exception) {
+ return Response.status(Response.Status.PARTIAL_CONTENT).header("Content-Type", MediaType.TEXT_PLAIN).entity(new String(exception.getMessage())).build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/be379f8e/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
index 98dbe18..35d4f34 100644
--- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ExportConfigurationServiceEndPoint.java
@@ -32,10 +32,12 @@ import org.slf4j.LoggerFactory;
import javax.jws.WebMethod;
import javax.jws.WebService;
-import javax.ws.rs.*;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -85,11 +87,16 @@ public class ExportConfigurationServiceEndPoint extends AbstractConfigurationSer
HttpResponse response = httpClient.execute(httpPut);
if (response.getStatusLine().getStatusCode() != 200) {
- throw new RuntimeException("Failed : HTTP error code : "
- + response.getStatusLine().getStatusCode());
+ logger.error("Failed to update the running config: Please check the acceccibilty to the URI: \n{}",
+ "http://localhost:" + configSharingService.getProperty("internalServerPort") + "/configUpdate/importConfigAdmin");
+ logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode());
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
}
- } catch (IOException e) {
+ } catch (Exception e) {
logger.warn("Unable to update Camel route [{}]", exportConfiguration.getItemId());
+ e.printStackTrace();
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/be379f8e/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
index 25ab70d..dec61e0 100644
--- a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/ImportConfigurationServiceEndPoint.java
@@ -83,11 +83,16 @@ public class ImportConfigurationServiceEndPoint extends AbstractConfigurationSer
HttpResponse response = httpClient.execute(httpPut);
if (response.getStatusLine().getStatusCode() != 200) {
- throw new RuntimeException("Failed : HTTP error code : "
- + response.getStatusLine().getStatusCode());
+ logger.error("Failed to update the running config: Please check the acceccibilty to the URI: \n{}",
+ "http://localhost234:" + configSharingService.getProperty("internalServerPort") + "/configUpdate/importConfigAdmin");
+ logger.error("HTTP Status code returned {}", response.getStatusLine().getStatusCode());
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
}
- } catch (IOException e) {
+ } catch (Exception e) {
logger.warn("Unable to update Camel route [{}]", importConfiguration.getItemId());
+ e.printStackTrace();
+ throw new PartialContentException("RUNNING_CONFIG_UPDATE_FAILED");
+
}
}
return importConfigSaved;
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/be379f8e/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/PartialContentException.java
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/PartialContentException.java b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/PartialContentException.java
new file mode 100644
index 0000000..e9f0635
--- /dev/null
+++ b/extensions/router/router-rest/src/main/java/org/apache/unomi/router/rest/PartialContentException.java
@@ -0,0 +1,74 @@
+/*
+ * 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.unomi.router.rest;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public class PartialContentException extends WebApplicationException {
+
+ private static final long serialVersionUID = -6820343767511628388L;
+
+ /**
+ * Construct a new "partial content" exception.
+ */
+ public PartialContentException() {
+ super((Throwable) null, Response.Status.PARTIAL_CONTENT);
+ }
+
+ /**
+ * Construct a new "partial content" exception.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ */
+ public PartialContentException(String message) {
+ super(message, (Throwable) null, Response.Status.PARTIAL_CONTENT);
+ }
+
+ public PartialContentException(String message, Response response) {
+ super(message, (Throwable) null, Response.Status.PARTIAL_CONTENT);
+ }
+
+ /**
+ * Construct a new "partial content" exception.
+ *
+ * @param cause the underlying cause of the exception.
+ */
+ public PartialContentException(Throwable cause) {
+ super(cause, Response.Status.PARTIAL_CONTENT);
+ }
+
+ /**
+ * Construct a new "partial content" exception.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the underlying cause of the exception.
+ */
+ public PartialContentException(String message, Throwable cause) {
+ super(message, cause, Response.Status.PARTIAL_CONTENT);
+ }
+
+ public PartialContentException(Response response, Throwable cause) {
+ super(cause, Response.Status.PARTIAL_CONTENT);
+ }
+
+ public PartialContentException(String message, Response response, Throwable cause) {
+ super(message, cause, Response.Status.PARTIAL_CONTENT);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/be379f8e/extensions/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/extensions/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/extensions/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 9be4a07..ebf1daf 100644
--- a/extensions/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/extensions/router/router-rest/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -36,11 +36,14 @@
<property name="realmName" value="cxs"/>
</bean>
+ <bean id="exceptionMapper" class="org.apache.unomi.router.rest.ConfigRestExceptionMapper"/>
+
<jaxrs:server address="/importConfiguration" id="restImportConfigurationService">
<jaxrs:providers>
<ref component-id="json-provider"/>
<ref component-id="cors-filter"/>
<ref component-id="jaas-filter"/>
+ <ref component-id="exceptionMapper"/>
</jaxrs:providers>
<jaxrs:serviceBeans>
@@ -53,6 +56,7 @@
<ref component-id="json-provider"/>
<ref component-id="cors-filter"/>
<ref component-id="jaas-filter"/>
+ <ref component-id="exceptionMapper"/>
</jaxrs:providers>
<jaxrs:serviceBeans>