Java Code Examples for org.apache.http.client.methods.HttpGet#reset()

The following examples show how to use org.apache.http.client.methods.HttpGet#reset() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public void getRepositoryList(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException,
		RepositoryException, UnauthorizedException, QueryInterruptedException {
	checkServerURL();

	HttpGet method = applyAdditionalHeaders(new HttpGet(Protocol.getRepositoriesLocation(serverURL)));

	try {
		getTupleQueryResult(method, handler);
	} catch (MalformedQueryException e) {
		// This shouldn't happen as no queries are involved
		logger.warn("Server reported unexpected malfored query error", e);
		throw new RepositoryException(e.getMessage(), e);
	} finally {
		method.reset();
	}
}
 
Example 2
@Test
public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException,
    URISyntaxException {
  URI uri1 = URI.create(getEndpoint().toString() + "$metadata");

  HttpGet get1 = new HttpGet(uri1);
  HttpResponse response1 = getHttpClient().execute(get1);
  assertNotNull(response1);

  URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
  assertEquals(uri1.getHost(), serviceRoot1.getHost());

  get1.reset();

  URI uri2 =
      new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(),
          uri1.getFragment());

  HttpGet get2 = new HttpGet(uri2);
  HttpResponse response2 = getHttpClient().execute(get2);
  assertNotNull(response2);

  URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
  assertEquals(uri2.getHost(), serviceRoot2.getHost());
}
 
Example 3
Source Project: cloud-odata-java   File: TestIssue105.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException, URISyntaxException {
  URI uri1 = URI.create(getEndpoint().toString() + "$metadata");

  HttpGet get1 = new HttpGet(uri1);
  HttpResponse response1 = getHttpClient().execute(get1);
  assertNotNull(response1);

  URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
  assertEquals(uri1.getHost(), serviceRoot1.getHost());

  get1.reset();

  URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(), uri1.getFragment());

  HttpGet get2 = new HttpGet(uri2);
  HttpResponse response2 = getHttpClient().execute(get2);
  assertNotNull(response2);

  URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
  assertEquals(uri2.getHost(), serviceRoot2.getHost());
}
 
Example 4
public void getNamespaces(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException,
		RepositoryException, UnauthorizedException, QueryInterruptedException {
	checkRepositoryURL();

	HttpGet method = applyAdditionalHeaders(new HttpGet(Protocol.getNamespacesLocation(getQueryURL())));

	try {
		getTupleQueryResult(method, handler);
	} catch (MalformedQueryException e) {
		logger.warn("Server reported unexpected malfored query error", e);
		throw new RepositoryException(e.getMessage(), e);
	} finally {
		method.reset();
	}
}
 
Example 5
public void getContextIDs(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException,
		RepositoryException, UnauthorizedException, QueryInterruptedException {
	checkRepositoryURL();

	HttpGet method = applyAdditionalHeaders(new HttpGet(Protocol.getContextsLocation(getQueryURL())));

	try {
		getTupleQueryResult(method, handler);
	} catch (MalformedQueryException e) {
		logger.warn("Server reported unexpected malfored query error", e);
		throw new RepositoryException(e.getMessage(), e);
	} finally {
		method.reset();
	}
}
 
Example 6
@Test
public void checkContextForDifferentWithHostHeader() throws ClientProtocolException, IOException,
    ODataException, URISyntaxException {
  try {
    FitStaticServiceFactory.bindService("123", getService());

    // 1st request: cache uri
    URI uri = URI.create(getEndpoint().toString() + "$metadata");
    HttpGet get1 = new HttpGet(uri);
    HttpResponse response1 = getHttpClient().execute(get1);
    assertNotNull(response1);

    URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals(uri.getHost(), serviceRoot1.getHost());

    get1.reset();

    HttpGet get2 = new HttpGet(uri);
    get2.addHeader("Host", "bla:123");
    HttpResponse response2 = getHttpClient().execute(get2);
    assertNotNull(response2);

    URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot();
    assertEquals("bla", serviceRoot2.getHost());
    assertEquals(123, serviceRoot2.getPort());

    URI requestUri = getService().getProcessor().getContext().getPathInfo().getRequestUri();
    assertEquals("bla", requestUri.getHost());
    assertEquals(123, requestUri.getPort());

  } finally {
    FitStaticServiceFactory.unbindService("123");
  }
}
 
Example 7
@Override
public List<Stock> execute(String[] codes, StockType stockType, boolean simple) {
    barrier.reset();

    InterfaceType interfaceType = getInterfaceType();
    if (interfaceType == InterfaceType.SINA) {
        if (stockType == StockType.ZHULI || stockType == StockType.PANKOU) {
            return null;
        }
    }

    String url = getUrl(codes, stockType);
    if (url == null) {
        return null;
    }

    String id = RandomUtil.uuidRandom();

    AbstractStockCallback callback = getCallback();
    callback.setCodes(codes);
    callback.setStockType(stockType);
    callback.setInterfaceType(interfaceType);
    callback.setSimple(simple);
    callback.setId(id);
    callback.setCacheMap(cacheMap);
    callback.setBarrier(barrier);

    HttpGet httpGet = new HttpGet(url);

    CloseableHttpAsyncClient httpAsyncClient = clientExecutor.getClient();
    httpAsyncClient.execute(httpGet, callback);
    try {
        barrier.await();
    } catch (Exception e) {
        e.printStackTrace();

        return null;
    } finally {
        httpGet.reset();
    }

    List<Stock> stock = cacheMap.get(id);
    cacheMap.remove(id);

    return stock;
}