类com.google.api.client.http.HttpResponseException源码实例Demo

下面列出了怎么用com.google.api.client.http.HttpResponseException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Xero-Java   文件: ProjectApi.java
/**
* create one or more new projects
* <p><b>201</b> - OK/success, returns the new project object
* <p><b>400</b> - A failed request due to validation error
* @param xeroTenantId Xero identifier for Tenant
* @param projectCreateOrUpdate Create a new project with ProjectCreateOrUpdate object
* @param accessToken Authorization token for user set in header of each request
* @return Project
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Project  createProject(String accessToken, String xeroTenantId, ProjectCreateOrUpdate projectCreateOrUpdate) throws IOException {
    try {
        TypeReference<Project> typeRef = new TypeReference<Project>() {};
        HttpResponse response = createProjectForHttpResponse(accessToken, xeroTenantId, projectCreateOrUpdate);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : createProject -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
private <T> T makeGetRequest(String url, Optional<Map<String, String>> parameters, Class<T> clazz)
        throws IOException, InvalidTokenException, PermissionDeniedException {
  HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
  HttpRequest getRequest =
      requestFactory.buildGetRequest(
          new GenericUrl(url + "?" + generateParamsString(parameters)));

  HttpResponse response;
  try {
    response = getRequest.execute();
  } catch (HttpResponseException e) {
    response =
        handleHttpResponseException(
            () ->
                requestFactory.buildGetRequest(
                    new GenericUrl(url + "?" + generateParamsString(parameters))),
            e);
  }

  Preconditions.checkState(response.getStatusCode() == 200);
  String result =
      CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
  return objectMapper.readValue(result, clazz);
}
 
源代码3 项目: Xero-Java   文件: ProjectApi.java
/**
* list all projects
* Allows you to retrieve, create and update projects.
* <p><b>200</b> - OK/success, returns a list of project objects
* <p><b>400</b> - A failed request due to validation error
* @param xeroTenantId Xero identifier for Tenant
* @param projectIds Search for all projects that match a comma separated list of projectIds
* @param contactID Filter for projects for a specific contact
* @param states Filter for projects in a particular state (INPROGRESS or CLOSED)
* @param page set to 1 by default. The requested number of the page in paged response - Must be a number greater than 0.
* @param pageSize Optional, it is set to 50 by default. The number of items to return per page in a paged response - Must be a number between 1 and 500.
* @param accessToken Authorization token for user set in header of each request
* @return Projects
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Projects  getProjects(String accessToken, String xeroTenantId, List<UUID> projectIds, UUID contactID, String states, Integer page, Integer pageSize) throws IOException {
    try {
        TypeReference<Projects> typeRef = new TypeReference<Projects>() {};
        HttpResponse response = getProjectsForHttpResponse(accessToken, xeroTenantId, projectIds, contactID, states, page, pageSize);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getProjects -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码4 项目: Xero-Java   文件: ProjectApi.java
/**
* update a specific project
* Allows you to update a specific projects.
* <p><b>204</b> - Success - return response 204 no content
* <p><b>400</b> - A failed request due to validation error
* @param xeroTenantId Xero identifier for Tenant
* @param projectId You can specify an individual project by appending the projectId to the endpoint
* @param projectCreateOrUpdate Request of type ProjectCreateOrUpdate
* @param accessToken Authorization token for user set in header of each request
* @throws IOException if an error occurs while attempting to invoke the API
**/
public void updateProject(String accessToken, String xeroTenantId, UUID projectId, ProjectCreateOrUpdate projectCreateOrUpdate) throws IOException {
    try {
        updateProjectForHttpResponse(accessToken, xeroTenantId, projectId, projectCreateOrUpdate);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : updateProject -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    
}
 
@Test
public void testRetryOnHttpError() throws IOException {
  MockSleeper sleeper = new MockSleeper();
  RetryInitializer initializer = new RetryInitializer(
      retryOnIOAndServiceUnavailableErrors(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(503);
  HttpRequest request = TestUtils.createRequest(failingRequest);
  initializer.initialize(request);
  final HttpUnsuccessfulResponseHandler retryHandler = request.getUnsuccessfulResponseHandler();

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(MAX_RETRIES, sleeper.getCount());
  assertEquals(MAX_RETRIES + 1, failingRequest.getCount());
  assertSame(retryHandler, request.getUnsuccessfulResponseHandler());
}
 
@Test
public void testCredentialsRetryHandler() throws Exception {
  FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
      .setCredentials(new MockGoogleCredentials("token"))
      .build());
  RetryConfig retryConfig = RetryConfig.builder()
      .setMaxRetries(MAX_RETRIES)
      .build();
  CountingLowLevelHttpRequest countingRequest = CountingLowLevelHttpRequest.fromStatus(401);
  HttpRequest request = TestUtils.createRequest(countingRequest);
  FirebaseRequestInitializer initializer = new FirebaseRequestInitializer(app, retryConfig);
  initializer.initialize(request);
  request.getHeaders().setAuthorization((String) null);

  try {
    request.execute();
  } catch (HttpResponseException e) {
    assertEquals(401, e.getStatusCode());
  }

  assertEquals("Bearer token", request.getHeaders().getAuthorization());
  assertEquals(MAX_RETRIES + 1, countingRequest.getCount());
}
 
@Test
public void testDoesNotRetryOnUnspecifiedHttpStatus() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(404);
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(MAX_RETRIES);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(404, e.getStatusCode());
  }

  assertEquals(0, sleeper.getCount());
  assertEquals(1, failingRequest.getCount());
}
 
