I want to get an object of CSSimplefile in livesite controller so that I can set extended attributes to the given file.
Are you baking your HTML? Because if you're deploying to the livesite runtime, your requirement doesn't make much sense. In that scenario, you'd want to get this content from LSCS.
You can get your CSClient in the usual way for servlets and JSPs -- by using request.getAttribute("iw.csclient"). Otherwise, there's a bean that's also defined for you somewhere. However, referencing any CSSDK packages on the runtime side will cause an immediate LinkageError.
I am not going to deploy it to runtime. I just created a form in a component and I am reading the data from a controller and just creating a dcr at some location in teamsite. Now after creation, I want to add extended attributes to the file.
Requirement is weird but need help.
I tried this:
CSClient client = (CSClient)context.getRequest().getAttribute("iw.csclient");System.out.print(client.getCurrentUser());
But its throwing some error. Is this possible in controller ?
Post the stack trace.
2015-02-20 16:03:11,954 INFO [STDOUT] 16:03:11,954 ERROR [PreviewRenderingManager] render: handleException(RuntimeException)2015-02-20 16:03:11,954 INFO [STDOUT] 16:03:11,954 ERROR [PreviewRenderingManager] Unhandled exception thrown during renderingcom.interwoven.livesite.runtime.rendering.RenderingException: Unhandled Exception at com.interwoven.livesite.runtime.rendering.RenderingManager.handleException(RenderingManager.java:1006) at com.interwoven.livesite.runtime.rendering.RenderingManager.render(RenderingManager.java:249) at com.interwoven.livesite.runtime.impl.BaseRequestContext.render(BaseRequestContext.java:233) at com.interwoven.livesite.iw.servlet.preview.PreviewFilter.processRequestFurther(PreviewFilter.java:213) at com.interwoven.livesite.iw.servlet.preview.PreviewFilter.doFilter(PreviewFilter.java:142) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) at java.lang.Thread.run(Thread.java:619)Caused by: java.lang.RuntimeException: Could not invoke method: processRequest, reason: null at com.interwoven.livesite.common.util.ClassUtils.executeMethod(ClassUtils.java:113) at com.interwoven.livesite.common.pojo.PojoMethodCall.executeMethod(PojoMethodCall.java:400) at com.interwoven.livesite.runtime.controller.RuntimeController.execute(RuntimeController.java:162) at com.interwoven.livesite.runtime.controller.RuntimeControllerExecutor.executeComponentControllers(RuntimeControllerExecutor.java:140) at com.interwoven.livesite.runtime.rendering.RenderingManager.doSetupRenderingObjects(RenderingManager.java:476) at com.interwoven.livesite.runtime.rendering.RenderingManager.renderPageGoal(RenderingManager.java:297) at com.interwoven.livesite.runtime.rendering.RenderingManager.render(RenderingManager.java:233) ... 23 moreCaused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.interwoven.livesite.common.util.ClassUtils.executeMethod(ClassUtils.java:105) ... 29 moreCaused by: java.lang.NullPointerException at com.techaspect.custom.ProductController.processRequest(Unknown Source) ... 34 more
Caused by: java.lang.NullPointerException at com.techaspect.custom.ProductController.processRequest(Unknown Source) ... 34 more
Well, you coded something incorrectly in your ProductController. You should compile with the debug flag on, so you ca actually get a line number.
CSClient client = (CSClient) context.getRequest().getAttribute("iw.csclient");
I get the above error, when I add this line of code.
That doesn't mean that this is the line where the NPE happens. There's nothing in this line that can be dereferencing a null object -- unless your context is null?
if(context.getRequest().getAttribute("iw.csclient")==null){ System.out.println("CSClient attribute is null");}else{ System.out.println("client"+context.getRequest().getAttribute("iw.csclient"));}
I tried the above code and got
CSClient attribute is null
context.getRequest()
This is also fine.
I am not using sitepublisher login here. I am just trying to get CSSDK CSClient object through a controller. Is that the issue ?
Hm. I thought it used the same authentication wrapper but maybe not. You should at least have the IWAUTH cookie in place, so grab that from the request and feed it to this method:
public static CSClient getClientFromSession(String sessionId, Map<String, String> params) throws CSException { CSClient rval = null; Properties localProperties = new Properties(); localProperties.setProperty("cssdk.cfg.path", InstalledLocations.getIWHome() + "/cssdk/cssdk.cfg"); if (params != null) { for (Map.Entry<String, String> e : params.entrySet()) { localProperties.put(e.getKey(), e.getValue()); } } CSFactory localFactory = (CSFactory) CSFactory.getFactory(localProperties); rval = localFactory.getClient(sessionId, Locale.getDefault(), "TeamSite", null); return rval; }
Should I pass the IWAUTH cookie value to sessionId ?
Just keeping things in detail.
String sessionId = getCookieByName("IWAUTH", context);Map<String, String> params = new HashMap<String, String>(); params.put("com.interwoven.cssdk.factory.CSFactory","com.interwoven.cssdk.factory.CSJavaFactory");
public CSClient getClientFromSession(String sessionId, Map<String, String> params) throws CSException { CSClient rval = null; Properties localProperties = new Properties(); localProperties.setProperty("cssdk.cfg.path", InstalledLocations.getIWHome() + "/cssdk/cssdk.cfg"); if (params != null) { for (Map.Entry<String, String> e : params.entrySet()) { localProperties.put(e.getKey(), e.getValue()); } } CSFactory localFactory = (CSFactory) CSFactory.getFactory(localProperties); rval = localFactory.getClient(sessionId, Locale.getDefault(), "TeamSite", null); return rval; } public String getCookieByName(String name,RequestContext context) { Cookie[] cookies = context.getRequest().getCookies(); String sessionId = null; for (Cookie cookie : cookies) { if (name.equals(cookie.getName())) { sessionId = cookie.getValue(); } } return sessionId; }