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() . 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
Source File: RDF4JProtocolSession.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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
Source File: CxfCacheUriInfoIssueTest.java    From olingo-odata2 with 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 3
Source File: TestIssue105.java    From cloud-odata-java with 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
Source File: RDF4JProtocolSession.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: RDF4JProtocolSession.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
Source File: CxfCacheUriInfoIssueTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@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
Source File: AbstractStockServiceImpl.java    From Thunder with Apache License 2.0 4 votes vote down vote up
@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;
}