07-13-2010 06:14 AM
public void saveAlfresco(File file){
String userName = "admin";
String password = "admin";
try
{
String serverhost = "http://localhost:8080/alfresco/api";
// Start the session
System.out.println("Start the session");
AuthenticationUtils.startSession(userName, password);
// Get the content service
System.out.println("Get the content service");
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService(serverhost);
Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String ASSOC_CONTAINS = "{http://www.alfresco.org/model/content/1.0}contains";
String uuid = properties.getProperty("container").toString();
String filename = properties.getProperty("scanFile").toString();
System.out.println("Create a parent reference");
// Create a parent reference, this contains information about the association we are createing to the new content and the
// parent of the new content (the space retrived from the search)
ParentReference parentReference = new ParentReference(store, uuid, null, ASSOC_CONTAINS,
"{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + filename);
System.out.println("Define the content format new ContentFormat('image/tiff', 'UTF-8')");
// Define the content format for the content we are adding
ContentFormat contentFormat = new ContentFormat("image/tiff", "UTF-8");
NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, filename)};
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
Reference newContentNode = result[0].getDestination();
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = ContentUtils.convertToByteArray(fileInputStream);
System.out.println("Add content");
Content content = contentService.write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);
System.out.println("Saved!!!! " + content.getUrl());
}catch (RemoteException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
finally
{
// End the session
AuthenticationUtils.endSession();
}
}
AuthenticationUtils.startSession(userName, password);
and then when it run this line:
AuthenticationUtils.endSession();
the following error appears in Java console:Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/alfresco/webservice/util/AuthenticationUtils
at uk.co.mmscomputing.application.imageviewer.ImageTab.saveAlfresco(ImageTab.java:413)
at uk.co.mmscomputing.application.imageviewer.ImageTab.save(ImageTab.java:347)
at uk.co.mmscomputing.application.imageviewer.ImageTab$3.actionPerformed(ImageTab.java:147)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
07-13-2010 06:16 AM
WebServiceFactory.setEndpointAddress(serverhost);
AuthenticationUtils.startSession(userName, password);
…
Hope this helps.
07-13-2010 06:49 AM
String serverhost = "http://localhost:8080/alfresco/api";
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService(serverhost);
And the folowing error appears in Java console:Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: org/alfresco/webservice/util/AuthenticationUtils
at uk.co.mmscomputing.application.imageviewer.ImageTab.saveAlfresco(ImageTab.java:416)
at uk.co.mmscomputing.application.imageviewer.ImageTab.save(ImageTab.java:347)
at uk.co.mmscomputing.application.imageviewer.ImageTab$3.actionPerformed(ImageTab.java:147)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.alfresco.webservice.util.AuthenticationUtils
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 27 more
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/alfresco/applets/org/alfresco/webservice/util/AuthenticationUtils.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
… 31 more
07-13-2010 07:47 AM
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
Hope this helps.
07-13-2010 09:14 AM
public void saveAlfresco(File file){
String userName = "admin";
String password = "admin";
try
{
String serverhost = "http://localhost:8080/alfresco/api";
WebServiceFactory.setEndpointAddress(serverhost);
// Get the content service
System.out.println("Get the content service");
ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
// Start the session
System.out.println("Start the session");
AuthenticationUtils.startSession(userName, password);
Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
String ASSOC_CONTAINS = "{http://www.alfresco.org/model/content/1.0}contains";
String uuid = properties.getProperty("container").toString();
String filename = properties.getProperty("scanFile").toString();
System.out.println("Create a parent reference");
// Create a parent reference, this contains information about the association we are createing to the new content and the
// parent of the new content (the space retrived from the search)
ParentReference parentReference = new ParentReference(store, uuid, null, ASSOC_CONTAINS,
"{" + Constants.NAMESPACE_CONTENT_MODEL + "}" + filename);
System.out.println("Define the content format new ContentFormat('image/tiff', 'UTF-8')");
// Define the content format for the content we are adding
ContentFormat contentFormat = new ContentFormat("image/tiff", "UTF-8");
NamedValue[] properties = new NamedValue[]{Utils.createNamedValue(Constants.PROP_NAME, filename)};
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
CML cml = new CML();
cml.setCreate(new CMLCreate[]{create});
UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
Reference newContentNode = result[0].getDestination();
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = ContentUtils.convertToByteArray(fileInputStream);
System.out.println("Add content");
Content content = contentService.write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);
System.out.println("Saved!!!! " + content.getUrl());
}catch (RemoteException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
finally
{
// End the session
AuthenticationUtils.endSession();
}
}
Exception in thread "AWT-EventQueue-5" java.lang.NoClassDefFoundError: org/alfresco/webservice/types/Store
at uk.co.mmscomputing.application.imageviewer.MainApp.getCenterPanel(MainApp.java:30)
at uk.co.mmscomputing.util.UtilMainApp.createGUI(UtilMainApp.java:97)
at uk.co.mmscomputing.util.UtilMainApp$2.run(UtilMainApp.java:135)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.alfresco.webservice.types.Store
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 11 more
Caused by: java.io.IOException: open HTTP connection failed:http://192.168.2.24:8080/alfresco/applets/org/alfresco/webservice/types/Store.class
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
… 15 more
07-13-2010 09:32 AM
07-14-2010 07:21 AM
<applet code="uk.co.mmscomputing.application.imageviewer.MainApp.class"
codebase="http://192.168.2.24:8080/alfresco/applets"
archive="scan-plugin-mmsc.jar"
width="100%" height="600">
<PARAM name="scanFile" value="<%= scan.getFileName() %>">
<PARAM name="container" value="<%= scan.getSpaceNodeRef().getId() %>">
Your browser does not support the applet tag.
</applet>
07-21-2010 03:35 AM
<applet code="uk.co.mmscomputing.application.imageviewer.MainApp.class"
codebase="http://192.168.2.24:8080/alfresco/applets"
archive="scan-plugin-mmsc.jar, alfresco-web-service-client-3.2.jar, activation.jar, alfresco-core.jar, axis-1.4.jar, bcprov-jdk15-137.jar, commons-discovery-0.2.jar, commons-logging-1.1.jar, jaxrpc.jar, mail.jar, opensaml-1.0.1.jar, saaj.jar, wsdl4j-1.5.1.jar, wsdl4j-1.6.2.jar, wss4j.jar, xalan.jar, xercesImpl-2.8.0.jar, xmlsec-1.4.1.jar"
width="100%" height="600">
<PARAM name="scanFile" value="<%= scan.getFileName() %>">
<PARAM name="container" value="<%= scan.getSpaceNodeRef().getId() %>">
Your browser does not support the applet tag.
</applet>
07-23-2010 10:46 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.