@Override public ODataResponse build(final long jpaEntityCount) throws ODataJPARuntimeException { ODataResponse odataResponse = null; try { odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount)); odataResponse = ODataResponse.fromResponse(odataResponse).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } return odataResponse; }
@Override public ODataResponse build(final long jpaEntityCount) throws ODataJPARuntimeException { ODataResponse odataResponse = null; try { odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount)); odataResponse = ODataResponse.fromResponse(odataResponse).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } return odataResponse; }
public static HttpStatusCodes checkStatus(HttpResponse response) throws ODataApplicationException { final StatusLine statusLine = response.getStatusLine(); HttpStatusCodes httpStatusCode = HttpStatusCodes.fromStatusCode(statusLine.getStatusCode()); if (400 <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= 599) { if (response.getEntity() != null) { try { final ContentType responseContentType = ContentType.parse( response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue()); final String mimeType = responseContentType.getMimeType(); if (ODATA_MIME_TYPE.matcher(mimeType).matches()) { final ODataErrorContext errorContext = EntityProvider.readErrorDocument( response.getEntity().getContent(), responseContentType.toString()); throw new ODataApplicationException(errorContext.getMessage(), errorContext.getLocale(), httpStatusCode, errorContext.getErrorCode(), errorContext.getException()); } } catch (EntityProviderException e) { throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e); } catch (IOException e) { throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e); } } throw new ODataApplicationException(statusLine.getReasonPhrase(), response.getLocale(), httpStatusCode); } return httpStatusCode; }
public static HttpStatusCodes checkStatus(HttpResponse response) throws ODataApplicationException { final StatusLine statusLine = response.getStatusLine(); HttpStatusCodes httpStatusCode = HttpStatusCodes.fromStatusCode(statusLine.getStatusCode()); if (400 <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= 599) { if (response.getEntity() != null) { try { final ContentType responseContentType = getContentTypeHeader(response); final String mimeType = responseContentType.getMimeType(); if (ODATA_MIME_TYPE.matcher(mimeType).matches()) { final ODataErrorContext errorContext = EntityProvider.readErrorDocument( response.getEntity().getContent(), responseContentType.toString()); throw new ODataApplicationException(errorContext.getMessage(), errorContext.getLocale(), httpStatusCode, errorContext.getErrorCode(), errorContext.getException()); } } catch (EntityProviderException e) { throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e); } catch (IOException e) { throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e); } } throw new ODataApplicationException(statusLine.getReasonPhrase(), response.getLocale(), httpStatusCode); } return httpStatusCode; }
} catch (EntityProviderException e) { throw new ODataException(ODataExceptionType.INPUT_DATA_SERIALIZATION_FAILED, "Error during serialization of input payload. " + e.getMessage(), e); ODataConnectivityUtil.safeCloseHttpResponse(httpResponse); throw new ODataException(ODataExceptionType.RESPONSE_DESERIALIZATION_FAILED, "Error while deserializing response. " + e.getMessage(), e); } catch (IllegalStateException | IOException e) { ODataConnectivityUtil.safeCloseHttpResponse(httpResponse);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
} catch (EntityProviderException e) { throw new ODataException(ODataExceptionType.INPUT_DATA_SERIALIZATION_FAILED, "Error during serialization of input payload." + e.getMessage(), e);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
@Override public ODataResponse build(final GetFunctionImportUriInfo resultsView, final Object result) throws ODataJPARuntimeException { try { final EdmFunctionImport functionImport = resultsView.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); if (result != null) { ODataResponse response = null; if (type.getDefaultType().equals(byte[].class)) { response = EntityProvider.writeBinary("application/octet-stream", (byte[]) result); } else { final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value); } return ODataResponse.fromResponse(response).build(); } else { throw new ODataNotFoundException(ODataHttpException.COMMON); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } }
@Override public ODataResponse build(final GetFunctionImportUriInfo resultsView, final Object result) throws ODataJPARuntimeException { try { final EdmFunctionImport functionImport = resultsView.getFunctionImport(); final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType(); if (result != null) { ODataResponse response = null; if (type.getDefaultType().equals(byte[].class)) { response = EntityProvider.writeBinary("application/octet-stream", (byte[]) result); } else { final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null); response = EntityProvider.writeText(value); } return ODataResponse.fromResponse(response).build(); } else { throw new ODataNotFoundException(ODataHttpException.COMMON); } } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } }
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
throw new ODataApplicationException( e.getMessage(), Locale.getDefault(), IGWe.getHttpStatusCode(), IGWe.getErrorCode(), IGWe); //NOPMD - suppressed as the exception is preserved
IGWe.setHttpStatusCode(HttpStatusCodes.BAD_REQUEST); throw new ODataApplicationException( e.getMessage(), Locale.getDefault(), IGWe.getHttpStatusCode(), IGWe.getErrorCode(), IGWe); //NOPMD - suppressed as the exception is preserved
@Override public ODataResponse build(final PostUriInfo uriInfo, final Object createdObject, final String contentType) throws ODataJPARuntimeException, ODataNotFoundException { if (createdObject == null) { throw new ODataNotFoundException(ODataNotFoundException.ENTITY); } EdmEntityType edmEntityType = null; ODataResponse odataResponse = null; try { edmEntityType = uriInfo.getTargetEntitySet().getEntityType(); Map<String, Object> edmPropertyValueMap = null; JPAEntityParser jpaResultParser = new JPAEntityParser(); edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(createdObject, edmEntityType); EntityProviderWriteProperties feedProperties = null; try { feedProperties = getEntityProviderPropertiesforPost(oDataJPAContext); } catch (ODataException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e); } odataResponse = EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), edmPropertyValueMap, feedProperties); odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.CREATED).build(); } catch (EntityProviderException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } catch (EdmException e) { throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e); } return odataResponse; }
IGWe.setHttpStatusCode(HttpStatusCodes.BAD_REQUEST); throw new ODataApplicationException( e.getMessage(), Locale.getDefault(), IGWe.getHttpStatusCode(), IGWe.getErrorCode(), IGWe); //NOPMD - suppressed as the exception is preserved
IGWe.setHttpStatusCode(HttpStatusCodes.BAD_REQUEST); throw new ODataApplicationException( e.getMessage(), Locale.getDefault(), IGWe.getHttpStatusCode(), IGWe.getErrorCode(), IGWe); //NOPMD - suppressed as the exception is preserved