Hello guys!
In a page, I have a button. The button starts a thread, just like this, but I 
get the exception in the bottom. Here is some code:
      @Override
      protected void onSubmit(final AjaxRequestTarget target, Form<?> form) {
        final FileUpload fileUpload = fileUploadField.getFileUpload();
        if (fileUpload != null) {

          final PhonebookImporter importer = new 
PhonebookImporter(((AppSession) Session.get()).getManager());

          logger.debug("User " + context.getEmail()
              + " uploaded an import file - " + fileUpload.getClientFileName());

          byte[] bytes = fileUpload.getBytes();

          String uploadFolder;

          try {
            uploadFolder = System.getenv("CATALINA_HOME")
                + props.get("uploadFolder");
          } catch (SMSOfficeException e1) {
            logger.error("Could not resolve property!", e1);
            uploadFolder = 
"/home/project/services/apache-tomcat-6.0.20/webapps/ROOT/temp/";
          }

          User currentUser = ((AppSession) Session.get()).getContext()
              .getUser();

          final File uploaded = new File(uploadFolder
              + String.valueOf(currentUser.getId()) + "/" + 
fileUpload.getClientFileName());

          uploaded.getParentFile().mkdirs();

          try {
            FileOutputStream fos = new FileOutputStream(uploaded, false);
            fos.write(bytes);
            fos.close();
            logger.info("File written on " + uploaded.getAbsolutePath());
          } catch (IOException e) {
            logger.error("I/O Exception occurred!", e);
            return;
          }

          final ImportListener listener = new ImportListener() {

            public void info(String object, ImportMessage type) {
              textModel.append(getString(type.toString()) + object + "\n");
            }

          };

          importer.setUser(((AppSession) Session.get()).getContext().getUser());
          importer.setDomain(((AppSession) Session.get()).getContext()
              .getDomain());

          importer.addImportListener(listener);


          new Thread(new Runnable() {

            public void run() {

              try {

                boolean flag = importer.importContacts(uploaded, null);

                if (flag) {
                  BulkImport.this.info(BulkImport.this.getString("imported"));
                  logger.debug("User " + context.getEmail()
                      + " managed to import the contacts!");
                } else {
                  BulkImport.this.error(BulkImport.this.getString("enc_error"));
                  logger.error("User " + context.getEmail()
                      + " did NOT manage to import the contacts!");
                }
              } catch (Exception e) {
                logger.error("User " + context.getEmail()
                    + " did NOT manage to import the contacts!", e);
                
BulkImport.this.error(BulkImport.this.getString("not_imported"));
              }

              importer.removeImportListener(listener);
              target.addComponent(feed);

            }

          }).start();

        } else {
          BulkImport.this.error(getString("no_uploaded_file"));
        }

      }
And the exception:
16-04-2010 14:44:20,175 ERROR 
com.company.project.ui.bulk.BulkImport$2$2.run:183 - User mase...@velti.com did 
NOT manage to import the contacts!
   org.apache.wicket.WicketRuntimeException: There is no application attached 
to current thread Thread-17
            at org.apache.wicket.Application.get(Application.java:179)
            at org.apache.wicket.Component.getApplication(Component.java:1323)
            at org.apache.wicket.Component.getLocalizer(Component.java:1436)
            at org.apache.wicket.Component.getString(Component.java:1903)
            at org.apache.wicket.Component.getString(Component.java:1890)
            at com. 
company.project.ui.bulk.BulkImport$2$1.info(BulkImport.java:153)
            at com. 
company.project.phonebook.bulk.PhonebookImporter.fireImportInfo(PhonebookImporter.java:76)
            at com. 
company.project.core.ManagerBean.saveContacts(ManagerBean.java:212)
            at com. 
company.project.core.ManagerBean$$FastClassByCGLIB$$a2c3fbf0.invoke(<generated>)
            at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
            at 
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:692)
            at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
            at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
            at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
            at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
            at 
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625)
            at com. 
company.project.core.ManagerBean$$EnhancerByCGLIB$$d21cecde.saveContacts(<generated>)
            at com. 
company.project.phonebook.bulk.PhonebookImporter.importContacts(PhonebookImporter.java:127)
            at com. 
company.project.ui.bulk.BulkImport$2$2.run(BulkImport.java:171)
            at java.lang.Thread.run(Thread.java:619)
Thanks for any help in advance!

Best,
Martin

Reply via email to