List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:com.softinstigate.restheart.integrationtest.PutIndexIT.java
@Test public void testPutDocument() throws Exception { try {/* w ww. j a va 2 s.c o m*/ Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // *** PUT wrong index //resp = adminExecutor.execute(Request.Put(indexTmpUri).bodyString("{a:1}", halCT).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); //check("check put wrong index", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to put without etag resp = adminExecutor.execute( Request.Put(indexTmpUri).bodyString("{ keys: {a:1,b:2}, ops: { name: \"ciao\"} }", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put correct index", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Get(indexesTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = resp.returnResponse(); junit.framework.Assert.assertNotNull(httpResp); HttpEntity entity = httpResp.getEntity(); junit.framework.Assert.assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); junit.framework.Assert.assertNotNull(statusLine); junit.framework.Assert.assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); junit.framework.Assert.assertNotNull("content type not null", entity.getContentType()); junit.framework.Assert.assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); junit.framework.Assert.assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { junit.framework.Assert.fail("parsing received json"); } junit.framework.Assert.assertNotNull("check json not null", json); junit.framework.Assert.assertNotNull("check not null _returned property", json.get("_returned")); junit.framework.Assert.assertNotNull("check not null _size property", json.get("_size")); junit.framework.Assert.assertEquals("check _size value to be 5", 5, json.get("_size").asInt()); junit.framework.Assert.assertEquals("check _returned value to be 5", 5, json.get("_returned").asInt()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:org.metaservice.manager.blazegraph.FastRangeCountRequestBuilder.java
public MutationResult execute() throws ManagerException { try {/* w ww.ja v a2 s. c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(MutationResult.class); URIBuilder uriBuilder = new URIBuilder(path); if (subject != null) { uriBuilder.setParameter("s", format(subject)); } if (object != null) { uriBuilder.setParameter("o", format(object)); } if (predicate != null) { uriBuilder.setParameter("p", format(predicate)); } if (context != null) { uriBuilder.setParameter("c", format(context)); } uriBuilder.addParameter("ESTCARD", null); URI uri = uriBuilder.build(); LOGGER.debug("QUERY = " + uri.toString()); String s = Request.Get(uri).connectTimeout(1000).socketTimeout(10000) .setHeader("Accept", "application/xml").execute().returnContent().asString(); LOGGER.debug("RESULT = " + s); return (MutationResult) jaxbContext.createUnmarshaller().unmarshal(new StringReader(s)); } catch (JAXBException | URISyntaxException | IOException e) { throw new ManagerException(e); } }
From source file:org.mule.module.http.functional.listener.HttpListenerLifecycleTestCase.java
@Test public void disposeListenerReturns404() throws Exception { HttpListener httpListener = (HttpListener) ((Flow) getFlowConstruct("catchAllWithinTestPathFlow")) .getMessageSource();//from www . j a va 2 s. c om httpListener.dispose(); final Response response = Request.Get(getLifecycleConfigUrl("/path/somepath")).execute(); final HttpResponse httoResponse = response.returnResponse(); assertThat(httoResponse.getStatusLine().getStatusCode(), is(404)); }
From source file:com.ykun.commons.utils.http.HttpClientUtils.java
public static String get(String url) { return execute(Request.Get(url)); }
From source file:org.ow2.proactive.addons.webhook.service.JsonRestApacheRequestServiceTest.java
@Before public void setUp() throws IOException { when(mockJsonStringToHeaderMap.convert(anyString())).thenReturn(new HashMap<>()); this.jsonRestApacheRequestService = spy( new JsonRestApacheRequestService(mockJsonStringToHeaderMap, mockApacheHttpClientRequestGetter)); // Don't actually do the rest call - mock the protected method which executes the rest call //noinspection unchecked doReturn(new RestResponse(HttpStatus.SC_ACCEPTED, "Okay")).when(this.jsonRestApacheRequestService) .executeRequest(any(Request.class)); // Don't test the string to request mapping doReturn(Request.Get("")).when(mockApacheHttpClientRequestGetter).getHttpRequestByString(any(String.class), any(String.class)); }
From source file:org.exist.http.urlrewrite.URLRewritingTest.java
@Test public void findsParentController() throws IOException { final XmldbURI nestedCollectionName = XmldbURI.create("nested"); final XmldbURI docName = XmldbURI.create("test.xml"); final String testDocument = "<hello>world</hello>"; final String storeDocUri = getRestUri() + TEST_COLLECTION.append(nestedCollectionName).append(docName); HttpResponse response = executor//from w w w .j a v a 2 s . c o m .execute(Request.Put(storeDocUri).bodyString(testDocument, ContentType.APPLICATION_XML)) .returnResponse(); assertEquals(HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); final String retrieveDocUri = getAppsUri() + "/" + TEST_COLLECTION_NAME.append(nestedCollectionName).append(docName); response = executor.execute(Request.Get(retrieveDocUri)).returnResponse(); assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode()); final String responseBody; try (final FastByteArrayOutputStream baos = new FastByteArrayOutputStream( (int) response.getEntity().getContentLength())) { response.getEntity().writeTo(baos); responseBody = baos.toString(UTF_8); } assertTrue(responseBody.matches("<controller>.+</controller>")); }
From source file:org.mule.module.http.functional.listener.HttpListenerGlobalResponseBuilderTestCase.java
private void testResponseHeaders(String url, Collection<String> userAgentHeaderValues) throws IOException { final Response response = Request.Get(url).connectTimeout(1000).execute(); final HttpResponse httpResponse = response.returnResponse(); assertThat(isDateValid(httpResponse.getFirstHeader(HttpHeaders.Names.DATE).getValue()), Is.is(true)); final Header[] userAgentHeaders = httpResponse.getHeaders(HttpHeaders.Names.USER_AGENT); final Collection<String> headerValues = CollectionUtils.collect(Arrays.asList(userAgentHeaders), new Transformer() { @Override//w w w . j av a 2s . c o m public Object transform(Object input) { Header header = (Header) input; return header.getValue(); } }); assertThat(userAgentHeaders.length, is(userAgentHeaderValues.size())); assertThat(headerValues, Matchers .containsInAnyOrder(userAgentHeaderValues.toArray(new String[userAgentHeaderValues.size()]))); }
From source file:org.mule.module.http.functional.proxy.HttpProxyTemplateErrorHandlingTestCase.java
@Test public void noExceptionStrategy() throws Exception { HttpResponse response = Request.Get(getProxyUrl("noExceptionStrategy")).connectTimeout(RECEIVE_TIMEOUT) .execute().returnResponse(); assertThat(response.getStatusLine().getStatusCode(), is(500)); }
From source file:org.restheart.test.integration.PutIndexIT.java
@Test public void testPutDocument() throws Exception { try {//from w w w .j a v a2s . c om Response resp; // *** PUT tmpdb resp = adminExecutor.execute(Request.Put(dbTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put db", resp, HttpStatus.SC_CREATED); // *** PUT tmpcoll resp = adminExecutor.execute(Request.Put(collectionTmpUri).bodyString("{a:1}", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put coll1", resp, HttpStatus.SC_CREATED); // *** PUT wrong index //resp = adminExecutor.execute(Request.Put(indexTmpUri).bodyString("{a:1}", halCT).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); //check("check put wrong index", resp, HttpStatus.SC_NOT_ACCEPTABLE); // try to put without etag resp = adminExecutor.execute( Request.Put(indexTmpUri).bodyString("{ keys: {a:1,b:2}, ops: { name: \"ciao\"} }", halCT) .addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); check("check put correct index", resp, HttpStatus.SC_CREATED); resp = adminExecutor.execute(Request.Get(indexesTmpUri).addHeader(Headers.CONTENT_TYPE_STRING, Representation.HAL_JSON_MEDIA_TYPE)); HttpResponse httpResp = resp.returnResponse(); assertNotNull(httpResp); HttpEntity entity = httpResp.getEntity(); assertNotNull(entity); StatusLine statusLine = httpResp.getStatusLine(); assertNotNull(statusLine); assertEquals("check status code", HttpStatus.SC_OK, statusLine.getStatusCode()); assertNotNull("content type not null", entity.getContentType()); assertEquals("check content type", Representation.HAL_JSON_MEDIA_TYPE, entity.getContentType().getValue()); String content = EntityUtils.toString(entity); assertNotNull("", content); JsonObject json = null; try { json = JsonObject.readFrom(content); } catch (Throwable t) { fail("parsing received json"); } assertNotNull("check json not null", json); assertNotNull("check not null _returned property", json.get("_returned")); assertNotNull("check not null _size property", json.get("_size")); assertEquals("check _size value to be 4", 4, json.get("_size").asInt()); assertEquals("check _returned value to be 4", 4, json.get("_returned").asInt()); } finally { mongoClient.dropDatabase(dbTmpName); } }
From source file:com.qwazr.database.TableSingleClient.java
@Override public TableDefinition getTable(String table_name) { UBuilder uriBuilder = new UBuilder("/table/", table_name); Request request = Request.Get(uriBuilder.build()); return commonServiceRequest(request, null, null, TableDefinition.class, 200); }