Hello!
I want to override the site-index.jsp by changing it redirection option from the user dashboard to the site which the user is a member of, as I saw here:
https://forums.alfresco.com/comment/136003#comment-136003
I created my custom-site-index.jsp to test it following several guides/tutorials on the web but I can't get it to work due to an 401 error (Server returned HTTP response code: 401).
I read everywhere that I need to have an authentication(ticket/token) to be able to call the people API. However, I don't have any clue on how to get access to the People API.
How do I get access to the People API and is it possible to do what I want with the code below?
Thanks in advance!
<%@ page import="org.alfresco.web.site.*"%><%@ page import="org.springframework.extensions.surf.*"%><%@ page import="org.springframework.extensions.surf.site.*"%><%@ page import="org.springframework.extensions.surf.util.*"%><%@ page import="java.util.*"%><%@ page import="java.io.IOException"%><%@ page import="java.net.URL"%><%@ page import="org.apache.commons.io.IOUtils"%><%@ page import="org.json.simple.JSONArray"%><%@ page import="org.json.simple.JSONObject"%><%@ page import="org.json.simple.JSONValue"%><%@ page import="org.json.simple.parser.ParseException"%><%@ page import="org.json.JSONException"%> <% //retrieve user name from the session (site-index OTB fragment)String userid =(String)session.getAttribute(SlingshotUserFactory.SESSION_ATTRIBUTE_KEY_USER_ID); //retrieve JSON array from the people/userid/sitesString url ="http://localhost:8080/alfresco/service/api/people/"+ userid +"/sites";String peopleJson = IOUtils.toString(new URL(url)); JSONObject peopleJsonObject =(JSONObject) JSONValue.parseWithException(peopleJson); // get the site user id(shortName) JSONArray siteArray =(JSONArray) peopleJsonObject.get("shortName");// get the first site JSONObject usersitejson =(JSONObject) siteArray.get(0);String usersite = usersitejson.toString(); // Admin redirection validationif(usersite ==null|| usersite.length()==0|| userid =="admin") // forward to user specific dashboard page(admin){ response.sendRedirect(request.getContextPath()+"/page/user/"+ URLEncoder.encode(userid)+"/dashboard");}else// forward to user respective site documentlibrary { response.sendRedirect(request.getContextPath()+"/page/sites/"+ URLEncoder.encode(usersite)+"/documentlibrary");}%>
Please forgive me for so many not-used dependencies being imported.
SEVERE: Servlet.service()for servlet jsp threw exception java.io.IOException: Server returned HTTP response code:401for URL: http://localhost:8080/alfresco/service/api/people/admin/sites'body'// get the site user id(shortName)66: JSONArray siteArray =(JSONArray) peopleJsonObject.get("shortName"); Stacktrace: at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:460) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) at org.springframework.extensions.surf.render.bean.JSPProcessor.doInclude(JSPProcessor.java:239) at org.springframework.extensions.surf.render.bean.JSPProcessor.executeBody(JSPProcessor.java:154) ... 58 more Caused by: java.io.IOException: Server returned HTTP response code:401for URL: http://localhost:8080/alfresco/service/api/people/admin/sites at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1627) at java.net.URL.openStream(URL.java:1037) at org.apache.commons.io.IOUtils.toString(IOUtils.java:894) at org.apache.commons.io.IOUtils.toString(IOUtils.java:879) at org.apache.jsp.custom_002dsite_002dindex_jsp._jspService(custom_002dsite_002dindex_jsp.java:150) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) ... 72 more