| 

.NET C# Java Javascript Exception

Re: Dokumente in Blobs ablegen

Dies ist das Archiv des ehemaligen Forums zum Thema Groovy, Grails, Griffon und Bean Scripting Framework, welches unter groovy-forum.de existierte. Die neue Adresse des Groovy-Forums ist: http://codekicker.de/fragen/themen/groovy.


Re: Dokumente in Blobs ablegen

krey - 12.02.2008 13:40
Hallo,

das sollte dein Problem lösen:

class Anhang {
    byte[] anhang
    static transients = ["anhang"]
/** Don't invoke this.  Used by Hibernate only. */
    void setAnhangBlob(Blob anhangBlob) {
        this.anhang = this.toByteArray(anhangBlob);
    }

    /** Don't invoke this.  Used by Hibernate only. */
    Blob getAnhangBlob() {
        return this.anhang == null ? null : Hibernate.createBlob(this.anhang);
    }

    private byte[] toByteArray(Blob fromBlob) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            return toByteArrayImpl(fromBlob, baos);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (baos != null) {
                try {
                    baos.close();
                } catch (IOException ex) {
                }
            }
        }
    }

    private byte[] toByteArrayImpl(Blob fromBlob, ByteArrayOutputStream baos) throws SQLException, IOException {
        byte[] buf = new byte[4000];
        InputStream is = fromBlob.getBinaryStream();
        try {
            while (1 == 1) {
                int dataSize = is.read(buf);

                if (dataSize == -1)
                    break;
                baos.write(buf, 0, dataSize);
            }
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException ex) {
                }
            }
        }
        return baos.toByteArray();
    }
}


Re: Dokumente in Blobs ablegen

LaermTot - 20.02.2008 10:11
Hallo

ich bin heute leider erst dazugekommen deinen Code zu testen .. ich hab den Code compiliert und entsprechende Views etc. erzeugen lassen.

Wenn ich die Applikation nun starte und ein binäres Dokument, z.B. ein WORD-File ablegen möchte bekomme ich immer folgende Exception:

Message: Invalid property 'anhangBlob' of bean class [Anhang]: Getter for property 'anhangBlob' threw exception; nested exception is java.lang.reflect.InvocationTargetException
Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'anhangBlob' of bean class [Anhang]: Getter for property 'anhangBlob' threw exception; nested exception is java.lang.reflect.InvocationTargetException
Class: AnhangController
At Line: [75]
Code Snippet:
75: if(!anhang.hasErrors() && anhang.save()) {
76: flash.message = "Anhang ${anhang.id} created"

...

org.codehaus.groovy.runtime.InvokerInvocationException: org.springframework.beans.InvalidPropertyException: Invalid property 'anhangBlob' of bean class [Anhang]: Getter for property 'anhangBlob' threw exception; nested exception is java.lang.reflect.InvocationTargetException

	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:92)

	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)

	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:899)

	at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:946)

	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:740)

	at groovy.lang.Closure.call(Closure.java:292)

	at groovy.lang.Closure.call(Closure.java:287)

	at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleAction(SimpleGrailsControllerHelper.java:525)

	at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.executeAction(SimpleGrailsControllerHelper.java:398)

	at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:237)

	at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsControllerHelper.handleURI(SimpleGrailsControllerHelper.java:153)

	at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:88)

	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)

	at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:251)

	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)

	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)

	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)

	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:367)

	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)

	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)

	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)

	at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:268)

	at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)

	at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:197)

	at org.codehaus.groovy.grails.web.util.WebUtils.forwardRequestForUrlMappingInfo(WebUtils.java:184)

	at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:116)

	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)

	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)

	at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:119)

	at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:75)

	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)

	at org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:142)

	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)

	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)

	at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:68)

	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)

	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)

	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)

	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)

	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:183)

	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:138)

	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1089)

	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)

	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)

	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)

	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)

	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)

	at org.mortbay.jetty.Server.handle(Server.java:295)

	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:503)

	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:841)

	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:639)

	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:210)

	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:379)

	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:361)

	at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)

Caused by: org.springframework.beans.InvalidPropertyException: Invalid property 'anhangBlob' of bean class [Anhang]: Getter for property 'anhangBlob' threw exception; nested exception is java.lang.reflect.InvocationTargetException

	at AnhangController$_closure8.doCall(AnhangController.groovy:75)

	at AnhangController$_closure8.doCall(AnhangController.groovy)

Caused by: java.lang.reflect.InvocationTargetException

	... 2 more

Caused by: groovy.lang.MissingPropertyException: No such property: Hibernate for class: Anhang

	at Anhang.getProperty(Anhang.groovy)

	at Anhang.getAnhangBlob(Anhang.groovy:13)

	... 2 more

Was mach ich da falsch ???


Gruß

Volgrrrr


Stelle deine Groovy-Frage jetzt!


Diese Seite zeigt den Thread "Re: Dokumente in Blobs ablegen" der ehemaligen Webseite groovy-forum.de, welche durch einen Serverunfall zerstört wurde. codekicker.de hat viele Konversationen über die beliebte Programmiersprache Groovy und zugehörige Frameworks wie das Grails-Framework retten können.

Hast Du eine Frage zum Thema Groovy, Grails oder allgemein Java? Viele ehemalige groovy-forum.de Mitglieder beantworten dir auf codekicker.de deine Frage! Stelle jetzt eine Frage!

Viele weitere Diskussionen zu Grails und Groovy befinden sich auf der Threadübersicht des alten groovy-forum.de.