Hi,

I am getting a peculiar stack trace upon trying to define the plugin.
do you think it could be caused by using Base2.2 classes in a Base2.1.1
codebase?  i tried to include the revised classes in the plugin JAR.. but
i suppose this probably doesn't work..

i had to include Base2.2 versions of
net.sf.basedb.core.Path
net.sf.basedb.util.FileExportOutputStream
net.sf.basedb.core.plugin.AbstractExporterPlugin
net.sf.basedb.core.plugin.ExportOutputStream
net.sf.basedb.core.plugin.ImmediateDownloadExporter

do you think it would be safe to just replace these files in 2.1.1
and rebuild it?

-keith


Version

        

BASE 2.1.1 (build #2996; schema #20)

Web server

        

Apache Tomcat/5.5.20

Database Dialect

        

org.hibernate.dialect.MySQLInnoDBDialect

JDBC Driver

        

com.mysql.jdbc.Driver (version 3.1)

Java runtime

        

Java(TM) 2 Runtime Environment, Standard Edition 
                                (1.5.0_06-112), 
                                Apple Computer, Inc. <http://apple.com/>

Operating system

        

Mac OS X 
                                ppc
                                10.4.8
                                

Memory

        

Total: 89.1 MB

                                Free: 55.7 MB

                                Max: 494.5 MB

Browser

        

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 
Firefox/1.5.0.8

Error message

        

Could not instantiate plugin class: edu.ucsd.basedb.plugins.DownloadPlugin

Stack trace

        


...at PluginDefinition.newInstance(PluginDefinition.java:930)
...at PluginDefinition.loadPluginInformation(PluginDefinition.java:1026)
...at PluginDefinition.getNew(PluginDefinition.java:140)
...at 
org.apache.jsp.admin.plugindefinitions.index_jsp._jspService(index_jsp.java:160)
...at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
...at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
...at 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
...at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

...at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
...at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
...at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
...at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
...at 
net.sf.basedb.clients.web.servlet.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:71)
...at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
...at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
...at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
...at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
...at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
...at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
...at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
...at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
...at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
...at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
...at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
...at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
...at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
...at java.lang.Thread.run(Thread.java:613)

Caused by: java.util.zip.ZipException
...at java.util.zip.ZipFile.open(Native Method)
...at java.util.zip.ZipFile.(ZipFile.java:203)
...at java.util.jar.JarFile.(JarFile.java:132)
...at java.util.jar.JarFile.(JarFile.java:97)
...at net.sf.basedb.util.JarClassLoader.loadJarFile(JarClassLoader.java:206)
...at net.sf.basedb.util.JarClassLoader.(JarClassLoader.java:144)
...at net.sf.basedb.util.JarClassLoader.getInstance(JarClassLoader.java:85)
...at PluginDefinition.newInstance(PluginDefinition.java:919)
...at PluginDefinition.loadPluginInformation(PluginDefinition.java:1026)
...at PluginDefinition.getNew(PluginDefinition.java:140)
...at 
org.apache.jsp.admin.plugindefinitions.index_jsp._jspService(index_jsp.java:160)
...at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
...at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
...at 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
...at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
...at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
...at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
...at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
...at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
...at 
net.sf.basedb.clients.web.servlet.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:71)
...at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
...at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
...at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
...at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
...at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
...at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
...at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
...at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
...at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
...at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
...at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
...at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
...at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
...at java.lang.Thread.run(Thread.java:613)


> Is there a way to get the Httpresponse object from inside a plugin?  

Not really, since plugins are executed in the background or maybe even 
on a different server.

In the the upcoming 2.2 release we have added the interface 
net.sf.basedb.core.plugin.ImmediateDownloadExporter
that more or less makes it possible for a plugin to send the output to 
the HTTP response. Look at the source code some of the existing export 
plugins (for example HelpExporter) to see how to use it.



