我在这里遵循此代码http://helpx.adobe.com/experience-manager/using/submitting-mobile-form-data-cq.html。首先,我尝试使用createuser.json.jsp中的以下代码创建会话,该代码在作者实例上运行并且工作正常 -
<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="org.apache.sling.jcr.api.SlingRepository" %>
<%@ page import="com.day.cq.security.UserManager" %>
<%@ page import="com.day.cq.security.UserManagerFactory" %>
<%@ page import="com.day.cq.security.User" %>
<%@ page import="com.day.cq.security.Authorizable" %>
<%@ page import="com.day.cq.security.profile.Profile" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="javax.jcr.Repository" %>
<%@ page import="javax.jcr.Session" %>
<%@ page import="javax.jcr.SimpleCredentials" %>
<%@ page import="org.apache.jackrabbit.commons.JcrUtils" %>
<%@ page import="org.apache.sling.commons.json.io.*" %><%
final SlingRepository repos = sling.getService(SlingRepository.class);
final UserManagerFactory umFactory = sling.getService(UserManagerFactory.class);
Session session = null;
try{
session = repos.loginAdministrative(null); // I'm able to create session
catch (Exception e)
{
System.out.println("Exception Occured: " + e.getMessage());
}
finally
{
session.logout();
session = null;
}%>
但是上面用于创建会话的代码在发布实例上不起作用。因此,我修改了下面的代码并尝试在作者实例上运行,但在这种情况下,不会调用createuser.json.jsp。我没有看到我添加的Sysout声明 -
<%@include file="/libs/foundation/global.jsp"%>
<%@ page import="org.apache.sling.jcr.api.SlingRepository" %>
<%@ page import="com.day.cq.security.UserManager" %>
<%@ page import="com.day.cq.security.UserManagerFactory" %>
<%@ page import="com.day.cq.security.User" %>
<%@ page import="com.day.cq.security.Authorizable" %>
<%@ page import="com.day.cq.security.profile.Profile" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="javax.jcr.Repository" %>
<%@ page import="javax.jcr.Session" %>
<%@ page import="javax.jcr.SimpleCredentials" %>
<%@ page import="org.apache.jackrabbit.commons.JcrUtils" %>
<%@ page import="org.apache.sling.commons.json.io.*" %><%
final SlingRepository repos = sling.getService(SlingRepository.class);
final UserManagerFactory umFactory = sling.getService(UserManagerFactory.class);
try
{ System.out.println("Hello session creating");
Repository repository = JcrUtils.getRepository("http://somehost:4502/crx");
Session session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()),"crx.default");
System.out.println("session: " + session);
catch (Exception e)
{
System.out.println("Exception Occured: " + e.getMessage());
}
finally
{
session.logout();
session = null;
}%>
如果我删除以下行,则调用createuser.json.jsp。
Repository repository = JcrUtils.getRepository("http://somehost:4502/crx");
Session session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()),"crx.default");
请让我知道我在这里做错了什么。感谢您的帮助。