Java Code Examples for com.google.api.client.http.httpheaders#set()
The following examples show how to use
com.google.api.client.http.httpheaders#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockHttpServerTest.java From googleads-java-lib with Apache License 2.0 | 6 votes |
/** * Tests behavior when URL validation is disabled. */ @Test public void testUrlMismatch_verifyDisabled() throws IOException { MockResponse mockResponse = new MockResponse("test response"); mockResponse.setValidateUrlMatches(false); HttpRequest request = mockHttpServer .getHttpTransport() .createRequestFactory() .buildGetRequest( new GenericUrl("http://www.example.com/does_not_match_mock_http_server_url")); request.setContent(new ByteArrayContent("text", "test content".getBytes(UTF_8))); HttpHeaders headers = new HttpHeaders(); headers.set("one", "1"); headers.set("two", "2"); request.setHeaders(headers); mockHttpServer.setMockResponse(mockResponse); HttpResponse response = request.execute(); ActualResponse actualResponse = mockHttpServer.getLastResponse(); assertEquals("Incorrect response code", 200, response.getStatusCode()); assertEquals( "Request header 'one' incorrect", "1", actualResponse.getRequestHeader("one").get(0)); assertEquals( "Request header 'two' incorrect", "2", actualResponse.getRequestHeader("two").get(0)); }
Example 2
Source File: DicomWebRetrieveRendered.java From java-docs-samples with Apache License 2.0 | 6 votes |
private static CloudHealthcare createClient() throws IOException { // Use Application Default Credentials (ADC) to authenticate the requests // For more information see https://cloud.google.com/docs/authentication/production GoogleCredentials credential = GoogleCredentials.getApplicationDefault() .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM)); HttpHeaders headers = new HttpHeaders(); headers.set("X-GFE-SSL", "yes"); // Retrieve using the PNG consumer imaging format. headers.setAccept("image/png"); // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests. HttpRequestInitializer requestInitializer = request -> { new HttpCredentialsAdapter(credential).initialize(request); request.setConnectTimeout(60000); // 1 minute connect timeout request.setReadTimeout(60000); // 1 minute read timeout }; // Build the client for interacting with the service. return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer) .setApplicationName("your-application-name") .build(); }
Example 3
Source File: StorageFactory.java From dlp-dataflow-deidentification with Apache License 2.0 | 6 votes |
public static InputStream downloadObject( Storage storage, String bucketName, String objectName, String base64CseKey, String base64CseKeyHash) throws Exception { // Set the CSEK headers final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.set("x-goog-encryption-algorithm", "AES256"); httpHeaders.set("x-goog-encryption-key", base64CseKey); httpHeaders.set("x-goog-encryption-key-sha256", base64CseKeyHash); Storage.Objects.Get getObject = storage.objects().get(bucketName, objectName); getObject.setRequestHeaders(httpHeaders); try { return getObject.executeMediaAsInputStream(); } catch (GoogleJsonResponseException e) { LOG.info("Error downloading: " + e.getContent()); System.exit(1); return null; } }
Example 4
Source File: ProjectApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createTimeEntryForHttpResponse(String accessToken, String xeroTenantId, UUID projectId, TimeEntryCreateOrUpdate timeEntryCreateOrUpdate) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createTimeEntry"); }// verify the required parameter 'projectId' is set if (projectId == null) { throw new IllegalArgumentException("Missing the required parameter 'projectId' when calling createTimeEntry"); }// verify the required parameter 'timeEntryCreateOrUpdate' is set if (timeEntryCreateOrUpdate == null) { throw new IllegalArgumentException("Missing the required parameter 'timeEntryCreateOrUpdate' when calling createTimeEntry"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createTimeEntry"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("projectId", projectId); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/projects/{projectId}/time"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(timeEntryCreateOrUpdate); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 5
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse updateTimesheetForHttpResponse(String accessToken, String xeroTenantId, UUID timesheetID, List<Timesheet> timesheet) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling updateTimesheet"); }// verify the required parameter 'timesheetID' is set if (timesheetID == null) { throw new IllegalArgumentException("Missing the required parameter 'timesheetID' when calling updateTimesheet"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling updateTimesheet"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("TimesheetID", timesheetID); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Timesheets/{TimesheetID}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(timesheet); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 6
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getSuperfundForHttpResponse(String accessToken, String xeroTenantId, UUID superFundID) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getSuperfund"); }// verify the required parameter 'superFundID' is set if (superFundID == null) { throw new IllegalArgumentException("Missing the required parameter 'superFundID' when calling getSuperfund"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getSuperfund"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("SuperFundID", superFundID); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Superfunds/{SuperFundID}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 7
Source File: AssetApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createAssetForHttpResponse(String accessToken, String xeroTenantId, Asset asset) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createAsset"); }// verify the required parameter 'asset' is set if (asset == null) { throw new IllegalArgumentException("Missing the required parameter 'asset' when calling createAsset"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createAsset"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Assets"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(asset); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 8
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getPayrollCalendarForHttpResponse(String accessToken, String xeroTenantId, UUID payrollCalendarID) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getPayrollCalendar"); }// verify the required parameter 'payrollCalendarID' is set if (payrollCalendarID == null) { throw new IllegalArgumentException("Missing the required parameter 'payrollCalendarID' when calling getPayrollCalendar"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getPayrollCalendar"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("PayrollCalendarID", payrollCalendarID); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/PayrollCalendars/{PayrollCalendarID}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 9
Source File: BankFeedsApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse deleteFeedConnectionsForHttpResponse(String accessToken, String xeroTenantId, FeedConnections feedConnections) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling deleteFeedConnections"); }// verify the required parameter 'feedConnections' is set if (feedConnections == null) { throw new IllegalArgumentException("Missing the required parameter 'feedConnections' when calling deleteFeedConnections"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling deleteFeedConnections"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/FeedConnections/DeleteRequests"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(feedConnections); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 10
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getLeaveApplicationForHttpResponse(String accessToken, String xeroTenantId, UUID leaveApplicationId) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getLeaveApplication"); }// verify the required parameter 'leaveApplicationId' is set if (leaveApplicationId == null) { throw new IllegalArgumentException("Missing the required parameter 'leaveApplicationId' when calling getLeaveApplication"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getLeaveApplication"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("LeaveApplicationId", leaveApplicationId); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/LeaveApplications/{LeaveApplicationId}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 11
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getEmployeeForHttpResponse(String accessToken, String xeroTenantId, UUID employeeId) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getEmployee"); }// verify the required parameter 'employeeId' is set if (employeeId == null) { throw new IllegalArgumentException("Missing the required parameter 'employeeId' when calling getEmployee"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getEmployee"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("EmployeeId", employeeId); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Employees/{EmployeeId}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 12
Source File: AssetApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createAssetTypeForHttpResponse(String accessToken, String xeroTenantId, AssetType assetType) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createAssetType"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createAssetType"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/AssetTypes"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(assetType); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 13
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createPayrollCalendarForHttpResponse(String accessToken, String xeroTenantId, List<PayrollCalendar> payrollCalendar) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createPayrollCalendar"); }// verify the required parameter 'payrollCalendar' is set if (payrollCalendar == null) { throw new IllegalArgumentException("Missing the required parameter 'payrollCalendar' when calling createPayrollCalendar"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createPayrollCalendar"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/PayrollCalendars"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(payrollCalendar); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 14
Source File: BankFeedsApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createFeedConnectionsForHttpResponse(String accessToken, String xeroTenantId, FeedConnections feedConnections) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createFeedConnections"); }// verify the required parameter 'feedConnections' is set if (feedConnections == null) { throw new IllegalArgumentException("Missing the required parameter 'feedConnections' when calling createFeedConnections"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createFeedConnections"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/FeedConnections"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(feedConnections); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 15
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createPayItemForHttpResponse(String accessToken, String xeroTenantId, PayItem payItem) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createPayItem"); }// verify the required parameter 'payItem' is set if (payItem == null) { throw new IllegalArgumentException("Missing the required parameter 'payItem' when calling createPayItem"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createPayItem"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/PayItems"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(payItem); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 16
Source File: AssetApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getAssetSettingsForHttpResponse(String accessToken, String xeroTenantId) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getAssetSettings"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getAssetSettings"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Settings"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 17
Source File: PayrollAuApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse createEmployeeForHttpResponse(String accessToken, String xeroTenantId, List<Employee> employee) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling createEmployee"); }// verify the required parameter 'employee' is set if (employee == null) { throw new IllegalArgumentException("Missing the required parameter 'employee' when calling createEmployee"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling createEmployee"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Employees"); String url = uriBuilder.build().toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("POST " + genericUrl.toString()); } HttpContent content = null; content = apiClient.new JacksonJsonHttpContent(employee); Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.POST, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 18
Source File: GoogleVideosInterface.java From data-transfer-project with Apache License 2.0 | 5 votes |
<T> T makePostRequest( String url, Optional<Map<String, String>> parameters, HttpContent httpContent, Class<T> clazz) throws IOException { HttpRequestFactory requestFactory = httpTransport.createRequestFactory(); HttpRequest postRequest = requestFactory.buildPostRequest( new GenericUrl(url + "?" + generateParamsString(parameters)), httpContent); // TODO: Figure out why this is necessary for videos but not for photos HttpHeaders headers = new HttpHeaders(); headers.setContentType("application/octet-stream"); headers.setAuthorization("Bearer " + this.credential.getAccessToken()); headers.set("X-Goog-Upload-Protocol", "raw"); postRequest.setHeaders(headers); HttpResponse response = postRequest.execute(); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new IOException( "Bad status code: " + statusCode + " error: " + response.getStatusMessage()); } String result = CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8)); if (clazz.isAssignableFrom(String.class)) { return (T) result; } else { return objectMapper.readValue(result, clazz); } }
Example 19
Source File: ProjectApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getTaskForHttpResponse(String accessToken, String xeroTenantId, UUID projectId, UUID taskId) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getTask"); }// verify the required parameter 'projectId' is set if (projectId == null) { throw new IllegalArgumentException("Missing the required parameter 'projectId' when calling getTask"); }// verify the required parameter 'taskId' is set if (taskId == null) { throw new IllegalArgumentException("Missing the required parameter 'taskId' when calling getTask"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getTask"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("projectId", projectId); uriVariables.put("taskId", taskId); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/projects/{projectId}/tasks/{taskId}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }
Example 20
Source File: ProjectApi.java From Xero-Java with MIT License | 5 votes |
public HttpResponse getProjectForHttpResponse(String accessToken, String xeroTenantId, UUID projectId) throws IOException { // verify the required parameter 'xeroTenantId' is set if (xeroTenantId == null) { throw new IllegalArgumentException("Missing the required parameter 'xeroTenantId' when calling getProject"); }// verify the required parameter 'projectId' is set if (projectId == null) { throw new IllegalArgumentException("Missing the required parameter 'projectId' when calling getProject"); } if (accessToken == null) { throw new IllegalArgumentException("Missing the required parameter 'accessToken' when calling getProject"); } HttpHeaders headers = new HttpHeaders(); headers.set("Xero-Tenant-Id", xeroTenantId); headers.setAccept("application/json"); headers.setUserAgent(this.getUserAgent()); // create a map of path variables final Map<String, Object> uriVariables = new HashMap<String, Object>(); uriVariables.put("projectId", projectId); UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/projects/{projectId}"); String url = uriBuilder.buildFromMap(uriVariables).toString(); GenericUrl genericUrl = new GenericUrl(url); if (logger.isDebugEnabled()) { logger.debug("GET " + genericUrl.toString()); } HttpContent content = null; Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken); HttpTransport transport = apiClient.getHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(credential); return requestFactory.buildRequest(HttpMethods.GET, genericUrl, content).setHeaders(headers) .setConnectTimeout(apiClient.getConnectionTimeout()) .setReadTimeout(apiClient.getReadTimeout()).execute(); }