@Before public void setUp() throws IOException { httpRequest = new NetHttpTransport() .createRequestFactory() .buildRequest("GET", new GenericUrl("https://www.google.com"), null); }
public GitHubClient(AccessTokenFactory tokenFactory) { this.tokenFactory = tokenFactory; requestFactory = new NetHttpTransport().createRequestFactory(); }
public SlackService(Proxy proxy) { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.setProxy(proxy); requestFactory = builder.build().createRequestFactory(); }
public SlackService(Proxy proxy) { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); builder.setProxy(proxy); requestFactory = builder.build().createRequestFactory(); }
public static String uploadFile(String appPath, String serverURL, String username, String password) throws IOException { HttpHeaders headers = new HttpHeaders(); if (username != null) { headers.setBasicAuthentication(username, password); } HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory(request -> { request.setParser(new JsonObjectParser(new JacksonFactory())); request.setHeaders(headers); }); MultipartContent multipartContent = new MultipartContent(); FileContent fileContent = new FileContent("application/octet-stream", new File(appPath)); MultipartContent.Part filePart = new MultipartContent.Part(new HttpHeaders() .set("Content-Disposition", "form-data; name=\"file\"; filename=\"" + fileContent.getFile().getName() + "\""), fileContent); multipartContent.addPart(filePart); HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(serverURL), multipartContent); HttpResponse response = request.execute(); LoggerFactory.getLogger(AppiumDriverWrapper.class).info("response:" + response.parseAsString()); AppiumResponse appiumResponse = request.execute().parseAs(AppiumResponse.class); LoggerFactory.getLogger(AppiumDriverWrapper.class).info("File id:" + appiumResponse.uploadStatus.fileInfo.file); return appiumResponse.uploadStatus.fileInfo.file; }
@Override public JsonRPCResponse invokeAndReadResponse(JsonRPCRequest requestObject, URI endpointUri, boolean sslVerificationDisabled) throws SteemCommunicationException { try { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification if needed if (sslVerificationDisabled && endpointUri.getScheme().equals("https")) { builder.doNotValidateCertificate(); } String requestPayload = requestObject.toJson(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl(endpointUri), ByteArrayContent.fromString("application/json", requestPayload)); LOGGER.debug("Sending {}.", requestPayload); HttpResponse httpResponse = httpRequest.execute(); int status = httpResponse.getStatusCode(); String responsePayload = httpResponse.parseAsString(); if (status >= 200 && status < 300 && responsePayload != null) { return new JsonRPCResponse(CommunicationHandler.getObjectMapper().readTree(responsePayload)); } else { throw new ClientProtocolException("Unexpected response status: " + status); } } catch (GeneralSecurityException | IOException e) { throw new SteemCommunicationException("A problem occured while processing the request.", e); } }
@Override public JsonRPCResponse invokeAndReadResponse(JsonRPCRequest requestObject, URI endpointUri, boolean sslVerificationDisabled) throws SteemCommunicationException { try { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification if needed if (sslVerificationDisabled && endpointUri.getScheme().equals("https")) { builder.doNotValidateCertificate(); } String requestPayload = requestObject.toJson(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl(endpointUri), ByteArrayContent.fromString("application/json", requestPayload)); LOGGER.debug("Sending {}.", requestPayload); HttpResponse httpResponse = httpRequest.execute(); int status = httpResponse.getStatusCode(); String responsePayload = httpResponse.parseAsString(); if (status >= 200 && status < 300 && responsePayload != null) { return new JsonRPCResponse(CommunicationHandler.getObjectMapper().readTree(responsePayload)); } else { throw new ClientProtocolException("Unexpected response status: " + status); } } catch (GeneralSecurityException | IOException e) { throw new SteemCommunicationException("A problem occured while processing the request.", e); } }
reportServiceLogger = new ReportServiceLogger(loggerDelegate); requestFactory = new NetHttpTransport().createRequestFactory();
/** * Create a new TestNet account as described in the TestNet main page * (https://testnet.steem.vc). * * @param username * The account to create. * @param password * The password to set for the <code>username</code>. * @throws IOException * In case something went wrong. * @throws GeneralSecurityException * In case something went wrong. */ private static void createTestNetAccount(String username, String password) throws IOException, GeneralSecurityException { NetHttpTransport.Builder builder = new NetHttpTransport.Builder(); // Disable SSL verification: builder.doNotValidateCertificate(); HttpRequest httpRequest = builder.build().createRequestFactory(new HttpClientRequestInitializer()) .buildPostRequest(new GenericUrl("https://testnet.steem.vc/create"), ByteArrayContent.fromString( "application/x-www-form-urlencoded", "username=" + username + "&password=" + password)); try { httpRequest.execute(); } catch (HttpResponseException e) { if (e.getStatusCode() != 409) { LOGGER.info("Account already existed."); } } } }
final Object payload, final ResponseReader<T> responseReader) { final HttpRequestFactory requestFactory = transport.createRequestFactory();