Exemplo n.º 1
0
  public static boolean canGetWebResources(ProxyConfiguration proxyConfiguration, int timeout) {
    try {
      // TODO: add better method to check web resources
      int result = testHTTPConnection(new URI("http://www.un.org/"), proxyConfiguration, timeout);
      //            int rawresult = testHTTPConnection(new URI("http://157.150.34.32"),
      // proxyConfiguration, timeout);

      switch (result) {
        case HttpURLConnection.HTTP_OK:
        case HttpURLConnection.HTTP_CREATED:
        case HttpURLConnection.HTTP_NO_CONTENT:
        case HttpURLConnection.HTTP_NOT_AUTHORITATIVE:
        case HttpURLConnection.HTTP_ACCEPTED:
        case HttpURLConnection.HTTP_PARTIAL:
        case HttpURLConnection.HTTP_RESET:
          return true;

        default:
          return false;
      }
    } catch (URISyntaxException e) {
      LogWrapper.w(TAG, e.toString());
      //            APL.getEventReport().send(e);
    }

    return false;
  }
Exemplo n.º 2
0
 public void connect() throws IOException {
   try {
     FileSystem fs = FileSystem.get(url.toURI(), conf);
     is = fs.open(new Path(url.getPath()));
   } catch (URISyntaxException e) {
     throw new IOException(e.toString());
   }
 }
 @Override
 public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
   try {
     return getSFTPHost(uri, true);
   } catch (URISyntaxException e) {
     throw new FileSystemException(e.toString());
   }
 }
Exemplo n.º 4
0
 @Override
 public URI getNodeUri() throws XQException {
   opened();
   if (!it.node()) throw new BXQException(NODE);
   final ANode node = (ANode) it;
   try {
     return new URI(Token.string(node.base()));
   } catch (final URISyntaxException ex) {
     throw new BXQException(ex.toString());
   }
 }
Exemplo n.º 5
0
  public Text evaluate(final Text fromUrl, final Text toUrl, final IntWritable type) {

    if (fromUrl == null || toUrl == null) {
      return null;
    }
    boolean isFrom = true; // type == 0
    if (type.compareTo(new IntWritable(1)) == 0) { // type == 1
      isFrom = false;
    }
    String fqdn = "";
    try {
      if (isFrom) {
        URI uri = new URI(fromUrl.toString());
        fqdn = uri.getHost();
      } else {
        List<String> result = new ArrayList<String>();
        Pattern pattern =
            Pattern.compile(
                "\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)"
                    + "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov"
                    + "|mil|biz|info|mobi|name|aero|jobs|museum"
                    + "|travel|[a-z]{2}))(:[\\d]{1,5})?"
                    + "(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?"
                    + "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?"
                    + "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)"
                    + "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?"
                    + "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*"
                    + "(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");

        Matcher matcher = pattern.matcher(toUrl.toString());
        while (matcher.find()) {
          result.add(matcher.group());
        }

        if (result.size() == 0) {
          URI uri = new URI(fromUrl.toString());
          fqdn = uri.getHost();
        } else {
          String firstRes = result.get(0);
          if (firstRes.startsWith("//")) {
            firstRes = "http:" + firstRes;
          }
          URI uri = new URI(firstRes);
          fqdn = uri.getHost();
        }
      }
    } catch (URISyntaxException e) {
      fqdn = "ERROR" + e.toString();
    }
    if (fqdn == null) {
      return new Text("unknown://");
    }
    return new Text(fqdn);
  }
Exemplo n.º 6
0
 /**
  * Creates an GeneListInputAgent for reading in a text file.
  *
  * @param fileName Filename of file wanted to be read in
  */
 public GeneListInputAgent(String fileName) {
   this.fileName = fileName;
   try {
     File filePath = new File(this.getClass().getResource(fileName).toURI());
     System.err.println(filePath.toString() + ": FILEPATH");
     reader = new BufferedReader(new FileReader(filePath));
   } catch (FileNotFoundException fileException) {
     // TODO add log statement
     System.err.println("File " + fileName + " not found!");
   } catch (URISyntaxException URIException) {
     System.err.println(URIException.toString());
   }
   fileLines = toArray();
 }
