Example #1
0
  public void build(String url, UploadCallback callback) {
    try {
      for (Map.Entry<String, Object> entry : params.entrySet()) {
        String name = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof String)
          builder.addPart(name, new StringBody((String) value, Consts.UTF_8));
        else if (value instanceof File)
          builder.addPart(
              name,
              new FileBody((File) value, ContentType.create("image/*"), ((File) value).getName()));
      }

      HttpPost post = new HttpPost(url);
      builder.setCharset(Consts.UTF_8);
      post.setEntity(builder.build());

      HttpClient client = new DefaultHttpClient();
      HttpResponse response = client.execute(post);
      if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
        String responseBody = EntityUtils.toString(response.getEntity());
        if (callback != null) callback.onSuccess(JSON.parseObject(responseBody));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
    @Override
    protected JSONArray doInBackground(Void... params) {
      HttpClient httpclient = new DefaultHttpClient();
      HttpGet httpget =
          new HttpGet("http://apexbackend.azurewebsites.net/api/advices/patient/" + patientId);

      httpget.setHeader(HTTP.CONTENT_TYPE, "application/x-www-form-urlencoded;charset=UTF-8");
      httpget.setHeader("Authorization", "Bearer " + access_token);

      JSONArray json = new JSONArray();

      // Execute HTTP Get Request
      try {
        HttpResponse response = httpclient.execute(httpget);
        String json_string = EntityUtils.toString(response.getEntity());
        json = new JSONArray(json_string);
        System.out.println(json);
      } catch (IOException | JSONException e) {
        e.printStackTrace();
      }

      return json;
    }
Example #3
0
    public CloseableHttpResponse execute(HttpRoute httproute, HttpRequestWrapper httprequestwrapper, HttpClientContext httpclientcontext, HttpExecutionAware httpexecutionaware)
        throws IOException, HttpException
    {
        Object obj;
        CloseableHttpResponse closeablehttpresponse;
        int j;
        Args.notNull(httproute, "HTTP route");
        Args.notNull(httprequestwrapper, "HTTP request");
        Args.notNull(httpclientcontext, "HTTP context");
        obj = httpclientcontext.getRedirectLocations();
        if (obj != null)
        {
            ((List) (obj)).clear();
        }
        RequestConfig requestconfig = httpclientcontext.getRequestConfig();
        int i;
        if (requestconfig.getMaxRedirects() > 0)
        {
            i = requestconfig.getMaxRedirects();
        } else
        {
            i = 50;
        }
        obj = httprequestwrapper;
        j = 0;
_L1:
        closeablehttpresponse = requestExecutor.execute(httproute, ((HttpRequestWrapper) (obj)), httpclientcontext, httpexecutionaware);
        if (!requestconfig.isRedirectsEnabled() || !redirectStrategy.isRedirected(((HttpRequest) (obj)), closeablehttpresponse, httpclientcontext))
        {
            break MISSING_BLOCK_LABEL_507;
        }
        if (j >= i)
        {
            java.net.URI uri;
            HttpHost httphost;
            AuthScheme authscheme;
            try
            {
                throw new RedirectException((new StringBuilder()).append("Maximum redirects (").append(i).append(") exceeded").toString());
            }
            // Misplaced declaration of an exception variable
            catch (HttpRoute httproute)
            {
                closeablehttpresponse.close();
                throw httproute;
            }
            // Misplaced declaration of an exception variable
            catch (HttpRoute httproute)
            {
                closeablehttpresponse.close();
                throw httproute;
            }
            // Misplaced declaration of an exception variable
            catch (HttpRoute httproute) { }
            break MISSING_BLOCK_LABEL_457;
        }
        j++;
        obj = redirectStrategy.getRedirect(((HttpRequest) (obj)), closeablehttpresponse, httpclientcontext);
        if (!((HttpRequest) (obj)).headerIterator().hasNext())
        {
            ((HttpRequest) (obj)).setHeaders(httprequestwrapper.getOriginal().getAllHeaders());
        }
        obj = HttpRequestWrapper.wrap(((HttpRequest) (obj)));
        if (obj instanceof HttpEntityEnclosingRequest)
        {
            RequestEntityProxy.enhance((HttpEntityEnclosingRequest)obj);
        }
        uri = ((HttpRequestWrapper) (obj)).getURI();
        httphost = URIUtils.extractHost(uri);
        if (httphost != null)
        {
            break MISSING_BLOCK_LABEL_298;
        }
        throw new ProtocolException((new StringBuilder()).append("Redirect URI does not specify a valid host name: ").append(uri).toString());
        if (httproute.getTargetHost().equals(httphost))
        {
            break MISSING_BLOCK_LABEL_375;
        }
        httproute = httpclientcontext.getTargetAuthState();
        if (httproute == null)
        {
            break MISSING_BLOCK_LABEL_332;
        }
        log.debug("Resetting target auth state");
        httproute.reset();
        httproute = httpclientcontext.getProxyAuthState();
        if (httproute == null)
        {
            break MISSING_BLOCK_LABEL_375;
        }
        authscheme = httproute.getAuthScheme();
        if (authscheme == null)
        {
            break MISSING_BLOCK_LABEL_375;
        }
        if (authscheme.isConnectionBased())
        {
            log.debug("Resetting proxy auth state");
            httproute.reset();
        }
        httproute = routePlanner.determineRoute(httphost, ((HttpRequest) (obj)), httpclientcontext);
        if (log.isDebugEnabled())
        {
            log.debug((new StringBuilder()).append("Redirecting to '").append(uri).append("' via ").append(httproute).toString());
        }
        EntityUtils.consume(closeablehttpresponse.getEntity());
        closeablehttpresponse.close();
          goto _L1