09-10-2008 06:36 AM
package org.alfresco.module.demoscripts;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
//import javax.transaction.Status;
import javax.transaction.UserTransaction;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.repo.web.scripts.Repository;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
/**
* Login and establish a ticket
*
* @author davidc
*/
public class JfolderWebScript extends DeclarativeWebScript
{
// dependencies
private static final Log logger = LogFactory.getLog(JfolderWebScript.class);
private AuthenticationService authenticationService;
/**
* @param authenticationService
*/
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
protected ServiceRegistry serviceRegistry ;
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
protected Repository repository;
public void setRepository(Repository repository){
this.repository = repository;
}
private TransactionService transactionService;
public TransactionService getTransactionService() {
return transactionService;
}
public void setTransactionService(TransactionService transactionService) {
this.transactionService = transactionService;
}
protected FileFolderService getFileFolderService()
{
return serviceRegistry.getFileFolderService();
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
// define username and password
String username = "admin";
String password = "ldapadmin";
//get path param
String path = req.getParameter("path");
if (path == null || path.length() == 0)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Path not specified");
}
String nodeId = req.getParameter("node");
UserTransaction txn = null ;
try
{
// get ticket
String currentUser = authenticationService.getCurrentUserName();
if (currentUser.equals("guest")) {
authenticationService.createAuthentication(username, password.toCharArray());
}
txn = transactionService.getUserTransaction();
txn.begin();
StoreRef storeRef = new StoreRef("workspace://SpacesStore");
NodeRef companyHomeRef = this.repository.getCompanyHome();
NodeRef nodeRef = companyHomeRef;
if (nodeId != null) {
nodeRef = new NodeRef(storeRef, nodeId);
}
FileFolderService fileFolderService = this.serviceRegistry.getFileFolderService();
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
List<FileInfo> children = getFileFolderService().listFiles(nodeRef);
Object[] rows = new Object[children.size()];
int i = 0;
for (FileInfo info : children) {
Map<String, Object> row = new HashMap<String, Object>();
row.put("nodeId", info.getNodeRef().getId());
row.put("name", info.getName());
//row.put("title", getProperty(info, ContentModel.PROP_TITLE, ""));
rows[i++] = row;
}
// add ticket to model for javascript and template access
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
model.put("ticket", authenticationService.getCurrentTicket());
model.put("path", path.toString());
model.put("node", nodeRef);
model.put("folderName", fileInfo.getName().toString());
model.put("folderId", nodeRef.getId());
model.put("rows", rows);
txn.commit();
return model;
}
catch (Throwable ex)
{ logger.error("",ex);
try { txn.rollback();}
catch (Exception ex2) { logger.error("Failed to rollback transaction", ex2);}
if (ex instanceof RuntimeException) { throw (RuntimeException) ex;}
else {throw new RuntimeException("Login failed", ex);}
return null;
}
finally
{
authenticationService.clearCurrentSecurityContext();
}
}
}
<bean id="webscript.org.alfresco.demo.jfolder.get" class="org.alfresco.module.demoscripts.JfolderWebScript" parent="webscript"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="repository" ref="webscripts.repo" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="authenticationService" ref="authenticationService" />
<property name="transactionService">
<ref bean="transactionService" />
</property>
</bean>
<exception>java.lang.NullPointerException</exception>
−
<callstack>
java.lang.NullPointerException
org.alfresco.module.demoscripts.JfolderWebScript.executeImpl(JfolderWebScript.java:130)
org.alfresco.web.scripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:251)
org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:87)
org.alfresco.repo.web.scripts.RepositoryContainer$1.execute(RepositoryContainer.java:311)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:236)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:166)
Quelqu'un aurait une idée? 09-10-2008 07:46 AM
Je souhaiterais récupérer les documents d'un espace les lister sous forme de liens pour pouvoir les télécharger par la suite.
09-10-2008 10:12 AM
09-11-2008 07:09 AM
<response>
−
<status>
500
<name>Erreur interne de servlet</name>
−
<description>
Le serveur a recontrer une erreur interne qui l'a empêché de satisfaire la requête.
</description>
</status>
<message/>
<exception>java.lang.NullPointerException</exception>
−
<callstack>
java.lang.NullPointerException
org.alfresco.module.demoscripts.JfolderWebScript.executeImpl(JfolderWebScript.java:66)
org.alfresco.web.scripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:251)
org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:87)
org.alfresco.repo.web.scripts.RepositoryContainer$1.execute(RepositoryContainer.java:311)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:236)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:166)
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:322)
org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:232)
org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:240)
org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)
org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:111)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.alfresco.web.app.servlet.MTWebScriptAuthenticationFilter.doFilter(MTWebScriptAuthenticationFilter.java:102)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
java.lang.Thread.run(Thread.java:595)
</callstack>
−
<server>
Alfresco Community Network v2.9.0 (C_dev 816) schema 124
</server>
<time>11 sept. 2008 11:08:49</time>
</response>
09-15-2008 10:37 AM
<response>
−
<status>
500
<name>Erreur interne de servlet</name>
−
<description>
Le serveur a recontrer une erreur interne qui l'a empêché de satisfaire la requête.
</description>
</status>
<message>Bad credentials presented</message>
−
<exception>
net.sf.acegisecurity.BadCredentialsException - Bad credentials presented
</exception>
−
<callstack>
net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:245)
org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
$Proxy44.getFileInfo(Unknown Source)
org.alfresco.module.demoscripts.JfolderWebScript.executeImpl(JfolderWebScript.java:129)
org.alfresco.web.scripts.DeclarativeWebScript.executeImpl(DeclarativeWebScript.java:251)
org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:87)
org.alfresco.repo.web.scripts.RepositoryContainer$1.execute(RepositoryContainer.java:311)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:236)
org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:166)
org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:322)
org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:232)
org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:240)
org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)
org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:111)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.alfresco.web.app.servlet.MTWebScriptAuthenticationFilter.doFilter(MTWebScriptAuthenticationFilter.java:102)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
java.lang.Thread.run(Thread.java:595)
</callstack>
−
<server>
Alfresco Community Network v2.9.0 (C_dev 816) schema 124
</server>
<time>15 sept. 2008 14:36:46</time>
</response>
package org.alfresco.module.demoscripts;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.security.AuthenticationService;
//import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.repo.web.scripts.Repository;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import javax.transaction.UserTransaction;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.service.cmr.model.FileInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
import java.util.List;
/**
* Login and establish a ticket
*
* @author davidc
*/
public class JfolderWebScript extends DeclarativeWebScript
{
// dependencies
private AuthenticationService authenticationService;
/**
* @param authenticationService
*/
public void setAuthenticationService(AuthenticationService authenticationService)
{
this.authenticationService = authenticationService;
}
protected Repository repository;
public void setRepository(Repository repository){
this.repository = repository;
}
protected ServiceRegistry serviceRegistry ;
public void setServiceRegistry(ServiceRegistry serviceRegistry) {
this.serviceRegistry = serviceRegistry;
}
protected FileFolderService getFileFolderService()
{
return serviceRegistry.getFileFolderService();
}
private TransactionService transactionService;
public void setTransactionService(TransactionService transactionService) {
this.transactionService = transactionService;
}
private static final Log logger = LogFactory.getLog(JfolderWebScript.class);
/* (non-Javadoc)
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status)
{
// define username and password
String username = "admin";
String password = "ldapadmin";
String currentUser = authenticationService.getCurrentUserName();
//execute path
String path = req.getParameter("path");
if (path == null || path.length() == 0)
{
throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "Path not specified");
}
String nodeId = req.getParameter("node");
StoreRef storeRef = new StoreRef("workspace://SpacesStore");
NodeRef companyHomeRef = this.repository.getCompanyHome();
NodeRef nodeRef = companyHomeRef;
if (nodeId != null) {
nodeRef = new NodeRef(storeRef, nodeId);
}
FileFolderService fileFolderService = this.serviceRegistry.getFileFolderService();
UserTransaction txn = null ;
try
{
// get ticket
if (currentUser == null) {
authenticationService.authenticate(username, password.toCharArray());
}
txn = transactionService.getUserTransaction();
ecrivain.println("transactionService is: "+txn);
txn.begin();
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
//List<FileInfo> children = getFileFolderService().listFiles(nodeRef);
txn.commit();
Map<String, Object> model = new HashMap<String, Object>(7, 1.0f);
model.put("ticket", authenticationService.getCurrentTicket());
model.put("path", path.toString());
model.put("node", nodeRef);
return model;
}
catch (Throwable ex)
{ logger.error("",ex);
try { txn.rollback();}
catch (Exception ex2) { logger.error("Failed to rollback transaction", ex2);}
if (ex instanceof RuntimeException) { throw (RuntimeException) ex;}
else {throw new RuntimeException("Login failed", ex);}
}
finally
{
authenticationService.clearCurrentSecurityContext();
}
}
}
<bean id="webscript.org.alfresco.demo.jfolder.get" class="org.alfresco.module.demoscripts.JfolderWebScript" parent="webscript"
abstract="false" singleton="true" lazy-init="default"
autowire="default" dependency-check="default">
<property name="authenticationService" ref="authenticationService" />
<property name="repository" ref="webscripts.repo" />
<property name="serviceRegistry" ref="ServiceRegistry" />
<property name="transactionService" ref="TransactionService" />
</bean>
09-26-2008 05:38 AM
09-26-2008 10:35 AM
10-13-2008 06:33 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.