As we transition to the new Hyland Community, some post links may be temporarily disrupted as we finalize redirects. We apologize for the inconvenience and are working to resolve this as quickly as possible. Details.
WebServiceFactory.setEndpointAddress(ALFRESCO_WS_API_URL); AuthenticationUtils.startSession(ADMIN_USERNAME, ADMIN_PASSWORD); String mimeType = new MimetypesFileTypeMap().getContentType(file.getNameWithExtension()); ContentFormat contentFormat = new ContentFormat(mimeType,"UTF-8"); Reference reference = new Reference(ConstantsAlfresco.STORE, null, yourFullPathOfTheContent); NamedValue[] properties = createProperties(yourUploadFormBean); //create all the custom properties for your content from your form ParentReference parentRef = new ParentReference(); parentRef.setStore(store); parentRef.setUuid(reference.getUuid()); parentRef.setPath(reference.getPath()); parentRef.setAssociationType(Constants.ASSOC_CONTAINS); parentRef.setChildName(Constants.ASSOC_CONTAINS); CMLCreate create = new CMLCreate(); create.setParent(parentRef); create.setProperty(properties); create.setType(yourCustomContentType); CML cml = new CML(); cml.setCreate(new CMLCreate[] {create}); UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml); ByteArrayOutputStream stream = new ByteArrayOutputStream(); int c; while ((c = form.getFile().getStream().read()) != -1) { stream.write((char) c); } Reference contentNode = result[0].getDestination(); Content content = WebServiceFactory.getContentService().write(contentNode, Constants.PROP_CONTENT, stream.toByteArray(), contentFormat); if (content == null) throw new RemoteException("Error during storing file");
type Status reportmessage /NewAppAlf/StatusMessage.jspdescription The requested resource (/NewAppAlf/StatusMessage.jsp) is not available.
16:46:01,126 INFO [STDOUT] inside try 16:46:01,126 INFO [STDOUT] For Testing Values…. 16:46:01,126 INFO [STDOUT] title::Valuebismlillah 16:46:01,126 INFO [STDOUT] title::::::bismlillah 16:46:01,126 INFO [STDOUT] Description:::::desp 16:46:01,126 INFO [STDOUT] file name:::test_file.doc 16:46:01,126 INFO [STDOUT] file name :::test_file.doc 16:46:01,126 INFO [STDOUT] ext name :::doc 16:46:01,126 INFO [STDOUT] inside alfresco part:::::::: 16:46:02,486 INFO [STDOUT] Error uploading file:::org.alfresco.webservice.util.WebServiceException: Error starting session. 16:46:02,486 ERROR [STDERR] org.alfresco.webservice.util.WebServiceException: Error starting session. 16:46:02,486 ERROR [STDERR] at org.alfresco.webservice.util.AuthenticationUtils.startSession(AuthenticationUtils.java:94) 16:46:02,486 ERROR [STDERR] at upload.doPost(upload.java:174) 16:46:02,486 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:710) 16:46:02,486 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 16:46:02,486 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 16:46:02,486 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182) 16:46:02,486 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 16:46:02,486 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 16:46:02,486 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) 16:46:02,486 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 16:46:02,486 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) 16:46:02,486 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) 16:46:02,486 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619) 16:46:02,486 ERROR [STDERR] Caused by: java.net.ConnectException: Connection refused: connect 16:46:02,486 ERROR [STDERR] at org.apache.axis.AxisFault.makeFault(AxisFault.java:101) 16:46:02,486 ERROR [STDERR] at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154) 16:46:02,486 ERROR [STDERR] at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) 16:46:02,486 ERROR [STDERR] at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) 16:46:02,486 ERROR [STDERR] at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.Call.invokeEngine(Call.java:2784) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.Call.invoke(Call.java:2767) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.Call.invoke(Call.java:2443) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.Call.invoke(Call.java:2366) 16:46:02,486 ERROR [STDERR] at org.apache.axis.client.Call.invoke(Call.java:1812) 16:46:02,486 ERROR [STDERR] at org.alfresco.webservice.authentication.AuthenticationServiceSoapBindingStub.startSession(AuthenticationServiceSoapBindingStub.java:187) 16:46:02,486 ERROR [STDERR] at org.alfresco.webservice.util.AuthenticationUtils.startSession(AuthenticationUtils.java:79) 16:46:02,486 ERROR [STDERR] … 21 more 16:46:02,486 ERROR [STDERR] Caused by: java.net.ConnectException: Connection refused: connect 16:46:02,486 ERROR [STDERR] at java.net.PlainSocketImpl.socketConnect(Native Method) 16:46:02,486 ERROR [STDERR] at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) 16:46:02,486 ERROR [STDERR] at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) 16:46:02,486 ERROR [STDERR] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) 16:46:02,486 ERROR [STDERR] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) 16:46:02,486 ERROR [STDERR] at java.net.Socket.connect(Socket.java:519) 16:46:02,486 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 16:46:02,486 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 16:46:02,486 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 16:46:02,486 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597) 16:46:02,486 ERROR [STDERR] at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153) 16:46:02,486 ERROR [STDERR] at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120) 16:46:02,486 ERROR [STDERR] at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191) 16:46:02,486 ERROR [STDERR] at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404) 16:46:02,486 ERROR [STDERR] at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138) 16:46:02,486 ERROR [STDERR] … 32 more 16:46:02,486 INFO [STDOUT] [Ljava.lang.StackTraceElement;@9882d2 16:46:02,486 INFO [STDOUT] org.alfresco.webservice.util.WebServiceException: Error starting session. 16:46:02,486 INFO [STDOUT] session ending
/** Admin user name and password used to connect to the repository */ protected static final String USERNAME = "admin"; protected static final String PASSWORD = "admin"; /** The store used throughout the samples */ protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore"); protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, "/app:company_home/cm:sample_folder9"); public static void main(String args[]) throws Exception { WebServiceFactory.setEndpointAddress("http://localhost:8080/alfresco/api"); AuthenticationUtils.startSession(USERNAME, PASSWORD); try { // Check to see if the sample folder has already been created or not WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null)); ParentReference parentRef = new ParentReference(); parentRef.setStore(STORE); parentRef.setUuid(SAMPLE_FOLDER.getUuid()); parentRef.setPath(SAMPLE_FOLDER.getPath()); parentRef.setAssociationType(Constants.ASSOC_CONTAINS); parentRef.setChildName(Constants.ASSOC_CONTAINS); NamedValue[] properties2 = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, "SampleContent1.txt")}; CMLCreate create2 = new CMLCreate(); create2.setParent(parentRef); create2.setProperty(properties2); create2.setType(Constants.TYPE_CONTENT); CML cml2 = new CML(); cml2.setCreate(new CMLCreate[] {create2}); UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml2); Reference contentNode = result[0].getDestination(); ContentFormat format = new ContentFormat(Constants.MIMETYPE_TEXT_PLAIN, "UTF-8"); byte[] content = "This is some test content provided by the Alfresco development team!".getBytes(); Content content1 = WebServiceFactory.getContentService().write(contentNode, Constants.PROP_CONTENT, content, format); } catch (Exception e){ e.printStackTrace(); } }
/** Admin user name and password used to connect to the repository */ protected static final String USERNAME = "admin"; protected static final String PASSWORD = "admin"; /** The store used throughout the samples */ protected static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore"); static String parentSpace = "/app:company_home/cm:sample_folder6"; protected static final Reference SAMPLE_FOLDER = new Reference(STORE, null, parentSpace); static String fileName= "SampleContext.txt"; static boolean success = true; protected static void downloadContent() throws Exception { try { // Check to see if the sample folder has already been created or not WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{SAMPLE_FOLDER}, STORE, null)); } catch (Exception exception) { System.out.println("Error while getting repository service"); exception.printStackTrace(); success=false; } } public static void main(String args[]) { try{ AuthenticationUtils.startSession("admin", "admin"); downloadContent(); System.out.println("Success Value is "+success); if(success){ ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService(); System.out.println("ISO9075.encode(fileName)"+ISO9075.encode(fileName)); Reference contentReference = new Reference(STORE,null,parentSpace+"/cm:"+fileName);// Reference contentReference = new Reference(STORE,null,parentSpace); System.out.println("UUID IS …….."+contentReference.getPath()); System.out.println("3"+fileName); Content[] readResult = contentService.read(new Predicate(new Reference[]{contentReference}, STORE, null), Constants.PROP_CONTENT); System.out.println("Before for……."+readResult.length); System.out.println("URL is "+readResult[0].getUrl()); System.out.println("Node is "+readResult[0].getNode().getUuid()); for(Content content: readResult) { String[] splitedUrl = content.getUrl().split("/"); if(splitedUrl[splitedUrl.length-1].equals(fileName)){ System.out.println("Inside If"); InputStream in=ContentUtils.getContentAsInputStream(content); // response.reset(); // response.setHeader ("Content-Disposition", "attachment;filename=\""+fileName+"\""); // ServletOutputStream sosStream = response.getOutputStream(); int ibit = 256; while ((ibit) >= 0) { ibit = in.read(); // sosStream.write(ibit); } // sosStream.flush(); // sosStream.close(); in.close(); } } } }catch (Exception e){ e.printStackTrace(); } }