Exemplo n.º 7
0
 /**
  * Get named property as URI from config.xml
  *
  * @param key The configuration key
  * @return URI or null if property does not found or not valid URI
  */
 @CheckForNull
 public URI getPropertyAsURI(String key) {
   String value = getString(key);
   if (StringUtils.isBlank(value)) {
     log.debug("property {} not found or contains empty string", key);
     return null;
   }
   log.trace(value);
   try {
     return new URI(value);
   } catch (URISyntaxException e) {
     log.warn(e.toString());
     return null;
   }
 }
  /**
   * Perform the publication.
   *
   * @param build Build on which to apply publication
   * @param launcher Unused
   * @param listener Unused
   * @return boolean true if the publishing successfully complete true if the publishing could not
   *     complete
   * @throws IOException In case of file IO mismatch
   * @throws InterruptedException In case of interuption
   */
  @Override
  public boolean perform(
      final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
      throws IOException, InterruptedException {

    /** Define if we must parse multiple file by searching for ',' in the name var. */
    String[] files = name.split(",");

    ArrayList<String> filesToParse = new ArrayList<String>();
    for (int i = 0; i < files.length; i++) {
      FileSet fileSet = new FileSet();
      File workspace = build.getArtifactsDir();
      fileSet.setDir(workspace);
      fileSet.setIncludes(files[i].trim());
      Project antProject = new Project();
      fileSet.setProject(antProject);
      String[] tmpFiles = fileSet.getDirectoryScanner(antProject).getIncludedFiles();

      for (int j = 0; j < tmpFiles.length; j++) {
        filesToParse.add(tmpFiles[j]);
      }
    }

    try {
      ACIPluginBuildAction buildAction;
      buildAction = new ACIPluginBuildAction(build, filesToParse);
      build.addAction(buildAction);
    } catch (ParserConfigurationException ex) {
      listener.getLogger().println(ex.toString());
      return false;
    } catch (SAXException ex) {
      listener.getLogger().println(ex.toString());
      return false;
    } catch (URISyntaxException ex) {
      listener.getLogger().println(ex.toString());
      return false;
    }
    return true;
  }
Exemplo n.º 9
0
  public static Hallmark parseHallmark(String hallmarkString) {

    byte[] hallmarkBytes = Convert.parseHexString(hallmarkString);

    ByteBuffer buffer = ByteBuffer.wrap(hallmarkBytes);
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    byte[] publicKey = new byte[32];
    buffer.get(publicKey);
    int hostLength = buffer.getShort();
    if (hostLength > 300) {
      throw new IllegalArgumentException("Invalid host length");
    }
    byte[] hostBytes = new byte[hostLength];
    buffer.get(hostBytes);
    String host = Convert.toString(hostBytes);
    int weight = buffer.getInt();
    int date = buffer.getInt();
    buffer.get();
    byte[] signature = new byte[64];
    buffer.get(signature);

    byte[] data = new byte[hallmarkBytes.length - 64];
    System.arraycopy(hallmarkBytes, 0, data, 0, data.length);

    boolean isValid =
        host.length() < 100
            && weight > 0
            && weight <= Constants.MAX_BALANCE_NXT
            && Crypto.verify(signature, data, publicKey, true);
    try {
      return new Hallmark(hallmarkString, publicKey, signature, host, weight, date, isValid);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e.toString(), e);
    }
  }
Exemplo n.º 10
0
  /**
   * Returns the URL for the file.
   *
   * @return the associated url
   * @throws IOException if the URL cannot be generated
   */
  public URL makeUrl() throws Exception {

    // return the reference if it was already established
    if (this.referencedUrl != null) return this.referencedUrl;

    String loc = Val.chkStr(this.getLocation());
    URL locUrl = null;

    // determine the base location URIs
    URI rootUri = null;
    List<URI> baseUris = null;
    GxeFile parentFile = this;
    while (parentFile != null) {
      if (parentFile.isRoot) {
        baseUris = parentFile.getBaseLocations();
        break;
      }
      parentFile = parentFile.getParent();
    }
    boolean hasBaseUris = (baseUris != null) && (baseUris.size() > 0);
    if (hasBaseUris) rootUri = baseUris.get(0);

    if (locUrl == null) {
      locUrl = Thread.currentThread().getContextClassLoader().getResource(loc);
    }

    if ((locUrl == null) && !loc.startsWith("$base")) {
      if ((this.getParent() != null) && (this.getParent().getReferencedUrl() != null)) {
        try {
          URL parentUrl = this.getParent().getReferencedUrl();
          URI parentUri = parentUrl.toURI();
          URI thisUri = parentUri.resolve(loc);
          File thisFile = new File(thisUri);
          locUrl = thisUri.toURL();
          if (!thisFile.exists() && hasBaseUris && (rootUri != null)) {
            URI relUri = rootUri.relativize(thisUri);
            int n = baseUris.size();
            for (int i = 0; i < n; i++) {
              URI testUri = baseUris.get(i).resolve(relUri);
              // this won't work for http based URIs
              if ((new File(testUri)).exists()) {
                locUrl = testUri.toURL();
                break;
              }
            }
          }
        } catch (URISyntaxException e) {
          LOGGER.log(
              Level.CONFIG, "While attemting to load: " + loc + ", error: " + e.toString(), e);
        }
      }
    }

    if ((locUrl == null) && loc.startsWith("$base")) {
      String relLoc = Val.chkStr(loc.substring(5));
      if (relLoc.startsWith("/")) relLoc = Val.chkStr(relLoc.substring(1));
      if ((relLoc.length() > 0) && hasBaseUris) {
        try {
          URI relUri = new URI(relLoc);
          int n = baseUris.size();
          for (int i = 0; i < n; i++) {
            URI testUri = baseUris.get(i).resolve(relUri);
            // this won't work for http based URIs
            if ((new File(testUri)).exists()) {
              locUrl = testUri.toURL();
              break;
            }
          }
        } catch (URISyntaxException e) {
          LOGGER.log(
              Level.CONFIG, "While attemting to load: " + loc + ", error: " + e.toString(), e);
        }
      }
    }

    // throw an exception if the URL was not generated, otherwise save and return the reference
    if (locUrl == null) {
      throw new IOException("Unable to create resource URL for path: " + loc);
    } else {
      this.referencedUrl = locUrl;
    }
    return this.referencedUrl;
  }
