@Override public int getStatusCode() { return response.getStatusCode(); }
/** * {@inheritDoc } */ @Override public void close() { for (ODataResponse response : responses.values()) { response.close(); } closed = true; } }
@Override public String getReasonPhrase() { return response.getStatusMessage(); }
private void checkStatus(ODataResponse response, int expectedStatusCode) throws CMODataClientException { if (response.getStatusCode() != expectedStatusCode) { IOException suspressed = null; String bodyContent = "<n/a>"; try { /* * Does not work for http-4xx and http.5xx since Olingo prefers to answer * with an exception in this case rather with an response entity. But it might * be helpful also for inexpected http responses outside that range. */ bodyContent = IOUtils.toString(response.getRawResponse()); } catch(IOException e) { suspressed = e; logger.warn("Cannot read response body content.", e); } CMODataClientException e = new CMODataClientException( format("Response status code '%d' does not match expected status code '%d'. Response body: '%s'.", response.getStatusCode(), expectedStatusCode, bodyContent)); if(suspressed != null) e.addSuppressed(suspressed); throw e; } }
private ODataResponse nextExpected() { // consume item for condition above (used like a counter ...) expectedItemsIterator.next(); final Map<String, Collection<String>> nextItemHeaders = ODataBatchUtilities.nextItemHeaders(batchLineIterator, boundary); if (nextItemHeaders.isEmpty()) { throw new IllegalStateException("Expected item not found"); } final Map.Entry<Integer, String> responseLine = ODataBatchUtilities.readResponseLine(batchLineIterator); LOG.debug("Retrieved item response {}", responseLine); final Map<String, Collection<String>> headers = ODataBatchUtilities.readHeaders(batchLineIterator); LOG.debug("Retrieved item headers {}", headers); Collection<String> contentId = nextItemHeaders.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME); if (contentId == null || contentId.isEmpty()) { contentId = headers.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME); if (contentId == null || contentId.isEmpty()) { throw new IllegalStateException("Content-ID is missing"); } } current = getResponse(contentId.iterator().next()); if (current == null) { throw new IllegalStateException("Unexpected '" + contentId + "' item found"); } current.initFromBatch(responseLine, headers, batchLineIterator, boundary); if (current.getStatusCode() >= 400 && !continueOnError) { // found error .... breaking = true; } return current; }
throw new NoSuchElementException("No item found"); current = expectedItemsIterator.next().initFromBatch(responseLine, headers, batchLineIterator, boundary);
private void checkStatus(ODataResponse response, int expectedStatusCode) throws CMODataClientException { if (response.getStatusCode() != expectedStatusCode) { IOException suspressed = null; String bodyContent = "<n/a>"; try { /* * Does not work for http-4xx and http.5xx since Olingo prefers to answer * with an exception in this case rather with an response entity. But it might * be helpful also for inexpected http responses outside that range. */ bodyContent = IOUtils.toString(response.getRawResponse()); } catch(IOException e) { suspressed = e; logger.warn("Cannot read response body content.", e); } CMODataClientException e = new CMODataClientException( format("Response status code '%d' does not match expected status code '%d'. Response body: '%s'.", response.getStatusCode(), expectedStatusCode, bodyContent)); if(suspressed != null) e.addSuppressed(suspressed); throw e; } }
private ODataResponse nextExpected() { // consume item for condition above (used like a counter ...) expectedItemsIterator.next(); final Map<String, Collection<String>> nextItemHeaders = ODataBatchUtilities.nextItemHeaders(batchLineIterator, boundary); if (nextItemHeaders.isEmpty()) { throw new IllegalStateException("Expected item not found"); } final Map.Entry<Integer, String> responseLine = ODataBatchUtilities.readResponseLine(batchLineIterator); LOG.debug("Retrieved item response {}", responseLine); final Map<String, Collection<String>> headers = ODataBatchUtilities.readHeaders(batchLineIterator); LOG.debug("Retrieved item headers {}", headers); Collection<String> contentId = nextItemHeaders.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME); if (contentId == null || contentId.isEmpty()) { contentId = headers.get(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME); if (contentId == null || contentId.isEmpty()) { throw new IllegalStateException("Content-ID is missing"); } } current = getResponse(contentId.iterator().next()); if (current == null) { throw new IllegalStateException("Unexpected '" + contentId + "' item found"); } current.initFromBatch(responseLine, headers, batchLineIterator, boundary); if (current.getStatusCode() >= 400 && !continueOnError) { // found error .... breaking = true; } return current; }
throw new NoSuchElementException("No item found"); current = expectedItemsIterator.next().initFromBatch(responseLine, headers, batchLineIterator, boundary);
if (res.getStatusCode() >= 400) { errors.add(new ODataResponseError(ODataErrorResponseChecker.checkResponse( service.getClient(), new ResponseStatusLine(res), res.getRawResponse(), ((ODataRequest) request).getAccept()), index, requests.get(index))); if (!service.getClient().getConfiguration().isContinueOnError()) { if (res instanceof ODataEntityCreateResponse && (res.getStatusCode() == 201 || res .getStatusCode() == 204)) { if (res.getStatusCode() == 201) { handler.setEntity(((ODataEntityCreateResponse<?>) res).getBody()); LOG.debug("Upgrade created object '{}'", handler); handler.applyChanges(); } else if (res instanceof ODataEntityUpdateResponse && (res.getStatusCode() == 200 || res .getStatusCode() == 204)) { if (res.getStatusCode() == 201) { handler.setEntity(((ODataEntityUpdateResponse<?>) res).getBody()); LOG.debug("Upgrade updated object '{}'", handler);
/** * {@inheritDoc } */ @Override public void close() { for (ODataResponse response : responses.values()) { response.close(); } closed = true; } }
@Override public int getStatusCode() { return response.getStatusCode(); }
@Override public String getReasonPhrase() { return response.getStatusMessage(); }
if (res.getStatusCode() >= 400) { errors.add(new ODataResponseError(ODataErrorResponseChecker.checkResponse( service.getClient(), new ResponseStatusLine(res), res.getRawResponse(), ((ODataRequest) request).getAccept()), index, requests.get(index))); if (!service.getClient().getConfiguration().isContinueOnError()) { if (res instanceof ODataEntityCreateResponse && (res.getStatusCode() == 201 || res .getStatusCode() == 204)) { if (res.getStatusCode() == 201) { handler.setEntity(((ODataEntityCreateResponse<?>) res).getBody()); LOG.debug("Upgrade created object '{}'", handler); handler.applyChanges(); } else if (res instanceof ODataEntityUpdateResponse && (res.getStatusCode() == 200 || res .getStatusCode() == 204)) { if (res.getStatusCode() == 201) { handler.setEntity(((ODataEntityUpdateResponse<?>) res).getBody()); LOG.debug("Upgrade updated object '{}'", handler);
@Override public void close() { super.close(); if (current != null && !(current instanceof AsyncResponseImpl) && !(current instanceof ODataBatchErrorResponse)) { current.close(); } }
&& response instanceof ODataEntityCreateResponse && (response.getStatusCode() == 201 || response .getStatusCode() == 204)) { if (response.getStatusCode() == 201) { entry.getValue().setEntity(((ODataEntityCreateResponse<?>) response).getBody()); responses.put(index, entry.getValue().getEntityURI()); && response instanceof ODataEntityUpdateResponse && (response.getStatusCode() == 200 || response .getStatusCode() == 204)) { if (response.getStatusCode() == 200) { entry.getValue().setEntity(((ODataEntityUpdateResponse<?>) response).getBody()); responses.put(index, entry.getValue().getEntityURI());
@Override public void close() { super.close(); if (current != null && !(current instanceof AsyncResponseImpl) && !(current instanceof ODataBatchErrorResponse)) { current.close(); } }
&& response instanceof ODataEntityCreateResponse && (response.getStatusCode() == 201 || response .getStatusCode() == 204)) { if (response.getStatusCode() == 201) { entry.getValue().setEntity(((ODataEntityCreateResponse<?>) response).getBody()); responses.put(index, entry.getValue().getEntityURI()); && response instanceof ODataEntityUpdateResponse && (response.getStatusCode() == 200 || response .getStatusCode() == 204)) { if (response.getStatusCode() == 200) { entry.getValue().setEntity(((ODataEntityUpdateResponse<?>) response).getBody()); responses.put(index, entry.getValue().getEntityURI());
@Override public ODataResponse next() { if (current != null) { current.close(); } if (closed) { throw new IllegalStateException("Invalid request - the item has been closed"); } if (!hasNext()) { throw new NoSuchElementException("No item found"); } if (unexpected) { breaking = true; return nextUnexpected(); } else { return nextExpected(); } }
@Override public ODataResponse next() { if (current != null) { current.close(); } if (closed) { throw new IllegalStateException("Invalid request - the item has been closed"); } if (!hasNext()) { throw new NoSuchElementException("No item found"); } if (unexpected) { breaking = true; return nextUnexpected(); } else { return nextExpected(); } }