/*
        Copyright (C) 2006 Nicklas Nordborg

        This file is part of BASE - BioArray Software Environment.
        Available at http://base.thep.lu.se/

        BASE is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
        as published by the Free Software Foundation; either version 2
        of the License, or (at your option) any later version.

        BASE is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place - Suite 330,
        Boston, MA  02111-1307, USA.
*/
package edu.ucsd.basedb.plugins;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import net.sf.basedb.core.Annotation;
import net.sf.basedb.core.AnnotationType;
import net.sf.basedb.core.BaseException;
import net.sf.basedb.core.BioAssaySet;
import net.sf.basedb.core.DbControl;
import net.sf.basedb.core.File;
import net.sf.basedb.core.Include;
import net.sf.basedb.core.InvalidUseOfNullException;
import net.sf.basedb.core.Item;
import net.sf.basedb.core.ItemParameterType;
import net.sf.basedb.core.ItemQuery;
import net.sf.basedb.core.ItemResultList;
import net.sf.basedb.core.Job;
import net.sf.basedb.core.Permission;
import net.sf.basedb.core.PluginParameter;
import net.sf.basedb.core.ProgressReporter;
import net.sf.basedb.core.RawBioAssay;
import net.sf.basedb.core.RequestInformation;
import net.sf.basedb.core.plugin.About;
import net.sf.basedb.core.plugin.AboutImpl;
import net.sf.basedb.core.plugin.AbstractExporterPlugin;
import net.sf.basedb.core.plugin.ExportOutputStream;
import net.sf.basedb.core.plugin.GuiContext;
import net.sf.basedb.core.plugin.InteractivePlugin;
import net.sf.basedb.core.plugin.Permissions;
import net.sf.basedb.core.plugin.Plugin;
import net.sf.basedb.core.plugin.Request;
import net.sf.basedb.core.plugin.Response;