Exemplo n.º 11
0
  @SuppressWarnings("unchecked")
  public String execute() {

    String sawsdlExt = ".sawsdl";
    String wsdlExt = ".wsdl";
    String sawadlExt = ".sawadl";
    String wadlExt = ".wadl";
    StringBuffer buf = new StringBuffer();

    SAXBuilder sbuilder = new SAXBuilder();
    Document doc = null;

    @SuppressWarnings("rawtypes")
    Map session = ActionContext.getContext().getSession();
    String importURL = "";
    errormsg = "";
    String filename = "";

    System.out.println("wsloc = " + wsloc);
    if (WSFile != null) System.out.println("OWLFile size = " + WSFile.getTotalSpace());

    try {
      XMLParser wsParser = null;
      session.remove("wsname");
      session.remove("wsdlparser");
      session.remove("wadlparser");
      if (wsloc.indexOf("http:") != -1) {
        importURL = wsloc;
        if (wsloc.equalsIgnoreCase(wsdlExt) || wsloc.equalsIgnoreCase(sawsdlExt)) {
          doc = sbuilder.build(importURL);
          wsParser = new SAWSDLParser(doc);
          session.put("wsdlparser", wsParser);
          session.remove("wadlparser");
          int start = importURL.lastIndexOf("/");
          filename = importURL.substring(start, importURL.length());
          session.put("wsname", filename);
        } else if (wsloc.equalsIgnoreCase(wadlExt) || wsloc.equalsIgnoreCase(sawadlExt)) {
          doc = sbuilder.build(importURL);
          wsParser = new WADLParser(doc);
          session.put("wadlparser", wsParser);
          session.remove("wsdlparser");
          int start = importURL.lastIndexOf("/");
          filename = importURL.substring(start, importURL.length());
          session.put("wsname", filename);
        }
      } else {
        if (WSFile != null) {
          if (wsloc.endsWith(wsdlExt) || wsloc.endsWith(sawsdlExt)) {
            doc = sbuilder.build(WSFile);
            wsParser = new SAWSDLParser(doc);
            session.put("wsdlparser", wsParser);
            filename = wsloc;
            session.put("wsname", filename);
          } else if (wsloc.endsWith(wadlExt) || wsloc.endsWith(sawadlExt)) {
            doc = sbuilder.build(WSFile);
            wsParser = new WADLParser(doc);
            session.put("wadlparser", wsParser);
            filename = wsloc;
            session.put("wsname", filename);
          } else {
            errormsg = "File is not wsdl or wadl file.";
          }
        } else {
          errormsg = "WSDL file lost.";
        }
      }

      if (wsParser == null) {
        errormsg = "WSDL is invalidate";
        return ERROR;
      }

      if (isWSDL(doc)) {

        boolean hasSAWSDLNS = false;
        @SuppressWarnings("rawtypes")
        List nameSpaces = doc.getRootElement().getAdditionalNamespaces();
        for (int i = 0; i < nameSpaces.size(); i++) {
          Namespace ns = (Namespace) nameSpaces.get(i);
          if (ns.getURI().equalsIgnoreCase(SAWSDLParser.sawsdlNS.getURI())) {
            hasSAWSDLNS = true;
            break;
          }
        }
        if (!hasSAWSDLNS) {
          doc.getRootElement().addNamespaceDeclaration(SAWSDLParser.sawsdlNS);
        }

        boolean wsdlV1 = ((SAWSDLParser) wsParser).isWsdlV1();
        if (wsdlV1 == true) {
          LoadWSDLTree.loadWSDL((SAWSDLParser) wsParser, buf, filename);
        } else {
          // not implement yet
        }
        innerTreeHtml = buf.toString();
        type = "wsdl";
      } else if (isWADL(doc)) {
        // not implement yet
        LoadWADLTree.loadWADL((WADLParser) wsParser, buf, wsloc);
        innerTreeHtml = buf.toString();
        type = "wadl";
      }

    } catch (IOException e) {
      e.printStackTrace();
      errormsg = e.toString();
    } catch (URISyntaxException e) {
      e.printStackTrace();
      errormsg = e.toString();
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
      errormsg = e.toString();
    } catch (JDOMException e) {
      e.printStackTrace();
      errormsg = e.toString();
    } catch (Exception e) {
      e.printStackTrace();
      errormsg = e.toString();
    }

    System.out.println("errormsg = " + errormsg);

    System.out.println("draw finish");

    return SUCCESS;
  }
