/** * Get wrapped {@link ODataApplicationException} or a new created * {@link ODataApplicationException}. * * @return an {@link ODataApplicationException} */ public ODataApplicationException convert() { if(rootCause instanceof ODataApplicationException) { return (ODataApplicationException) rootCause; } return new ODataApplicationException(rootCause.getMessage(), Locale.ENGLISH, HttpStatusCodes.INTERNAL_SERVER_ERROR); }
protected ODataJPARuntimeException createApplicationError(String message, Locale locale) { return ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL, new ODataApplicationException(message, locale)); } }
protected ODataJPARuntimeException createApplicationError(String message, Locale locale) { return ODataJPARuntimeException.throwException( ODataJPARuntimeException.GENERAL, new ODataApplicationException(message, locale)); }
public ExtensionException(String msg, int statusCode, Locale locale) { this(new ODataApplicationException(msg, locale, HttpStatusCodes.fromStatusCode(statusCode))); }
private ExtensionHolder getFunctionImportExtensionHolder(String functionName) throws ODataException { ExtensionHolder holder = null; if (extensionRegistry.isFunctionExtensionRegistered(functionName)) { holder = extensionRegistry.getFunctionExtension(functionName); } else { throw new ODataApplicationException(NO_IMPLEMENTATION, Locale.ENGLISH); } return holder; }
private ExtensionHolder getActionImportExtensionHolder(String functionName) throws ODataException { ExtensionHolder holder = null; if (extensionRegistry.isActionExtensionRegistered(functionName)) { holder = extensionRegistry.getActionExtension(functionName); } else { throw new ODataApplicationException(NO_IMPLEMENTATION, Locale.ENGLISH); } return holder; }
private void handleDraftCreateWithNavigations(PostUriInfo uriInfo, ODataEntry content) throws EdmException, ODataApplicationException { if(uriInfo.getNavigationSegments().size() > 1) { throw new ODataApplicationException("Unable to create. Create with navigation supported only from parent entity", LocaleUtil.getLocaleforException()); } if(!uriInfo.getNavigationSegments().isEmpty()) { Map<String,String> referenceMap = this.getReferenceMap(uriInfo); for(Map.Entry<String, String> entry:referenceMap.entrySet()){ content.getProperties().put(entry.getValue(), this.getKeyPredicateValue((UriInfo)uriInfo, entry.getKey())); } } }
private Map<String,String> getReferenceMap(PostUriInfo uriInfo) throws EdmException, ODataApplicationException{ // Is navigation segment always of size one? // // add try catch // Map<String,String> referenceMap = new HashMap<>(); EdmReferentialConstraint refConstraint = uriInfo.getNavigationSegments().get(0).getNavigationProperty().getRelationship().getReferentialConstraint(); if(refConstraint == null) throw new ODataApplicationException (NO_REF_CONSTRAINT, LocaleUtil.getLocaleforException()); List<String> principalPropertyList = refConstraint.getPrincipal().getPropertyRefNames(); List<String> dependentPropertList = refConstraint.getDependent().getPropertyRefNames(); for (int i = 0; i < principalPropertyList.size(); i++) { referenceMap.put(principalPropertyList.get(i), dependentPropertList.get(i)); } return referenceMap; }
private List<EdmProperty> getEdmProperties(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandTreeNode) throws ODataApplicationException { try { String name = entitySet.getName(); if (edmPropertyMap.containsKey(name)) { return edmPropertyMap.get(name); } List<EdmProperty> edmProperties = new ArrayList<EdmProperty>(); edmProperties.addAll(expandTreeNode.getProperties()); boolean hit = false; for (EdmProperty keyProperty : entitySet.getEntityType().getKeyProperties()) { hit = false; for (EdmProperty property : edmProperties) { if (property.getName().equals(keyProperty.getName())) { hit = true; break; } } if (hit == false) { edmProperties.add(keyProperty); } } edmPropertyMap.put(name, edmProperties); return edmProperties; } catch (EdmException e) { throw new ODataApplicationException(e.getMessage(), Locale.getDefault(), e); } }
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; }
private void handleCreateWithNavigations(PostUriInfo uriInfo, ODataEntry content) throws EdmException, ODataApplicationException { if(uriInfo.getNavigationSegments().size() > 1) { throw new ODataApplicationException("Unable to create. Create with navigation supported only from parent entity", LocaleUtil.getLocaleforException()); } if(uriInfo.getNavigationSegments().isEmpty()) { return; } List<KeyPredicate> keyPredicateList = uriInfo.getKeyPredicates(); if(!keyPredicateList.isEmpty()) { Map<String,String> referenceMap = this.getReferenceMap(uriInfo); if(!referenceMap.isEmpty()){ String fromProperty = ""; for(KeyPredicate keyPredicate: keyPredicateList) { fromProperty = keyPredicate.getProperty().getName(); if(referenceMap.containsKey(fromProperty)) content.getProperties().put(referenceMap.get(fromProperty), keyPredicate.getLiteral()); // Overrides if property is also passed in the payload } } } }
private ODataApplicationException handleException(Exception e) { if (e instanceof ODataApplicationException) { return (ODataApplicationException) e; } if (e instanceof ExtensionWrappedDataProviderException) { return convertToODataApplicationException((ExtensionWrappedDataProviderException) e); } if (e instanceof InvocationTargetException) { Throwable exception = getTargetException((InvocationTargetException) e); if (exception instanceof ODataApplicationException) { return (ODataApplicationException) exception; } else if (exception instanceof ExtensionException) { return ((ExtensionException) exception).convert(); } else { /* * This case occurs when extension code threw an unchecked * exception like Nullpointer exception. Here we pass this * exception to create the ODataApplicationException so that * this exception stack trace is logged. */ return new ODataApplicationException("Unable to execute the operation. Please check the logs for more details.",LocaleUtil.getLocaleforException(), exception); } } return new ODataApplicationException("Unable to execute the operation. Please check the logs for more details.",LocaleUtil.getLocaleforException(), e); }
private <T> void readContent(UriInfoWithType uriInfo, Map<String, String> responseHeaders, InputStream content, Olingo2ResponseHandler<T> responseHandler) { try { responseHandler.onResponse(this.<T>readContent(uriInfo, content), responseHeaders); } catch (Exception e) { responseHandler.onException(e); } catch (Error e) { responseHandler.onException(new ODataApplicationException("Runtime Error Occurred", Locale.ENGLISH, e)); } }
private ODataResponse writeErrorDocument(ODataErrorContext context) throws ODataApplicationException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IErrorDocumentProducer producer = ErrorDocumentProducerFactory.getErrorDocumentProducer(context.getContentType()); producer.writeErrorDocument(outputStream, context); ODataResponseBuilder response = ODataResponse.entity(new ByteArrayInputStream(outputStream.toByteArray())) .header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10) .status(context.getHttpStatus()); response.contentHeader(context.getContentType()); return response.build(); } catch (Exception e) { logger.error(e.getMessage()); throw new ODataApplicationException(e.getLocalizedMessage(),context.getLocale(), e); } }
private ODataResponse writeErrorDocument(ODataErrorContext context) throws ODataApplicationException { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IErrorDocumentProducer producer = ErrorDocumentProducerFactory.getErrorDocumentProducer(context.getContentType()); producer.writeErrorDocument(outputStream, context); ODataResponseBuilder response = ODataResponse.entity(new ByteArrayInputStream(outputStream.toByteArray())) .header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10) .status(context.getHttpStatus()); response.contentHeader(context.getContentType()); return response.build(); } catch (Exception e) { gwLogger.logErrors(GatewayLogMessage.CoreRtWriteErrorDocFailed, e.getMessage()); throw new ODataApplicationException(e.getLocalizedMessage(),context.getLocale(), e); } }
private static ODataApplicationException convertToODataApplicationException(ErrorResponseImpl errorResponse, String operation) { ODataApplicationException oDataApplicationException = null; String errorMessage = null; String errorCode = errorResponse.getErrorCode() != null ? errorResponse.getErrorCode() : ""; HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(errorResponse.getStatusCode()) == null ? HttpStatusCodes.INTERNAL_SERVER_ERROR : HttpStatusCodes.fromStatusCode(errorResponse.getStatusCode()); if (errorResponse.getCause() == null) { errorMessage = errorResponse.getMessage() == null ? "Error in " + operation + " operation" : errorResponse.getMessage(); oDataApplicationException = new ODataApplicationException(errorMessage, Locale.getDefault(), statusCode, errorCode); } else { errorMessage = errorResponse.getMessage() != null ? errorResponse.getMessage() : errorResponse.getCause().getMessage(); oDataApplicationException = new ODataApplicationException(errorMessage, Locale.getDefault(), statusCode, errorCode, errorResponse.getCause()); } return oDataApplicationException; } }
public static EdmEntitySet getEdmEntitySet(final UriInfo uriInfo, Locale locale) throws ODataException { EdmEntitySet entitySet = null; // First must be an entity or a function import. if (uriInfo.getStartEntitySet() != null) { entitySet = uriInfo.getStartEntitySet(); } else if (uriInfo.getFunctionImport() != null) { entitySet = uriInfo.getFunctionImport().getEntitySet(); } else { throw new ODataApplicationException("INVALID_RESOURCE_TYPE", locale, HttpStatusCodes.NOT_IMPLEMENTED, "INVALID_RESOURCE_TYPE_CODE"); } int navigationCount = 0; while (entitySet != null && navigationCount < uriInfo.getNavigationSegments().size()) { final NavigationSegment uriResourceNavigation = uriInfo.getNavigationSegments().get(navigationCount); try { if(entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()) == null) { entitySet.getEntityContainer().getEntitySet(uriResourceNavigation.getNavigationProperty().getType().getName()); break; }else { entitySet = entitySet.getRelatedEntitySet(uriResourceNavigation.getNavigationProperty()); } } catch (EdmException e) { throw new ODataApplicationException("NAVIGATION_NOT_SUPPORTED", locale, HttpStatusCodes.NOT_IMPLEMENTED, "NAVIGATION_NOT_SUPPORTED_CODE", e); } navigationCount++; } return entitySet; } }
@Override public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); List<Map<String, Object>> values = new ArrayList<Map<String, Object>>(); Object relatedData = null; try { relatedData = readRelatedData(context); for (final Object entryData : (List<?>) relatedData) { values.add(getStructuralTypeValueMap(entryData, entityType)); } } catch (final ODataNotFoundException e) { values.clear(); } WriteFeedCallbackResult result = new WriteFeedCallbackResult(); result.setFeedData(values); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .selfLink(context.getSelfLink()).build(); result.setInlineProperties(inlineProperties); return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }
@Override public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) throws ODataApplicationException { try { final EdmEntityType entityType = context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType(); WriteEntryCallbackResult result = new WriteEntryCallbackResult(); Object relatedData; try { relatedData = readRelatedData(context); } catch (final ODataNotFoundException e) { relatedData = null; } if (relatedData == null) { result.setEntryData(Collections.<String, Object> emptyMap()); } else { result.setEntryData(getStructuralTypeValueMap(relatedData, entityType)); EntityProviderWriteProperties inlineProperties = EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks( getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode()) .build(); result.setInlineProperties(inlineProperties); } return result; } catch (final ODataException e) { throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e); } }
public IDataProviderResponse deleteEntity(DeleteUriInfo uriInfo, ODataContext context) throws ODataException { timings = new SAPStatistics(); BaseDataProviderResponse response = new BaseDataProviderResponse(); EdmEntitySet entitySet = uriInfo.getStartEntitySet(); EntityMetadata entityMetadata = new EntityMetadataV2(entitySet); Map<String, Object> keys = getKeys(uriInfo.getKeyPredicates()); DeleteResponseImpl deleteResponse = null; DeleteRequestImpl deleteRequest = new DeleteRequestImpl(null, entitySet.getName(), entityMetadata, context.getRequestHeaders(), keys, context.getHttpMethod()); try { deleteResponse = (DeleteResponseImpl) ProcessorHelper.invokeOperation(deleteRequest, serviceName, ProcessorHelper.DELETE, timings); if ((ErrorResponseImpl) deleteResponse.getErrorResponse() != null) { response.setException(convertToODataApplicationException( (ErrorResponseImpl) deleteResponse.getErrorResponse(), ProcessorHelper.DELETE)); } setResponseHeaders(response, deleteResponse.getHeaders()); setStatisticsInContext(context, response); } catch (ServiceSDKException e) { log.error("Exception in delete Entity", e); if (e.getStatusCode() == 501) { ErrorResponseImpl errorResp = new ErrorResponseImpl(501, "", "Method Not Implemented", null, null); response.setException(new ODataApplicationException(errorResp.getMessage(), Locale.getDefault(), HttpStatusCodes.NOT_IMPLEMENTED, "")); } else throw new ODataException(e.getMessage(), e); } return response; }