首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到AEM6 ::Sling Servlet 404

找不到AEM6 ::Sling Servlet 404
EN

Stack Overflow用户
提问于 2015-02-25 11:47:57
回答 1查看 5.3K关注 0票数 0

我已经创建了一个具有表单的登录组件,它具有指向指向siteminder URL https://test1-myuhc.uhc.com/siteminderagent/forms/login-aa.fcc的URL的POST操作

代码语言:javascript
复制
<input type="hidden" name="target" value="/bin/uhc/myuhcauthenticationhandler">

在表单内部,“target”隐藏字段是siteminder转发请求的地方。我在这里设置的目标指向一个Sling Servlet。Servlet在某种身份验证后确实重定向到AEM.The中的相应页面,问题是当我提交组件上的登录按钮时,siteminder将请求转发给https://test1-myuhc.uhc.com/bin/uhc/myuhcauthenticationhandler,这给出了一个404错误。当我将目标设置为存在于/content下的某个实际页面时,它可以正常工作。我能做些什么来解决这个问题。

代码如下:

代码语言:javascript
复制
package com.myuhc.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.settings.SlingSettingsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// TODO: Auto-generated Javadoc
/**
 * The Class LoginAuthenticationHandlerServlet.
 */
/*@SlingServlet(
        paths={"/bin/myuhc/authenticationhandler"},
        methods = {"POST","GET"},
        metatype=true
        )*/
@Component(immediate = true, metatype = true)
@Service
@Properties({
        @Property(name = "sling.servlet.paths", value = "/bin/uhc/myuhcauthenticationhandler"),
        @Property(name = "sling.servlet.methods", value = {"GET","POST"}) })
public class LoginAuthenticationHandlerServlet extends SlingAllMethodsServlet {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The Constant log. */
    private static final Logger log = LoggerFactory.getLogger(LoginAuthenticationHandlerServlet.class);

    @Reference
    private SlingSettingsService settingsService;

    /* (non-Javadoc)
     * @see org.apache.sling.api.servlets.SlingAllMethodsServlet#doPost(org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.SlingHttpServletResponse)
     */
    @Override
    protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) {
        try {
            if (settingsService.getRunModes().contains("publish")) {
                //response.setStatus(HttpServletResponse.SC_OK);
                response.setContentType("text/plain");
                Cookie[] cookies = request.getCookies();
                String cookieValue = null;
                String uhcRole = null;
                String uhcaccountstatus = null;
                String url = null;
                String LOGIN_PAGE = "/content/myuhc/en/myuhc-login-page.html";
                String HOME_PAGE = "/content/myuhc/en/myuhc-home-page.html";
                //getting headers
                uhcRole = request.getHeader("uhcRole");
                uhcaccountstatus = request.getHeader("uhcaccountstatus");
                //getting SMRESPONSECODE cookie set by Siteminder
                if (cookies !=null) {
                    for (Cookie cookie : cookies) {
                        if(cookie.getName().equals("SMRESPONSECODE")) {
                            cookieValue = cookie.getValue();
                        }
                        // TODO:: Needs to be validated
                        cookie.setMaxAge(-1);
                    }
                    //Setting the URL by checking the different conditions
                    if (cookieValue !=null) {
                        if (cookieValue.equals("1")) {
                            request.setAttribute("message", "Member not found");
                            url = LOGIN_PAGE;
                        }
                        else if(cookieValue.equals("2")) {
                            request.setAttribute("message", "Wrong password. Please try again.");
                            url = LOGIN_PAGE;
                        }
                        else if((uhcaccountstatus!=null) && !uhcaccountstatus.equals("A") && cookieValue.equals("3")) {
                            request.setAttribute("message", "Member not found");
                            url = LOGIN_PAGE;
                        }
                        else if((uhcaccountstatus!=null) && (uhcRole!=null) && !uhcRole.equals("employer") && uhcaccountstatus.equals("A") && cookieValue.equals("0")) {
                            url = HOME_PAGE;
                        }
                        else if((uhcRole!=null) && uhcRole.equals("employer") && cookieValue.equals("4")) {
                            url = HOME_PAGE;
                        }
                        else if (cookieValue.equals("5") || cookieValue.equals("6")) {
                            request.setAttribute("message", "Member not found or Wrong password");
                            url = LOGIN_PAGE;
                        }

                    }else {
                        log.info("No Cookies found!");
                    }
                }
                //Forwarding the request to the url set above
                request.getRequestDispatcher(url).forward(request, response);
            }
        }
        catch (ServletException e) {
            log.info("Inside ServletException -->"+e.getMessage());
        }
        catch (IOException e) {
            log.info("Inside IOException -->"+e.getMessage());
        }
    }

    /* (non-Javadoc)
     * @see org.apache.sling.api.servlets.SlingAllMethodsServlet#doGet(org.apache.sling.api.SlingHttpServletRequest, org.apache.sling.api.SlingHttpServletResponse)
     */
    @Override
    protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response) {
        try {
            if (settingsService.getRunModes().contains("publish")) {
                //response.setStatus(HttpServletResponse.SC_OK);
                response.setContentType("text/plain");
                Cookie[] cookies = request.getCookies();
                String cookieValue = null;
                String uhcRole = null;
                String uhcaccountstatus = null;
                String url = null;
                String LOGIN_PAGE = "/content/myuhc/en/myuhc-login-page.html";
                String HOME_PAGE = "/content/myuhc/en/myuhc-home-page.html";
                //getting headers
                uhcRole = request.getHeader("uhcRole");
                uhcaccountstatus = request.getHeader("uhcaccountstatus");
                //getting SMRESPONSECODE cookie set by Siteminder
                if (cookies !=null) {
                    for (Cookie cookie : cookies) {
                        if(cookie.getName().equals("SMRESPONSECODE")) {
                            cookieValue = cookie.getValue();
                        }
                        // TODO:: Needs to be validated
                        cookie.setMaxAge(-1);
                    }
                    //Setting the URL by checking the different conditions
                    if (cookieValue !=null) {
                        if (cookieValue.equals("1")) {
                            request.setAttribute("message", "Member not found");
                            url = LOGIN_PAGE;
                        }
                        else if(cookieValue.equals("2")) {
                            request.setAttribute("message", "Wrong password. Please try again.");
                            url = LOGIN_PAGE;
                        }
                        else if((uhcaccountstatus!=null) && !uhcaccountstatus.equals("A") && cookieValue.equals("3")) {
                            request.setAttribute("message", "Member not found");
                            url = LOGIN_PAGE;
                        }
                        else if((uhcaccountstatus!=null) && (uhcRole!=null) && !uhcRole.equals("employer") && uhcaccountstatus.equals("A") && cookieValue.equals("0")) {
                            url = HOME_PAGE;
                        }
                        else if((uhcRole!=null) && uhcRole.equals("employer") && cookieValue.equals("4")) {
                            url = HOME_PAGE;
                        }
                        else if (cookieValue.equals("5") || cookieValue.equals("6")) {
                            request.setAttribute("message", "Member not found or Wrong password");
                            url = LOGIN_PAGE;
                        }

                    }else {
                        log.info("No Cookies found!");
                    }
                }
                //Forwarding the request to the url set above
                request.getRequestDispatcher(url).forward(request, response);
            }
        }
        catch (ServletException e) {
            log.info("Inside ServletException -->"+e.getMessage());
        }
        catch (IOException e) {
            log.info("Inside IOException -->"+e.getMessage());
        }
    }
}