Exemplo n.º 12
0
  /**
   * @see org.geotools.xml.XSIElementHandler#startElement(java.lang.String, java.lang.String,
   *     org.xml.sax.Attributes)
   */
  public void startElement(String namespaceURI, String localName, Attributes atts)
      throws SAXException {
    id = atts.getValue("", "id");

    if (id == null) {
      id = atts.getValue(namespaceURI, "id");
    }

    String min = atts.getValue("", "minOccurs");

    if (min == null) {
      min = atts.getValue(namespaceURI, "minOccurs");
    }

    String max = atts.getValue("", "maxOccurs");

    if (max == null) {
      max = atts.getValue(namespaceURI, "maxOccurs");
    }

    String namespace1 = atts.getValue("", "namespace");

    if (namespace1 == null) {
      namespace1 = atts.getValue(namespaceURI, "namespace");
    }

    try {
      if (namespace1 != null) {
        if (namespace1.toLowerCase().equals("##any")) {
          this.namespace = Any.ALL;
        } else {
          if (namespace1.toLowerCase().equals("##other")) {
            // TODO improve this
            this.namespace = Any.ALL;
          } else {
            if (namespace1.toLowerCase().equals("##targetNamespace")) {
              try {
                this.namespace = new URI(namespaceURI);
              } catch (URISyntaxException e) {
                logger.warning(e.toString());
                this.namespace = new URI(namespace1);
              }
            } else {
              this.namespace = new URI(namespace1);
            }
          }
        }
      }
    } catch (URISyntaxException e) {
      logger.warning(e.toString());
      throw new SAXException(e);
    }

    if ((null == min) || "".equalsIgnoreCase(min)) {
      minOccurs = 1;
    } else {
      minOccurs = Integer.parseInt(min);
    }

    if ((null == max) || "".equalsIgnoreCase(max)) {
      maxOccurs = 1;
    } else {
      if ("unbounded".equalsIgnoreCase(max)) {
        maxOccurs = ElementGrouping.UNBOUNDED;
      } else {
        maxOccurs = Integer.parseInt(max);
      }
    }
  }
  public double getDistance(GeoPoint point1, GeoPoint point2) {
    double distance = -1;
    InputStream is = null;

    Uri.Builder uribuilder = new Uri.Builder();
    uribuilder.encodedPath(API_URL);
    uribuilder.appendQueryParameter(
        "ll1", (point1.getLatitudeE6() / 1E6) + "," + (point1.getLongitudeE6() / 1E6));
    uribuilder.appendQueryParameter(
        "ll2", (point2.getLatitudeE6() / 1E6) + "," + (point2.getLongitudeE6() / 1E6));
    String uri = uribuilder.toString();

    try {
      HttpGet httpGet = new HttpGet();
      HttpResponse response = null;
      httpGet.setURI(new URI(uri));
      response = mHttpClient.execute(httpGet);
      if (response == null) {
        Log.w(TAG, "getDistance:Response is null");
        return -1;
      }
      int status = response.getStatusLine().getStatusCode();
      if (status != HttpStatus.SC_OK) {
        Log.w(TAG, "getDistance:HttpStatus=" + status);
        return -1;
      }
      is = response.getEntity().getContent();
    } catch (ClientProtocolException e) {
      Log.e(TAG, "getDistance:" + e.toString());
      e.printStackTrace();
      return -1;
    } catch (URISyntaxException e) {
      Log.e(TAG, "getDistance:" + e.toString());
      e.printStackTrace();
      return -1;
    } catch (IOException e) {
      Log.e(TAG, "getDistance:" + e.toString());
      e.printStackTrace();
      return -1;
    }

    try {
      XmlPullParser parser = Xml.newPullParser();
      parser.setInput(is, "UTF-8");

      int eventType = parser.getEventType();

      while (eventType != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
          case XmlPullParser.START_TAG:
            String tag = parser.getName();
            if (tag.equals("distance")) {
              distance = Double.parseDouble(parser.nextText());
              break;
            }
            break;
        }
        eventType = parser.next();
      }
      if (distance < 0) {
        Log.w(TAG, "getDistance: Tag 'distance' not found");
        return -1;
      }

    } catch (XmlPullParserException e) {
      Log.e(TAG, "getDistance:" + e.toString());
      e.printStackTrace();
      return -1;
    } catch (IOException e) {
      Log.e(TAG, "getDistance:" + e.toString());
      e.printStackTrace();
      return -1;
    }

    return distance;
  }