/**
        An example analysis plugin that creates a new bioassay set 
        by multiplying each intensitity value with the same factor, filtering
        out intensities below a cutoff value.
        
        @base.modified $Date: 2006/12/19 02:54:21 $
        @author Nicklas
        @version 2.0
*/
public class DownloadPlugin 
        extends AbstractExporterPlugin
        implements InteractivePlugin
{

        private static final About about = 
                new AboutImpl
                (
                        "Download RawBioAssay source files",
                        "A plugin that downloads bioassays", 
                        "2.0",
                        "2006, Keith Ching",
                        null,
                        null,
                        "http://bioinformatics-renlab.ucsd.edu";
                );
        /*
        From the AbstractExporterPlugin class
        --------------------------------------------
        */
        private static final Set<GuiContext> guiContexts = 
Collections.singleton(
                new GuiContext(Item.RAWBIOASSAY, GuiContext.Type.LIST)
        );
        
        // Job configuration is created by getConfigureJob()
        private RequestInformation configureJob;
        
        // The selected source bioassay set
        private ItemParameterType<RawBioAssay> rawBioAssaysType;
        private PluginParameter<RawBioAssay> rawBioAssaysParameter;

        private static final Set<Permissions> permissions = new 
HashSet<Permissions>();
        /**
                Create a new plugin instance.
        */
        public DownloadPlugin()
        {}
        
        /*
                From the Plugin interface
                -------------------------------------------
        */
        public About getAbout()
        {
                return about;
        }
        public Plugin.MainType getMainType()
        {
                return Plugin.MainType.EXPORT;
        }
        public boolean supportsConfigurations()
        {
                return false;
        }
        public boolean requiresConfiguration()
        {
                return false;
        }
        
        /**
        Request use access to Experiment:s and read access to RawBioAssay:s, 
ArrayDesign:s, 
        Formulas:s, Job:s and and Reporter:s.
*/
public Collection<Permissions> getPermissions()
{
        if (permissions.size() == 0)
        {
                // Grant write access to RawBioAssays and read access to 
ArrayDesign, File and Reporter
//              permissions.add(new Permissions(Item.EXPERIMENT, null, 
EnumSet.of(Permission.USE)));
                permissions.add(new Permissions(Item.RAWBIOASSAY, null, 
EnumSet.of(Permission.READ)));
                permissions.add(new Permissions(Item.FILE, null, 
EnumSet.of(Permission.CREATE, Permission.WRITE)));
//              permissions.add(new Permissions(Item.FORMULA, null, 
EnumSet.of(Permission.READ)));
                permissions.add(new Permissions(Item.JOB, null, 
EnumSet.of(Permission.READ)));
//              permissions.add(new Permissions(Item.REPORTER, null, 
EnumSet.of(Permission.READ)));
                permissions.add(new Permissions(Item.FILE, null, 
EnumSet.of(Permission.CREATE, Permission.WRITE)));
                permissions.add(new Permissions(Item.DIRECTORY, null, 
EnumSet.of(Permission.CREATE, Permission.WRITE)));
                permissions.add(new Permissions(Item.USER, null, 
EnumSet.of(Permission.READ)));
                permissions.add(new Permissions(Item.CLIENT, null, 
EnumSet.of(Permission.READ)));
        }
        return permissions;
}
        private net.sf.basedb.core.File getRawBioAssayFile(DbControl dc,  
RawBioAssay rawBioAssay){
                net.sf.basedb.core.File file = null;
                if(!rawBioAssay.isAnnotated()){
                        throw new BaseException("RawBioAssay 
"+rawBioAssay.getName()+" has no annotations");
                }
                
                // get all annotation types for rawbioassay
                ItemQuery<AnnotationType> typeQuery = 
AnnotationType.getQuery(Item.RAWBIOASSAY);
                typeQuery.include(Include.MINE, Include.SHARED, 
Include.IN_PROJECT, Include.OTHERS);
                ItemResultList<AnnotationType> typeList = typeQuery.list(dc);
                for(AnnotationType type : typeList){
                        if(type.getName().equals("FileID")){
                                 Annotation ann = 
rawBioAssay.getAnnotationSet().getAnnotation(type);
                                 int fileID = (Integer)ann.getValues().get(0);
                                 file = net.sf.basedb.core.File.getById(dc, 
fileID);
                        }
                }
                if(typeList.isEmpty()){
                  throw new BaseException("No annotations");
                }               
                if(file == null){
          throw new BaseException("FileID not found.");
                }
                
                return file;
        }

        @SuppressWarnings("unchecked")
        protected void performExport(ExportOutputStream out, ProgressReporter 
progress)
        throws IOException
        {
                // Open a connection to the database
                // sc is set by init() method
                DbControl dc = sc.newDbControl();
                try
                {

                        ZipOutputStream zipOut = new ZipOutputStream(new 
BufferedOutputStream(out));
                        zipOut.setMethod(ZipOutputStream.DEFLATED);
                        zipOut.setLevel(6);

                        List<RawBioAssay> sources = 
(List<RawBioAssay>)job.getValues("rawBioAssays");
                        
                        // rawBioAssays parameter
                        if (sources == null || sources.size() == 0)
                        {
                                throw new InvalidUseOfNullException("sources");
                        }
                        final int BUFFER = 2048;
                        byte data[] = new byte[BUFFER];
                        int filecount = 0;
                        for (RawBioAssay rba : sources)
                        {
                                dc.reattachItem(rba);
                                File file = getRawBioAssayFile(dc, rba);

                                if (progress != null){
                                        progress.display( (int) (filecount * 
100 / sources.size()) , "Adding "+file.getName());
                                }
                                
                                InputStream in = file.getDownloadStream(0);
                                BufferedInputStream buf = new 
BufferedInputStream(in, BUFFER);
                                ZipEntry entry = new ZipEntry(file.getName());
                                zipOut.putNextEntry(entry);
                                int count;
                                while((count = buf.read(data, 0, BUFFER)) != 
-1){
                                        zipOut.write(data, 0, count);
                                }
                                buf.close();
                                filecount++;
                                if (progress != null){
                                        progress.display( (int) (filecount * 
100 / sources.size()) , "Added "+file.getName());
                                }
                        }
                        zipOut.close();
                        out.close();
                }catch (BaseException be)
                {
                        // All exceptions must be catched and sent back 
                        // using the response object
                        progress.display(0, be.getMessage());
                }
                finally
                {
                        // IMPORTANT!!! Make sure opened connections are closed
                        if (dc != null) dc.close();
                }
        }
        // -------------------------------------------
        
        /*
                From the InteractivePlugin interface
                -------------------------------------------
        */
        /**
                Return a set containing the context [BIOASSAYSET, ITEM].
        */
        public Set<GuiContext> getGuiContexts()
        {
                return guiContexts;
        }
        /**
                Check if the item is a [EMAIL PROTECTED] BioAssaySet}.
        */
        public String isInContext(GuiContext context, Object item)
        {
                   String message = null;
//                 if (item == null)
//                 {
//                    message = "The object is null";
//                 }
//                 else if (!(item instanceof RawBioAssay))
//                 {
//                    message = "The object is not a RawBioAssay: " + item;
//                 }
                return message;
        }
        /**
                The [EMAIL PROTECTED] Request#COMMAND_CONFIGURE_PLUGIN} command 
will not ask
                for any parameters.
                <p>
                The [EMAIL PROTECTED] Request#COMMAND_CONFIGURE_JOB} command 
will ask for
                a bioassay set, a multiplcation factor and a cutoff value.
        */
        public RequestInformation getRequestInformation(GuiContext context, 
String command)
                throws BaseException
        {
                RequestInformation requestInformation = null;
                if (command.equals(Request.COMMAND_CONFIGURE_JOB))
                {
                        requestInformation = getConfigureJob(context);
                }
                return requestInformation;
        }
        /**
                Store configuration settings for [EMAIL PROTECTED] 
Request#COMMAND_CONFIGURE_PLUGIN} and
                [EMAIL PROTECTED] Request#COMMAND_CONFIGURE_JOB}.
        */
        public void configure(GuiContext context, Request request, Response 
response)
        {
                String command = request.getCommand();
                try
                {
                        if (command.equals(Request.COMMAND_CONFIGURE_JOB))
                        {
                                List<Throwable> errors = 
                                        
validateRequestParameters(getConfigureJob(context).getParameters(), request);
                                if (errors != null)
                                {
                                        response.setError(errors.size()+" 
invalid parameter(s) were found in the request", errors);
                                        return;
                                }

                                storeValues(job, request, 
rawBioAssaysParameter);
                                response.setDone("Job configuration complete", 
Job.ExecutionTime.SHORT);
                                // TODO - maybe check file size to make a 
better estimate
                        }
                }
                catch (Throwable ex)
                {
                        response.setError(ex.getMessage(), Arrays.asList(ex));
                }
        }
        // -------------------------------------------

        
        
        private RequestInformation getConfigureJob(GuiContext context)
        {
                if (configureJob == null)
                {
                        DbControl dc = sc.newDbControl();
                        Set<Integer> rawset = 
sc.getCurrentContext(Item.RAWBIOASSAY).getSelected();
                        List<RawBioAssay> rawBioAssays = new 
ArrayList<RawBioAssay>();
                        for (Integer rawid : rawset) {
                                rawBioAssays.add(RawBioAssay.getById(dc, 
rawid.intValue()));
                        }

                        rawBioAssaysType = new 
ItemParameterType<RawBioAssay>(RawBioAssay.class, null, true, 0, rawBioAssays);
                        rawBioAssaysParameter = new 
PluginParameter<RawBioAssay>(
                                "rawBioAssays", "Raw bioassays", "Select the 
raw bioassays to download",
                                rawBioAssaysType);
                        
                        
                        // Create parameter list and request informaion
                        List<PluginParameter<?>> parameters = new 
ArrayList<PluginParameter<?>>();
                        parameters.add(rawBioAssaysParameter);

                        
                        configureJob = new RequestInformation
                        (
                                Request.COMMAND_CONFIGURE_JOB,
                                "Specify rawbioassays to download",
                                about.getDescription(),
                                parameters
                        );
                        // close the connection
                        if (dc != null) dc.close();
                }
                return configureJob;
        }

        
}



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
The BASE general discussion mailing list
basedb-users@lists.sourceforge.net
unsubscribe: send a mail with subject "unsubscribe" to
[EMAIL PROTECTED]

Reply via email to