@Test
public void testRetryOnHttpClientErrorWhenSpecified() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(429);
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(MAX_RETRIES);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(429, e.getStatusCode());
  }

  assertEquals(MAX_RETRIES, sleeper.getCount());
  assertArrayEquals(new long[]{500, 1000, 2000, 4000}, sleeper.getDelays());
  assertEquals(MAX_RETRIES + 1, failingRequest.getCount());
}
 
@Test
public void testExponentialBackOffDoesNotExceedMaxInterval() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(503);
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(10);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(10, sleeper.getCount());
  assertArrayEquals(
      new long[]{500, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 120000, 120000},
      sleeper.getDelays());
  assertEquals(11, failingRequest.getCount());
}
 
@Test
public void testRetryAfterGivenAsSeconds() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(
      503, ImmutableMap.of("retry-after", "2"));
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(MAX_RETRIES);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(MAX_RETRIES, sleeper.getCount());
  assertArrayEquals(new long[]{2000, 2000, 2000, 2000}, sleeper.getDelays());
  assertEquals(MAX_RETRIES + 1, failingRequest.getCount());
}
 
@Test
public void testInvalidRetryAfterFailsOverToExpBackOff() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(
      503, ImmutableMap.of("retry-after", "not valid"));
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(4);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(4, sleeper.getCount());
  assertArrayEquals(new long[]{500, 1000, 2000, 4000}, sleeper.getDelays());
  assertEquals(5, failingRequest.getCount());
}
 
@Test
public void testDoesNotRetryWhenRetryAfterIsTooLong() throws IOException {
  MultipleCallSleeper sleeper = new MultipleCallSleeper();
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(
      503, ImmutableMap.of("retry-after", "121"));
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(MAX_RETRIES);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(0, sleeper.getCount());
  assertEquals(1, failingRequest.getCount());
}
 
