AnsweredAssumed Answered

Error al subir archivo mediante Webservice

Question asked by kunkunkunkun on Feb 21, 2011
Latest reply on Mar 7, 2011 by kunkunkunkun
Hola, llevo un par de días con el asunto, y no logro sacarlo adelante, la cosa es que tengo hecho un dialog, similar al "add content" , la única diferencia, es que en vez de subir un archivo que tienes almacenado en tu PC, cuando pulsas el botón, éste maneja una clase java que llama al escáner y obtiene la imagen. (hasta ahí bien, y sencillito).
Una vez que tengo la imagen, en un bufferedimage, mi intención es que automáticamente sea subida mediante webservices. Pero pega un error que no consigo acatar :S

Este es el log del error:

javax.faces.FacesException: Error calling action method of component with id dialog:dialog-body:_idJsp19
caused by:
javax.faces.el.EvaluationException: Exception while invoking expression #{formulario.guardar}
caused by:
javax.faces.FacesException: java.lang.NoClassDefFoundError: org/alfresco/webservice/types/Store
caused by:
java.lang.NoClassDefFoundError: org/alfresco/webservice/types/Store

Hide Details

javax.faces.FacesException: Error calling action method of component with id dialog:dialog-body:_idJsp19
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:109)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:110)
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:592)
at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy190.doFilter(Unknown Source)
at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.repo.web.filter.beans.NullFilter.doFilter(NullFilter.java:74)
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:592)
at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:122)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy190.doFilter(Unknown Source)
at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:88)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:655)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{formulario.guardar}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:168)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
… 43 more
Caused by: javax.faces.FacesException: java.lang.NoClassDefFoundError: org/alfresco/webservice/types/Store
at org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:282)
at org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:268)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:49)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:314)
at org.springframework.web.jsf.DelegatingVariableResolver.resolveVariable(DelegatingVariableResolver.java:108)
at org.alfresco.web.app.AlfrescoVariableResolver.resolveVariable(AlfrescoVariableResolver.java:94)
at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(ValueBindingImpl.java:570)
at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:458)
at org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(MethodBindingImpl.java:183)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:117)
… 44 more
Caused by: java.lang.NoClassDefFoundError: org/alfresco/webservice/types/Store
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.myfaces.shared_impl.util.ClassUtils.newInstance(ClassUtils.java:277)
… 54 more

Y aquí está el código de la clase java que maneja esto:


import org.alfresco.webservice.authoring.AuthoringServiceSoapBindingStub;
import org.alfresco.webservice.authoring.CheckoutResult;
import org.alfresco.webservice.content.Content;
import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLAddAspect;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.ContentFormat;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.types.Version;
import org.alfresco.webservice.types.VersionHistory;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.ContentUtils;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;

public class Formulario{
   
   private BufferedImage bimg;
   
    public void guardar(){
      MorenaImage morenaImage;
      MorenaSource scan;
      Image image;      
      //File file = new File("prueba.jpg");      
             
      try{         
         scan = TwainManager.selectSource(null);
            scan.setVisible(false);
           scan.setResolution(300);
           scan.setColorMode();
   
           morenaImage = new MorenaImage(scan);
           image = Toolkit.getDefaultToolkit().createImage(morenaImage);
           bimg = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
           bimg.createGraphics().drawImage(image, 0, 0, null);
            //ImageIO.write(bimg,"jpg", file);
            uploadAlfresco();
      }
      catch(Exception e){
         e.printStackTrace();
      }
    }   

            /*————————————————————————————————–*/           
            /*****************************Subir la imagen al servidor Alfresco***********************************/
            /*————————————————————————————————–*/
   
   private void uploadAlfresco(){
      String serverhost = "http://localhost:8080/Alfresco/api";
       String user = "admin";
       String pass = "admin";
        ByteArrayOutputStream temp;
        int longitud, k;
        URL url, urlImagen;
        HttpURLConnection conexion;
        OutputStream salida;
        InputStream entrada;
           
            try{
               WebServiceFactory.setEndpointAddress(serverhost);
               AuthenticationUtils.startSession(user, pass);
            }
            catch(Exception e){
               e.printStackTrace();
            }
        try{
            //Crear la referencia al nodo padre donde se añadira el contenido
         Store store = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
            ParentReference parentReference = new ParentReference(store, null, "/app:company_home", Constants.ASSOC_CONTAINS, null);

            // Asignamos un nombre para el nodo que vamos a crea en company_home 
            String name = "Imagen (" + System.currentTimeMillis() + ")"; 
            parentReference.setChildName("cm:" + name);               

            // Comienza la construcci—n de nodo
            NamedValue[] properties = new NamedValue[1];
            properties[0] = Utils.createNamedValue(Constants.PROP_NAME, name); 
            CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
           
            // Contruimos CML Block, con el nodo
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] {create});
           
            // Creamos y recuperamos el contenido via Repository Web Service 
            UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
            Reference newContentNode = result[0].getDestination();            
           
            // Escribimos el contenido 
            temp = new ByteArrayOutputStream();
            ImageIO.write(bimg, "jpg", temp);
            temp.close();
           
            longitud = temp.size();
            if( longitud > 1024*1024 )
                throw new Exception("La imagen es demasiado grande");
                              
            byte[] bytes = temp.toByteArray();
           
            ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
            ContentFormat contentFormat = new ContentFormat("image/jpeg", "UTF-8");
            Content content = contentService.write(newContentNode, Constants.PROP_CONTENT, bytes, contentFormat);
                
            AuthenticationUtils.endSession();               
           
       }   
      catch (RemoteException e) {
            e.printStackTrace();
             }
        catch (FileNotFoundException e) {
            e.printStackTrace();
             }
        catch (Exception e) {
            e.printStackTrace();
             }
        finally
        {
            AuthenticationUtils.endSession();
        }   
   }
}   
A ver si alguien es capaz de echarme una mano :)
Gracias!

Outcomes