示例#1
0
    @SuppressWarnings("deprecation")
    private Scheme configureScheme() {
      if (enableSSL) {
        try {
          if (sslSocketFactory == null) {
            SSLContext context = SSLContext.getInstance("TLS");

            if (relaxedSSLSettings) {
              context.init(
                  null,
                  new TrustManager[] {
                    new X509TrustManager() {
                      public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return null;
                      }

                      public void checkClientTrusted(
                          java.security.cert.X509Certificate[] certs, String authType) {}

                      public void checkServerTrusted(
                          java.security.cert.X509Certificate[] certs, String authType) {}
                    }
                  },
                  null);
            }

            sslSocketFactory =
                relaxedSSLSettings
                    ? new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)
                    : new SSLSocketFactory(context);
          }
          return new Scheme("https", port, sslSocketFactory);
        } catch (NoSuchMethodError e) {
          try {
            AndroidSSLSocketFactory androidSSLSocketFactory =
                new AndroidSSLSocketFactory((KeyStore) null);
            androidSSLSocketFactory.setHostnameVerifier(
                SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            return new Scheme("https", androidSSLSocketFactory, port);
          } catch (Exception e1) {
            throw Exceptions.propagate(e1);
          }
        } catch (Exception e) {
          throw Exceptions.propagate(e);
        }
      } else {
        return new Scheme("http", port, PlainSocketFactory.getSocketFactory());
      }
    }
 private String getString(String resourceName) {
   try {
     return IOUtils.toString(getClass().getResourceAsStream(resourceName), "UTF-8");
   } catch (IOException e) {
     throw Exceptions.propagate(e);
   }
 }
示例#3
0
 /**
  * @param Will be JSON-encoded.
  * @return the view query for chained calls
  */
 public ViewQuery endKey(Object o) {
   reset();
   try {
     endKey = mapper.writeValueAsString(o);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
   return this;
 }
示例#4
0
 public String toJson(ObjectMapper mapper) {
   ObjectNode rootNode = mapper.createObjectNode();
   ArrayNode keysNode = rootNode.putArray("keys");
   for (Object key : keys) {
     keysNode.addPOJO(key);
   }
   try {
     return mapper.writeValueAsString(rootNode);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
示例#5
0
 public ContinuousChangesFeed(String dbName, HttpResponse httpResponse) {
   this.httpResponse = httpResponse;
   try {
     reader = new BufferedReader(new InputStreamReader(httpResponse.getContent(), "UTF-8"));
     thread.setName(
         String.format(
             "ektorp-%s-changes-listening-thread-%s", dbName, THREAD_COUNT.getAndIncrement()));
     thread.start();
   } catch (UnsupportedEncodingException e) {
     throw Exceptions.propagate(e);
   }
 }
示例#6
0
 private DesignDocument.View loadViewFromFile(
     Map<String, DesignDocument.View> views, View input, Class<?> repositoryClass) {
   try {
     InputStream in = repositoryClass.getResourceAsStream(input.file());
     if (in == null) {
       throw new FileNotFoundException("Could not load view file with path: " + input.file());
     }
     String json = IOUtils.toString(in, "UTF-8");
     return mapper().readValue(json.replaceAll("\n", ""), DesignDocument.View.class);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
示例#7
0
 private HttpResponse executePutPost(
     HttpEntityEnclosingRequestBase request, String content, boolean useBackend) {
   try {
     if (LOG.isTraceEnabled()) {
       LOG.trace("Content: {}", content);
     }
     StringEntity e = new StringEntity(content, "UTF-8");
     e.setContentType("application/json");
     request.setEntity(e);
     return executeRequest(request, useBackend);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }
示例#8
0
 private HttpResponse executeRequest(HttpRequestBase request, boolean useBackend) {
   try {
     org.apache.http.HttpResponse rsp;
     if (useBackend) {
       rsp = backend.execute(request);
     } else {
       rsp =
           client.execute(
               (HttpHost) client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request);
     }
     if (LOG.isTraceEnabled()) {
       LOG.trace(
           String.format(
               "%s %s %s %s",
               request.getMethod(),
               request.getURI(),
               rsp.getStatusLine().getStatusCode(),
               rsp.getStatusLine().getReasonPhrase()));
     }
     return StdHttpResponse.of(rsp, request);
   } catch (Exception e) {
     throw Exceptions.propagate(e);
   }
 }