Hi all,I want to integrate an applet into Alfresco. This applet scan a file from device, save it in the local machine and then upload it into Alfresco. To upload the file the applet use Alfresco webservices. This is the code:
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();
}
}
This code return an error when execute this line:
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)
The userName and password are correct. What´s the problem? Does It need more configuration? I never use web services before.Thanks a lot in advance,