@Test
  public void createGetMethodNoHttpParams() throws URIException {
    final GetMethod get =
        manager.createGetMethod(
            "http://sourceforge.net/", new HashMap<String, HttpParamInfo>(), CHARSET, false);

    assertEquals("Unexpected URI created", "http://sourceforge.net/", get.getURI().getURI());
  }
Exemplo n.º 2
0
 // TODO Jean
 public static URL createQuery(final int port, final CidsBean bean) {
   if ((port < 0) || (port > 65535)) {
     log.warn("Crossover: verdisCrossoverPort ist ungültig: " + port);
   } else {
     try {
       // ToDo ugly because is static
       PARAMETER_KASSENZEICHEN.setValue(
           String.valueOf(bean.getProperty("kassenzeichennummer8"))); // kz.getId().toString());
       final GetMethod tmp = new GetMethod(server + port + request);
       tmp.setQueryString(new NameValuePair[] {PARAMETER_KASSENZEICHEN});
       if (log.isDebugEnabled()) {
         log.debug("Crossover: verdisCrossOverQuery: " + tmp.getURI().toString());
       }
       return new URL(tmp.getURI().toString());
     } catch (Exception ex) {
       log.error("Crossover: Fehler beim fernsteuern von VerdIS.", ex);
     }
   }
   return null;
 }
Exemplo n.º 3
0
  /**
   * login后密码验证成功后跳入ajaxLogin,获得唯一标示码。
   *
   * @param client
   * @param ajaxUrl
   * @return
   * @throws IOException
   * @throws HttpException
   */
  public static String ajaxLogin(HttpClient client, String ajaxUrl)
      throws IOException, HttpException {
    GetMethod getByAjax = new GetMethod(ajaxUrl);
    client.executeMethod(getByAjax);
    System.out.println(getByAjax.getURI());
    // printCookie(client);
    // mergeCookie(client);
    // printCookie(client);
    System.out.println("-------------ajaxLogin结束--------------");
    // System.out.println(getByAjax.getResponseBodyAsString());
    String responseBodyAsString = getByAjax.getResponseBodyAsString();
    getByAjax.releaseConnection();

    return getUniqueid(responseBodyAsString);
  }
  @Test
  public void createGetMethodWithHttpParams() throws URIException {
    final Map<String, HttpParamInfo> params = new LinkedHashMap<String, HttpParamInfo>();
    params.put(
        "param1", new HttpParamInfo("param1", false, null, null, new NodeVariable("param1Value")));
    params.put(
        "param2", new HttpParamInfo("param2", false, null, null, new NodeVariable("param2Value")));

    final GetMethod get =
        manager.createGetMethod("http://sourceforge.net/", params, CHARSET, false);

    assertEquals(
        "Unexpected URI created",
        "http://sourceforge.net/?param1=param1Value&param2=param2Value",
        get.getURI().getURI());
  }
Exemplo n.º 5
0
  public synchronized InputStream getStream() throws Exception {
    // data URL will be like /ngwmn_cache/data/$AGENCY/$SITE/WATERLEVEL
    // example http://cida-wiwsc-ngwmndev.er.usgs.gov:8080/ngwmn_cache/data/TWDB/6550504/WATERLEVEL
    client = new HttpClient();
    String url = MessageFormat.format("{0}/data/{1}/{2}/WATERLEVEL", baseURL, agency, site);
    method = new GetMethod(url);

    logger.info("trying to fetch some data from {} ", method.getURI());

    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
      throw new RuntimeException("status " + statusCode);
    }

    InputStream is = method.getResponseBodyAsStream();

    return is;
  }
Exemplo n.º 6
0
  public WebResponse doGet(String url, String referer)
      throws WebBrowserException, WebServerException {
    try {
      GetMethod getMethod = new GetMethod(url);
      setHttpRequestHeader(getMethod);
      if (referer != null && referer.trim().length() != 0) {
        getMethod.setRequestHeader("Referer", referer);
      }
      logHttpGetRequest(getMethod);
      int status = httpClient.executeMethod(getMethod);
      String strResp = getMethod.getResponseBodyAsString();
      byte[] byteResp = getMethod.getResponseBody();
      String respEnc = getResponseEncoding(getMethod);
      logHttpResponse(getMethod, strResp);
      getMethod.releaseConnection();

      // http:301,302,303,307
      if (status == HttpStatus.SC_MOVED_PERMANENTLY
          || status == HttpStatus.SC_MOVED_TEMPORARILY
          || status == HttpStatus.SC_SEE_OTHER
          || status == HttpStatus.SC_TEMPORARY_REDIRECT) {
        Header locationHeader = getMethod.getResponseHeader("Location");
        String location = locationHeader.getValue();
        if (logger.isDebugEnabled()) {
          logger.debug("Redirect To Location = " + location);
        }
        if (location.startsWith("http")) {
          return doGet(location);
        } else {
          return doGet("http://" + getResponseHost(getMethod) + location);
        }
      } else if (status == HttpStatus.SC_OK) { // http:200
        return new WebResponse(getMethod.getURI().toString(), byteResp, respEnc);
      } else {
        throw new WebServerException("Server Exception[code=" + status + "]");
      }
    } catch (HttpException e) {
      throw new WebBrowserException(e);
    } catch (IOException e) {
      throw new WebBrowserException(e);
    }
  }
Exemplo n.º 7
0
  private void checkUpdate()
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    String url;
    try {
      url = Registry.getProperty("updater.url");
    } catch (Exception e) {
      throw new IOException(e.getMessage()); // i hate leaking "exception"
    }
    HttpClient client = new HttpClient();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("version", Build.getVersion());
    params.put("release", "" + Build.getRelease());
    if (PreferencesManager.getVersionIndependentPreferences()
        .getBoolean("updater.include.usageData", true)) {
      params.put("uuid", Application.getUUID());
      params.put("platform.arch", Platform.getArch());
      params.put("platform.os", Platform.getOS().getCanonicalName());
      params.put("platform.os.version", Platform.getOS().getVersion());
      params.put("locale.country", LanguageBundle.getCurrentLocale().getCountry());
      params.put("locale.language", LanguageBundle.getCurrentLocale().getLanguage());
    }

    List<NameValuePair> nvp = new ArrayList<NameValuePair>();
    for (String key : params.keySet()) nvp.add(new NameValuePair(key, "" + params.get(key)));

    GetMethod request = new GetMethod(url);
    request.setQueryString(nvp.toArray(new NameValuePair[nvp.size()]));
    LogFactory.getLog(getClass()).info(String.format("Checking for updates: %s", request.getURI()));
    client.executeMethod(request);
    String response = request.getResponseBodyAsString();
    Document doc = DomUtil.parseXMLString(response);
    availableRelease = XPathHelper.xpathAsDouble(doc, "/korsakow/release");
    availableVersion = XPathHelper.xpathAsString(doc, "/korsakow/version");
    message = XPathHelper.xpathAsString(doc, "/korsakow/message");
  }