Package center.task

Examples of center.task.TaskException


          fis = new FileInputStream(((File) source).getCanonicalPath());
          prc.regResource(fis);
          isr = new java.io.InputStreamReader(fis, "utf-8");
          prc.regResource(isr);
        } catch (FileNotFoundException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (UnsupportedEncodingException e) {
          try {
            fis.close();
          } catch (IOException e1) {
            e1.printStackTrace();
          }
          throw new TaskException(State.DONE_ERR, e);
        } catch (IOException e) {
          try {
            fis.close();
          } catch (IOException e1) {
            e1.printStackTrace();
          }
          throw new TaskException(State.DONE_ERR, e);
        }
      }
      StringBuffer sb = new StringBuffer();
      prc.regResourceName(sb, "msg.full");
      int ch;
      Object r;
      Object prev = null;
      Object o = null;
      try {
        while ((ch = isr.read()) != -1) {
          fss.write((char) ch);
          if (fss.available() > 0)
            while ((r = fss.readObject()) != null) {
              if (r instanceof Skipped) {
                if ((prev != null) && (prev instanceof Prm)) {
                  ((Prm) prev).name = r.toString();
                  try {
                    o = cntx.getPrmByFullName(((Prm) prev).name);
                  } catch(Throwable e) {
                    o = e.getMessage();
                  }
                  String v = o.toString();
                  prc.regResourceName(v, "msg.part");
                  if (!Null.equ(v))
                    sb.append(v);
                  prev = null;
                } else {
                  String v = ((Skipped) r).getValue();
                  prc.regResourceName(v, "msg.part");
                  if (!Null.equ(v))
                    sb.append(v);
                }
                cntx.getPrmByFullName("update");
              } else if (r instanceof Prm) {
                prev = r;
                // System.out.println(r.toString() + "\t=\t" + r.getClass());
              } else {
                prev = null;
              }
            }
        }
        fss.write(FindStringStream.EOF);

        if (fss.available() > 0)
          while ((r = fss.readObject()) != null)
            if (r instanceof Skipped) {
              if ((prev != null) && (prev instanceof Prm)) {
                ((Prm) prev).name = r.toString();
                try {
                  o = cntx.getPrmByFullName(((Prm) prev).name);
                } catch(Throwable e) {
                  o = e.getMessage();
                }
                String v = o.toString();
                prc.regResourceName(v, "msg.part");
                if (!Null.equ(v))
                  sb.append(v);
                prev = null;
              } else {
                String v = ((Skipped) r).getValue();
                prc.regResourceName(v, "msg.part");
                if (!Null.equ(v))
                  sb.append(v);
              }
              cntx.getPrmByFullName("update");
            } else if (r instanceof Prm) {
              prev = r;
              // System.out.println(r.toString() + "\t=\t" + r.getClass());
            } else {
              prev = null;
            }
      } catch (IOException e) {
        throw new TaskException(State.DONE_ERR, e);
      }
    } finally {
      if (fis != null)
        try {
          fis.close();
View Full Code Here


        else prcs.free(p);
        if (r != null)
          r.close();
      }
    } catch (FileNotFoundException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (SAXException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      prc.regResourceName(rown, "row@count");
    }
    String rename = cntx.getPrmString("rename");
    if (x!=null && rename != null) {
View Full Code Here

          if (keyStore1 == null)
            System.out.println("javax.net.ssl.keyStore is not defined");
          else
            System.out.println("javax.net.ssl.keyStore = " + keyStore1);
        } catch (NoSuchProviderException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (NoSuchAlgorithmException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (KeyManagementException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (CertificateException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (UnrecoverableKeyException e) {
          throw new TaskException(State.DONE_ERR, e);
        } catch (KeyStoreException e) {
          throw new TaskException(State.DONE_ERR, e);
        }
      else
        server = HttpServer.create(new InetSocketAddress(port), 0);
      server.createContext(path, new XMLHttpHandler(cntx));
      server.setExecutor(executor);
      server.start();

      Process prc = Process.currentProcess();
      while (true) {
        try {
          if (prc.isWillBreak())
            return State.BROKEN;
          State st = cntx.ta.getState(cntx.id_task);
          if (st.getType().equals(TypeOfState.LAST))
            return st;
          if (st.equals(State.BREAKING))
            return State.BROKEN;
        } catch (SysException ex) {
          ex.printStackTrace();
        }
        Thread.sleep(2000);//!!!
      }
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (InterruptedException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      if (server != null)
        server.stop(0);
    }
  }
View Full Code Here

      if (proxy != null) {
        con = url.openConnection(proxy);
      } else
        con = url.openConnection();
    } catch (MalformedURLException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    }
    Map<String, Object> headers = cntx.getGroupParams(grp_in + ".header");
    String encode = cntx.getPrmNvl("charset", "UTF8");

    Object body = cntx.getPrmByFullName(grp_in + "/body");
    if (body != null) {
      long length = -1;
      con.setDoOutput(true);
      InputStream is = null;
      OutputByteBuffer obb = null;
      if (body instanceof InputStream) {
        try {
          obb = Process.getByteBuffer(8000, (InputStream) body);
          is = obb.getIS();
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else if (body instanceof OutputByteBuffer) {
        obb = (OutputByteBuffer)body;
        is = obb.getIS();
      } else if (body instanceof Element) {
        Element e = (Element) body;
        if (Strings.parseBooleanNvl(cntx.getPrmByFullName("skip-header-xml-body"), false)) {
          String n = e.getNodeName();
          try {
            obb = Process.getByteBuffer(8000, ("<"+n).getBytes(encode));
          } catch (UnsupportedEncodingException e1) {
            throw new TaskException(State.DONE_ERR, e1);
          }
        } else
          obb = Process.getByteBuffer(8000);
        XMLFileWaiter.putStream(e, obb, encode);
        try {
          obb.close();
          length = obb.getLength();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
        is = obb.getIS();
      } else if (body instanceof Document) {
        Document e = (Document) body;
        if (Strings.parseBooleanNvl(cntx.getPrmByFullName("skip-header-xml-body"), false)) {
          String n = e.getDocumentElement().getNodeName();
          try {
            obb = Process.getByteBuffer(8000, ("<"+n).getBytes(encode));
          } catch (UnsupportedEncodingException e1) {
            throw new TaskException(State.DONE_ERR, e1);
          }
        } else
          obb = Process.getByteBuffer(8000);
        XMLFileWaiter.putStream(e, obb, encode);
        try {
          obb.close();
          length = obb.getLength();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
        is = obb.getIS();
      } else {
        String r = Strings.getString(body);
        byte[] b = null;
        try {
          b = r.getBytes(encode);
          length = b.length;
        } catch (UnsupportedEncodingException e) {
          throw new TaskException(State.DONE_ERR, e);
        }
        is = new ByteArrayInputStream(b);
      }
      System.out.println("=============Request=============");
      if (length >= 0) {
        prc.regResourceName(obb, "query.body.length");
        String n = "Content-Length";
        String v = Long.toString(length);
        con.addRequestProperty(n, v);
        System.out.println(((n == null) ? "" : n + ":") + v);
      }
      for(Map.Entry<String, Object> i : headers.entrySet()) {
        String n = i.getKey();
        n = n.substring((grp_in + ".header/").length());
        Object v = i.getValue();
        if (v != null) {
          if (v instanceof Type)
            try {
              v = ((Type)v).getValue(cntx);
            } catch (CalculateException e) {
              v = null;
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
          con.addRequestProperty(n, Strings.getString(v));
          System.out.println(((n == null) ? "" : n + ":") + Strings.getString(v));
        } else
          con.setRequestProperty(n, null);
      }

      {
        int ch = 0;
        try {
          OutputStream os = con.getOutputStream();
          while((ch = is.read()) != -1) {
            System.out.print((char)ch);
            os.write(ch);
          }
          os.write("\r\n".getBytes());
          System.out.print("\r\n");
        } catch (IOException e) {
          throw new TaskException(State.DONE_ERR, e);
        } finally {
          try {
            is.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    } else {
      for(Map.Entry<String, Object> i : headers.entrySet()) {
        String n = i.getKey();
        n = n.substring((grp_in + ".header/").length());
        Object v = i.getValue();
        if (v != null)
          con.addRequestProperty(n, Strings.getString(v));
        else
          con.setRequestProperty(n, null);
      }
    }

    System.out.println("=============Response=============");
    InputStream is = null;
    try {
      Map<String, List<String>> flds = con.getHeaderFields();
      for(Map.Entry<String, List<String>> fld : flds.entrySet()) {
        List<String> val = fld.getValue();
        StringBuffer sb = new StringBuffer();
        for(String v:val) { 
          sb.append(v).append("\r\n");
        }
        if (sb.length() > 0)
          sb.setLength(sb.length() - 2);
        String n = fld.getKey();
        System.out.println(((n == null)? "" : n + ":") + sb.toString());
        cntx.ta.setParamObject(cntx.id_task, grp_out+".header/" + fld.getKey(), sb.toString());
      }
      is = con.getInputStream();
      int l = con.getContentLength();
      int l_b = l >= 0 ? (l < 1024*1024 ? l : 1024*1024) : 8000;
      OutputByteBuffer obb = new OutputByteBuffer(l_b);
      obb.write(is);
      obb.close();
      prc.regResourceName(obb, "msg.body");
      if (Strings.parseBooleanNvl(cntx.getPrmString("save-out-body"), true)) {
        String fn = cntx.getPrmString("filename");
        if (fn == null)
          cntx.ta.setParamObject(cntx.id_task, grp_out + "/body", obb);
        else {
          File f = new File(fn);
          FileOutputStream fos = new FileOutputStream(f.getCanonicalPath());
          InputStream isb = obb.getIS();
          try {
            byte[] buf = new byte[l_b];
            int lr = 0;
            while ((lr = isb.read(buf)) > 0)
              fos.write(buf, 0, lr);
          } finally {
            isb.close();
            fos.close();
          }
          cntx.ta.setParamObject(cntx.id_task, grp_out + "/body", f);
        }
      }
     
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
View Full Code Here

          send_done++;
          prc.regResourceName(send_done, "send_done");
        }
      }
    } catch (UnknownHostException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      poolmsg.free(msg);
      ru.vassaev.core.util.Sockets.close(s);
    }
    return State.DONE_OK;
View Full Code Here

  public State paramsValidateAndPrepare(Context cntx) throws SysException, TaskException {
    file = cntx.getPrmString("file");
    language = cntx.getPrmNvl("language", "ru");
    country = cntx.getPrmNvl("country", "RU");
    if (file == null)
      throw new TaskException(State.DONE_ERR, "Param by name 'file' isn't set");
    File x = new File(file);
    if (!x.exists())
      throw new TaskException(State.DONE_ERR, "There is no file by name "+ file);
    ws = new WorkbookSettings();
    ws.setLocale(new Locale(language, country));

    workbook = null;
    try {
      workbook = Workbook.getWorkbook(x, ws);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (BiffException e) {
      throw new TaskException(State.DONE_ERR, e);
    }
    return null;
  }
View Full Code Here

          cntx.log(false, "Start waiting (", timeout, ")");
          XMLMsg r = ib.takeResponseWithWait(key, timeout); //, id_task, ta, id_processor);
          cntx.log(false, "End waiting");

          if (r == null) {
            throw new TaskException(State.DONE_TOUT, "An expected response was not received on time");
          }
          PrmInterface r_prm = r.getPrmInterface();
          StringList flds = r_prm.getFieldNames();
          for (int j = 0; j < flds.size(); j++) {
            String k = flds.get(j).toString();
            cntx.ta.setParamObject(cntx.id_task, "out." + k, r_prm.getField(k));
          }
        } finally {
          th.interrupt();
        }
      } finally {
        if (is != null)
          is.close();
        s.close();
        freeMsg(m);
      }
      return State.DONE_OK;
    } catch (UnknownHostException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    }
  }
View Full Code Here

          cntx.getPrmByFullName("update_notfound");// Расчитать
                                // параметр
        }
      } catch (SQLException e) {
        cntx.log(false, e.getMessage(), " for SQL:", sql);
        throw new TaskException(State.DONE_ERR, e);
      } finally {
        select.freeStatement(pst);
      }
      return State.DONE_OK;
    } finally {
View Full Code Here

        xr.parse(new InputSource(r));
      } finally {
        r.close();
      }
    } catch (FileNotFoundException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (SAXException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      prc.regResourceName(rown, "row@count");
    }
    String rename = cntx.getPrmString("rename");
    if (x!=null && rename != null) {
View Full Code Here

          prc.start(s.getInputStream());
          sync.wait(timeout);
          result = rm.getResultMsg();
          if (result == null) {
            prc.kill();
            throw new TaskException(State.DONE_TOUT, "Timeout of receiving message");
          }
        }
      } finally {
        prcs.free(prc);
      }
      PrmInterface prmi = result.getPrmInterface();
      StringList flds = prmi.getFieldNames();
      for (String fld : flds) {
        cntx.setPrmByFullName(msg_grp_out + "/" + fld, prmi.getField(fld), false);
      }
    } catch (UnknownHostException e) {
      throw new TaskException(State.DONE_ERR, e);
    } catch (IOException e) {
      throw new TaskException(State.DONE_ERR, e);
    } finally {
      ru.vassaev.core.util.Sockets.close(s);
    }
    return State.DONE_OK;
  }
View Full Code Here

TOP

Related Classes of center.task.TaskException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.