@Test
public void testDoesNotRetryAfterInterruption() throws IOException {
  MockSleeper sleeper = new MockSleeper() {
    @Override
    public void sleep(long millis) throws InterruptedException {
      super.sleep(millis);
      throw new InterruptedException();
    }
  };
  RetryUnsuccessfulResponseHandler handler = new RetryUnsuccessfulResponseHandler(
      testRetryConfig(sleeper));
  CountingLowLevelHttpRequest failingRequest = CountingLowLevelHttpRequest.fromStatus(503);
  HttpRequest request = TestUtils.createRequest(failingRequest);
  request.setUnsuccessfulResponseHandler(handler);
  request.setNumberOfRetries(MAX_RETRIES);

  try {
    request.execute();
    fail("No exception thrown for HTTP error");
  } catch (HttpResponseException e) {
    assertEquals(503, e.getStatusCode());
  }

  assertEquals(1, sleeper.getCount());
  assertEquals(1, failingRequest.getCount());
}
 
源代码14 项目: Xero-Java   文件: AssetApi.java
/**
* searches fixed asset
* By passing in the appropriate options, you can search for available fixed asset in the system
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - bad input parameter
* @param xeroTenantId Xero identifier for Tenant
* @param status Required when retrieving a collection of assets. See Asset Status Codes
* @param page Results are paged. This specifies which page of the results to return. The default page is 1.
* @param pageSize The number of records returned per page. By default the number of records returned is 10.
* @param orderBy Requests can be ordered by AssetType, AssetName, AssetNumber, PurchaseDate and PurchasePrice. If the asset status is DISPOSED it also allows DisposalDate and DisposalPrice.
* @param sortDirection ASC or DESC
* @param filterBy A string that can be used to filter the list to only return assets containing the text. Checks it against the AssetName, AssetNumber, Description and AssetTypeName fields.
* @param accessToken Authorization token for user set in header of each request
* @return Assets
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Assets  getAssets(String accessToken, String xeroTenantId, AssetStatusQueryParam status, Integer page, Integer pageSize, String orderBy, String sortDirection, String filterBy) throws IOException {
    try {
        TypeReference<Assets> typeRef = new TypeReference<Assets>() {};
        HttpResponse response = getAssetsForHttpResponse(accessToken, xeroTenantId, status, page, pageSize, orderBy, sortDirection, filterBy);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getAssets -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
@Test
public void getEncodedTimeSeries_nullLabels_encodes() throws Exception {
  ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
  HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(400, inputStream);
  HttpResponseException.Builder httpResponseExceptionBuilder =
      new HttpResponseException.Builder(response);
  httpResponseExceptionBuilder.setStatusCode(400);
  httpResponseExceptionBuilder.setStatusMessage("ALREADY_EXISTS");
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
  when(metricDescriptorCreate.execute()).thenThrow(exception);
  when(metricDescriptorGet.execute())
      .thenReturn(new MetricDescriptor().setName("foo").setLabels(null));
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);
  writer.registerMetric(metric);

  TimeSeries timeSeries =
      writer.getEncodedTimeSeries(
          MetricPoint.create(metric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), 10L));

  assertThat(timeSeries.getMetric().getLabels()).isEmpty();
}
 
源代码16 项目: cyberduck   文件: DriveExceptionMappingService.java
@Override
public BackgroundException map(final IOException failure) {
    final StringBuilder buffer = new StringBuilder();
    if(failure instanceof GoogleJsonResponseException) {
        final GoogleJsonResponseException error = (GoogleJsonResponseException) failure;
        this.append(buffer, error.getDetails().getMessage());
        switch(error.getDetails().getCode()) {
            case HttpStatus.SC_FORBIDDEN:
                final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors();
                for(GoogleJsonError.ErrorInfo info : errors) {
                    if("usageLimits".equals(info.getDomain())) {
                        return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure);
                    }
                }
                break;
        }
    }
    if(failure instanceof HttpResponseException) {
        final HttpResponseException response = (HttpResponseException) failure;
        this.append(buffer, response.getStatusMessage());
        return new DefaultHttpResponseExceptionMappingService().map(new org.apache.http.client
                .HttpResponseException(response.getStatusCode(), buffer.toString()));
    }
    return super.map(failure);
}
 
源代码17 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches employees
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param ifModifiedSince Only records created or modified since this timestamp will be returned
* @param where Filter by an any element
* @param order Order by an any element
* @param page e.g. page&#x3D;1 – Up to 100 employees will be returned in a single API call
* @param accessToken Authorization token for user set in header of each request
* @return Employees
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Employees  getEmployees(String accessToken, String xeroTenantId, String ifModifiedSince, String where, String order, Integer page) throws IOException {
    try {
        TypeReference<Employees> typeRef = new TypeReference<Employees>() {};
        HttpResponse response = getEmployeesForHttpResponse(accessToken, xeroTenantId, ifModifiedSince, where, order, page);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getEmployees -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码18 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches for an Leave Application by unique id
* <p><b>200</b> - search results matching criteria
* @param xeroTenantId Xero identifier for Tenant
* @param leaveApplicationId Leave Application id for single object
* @param accessToken Authorization token for user set in header of each request
* @return LeaveApplications
* @throws IOException if an error occurs while attempting to invoke the API
**/
public LeaveApplications  getLeaveApplication(String accessToken, String xeroTenantId, UUID leaveApplicationId) throws IOException {
    try {
        TypeReference<LeaveApplications> typeRef = new TypeReference<LeaveApplications>() {};
        HttpResponse response = getLeaveApplicationForHttpResponse(accessToken, xeroTenantId, leaveApplicationId);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getLeaveApplication -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码19 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches PayRuns
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param ifModifiedSince Only records created or modified since this timestamp will be returned
* @param where Filter by an any element
* @param order Order by an any element
* @param page e.g. page&#x3D;1 – Up to 100 PayRuns will be returned in a single API call
* @param accessToken Authorization token for user set in header of each request
* @return PayRuns
* @throws IOException if an error occurs while attempting to invoke the API
**/
public PayRuns  getPayRuns(String accessToken, String xeroTenantId, String ifModifiedSince, String where, String order, Integer page) throws IOException {
    try {
        TypeReference<PayRuns> typeRef = new TypeReference<PayRuns>() {};
        HttpResponse response = getPayRunsForHttpResponse(accessToken, xeroTenantId, ifModifiedSince, where, order, page);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getPayRuns -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码20 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches Payroll Calendars
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param payrollCalendarID Payroll Calendar id for single object
* @param accessToken Authorization token for user set in header of each request
* @return PayrollCalendars
* @throws IOException if an error occurs while attempting to invoke the API
**/
public PayrollCalendars  getPayrollCalendar(String accessToken, String xeroTenantId, UUID payrollCalendarID) throws IOException {
    try {
        TypeReference<PayrollCalendars> typeRef = new TypeReference<PayrollCalendars>() {};
        HttpResponse response = getPayrollCalendarForHttpResponse(accessToken, xeroTenantId, payrollCalendarID);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getPayrollCalendar -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码21 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches for an Superfund by unique id
* <p><b>200</b> - search results matching criteria
* @param xeroTenantId Xero identifier for Tenant
* @param superFundID Superfund id for single object
* @param accessToken Authorization token for user set in header of each request
* @return SuperFunds
* @throws IOException if an error occurs while attempting to invoke the API
**/
public SuperFunds  getSuperfund(String accessToken, String xeroTenantId, UUID superFundID) throws IOException {
    try {
        TypeReference<SuperFunds> typeRef = new TypeReference<SuperFunds>() {};
        HttpResponse response = getSuperfundForHttpResponse(accessToken, xeroTenantId, superFundID);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getSuperfund -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码22 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches SuperfundProducts
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param ABN The ABN of the Regulated SuperFund
* @param USI The USI of the Regulated SuperFund
* @param accessToken Authorization token for user set in header of each request
* @return SuperFundProducts
* @throws IOException if an error occurs while attempting to invoke the API
**/
public SuperFundProducts  getSuperfundProducts(String accessToken, String xeroTenantId, String ABN, String USI) throws IOException {
    try {
        TypeReference<SuperFundProducts> typeRef = new TypeReference<SuperFundProducts>() {};
        HttpResponse response = getSuperfundProductsForHttpResponse(accessToken, xeroTenantId, ABN, USI);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getSuperfundProducts -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码23 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches SuperFunds
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param ifModifiedSince Only records created or modified since this timestamp will be returned
* @param where Filter by an any element
* @param order Order by an any element
* @param page e.g. page&#x3D;1 – Up to 100 SuperFunds will be returned in a single API call
* @param accessToken Authorization token for user set in header of each request
* @return SuperFunds
* @throws IOException if an error occurs while attempting to invoke the API
**/
public SuperFunds  getSuperfunds(String accessToken, String xeroTenantId, String ifModifiedSince, String where, String order, Integer page) throws IOException {
    try {
        TypeReference<SuperFunds> typeRef = new TypeReference<SuperFunds>() {};
        HttpResponse response = getSuperfundsForHttpResponse(accessToken, xeroTenantId, ifModifiedSince, where, order, page);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getSuperfunds -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码24 项目: Xero-Java   文件: PayrollAuApi.java
/**
* searches timesheets
* <p><b>200</b> - search results matching criteria
* <p><b>400</b> - validation error for a bad request
* @param xeroTenantId Xero identifier for Tenant
* @param ifModifiedSince Only records created or modified since this timestamp will be returned
* @param where Filter by an any element
* @param order Order by an any element
* @param page e.g. page&#x3D;1 – Up to 100 timesheets will be returned in a single API call
* @param accessToken Authorization token for user set in header of each request
* @return Timesheets
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Timesheets  getTimesheets(String accessToken, String xeroTenantId, String ifModifiedSince, String where, String order, Integer page) throws IOException {
    try {
        TypeReference<Timesheets> typeRef = new TypeReference<Timesheets>() {};
        HttpResponse response = getTimesheetsForHttpResponse(accessToken, xeroTenantId, ifModifiedSince, where, order, page);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : getTimesheets -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码25 项目: Xero-Java   文件: PayrollAuApi.java
/**
* Update a PayRun
* Update properties on a single PayRun
* <p><b>200</b> - A successful request
* @param xeroTenantId Xero identifier for Tenant
* @param payRunID PayRun id for single object
* @param payRun The payRun parameter
* @param accessToken Authorization token for user set in header of each request
* @return PayRuns
* @throws IOException if an error occurs while attempting to invoke the API
**/
public PayRuns  updatePayRun(String accessToken, String xeroTenantId, UUID payRunID, List<PayRun> payRun) throws IOException {
    try {
        TypeReference<PayRuns> typeRef = new TypeReference<PayRuns>() {};
        HttpResponse response = updatePayRunForHttpResponse(accessToken, xeroTenantId, payRunID, payRun);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : updatePayRun -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码26 项目: Xero-Java   文件: PayrollAuApi.java
/**
* Update a Payslip
* Update lines on a single payslips
* <p><b>200</b> - A successful request - currently returns empty array for JSON
* @param xeroTenantId Xero identifier for Tenant
* @param payslipID Payslip id for single object
* @param payslipLines The payslipLines parameter
* @param accessToken Authorization token for user set in header of each request
* @return Payslips
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Payslips  updatePayslip(String accessToken, String xeroTenantId, UUID payslipID, List<PayslipLines> payslipLines) throws IOException {
    try {
        TypeReference<Payslips> typeRef = new TypeReference<Payslips>() {};
        HttpResponse response = updatePayslipForHttpResponse(accessToken, xeroTenantId, payslipID, payslipLines);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : updatePayslip -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        if (e.getStatusCode() == 400 || e.getStatusCode() == 405) {
            TypeReference<com.xero.models.accounting.Error> errorTypeRef = new TypeReference<com.xero.models.accounting.Error>() {};
            com.xero.models.accounting.Error error = apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
            handler.validationError("Error", error.getMessage());
        } else {
            handler.execute(e);
        }
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码27 项目: Xero-Java   文件: PayrollAuApi.java
/**
* Update a Superfund
* Update properties on a single Superfund
* <p><b>200</b> - A successful request
* @param xeroTenantId Xero identifier for Tenant
* @param superFundID Superfund id for single object
* @param superFund The superFund parameter
* @param accessToken Authorization token for user set in header of each request
* @return SuperFunds
* @throws IOException if an error occurs while attempting to invoke the API
**/
public SuperFunds  updateSuperfund(String accessToken, String xeroTenantId, UUID superFundID, List<SuperFund> superFund) throws IOException {
    try {
        TypeReference<SuperFunds> typeRef = new TypeReference<SuperFunds>() {};
        HttpResponse response = updateSuperfundForHttpResponse(accessToken, xeroTenantId, superFundID, superFund);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : updateSuperfund -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码28 项目: Xero-Java   文件: IdentityApi.java
/**
* Allows you to delete a connection for this user (i.e. disconnect a tenant)
* Override the base server url that include version
* <p><b>204</b> - Success - connection has been deleted no content returned
* <p><b>404</b> - Resource not found
* @param id Unique identifier for retrieving single object
* @param accessToken Authorization token for user set in header of each request
* @throws IOException if an error occurs while attempting to invoke the API
**/
public void deleteConnection(String accessToken, UUID id) throws IOException {
    try {
        deleteConnectionForHttpResponse(accessToken, id);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : deleteConnection -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    
}
 
源代码29 项目: Xero-Java   文件: BankFeedsApi.java
/**
* <p><b>202</b> - Success returns Statements array of objects in response
* <p><b>400</b> - Statement failed validation
* <p><b>403</b> - Invalid application or feed connection
* <p><b>409</b> - Duplicate statement received
* <p><b>413</b> - Statement exceeds size limit
* <p><b>422</b> - Unprocessable Entity
* <p><b>500</b> - Intermittent Xero Error
* @param xeroTenantId Xero identifier for Tenant
* @param statements Statements array of objects in the body
* @param accessToken Authorization token for user set in header of each request
* @return Statements
* @throws IOException if an error occurs while attempting to invoke the API
**/
public Statements  createStatements(String accessToken, String xeroTenantId, Statements statements) throws IOException {
    try {
        TypeReference<Statements> typeRef = new TypeReference<Statements>() {};
        HttpResponse response = createStatementsForHttpResponse(accessToken, xeroTenantId, statements);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : createStatements -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        if (e.getStatusCode() == 400) {
            TypeReference<Statements> errorTypeRef = new TypeReference<Statements>() {};
            Statements bankFeedError = apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
            handler.validationError("Statements",bankFeedError);
        } else {
            handler.execute(e);
        }
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
源代码30 项目: Xero-Java   文件: BankFeedsApi.java
/**
* Delete an exsiting feed connection
* By passing in FeedConnections array object in the body, you can delete a feed connection.
* <p><b>202</b> - Success response for deleted feed connection
* <p><b>400</b> - bad input parameter
* @param xeroTenantId Xero identifier for Tenant
* @param feedConnections Feed Connections array object in the body
* @param accessToken Authorization token for user set in header of each request
* @return FeedConnections
* @throws IOException if an error occurs while attempting to invoke the API
**/
public FeedConnections  deleteFeedConnections(String accessToken, String xeroTenantId, FeedConnections feedConnections) throws IOException {
    try {
        TypeReference<FeedConnections> typeRef = new TypeReference<FeedConnections>() {};
        HttpResponse response = deleteFeedConnectionsForHttpResponse(accessToken, xeroTenantId, feedConnections);
        return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
    } catch (HttpResponseException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("------------------ HttpResponseException " + e.getStatusCode() + " : deleteFeedConnections -------------------");
            logger.debug(e.toString());
        }
        XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
        handler.execute(e);
    } catch (IOException ioe) {
        throw ioe;
    }
    return null;
}
 
 类方法
 同包方法