コード例 #1
0
ファイル: TestProperties.java プロジェクト: kipz/Flickr4Java
  private Properties load() {
    Properties properties = new Properties();
    InputStream in = null;
    try {
      in = getClass().getResourceAsStream("/setup.properties");
      properties.load(in);
    } catch (IOException e) {
      throw new FlickrRuntimeException("Problem loading setup.properties", e);
    } finally {
      IOUtilities.close(in);
    }

    return properties;
  }
コード例 #2
0
ファイル: REST.java プロジェクト: kipz/Flickr4Java
  /**
   * Invoke a non OAuth HTTP GET request on a remote host.
   *
   * <p>This is only used for the Flickr OAuth methods checkToken and getAccessToken.
   *
   * @param path The request path
   * @param parameters The parameters
   * @return The Response
   */
  @Override
  public Response getNonOAuth(String path, Map<String, String> parameters) {
    InputStream in = null;
    try {
      URL url = UrlUtilities.buildUrl(getHost(), getPort(), path, parameters);
      if (Flickr.debugRequest) {
        logger.debug("GET: " + url);
      }
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setRequestMethod("GET");
      if (proxyAuth) {
        conn.setRequestProperty("Proxy-Authorization", "Basic " + getProxyCredentials());
      }
      setTimeouts(conn);
      conn.connect();

      if (Flickr.debugStream) {
        in = new DebugInputStream(conn.getInputStream(), System.out);
      } else {
        in = conn.getInputStream();
      }

      Response response = null;
      synchronized (mutex) {
        Document document = builder.parse(in);
        response = (Response) responseClass.newInstance();
        response.parse(document);
      }
      return response;
    } catch (IllegalAccessException e) {
      throw new FlickrRuntimeException(e);
    } catch (InstantiationException e) {
      throw new FlickrRuntimeException(e);
    } catch (IOException e) {
      throw new FlickrRuntimeException(e);
    } catch (SAXException e) {
      throw new FlickrRuntimeException(e);
    } finally {
      IOUtilities.close(in);
    }
  }