Exemplo n.º 14
0
  public void getCdx(CDXQuery query, AuthToken authToken, CDXWriter responseWriter)
      throws IOException {
    CloseableIterator<String> iter = null;

    try {
      // Check for wildcards as shortcuts for matchType
      if (query.matchType == null) {
        if (query.url.startsWith("*.")) {
          query.matchType = MatchType.domain;
          query.url = query.url.substring(2);
        } else if (query.url.endsWith("*")) {
          query.matchType = MatchType.prefix;
          query.url = query.url.substring(0, query.url.length() - 1);
        } else {
          query.matchType = MatchType.exact;
        }
      }

      CDXAccessFilter accessChecker = null;

      if (!authChecker.isAllUrlAccessAllowed(authToken)) {
        accessChecker = authChecker.createAccessFilter(authToken);
      }

      //			// For now, don't support domain or host output w/o key as access check is too slow
      //			if (query.matchType == MatchType.domain || query.matchType == MatchType.host) {
      //				if (!authChecker.isAllUrlAccessAllowed(authToken)) {
      //					return;
      //				}
      //			}

      String startEndUrl[] =
          urlSurtRangeComputer.determineRange(query.url, query.matchType, "", "");

      if (startEndUrl == null) {
        responseWriter.printError(
            "Sorry, matchType=" + query.matchType.name() + " is not supported by this server");
        return;
      }

      if ((accessChecker != null) && !accessChecker.includeUrl(startEndUrl[0], query.url)) {
        if (query.showNumPages) {
          // Default to 1 page even if no results
          responseWriter.printNumPages(1, false);
        }
        return;
      }

      if (query.last || query.limit == -1) {
        query.limit = 1;
        query.setSort(SortType.reverse);
      }

      int maxLimit;

      if (query.fastLatest == null) {
        // Optimize: default fastLatest to true for last line or closest
        // sorted results
        if ((query.limit == -1) || (!query.closest.isEmpty() && (query.limit > 0))) {
          query.fastLatest = true;
        } else {
          query.fastLatest = false;
        }
      }

      // Paged query
      if (query.page >= 0 || query.showNumPages) {
        iter = createPagedCdxIterator(startEndUrl, query, authToken, responseWriter);

        if (iter == null) {
          return;
        }

        // Page size determines the max limit here
        maxLimit = Integer.MAX_VALUE;

      } else {
        // Non-Paged Merged query
        iter = createBoundedCdxIterator(startEndUrl, query, null, null);

        // TODO: apply collection-view filtering here. It should happen separately
        // from exclusion check. We'd need to parse CDX lines into CDXLine object
        // before passing it to writeCdxResponse(). Pass CDXFilter to getCdx()?
        // Pass CDX source object that escapsulates collection-view filtering?

        maxLimit = this.queryMaxLimit;
      }

      writeCdxResponse(responseWriter, iter, maxLimit, query, authToken, accessChecker);

    } catch (URIException e) {
      responseWriter.printError(e.toString());
    } catch (URISyntaxException e) {
      responseWriter.printError(e.toString());
    } finally {
      if (iter != null) {
        iter.close();
      }
    }
  }