示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldForwardHttpsAndHost() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForwardHttpsAndHost()
        {
            URI rootUri = _functionalTestHelper.baseUri();

            HttpClient httpclient = new DefaultHttpClient();

            try
            {
                HttpGet httpget = new HttpGet(rootUri);

                httpget.setHeader("Accept", "application/json");
                httpget.setHeader("X-Forwarded-Host", "foobar.com");
                httpget.setHeader("X-Forwarded-Proto", "https");

                HttpResponse response = httpclient.execute(httpget);

                string  length = response.getHeaders("CONTENT-LENGTH")[0].Value;
                sbyte[] data   = new sbyte[Convert.ToInt32(length)];
                response.Entity.Content.read(data);

                string responseEntityBody = StringHelper.NewString(data);

                assertTrue(responseEntityBody.Contains("https://foobar.com"));
                assertFalse(responseEntityBody.Contains("https://localhost"));
            }
            finally
            {
                httpclient.ConnectionManager.shutdown();
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldParameteriseUrisInRelationshipRepresentationWithoutHostHeaderUsingRequestUri() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldParameteriseUrisInRelationshipRepresentationWithoutHostHeaderUsingRequestUri()
        {
            HttpClient httpclient = new DefaultHttpClient();

            try
            {
                HttpGet httpget = new HttpGet(ServerUri + "db/data/relationship/" + _likes);

                httpget.setHeader("Accept", "application/json");
                HttpResponse response = httpclient.execute(httpget);
                HttpEntity   entity   = response.Entity;

                string entityBody = IOUtils.ToString(entity.Content, StandardCharsets.UTF_8);

                assertThat(entityBody, containsString(ServerUri + "db/data/relationship/" + _likes));
            }
            finally
            {
                httpclient.ConnectionManager.shutdown();
            }
        }
示例#3
0
        public virtual string httpGet(string url)
        {
            string domain = Resources.getString([email protected]_domain);
            string result = "";

            CookieStore      cookieStore  = new BasicCookieStore();
            BasicHttpContext localContext = new BasicHttpContext();

            localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

            // If we have a cookie stored, parse and use it. Otherwise, use a default http client.
            try
            {
                HttpClient httpClient = new DefaultHttpClient();
                HttpGet    httpGet    = new HttpGet(url);
                if (!authorizationCookie.Equals(""))
                {
                    string[] cookies = authorizationCookie.Split(";", true);
                    for (int i = 0; i < cookies.Length; i++)
                    {
                        string[] kvp = cookies[i].Split("=", true);
                        if (kvp.Length != 2)
                        {
                            throw new Exception("Illegal cookie: missing key/value pair.");
                        }
                        BasicClientCookie c = new BasicClientCookie(kvp[0], kvp[1]);
                        c.Domain = domain;
                        cookieStore.addCookie(c);
                    }
                }
                HttpResponse httpResponse = httpClient.execute(httpGet, localContext);
                result = EntityUtils.ToString(httpResponse.Entity);
            }
            catch (Exception e)
            {
                Log.e(TAG, e.LocalizedMessage);
            }

            return(result);
        }
示例#4
0
        protected HttpResponse execute(HttpUriRequest request)
        {
            DefaultHttpClient httpclient = new DefaultHttpClient();

            try {
                // Execute the request
                HttpResponse response = httpclient.execute(request);
                return response;

            }catch (UnknownHostException e){
                throw e;
            } catch (ClientProtocolException e) {
                e.PrintStackTrace();
            } catch (IOException e) {
                e.PrintStackTrace();
            } catch (IllegalArgumentException e) {
                e.PrintStackTrace();
            } catch (IllegalStateException e) {
                e.PrintStackTrace();
            }

            return null;
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespondToHttpClientGet() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRespondToHttpClientGet()
        {
            using (DefaultHttpClient httpclient = new DefaultHttpClient())
            {
                HttpGet httpget = new HttpGet(_serverUrl + "/?id=storeId+v=kernelVersion");
                using (CloseableHttpResponse response = httpclient.execute(httpget))
                {
                    HttpEntity entity = response.Entity;
                    if (entity != null)
                    {
                        using (Stream instream = entity.Content)
                        {
                            sbyte[] tmp = new sbyte[2048];
                            while ((instream.Read(tmp, 0, tmp.Length)) != -1)
                            {
                            }
                        }
                    }
                    assertThat(response, notNullValue());
                    assertThat(response.StatusLine.StatusCode, @is(HttpStatus.SC_OK));
                }
            }
        }
示例#6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void blockUntilServerAvailable(final java.net.URL url) throws Exception
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        private void BlockUntilServerAvailable(URL url)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final PointerTo<bool> flag = new PointerTo<>(false);
            PointerTo <bool> flag = new PointerTo <bool>(false);

            Thread t = new Thread(() =>
            {
                while (!flag.Value)
                {
                    try
                    {
                        HttpGet httpget = new HttpGet(url.toURI());
                        httpget.addHeader("Accept", "application/json");
                        DefaultHttpClient client = new DefaultHttpClient();
                        client.execute(httpget);

                        // If we get here, the server's ready
                        flag.Value = true;
                        latch.Signal();
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e);
                    }
                }
            });

            t.run();

            assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));

            t.Join();
        }