You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by dg...@apache.org on 2021/03/16 08:00:44 UTC
[unomi] 01/01: DMF-4381 : use url forwarding to move context.json
as a REST endpoint
This is an automated email from the ASF dual-hosted git repository.
dgriffon pushed a commit to branch SPIKE-simple-url-forward
in repository https://gitbox.apache.org/repos/asf/unomi.git
commit edf6fcfd116ffd288ae6723df6e55d57a25c0660
Author: David Griffon <dg...@jahia.com>
AuthorDate: Tue Mar 16 08:58:49 2021 +0100
DMF-4381 : use url forwarding to move context.json as a REST endpoint
---
.../org/apache/unomi/rest/ContextJsonEndpoint.java | 44 ++++++++++++++++++++++
.../java/org/apache/unomi/web/ContextServlet.java | 16 ++++++--
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/rest/src/main/java/org/apache/unomi/rest/ContextJsonEndpoint.java b/rest/src/main/java/org/apache/unomi/rest/ContextJsonEndpoint.java
new file mode 100644
index 0000000..ee85b7d
--- /dev/null
+++ b/rest/src/main/java/org/apache/unomi/rest/ContextJsonEndpoint.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.unomi.rest;
+
+import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing;
+import org.osgi.service.component.annotations.Component;
+
+import javax.jws.WebService;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@WebService
+@Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8")
+@CrossOriginResourceSharing(
+ allowAllOrigins = true,
+ allowCredentials = true
+)
+@Path("/")
+@Component(service=ContextJsonEndpoint.class,property = "osgi.jaxrs.resource=true")
+public class ContextJsonEndpoint {
+ @GET
+ @Path("/context.json")
+ public String get(@HeaderParam("Accept-Language") String language) {
+ return "{\"context\":\"alive\"}";
+ }
+}
diff --git a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
index f45a891..f1c66d7 100644
--- a/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
+++ b/wab/src/main/java/org/apache/unomi/web/ContextServlet.java
@@ -28,10 +28,7 @@ import org.apache.unomi.persistence.spi.CustomObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
+import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -72,6 +69,17 @@ public class ContextServlet extends HttpServlet {
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ if (true) {
+ RequestDispatcher dispatcher = getServletContext().getContext("/cxs")
+ .getRequestDispatcher("/cxs/context.json");
+ try {
+ dispatcher.forward(request, response);
+ return;
+ } catch (ServletException e) {
+ logger.error(e.getMessage());
+ }
+ }
+
try {
final Date timestamp = new Date();
if (request.getParameter("timestamp") != null) {