这是表格

代码语言:javascript
复制
<form id="site-login" method="post" action="https://test1-myuhc.uhc.com/siteminderagent/forms/login-aa.fcc">
                    <fieldset class="borderless">
                        <legend class="hide-text">
                           ${xss:encodeForHTML(xssAPI, loginTitle)}
                        </legend>
                        <div>
                            <label for="username" class="micro strong label--inline">${xss:encodeForHTML(xssAPI, usrnamelbl)}</label>
                            <input type="text" id="username" name="USER" class="input--login" />
                        </div>
                        <div>
                            <label for="password" class="micro strong label--inline">${xss:encodeForHTML(xssAPI, pswrdlbl)}</label>
                            <input type="password" id="password" name="PASSWORD" class="input--login" />
                        </div>
                        <button class="button--blue milli float-right">${xss:encodeForHTML(xssAPI, btnlbl)}</button>

                    </fieldset>
                    <input type="hidden" name="IDToken0" value="">
                    <input type="hidden" name="SMENC" value="ISO-8859-1">
                    <input type="hidden" name="SMLOCALE" value="en-us">
                    <input type="hidden" name="target" value="/bin/uhc/myuhcauthenticationhandler">
                    <input type="hidden" name="theme" value="myuhc">
                </form>

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2017-10-02 15:55:52

为servlet命名,如下所示,或者工作区中的任何唯一搜索,该名称应该是唯一的

代码语言:javascript
复制
@SlingServlet(
        paths={"/bin/myuhc/authenticationhandler"},
        methods = {"POST","GET"},
        metatype=true,
        name = "authentication handler servlet" // give name in servlet and build the project
        )

在干净地安装快照jar之后,再次安装快照jar

转到localhost:/system/ console /components (你可以直接进入felix控制台(系统/控制台/包) -> OSGI -> components)

ctrl+f搜索名称(在我们的示例中是“身份验证处理程序servlet”),在那里您将找到servlet的路径。检查以下内容

代码语言:javascript
复制
Implementation Class = LoginAuthenticationHandlerServlet 
sling.servlet.paths = [/bin/myuhc/authenticationhandler]

实现类和路径应该与您的servlet相匹配。如果路径不匹配,这意味着正在命中的servlet url属于其他servlet,而这个servlet甚至可能不存在。另外,仔细检查名称在工作区中应该是唯一的。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28710778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档