07-07-2011 05:03 PM
System.out.println("ticketFromApplet given to content handler is: " + ticketFromApplet);
System.out.println("NodeRef given to content handler is: " + nodeRef);
Ticket ticket = new Ticket("http://<host>:8080/alfresco", ticketFromApplet);
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
HttpServletRequest request = (HttpServletRequest) MessageContext.getCurrentContext() .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
ServletContext sc = request.getSession().getServletContext();
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
// get registry of services
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
SearchService searchService = serviceRegistry.getSearchService();
ResultSet rs = searchService.query(storeRef,SerchService.LANGUAGE_LUCENE, "ID:\"" + nodeRef + "\"");
ResultSetRow row = rs.getRow(0);
NodeRef docRef = row.getNodeRef();
ContentServiceImpl contentService = new ContentServiceImpl();
contentService.readContentIntoStream(ticket, docRef, QName.createQName("cm:content"), outputStream);07-08-2011 01:38 AM
07-08-2011 04:15 PM
13:09:54,348 INFO [STDOUT] ticketFromApplet given to content handler is: TICKET_30df483da72e1e75cc77015a5cd816aff1c397b4
13:09:54,348 INFO [STDOUT] NodeRef given to content handler is: workspace://SpacesStore/1558798a-941a-4c9f-a2ba-93fa445c44c6
13:09:54,348 INFO [STDOUT] Creating ticket…
13:09:54,348 INFO [STDOUT] Done.. Getting storeRef
13:09:54,348 INFO [STDOUT] getting request…
13:09:54,348 INFO [STDOUT] getting ApplicationContext…
13:09:54,348 ERROR [STDERR] java.lang.NullPointerException
13:09:54,348 ERROR [STDERR] at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:160)07-12-2011 12:58 AM
07-12-2011 04:34 PM
public ServletContext servContext = null;
public void init(javax.servlet.ServletConfig servletConfig) {
this.servContext = servletConfig.getServletContext();
}
public ContentHandlerResult getDocumentContent(
ContentHandlerInput contentHandlerInput) throws FlexSnapSIAPIException {
ContentHandlerResult result = new ContentHandlerResult();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
// now get the content and pass it on to Applet
String ticketFromApplet = contentHandlerInput.getDocumentId();
String nodeRef = contentHandlerInput.getClientInstanceId();
System.out.println("ticketFromApplet given to content handler is: " +
ticketFromApplet);
System.out.println("NodeRef given to content handler is: " +
nodeRef);
System.out.println("Creating ticket…");
Ticket ticket = new Ticket("http://ohqvuda15:8080/alfresco",
ticketFromApplet);
System.out.println("Done.. Getting storeRef");
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
"SpacesStore");
System.out.println("getting request…");
System.out.println("getting ApplicationContext…");
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(servContext);
// get registry of services
System.out.println("Getting service registry…");
ServiceRegistry serviceRegistry = (ServiceRegistry) wc.getBean(ServiceRegistry.SERVICE_REGISTRY);
System.out.println("creating search service");
SearchService searchService = serviceRegistry.getSearchService();
System.out.println("Getting results..");
ResultSet rs = searchService.query(storeRef,
SearchService.LANGUAGE_LUCENE, "ID:\"" + nodeRef + "\"");
System.out.println("getting row 0 from resutl set");
ResultSetRow row = rs.getRow(0);
System.out.println("getting noderef from this row");
NodeRef docRef = row.getNodeRef();
System.out.println("Creating contentserviceImpl");
ContentServiceImpl contentService = new ContentServiceImpl();
System.out.println("Reading content into stream…");
contentService.readContentIntoStream(ticket, docRef,
QName.createQName("cm:content"), outputStream);
System.out.println("Getting bytes out of this stream…");
byte[] binaryData = outputStream.toByteArray();
System.out.println(
"Putting these bytes in ContentHandlerResult …");
try {
result.put("KEY_DOCUMENT_CONTENT", binaryData);
} catch (Exception e) {
e.printStackTrace();
throw new FlexSnapSIAPIException(e.getMessage());
}
System.out.println("Done.");
} catch (FlexSnapSIAPIException flexsnapSIAPIException) {
//throw flexsnapSIAPIException;
flexsnapSIAPIException.printStackTrace();
} catch (Exception ex) {
//throw new FlexSnapSIAPIException(ex.getMessage());
ex.printStackTrace();
} finally {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}13:22:38,294 INFO [STDOUT] ticketFromApplet given to content handler is: TICKET_f623018e59c29d54d9a377b6da4fae513057e2c4
13:22:38,294 INFO [STDOUT] NodeRef given to content handler is: workspace://SpacesStore/1558798a-941a-4c9f-a2ba-93fa445c44c6
13:22:38,294 INFO [STDOUT] Creating ticket…
13:22:38,296 INFO [STDOUT] Done.. Getting storeRef
13:22:38,297 INFO [STDOUT] getting request…
13:22:38,297 INFO [STDOUT] getting ApplicationContext…
13:22:38,297 INFO [STDOUT] Getting service registry…
13:22:38,297 INFO [STDOUT] creating search service
13:22:38,297 INFO [STDOUT] Getting results..
13:22:38,315 ERROR [STDERR] net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
13:22:38,316 ERROR [STDERR] at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:477)
13:22:38,316 ERROR [STDERR] at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:355)
13:22:38,316 ERROR [STDERR] at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
13:22:38,316 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
13:22:38,316 ERROR [STDERR] at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:44)
13:22:38,316 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
13:22:38,316 ERROR [STDERR] at org.alfresco.repo.audit.AuditMethodInterceptor.proceedWithAudit(AuditMethodInterceptor.java:217)
13:22:38,316 ERROR [STDERR] at org.alfresco.repo.audit.AuditMethodInterceptor.proceed(AuditMethodInterceptor.java:184)
13:22:38,316 ERROR [STDERR] at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:137)
13:22:38,317 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
13:22:38,317 ERROR [STDERR] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
13:22:38,317 ERROR [STDERR] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
13:22:38,317 ERROR [STDERR] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
13:22:38,317 ERROR [STDERR] at $Proxy440.query(Unknown Source)
13:22:38,317 ERROR [STDERR] at com.matson.idm.viewstar.alfresco.IDMViewStarContentHandlerForAlfresco.getDocumentContent(Unknown Source)
13:22:38,317 ERROR [STDERR] at com.snowbound.snapserv.servlet.VirtualViewerRetrievalProcessor.getDocumentBytes(VirtualViewerRetrievalProcessor.java:1512)
13:22:38,317 ERROR [STDERR] at com.snowbound.snapserv.servlet.VirtualViewerRetrievalProcessor.getImageData(VirtualViewerRetrievalProcessor.java:279)
13:22:38,317 ERROR [STDERR] at com.snowbound.snapserv.servlet.FlexSnapSIRetrievalServlet.getImageData(FlexSnapSIRetrievalServlet.java:1008)
13:22:38,317 ERROR [STDERR] at com.snowbound.snapserv.servlet.FlexSnapSIRetrievalServlet.getImage(FlexSnapSIRetrievalServlet.java:880)
13:22:38,317 ERROR [STDERR] at com.snowbound.snapserv.servlet.FlexSnapSIRetrievalServlet.service(FlexSnapSIRetrievalServlet.java:182)
13:22:38,317 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
13:22:38,317 ERROR [STDERR] at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
13:22:38,317 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
13:22:38,317 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
13:22:38,317 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
13:22:38,318 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
13:22:38,318 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
13:22:38,318 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
13:22:38,318 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
13:22:38,318 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
13:22:38,318 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
13:22:38,318 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
13:22:38,318 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
13:22:38,318 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
13:22:38,318 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
13:22:38,318 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
13:22:38,318 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
07-13-2011 12:53 AM
07-13-2011 01:54 AM
07-13-2011 03:40 PM
11:41:59,868 INFO [STDOUT] ticketFromApplet given to content handler is: TICKET_a7df7515359d591682144901de6b8ada15c3c369
11:41:59,868 INFO [STDOUT] NodeRef given to content handler is: workspace://SpacesStore/119c7a97-ddc7-468a-8473-dca379f4c447
11:41:59,868 INFO [STDOUT] Creating ticket…
11:41:59,870 INFO [STDOUT] Authenticating …
11:41:59,872 ERROR [STDERR] java.lang.NullPointerException
11:41:59,872 ERROR [STDERR] at org.alfresco.web.app.servlet.AuthenticationHelper.getUser(AuthenticationHelper.java:463)
11:41:59,872 ERROR [STDERR] at org.alfresco.web.app.servlet.AuthenticationHelper.authenticate(AuthenticationHelper.java:170)
11:41:59,872 ERROR [STDERR] at org.alfresco.web.app.servlet.AuthenticationHelper.authenticate(AuthenticationHelper.java:151)
11:41:59,872 ERROR [STDERR] at com.matson.idm.viewstar.alfresco.IDMViewStarContentHandlerForAlfresco.getDocumentContent(Unknown Source)
11:41:59,873 ERROR [STDERR] at com.snowbound.snapserv.servlet.VirtualViewerRetrievalProcessor.getDocumentBytes(VirtualViewerRetrievalProcessor.java:1512)
07-14-2011 03:45 AM
package com.test.servlet;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public class CustomServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doGet(req, resp);
// Get servlet context
ServletContext objContext = getServletConfig().getServletContext();
// NodeRef of the document 1.txt
NodeRef objRef = new NodeRef("workspace://SpacesStore/3bf87bea-41cb-4a93-a98b-38ab3805085c");
// Get webapplication context
WebApplicationContext wc = WebApplicationContextUtils.getRequiredWebApplicationContext(objContext);
ServiceRegistry serviceRegistry = (ServiceRegistry) wc.getBean(ServiceRegistry.SERVICE_REGISTRY);
// Get authentication service
AuthenticationService objService = serviceRegistry.getAuthenticationService();
// MUST TO AVOID THE ERROR - a valid SecureContext was not provided in the RequestContext
// example : req.getParameter("alf_ticket") = TICKET_2fa55c64371087b642fdf8107083456f81fd1e1f
objService.validate(req.getParameter("alf_ticket"));
ContentService contentService = serviceRegistry.getContentService();
// Get the content reader
ContentReader contentReader = contentService.getReader(objRef, ContentModel.PROP_CONTENT);
// Read the data as string
System.out.println("Content Data is :: " + contentReader.getContentString());
}
}
07-15-2011 06:05 PM
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.