コード例 #1
0
  @Override
  protected String send(String serviceName, String routine, String serialise)
      throws ServerInvokationException {
    try {
      String url =
          "http://" + this.host + "/" + serviceName + "/" + URLEncoder.encode(routine, "UTF-8");
      Log.L.finer(url + "?" + serialise);
      String red = br.postPageRaw(url, serialise);

      URLConnectionAdapter con = br.getHttpConnection();
      if (con.getResponseCode() == HTTPConstants.ResponseCode.SUCCESS_OK.getCode()) {
        return red;
      } else if (con.getResponseCode()
          == HTTPConstants.ResponseCode.SERVERERROR_INTERNAL.getCode()) {
        // Exception
        throw new ServerInvokationException(red, new Requestor(serviceName, routine, serialise));
      } else {
        throw new RemoteCallCommunicationException("Wrong ResponseCode " + con.getResponseCode());
      }
    } catch (final ServerInvokationException e) {
      throw e;
    } catch (final IOException e) {

      throw new RemoteCallCommunicationException(e);
    } catch (final Exception e) {
      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      }
      throw new RuntimeException(e);
    }
  }
コード例 #2
0
ファイル: Loc.java プロジェクト: amicom/my-project
    /**
     * Creates a HashMap with the data obtained from the localization file. <br>
     * <b>Warning:</b> Overwrites any previously created HashMap
     * 
     * @param file
     *            {@link RFSFile} object to the localization file
     * @throws IllegalArgumentException
     *             if the parameter is null or doesn't exist
     * @see Loc#DATA
     */
    public static void parseLocalization(final URL file) throws IllegalArgumentException {
        if (file == null) { throw new IllegalArgumentException(); }

        if (Loc.DATA != null) {
            Log.L.finer("Previous HashMap will be overwritten!");
        }
        Loc.DATA = new HashMap<Integer, String>();

        BufferedReader reader = null;
        InputStreamReader isr = null;
        InputStream fis = null;
        try {
            reader = new BufferedReader(isr = new InputStreamReader(fis = file.openStream(), "UTF8"));

            String line;
            String key;
            String value;
            int split;
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("#")) {
                    continue;
                }

                if ((split = line.indexOf('=')) <= 0) {
                    continue;
                }

                key = line.substring(0, split).toLowerCase().trim();
                value = line.substring(split + 1).trim();
                value = value.replace("\\n", "\n").replace("\\r", "\r");

                Loc.DATA.put(key.hashCode(), value);
            }
        } catch (final FileNotFoundException e) {
            throw new IllegalArgumentException(e);
        } catch (final Exception e) {
            org.appwork.utils.logging.Log.exception(e);
        } finally {
            try {
                reader.close();
            } catch (final Throwable e) {
            }
            try {
                isr.close();
            } catch (final Throwable e) {
            }
            try {
                fis.close();
            } catch (final Throwable e) {
            }
        }
    }
コード例 #3
0
  @SuppressWarnings("unchecked")
  private void loadUnpacked() {
    URL ret = getClass().getResource("/");
    File root;
    if (ret.getProtocol().equalsIgnoreCase("file")) {
      try {
        root = new File(ret.toURI());
      } catch (URISyntaxException e) {
        Log.exception(e);
        Log.L.finer("Did not load unpacked Extensions from " + ret);
        return;
      }
    } else {
      Log.L.finer("Did not load unpacked Extensions from " + ret);
      return;
    }
    root = new File(root, AbstractExtension.class.getPackage().getName().replace('.', '/'));
    Log.L.finer("Load Extensions from: " + root.getAbsolutePath());
    File[] folders =
        root.listFiles(
            new FileFilter() {

              public boolean accept(File pathname) {
                return pathname.isDirectory();
              }
            });
    ClassLoader cl = getClass().getClassLoader();
    main:
    for (File f : folders) {
      File[] modules =
          f.listFiles(
              new FilenameFilter() {

                public boolean accept(File dir, String name) {
                  return name.endsWith("Extension.class");
                }
              });
      boolean loaded = false;
      for (File module : modules) {

        Class<?> cls;
        try {
          cls =
              cl.loadClass(
                  AbstractExtension.class.getPackage().getName()
                      + "."
                      + module.getParentFile().getName()
                      + "."
                      + module.getName().substring(0, module.getName().length() - 6));

          if (AbstractExtension.class.isAssignableFrom(cls)) {
            loaded = true;
            initModule((Class<AbstractExtension<?>>) cls);
            continue main;
          }
        } catch (IllegalArgumentException e) {
          Log.L.warning("Did not init Extension " + module + " : " + e.getMessage());
        } catch (Throwable e) {
          Log.exception(e);
          Dialog.getInstance().showExceptionDialog("Error", e.getMessage(), e);
        }
      }
      if (!loaded) {
        Log.L.warning("Could not load any Extension Module from " + f);
      }
    }
  }