I am doing openID SSO authentication for my web tool and I am trying to retrieve user email adress for further use. I am trying to use jax-rs service for that. The way I would like it to work is to redirect from jax-rs service to loading.jsp file and then send JQuery ajax call back to jax-rs service to retrieve the email address with securityContext.getUserPrincipal().getName() as a response and then from loading.jsp redirect to index.jsp. First step would be to work it out and understand on my basic localhost app.
The problem however is that I can't serve static file properly in the loading.jsp(nor index.jsp and I guess it is the same reason why I can redirect only to .jsp file not .html) and I am getting 404 error (loading.jsp:9 GET https://localhost:9444/static/js/jquery.min.js net::ERR_ABORTED 404) thus JQuery doesn't work.
Can you pleas help me with ho to serve the static files correctly so the loading.jsp can use JQuery and other static files as well? and index.jsp as well after redirect from loading.jsp.
I have searched trough various topics but I am failing to found out solution applicable specifically for my problem and also since this is my first project I am working on, everything is quite new so I am trying to avoid things like node.js or express.js as I am not very familiar with those yet and I feel I should go by little step. Sometimes the amount of information is messing in my head so I am trying to seek out any help possible as nothing worked so far.
Here is the jax rs service I am using:
package controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
@ApplicationPath("/")
@Path("/")
public class EmployeeResource extends Application{ // Has to extend Application
@Path("/mail")
@GET
@Produces(MediaType.APPLICATION_JSON)
private Response getEmployees(@Context SecurityContext securityContext) throws IOException {
Map<String, String> map= new HashMap<String, String>();
String mail=securityContext.getUserPrincipal().getName();
map.put("email", mail);
return Response
.status(Response.Status.OK)
.entity(map)
.build();
}
@GET
public Response redirect() {
System.out.println("I am in rest");
return Response
.status(Response.Status.MOVED_PERMANENTLY)
.header("Location", "loading.jsp")
.build();
}
}
I thought the problem could be the way I am doing the mapping in the web.xml. I am using websphere which as I understand hasn't default servlet so I have been trying like this(also other options that didn't work):
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<display-name>HelloVladTest</display-name>
<welcome-file-list>
<welcome-file>loading.html</welcome-file>
<welcome-file>loading.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/loading.jsp</url-pattern>
</servlet-mapping>
<security-constraint>
<display-name>SecurityConstraint</display-name>
<web-resource-collection>
<web-resource-name>SecuredResources</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>AllAuthenticated</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
</web-app>
and this is the important part of loading.jsp file where I am failing to load static content so far:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<!-- <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>-->
<script src="static/js/jquery.min.js"> </script>
<title>Insert title here</title>
</head>
<body>
<div id="div1"></div>
LOADING...
<script>
$(document).ready(function(){
});
</script>
</body>
</html>
and this is how I am storing the file in my eclipse dynamic web project:
sorry for size
If I missed some necessary information please let me know and I will add it and please don't be mad at me that there are tons of similar topics as I mentioned I went trough lot of those and so far nothing worked. I am grateful for any help I can get.