org.apache.olingo.odata2.core.exception.ODataRuntimeException Java Examples

The following examples show how to use org.apache.olingo.odata2.core.exception.ODataRuntimeException. 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: AtomEntityProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Serializes an error message according to the OData standard.</p>
 * <p>In case an error occurs, it is logged.
 * An exception is not thrown because this method is used in exception handling.</p>
 * @param status the {@link HttpStatusCodes} associated with this error
 * @param errorCode a String that serves as a substatus to the HTTP response code
 * @param message a human-readable message describing the error
 * @param locale the {@link Locale} that should be used to format the error message
 * @param innerError the inner error for this message. If it is null or an empty String no inner error tag is shown
 * inside the response xml
 * @return an {@link ODataResponse} containing the serialized error message
 */
@Override
public ODataResponse writeErrorDocument(final HttpStatusCodes status, final String errorCode, final String message,
    final Locale locale, final String innerError) {
  CircleStreamBuffer csb = new CircleStreamBuffer();

  try {
    OutputStream outStream = csb.getOutputStream();
    XMLStreamWriter writer = XmlHelper.getXMLOutputFactory().createXMLStreamWriter(outStream, DEFAULT_CHARSET);

    XmlErrorDocumentProducer producer = new XmlErrorDocumentProducer();
    producer.writeErrorDocument(writer, errorCode, message, locale, innerError);

    writer.flush();
    csb.closeWrite();

    ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
        .header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
        .status(status);
    return response.build();
  } catch (Exception e) {
    csb.close();
    throw new ODataRuntimeException(e);
  }
}
 
Example #2
Source File: MyCallback.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) {
  WriteEntryCallbackResult result = new WriteEntryCallbackResult();
  try {
    if ("Employees".equals(context.getSourceEntitySet().getName())) {
      if ("ne_Room".equals(context.getNavigationProperty().getName())) {
        HashMap<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
        for (String navPropName : context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty())
            .getEntityType().getNavigationPropertyNames()) {
          callbacks.put(navPropName, this);
        }
        EntityProviderWriteProperties inlineProperties =
            EntityProviderWriteProperties.serviceRoot(baseUri).callbacks(callbacks).expandSelectTree(
                context.getCurrentExpandSelectTreeNode()).build();
        result.setEntryData(dataProvider.getRoomData());
        result.setInlineProperties(inlineProperties);
      } else if ("ne_Team".equals(context.getNavigationProperty().getName())) {
        result.setEntryData(null);
      }
    }
  } catch (EdmException e) {
    throw new ODataRuntimeException("EdmException:", e);
  }
  return result;
}
 
Example #3
Source File: JsonEntityProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Serializes an error message according to the OData standard.</p>
 * <p>In case an error occurs, it is logged.
 * An exception is not thrown because this method is used in exception handling.</p>
 * @param status the {@link HttpStatusCodes status code} associated with this error
 * @param errorCode a String that serves as a substatus to the HTTP response code
 * @param message a human-readable message describing the error
 * @param locale the {@link Locale} that should be used to format the error message
 * @param innerError the inner error for this message; if it is null or an empty String
 * no inner error tag is shown inside the response structure
 * @return an {@link ODataResponse} containing the serialized error message
 */
@Override
public ODataResponse writeErrorDocument(final HttpStatusCodes status, final String errorCode, final String message,
    final Locale locale, final String innerError) {
  CircleStreamBuffer buffer = new CircleStreamBuffer();

  try {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(buffer.getOutputStream(), DEFAULT_CHARSET));
    new JsonErrorDocumentProducer().writeErrorDocument(writer, errorCode, message, locale, innerError);
    writer.flush();
    buffer.closeWrite();

    return ODataResponse.status(status)
        .entity(buffer.getInputStream())
        .header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
        .build();
  } catch (Exception e) {
    buffer.close();
    throw new ODataRuntimeException(e);
  }
}
 
Example #4
Source File: BatchHelper.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
/**
 * Fetch the calibrated length in case of binary data. 
 * Since after applying the charset the content length changes.
 * If the previously generated length is sent back then the batch response 
 * body is seen truncated
 * @param batchResponseBody
 * @return
 */
public int calculateLength(Object batchResponseBody) {
  if (batchResponseBody != null) {
    if (batchResponseBody instanceof String) {
      if (DEFAULT_ENCODING.equalsIgnoreCase(ISO_ENCODING)) {
        try {
          return ((String) batchResponseBody).getBytes(UTF8_ENCODING).length;
        } catch (UnsupportedEncodingException e) {
          throw new ODataRuntimeException(e);
        }
      } else {
        return getLength();
      }
    } else {
      return getLength();
    }
  }
  return getLength();
}
 
Example #5
Source File: ODataServlet.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
  // We have to create the Service Factory here because otherwise we do not have access to the error callback
  ODataServiceFactory serviceFactory = getServiceFactory(req);
  if(serviceFactory == null) {
    throw new ODataRuntimeException("Unable to get Service Factory. Check either '" +
        ODataServiceFactory.FACTORY_LABEL + "' or '" + ODataServiceFactory.FACTORY_INSTANCE_LABEL + "' config.");
  }

  String xHttpMethod = req.getHeader("X-HTTP-Method");
  String xHttpMethodOverride = req.getHeader("X-HTTP-Method-Override");
  if (xHttpMethod != null && xHttpMethodOverride != null) {
    if (!xHttpMethod.equalsIgnoreCase(xHttpMethodOverride)) {
      ODataExceptionWrapper wrapper = new ODataExceptionWrapper(req, serviceFactory);
      createResponse(resp, wrapper.wrapInExceptionResponse(
          new ODataBadRequestException(ODataBadRequestException.AMBIGUOUS_XMETHOD)));
      return;
    }
  }

  if (req.getPathInfo() != null) {
    handle(req, resp, xHttpMethod, xHttpMethodOverride, serviceFactory);
  } else {
    handleRedirect(req, resp, serviceFactory);
  }
}
 
Example #6
Source File: ODataRootLocator.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static ODataServiceFactory createServiceFactoryFromContext(final Application app,
    final HttpServletRequest servletRequest,
    final ServletConfig servletConfig) {
  try {
    Class<?> factoryClass;
    if (app instanceof AbstractODataApplication) {
      factoryClass = ((AbstractODataApplication) app).getServiceFactoryClass();
    } else {
      final String factoryClassName = servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL);
      if (factoryClassName == null) {
        throw new ODataRuntimeException("Servlet config missing: " + ODataServiceFactory.FACTORY_LABEL);
      }

      ClassLoader cl = (ClassLoader) servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL);
      if (cl == null) {
        factoryClass = Class.forName(factoryClassName);
      } else {
        factoryClass = Class.forName(factoryClassName, true, cl);
      }
    }
    return (ODataServiceFactory) factoryClass.newInstance();
  } catch (Exception e) {
    throw new ODataRuntimeException("Exception during ODataServiceFactory creation occured.", e);
  }
}
 
Example #7
Source File: EspmServiceFactory.java    From cloud-espm-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext()
		throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = this.getODataJPAContext();
	EntityManagerFactory emf;
	try {
		emf = JpaEntityManagerFactory.getEntityManagerFactory();
		oDataJPAContext.setEntityManagerFactory(emf);
		oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
		oDataJPAContext.setJPAEdmExtension(new EspmProcessingExtension());
		oDataJPAContext.setJPAEdmMappingModel("EspmEdmMapping.xml");
		return oDataJPAContext;
	} catch (Exception e) {
		throw new ODataRuntimeException(e);
	}

}
 
Example #8
Source File: ODataExceptionWrapper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public ODataExceptionWrapper(final ODataContext context, final Map<String, String> queryParameters,
    final List<String> acceptHeaderContentTypes) {
  contentType = getContentType(queryParameters, acceptHeaderContentTypes).toContentTypeString();
  messageLocale = MessageService.getSupportedLocale(getLanguages(context), DEFAULT_RESPONSE_LOCALE);
  httpRequestHeaders = context.getRequestHeaders();
  try {
    requestUri = context.getPathInfo().getRequestUri();
    errorContext.setPathInfo(context.getPathInfo());
    callback = getErrorHandlerCallbackFromContext(context);
  } catch (Exception e) {
    throw new ODataRuntimeException("Exception occurred", e);
  }
}
 
Example #9
Source File: BenefitsODataServiceFactory.java    From cloud-sfsf-benefits-ext with Apache License 2.0 5 votes vote down vote up
@Override
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
	ODataJPAContext oDataJPAContext = this.getODataJPAContext();
	try {
		oDataJPAContext.setEntityManagerFactory(EntityManagerFactoryProvider.getInstance().getEntityManagerFactory());
		oDataJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
		oDataJPAContext.setJPAEdmExtension(new BenefitsJPAEdmExtension());

		setContextInThreadLocal(oDataJPAContext.getODataContext());
		return oDataJPAContext;
	} catch (Exception e) {
		throw new ODataRuntimeException("Cannot initialize OData JPA Context", e); //$NON-NLS-1$
	}

}
 
Example #10
Source File: ErrorResponseTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
protected ODataSingleProcessor createProcessor() throws ODataException {
  final ODataSingleProcessor processor = mock(ODataSingleProcessor.class);

  when(((ServiceDocumentProcessor) processor).readServiceDocument(any(GetServiceDocumentUriInfo.class),
      any(String.class))).thenThrow(new ODataRuntimeException("unit testing"));
  when(((MetadataProcessor) processor).readMetadata(any(GetMetadataUriInfo.class),
      any(String.class))).thenThrow(
      new ODataRuntimeApplicationException("unit testing", Locale.ROOT, HttpStatusCodes.FORBIDDEN));

  return processor;
}
 
Example #11
Source File: ODataExceptionMapperImplTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testODataRuntimeException() throws Exception {
  // prepare
  String exceptionMessage = "Some odd runtime exception";
  Exception exception = new ODataRuntimeException(exceptionMessage);

  // execute
  Response response = exceptionMapper.toResponse(exception);

  // verify
  verifyResponse(response, exceptionMessage, HttpStatusCodes.INTERNAL_SERVER_ERROR);
}
 
Example #12
Source File: XmlExpandProducerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public XmlExpandProducerTest(final StreamWriterImplType type) {
  super(type);

  try {
    inlineBaseUri = new URI("http://hubbeldubbel.com/");
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #13
Source File: BatchHelper.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
protected static byte[] getBytes(final String body) {
  try {
    return body.getBytes(DEFAULT_ENCODING);
  } catch (UnsupportedEncodingException e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #14
Source File: UriParserImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void handleSystemQueryOptions() throws UriSyntaxException, UriNotMatchingException, EdmException {

    for (SystemQueryOption queryOption : systemQueryOptions.keySet()) {
      switch (queryOption) {
      case $format:
        handleSystemQueryOptionFormat(systemQueryOptions.get(SystemQueryOption.$format));
        break;
      case $filter:
        handleSystemQueryOptionFilter(systemQueryOptions.get(SystemQueryOption.$filter));
        break;
      case $inlinecount:
        handleSystemQueryOptionInlineCount(systemQueryOptions.get(SystemQueryOption.$inlinecount));
        break;
      case $orderby:
        handleSystemQueryOptionOrderBy(systemQueryOptions.get(SystemQueryOption.$orderby));
        break;
      case $skiptoken:
        handleSystemQueryOptionSkipToken(systemQueryOptions.get(SystemQueryOption.$skiptoken));
        break;
      case $skip:
        handleSystemQueryOptionSkip(systemQueryOptions.get(SystemQueryOption.$skip));
        break;
      case $top:
        handleSystemQueryOptionTop(systemQueryOptions.get(SystemQueryOption.$top));
        break;
      case $expand:
        handleSystemQueryOptionExpand(systemQueryOptions.get(SystemQueryOption.$expand));
        break;
      case $select:
        handleSystemQueryOptionSelect(systemQueryOptions.get(SystemQueryOption.$select));
        break;
      default:
        throw new ODataRuntimeException("Invalid System Query Option " + queryOption);
      }
    }
  }
 
Example #15
Source File: ExpandSelectTreeNodeImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ExpandSelectTreeNodeBuilder
    customExpandedLink(final String navigationPropertyName, final ExpandSelectTreeNode expandNode) {
  if (expandNode == null) {
    throw new ODataRuntimeException("ExpandNode must not be null");
  }
  if (customExpandedNavigationProperties == null) {
    customExpandedNavigationProperties = new HashMap<String, ExpandSelectTreeNode>();
  }
  customExpandedNavigationProperties.put(navigationPropertyName, expandNode);
  return this;
}
 
Example #16
Source File: ODataServlet.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Get an instance of a ODataServiceFactory from request attribute
 * ODataServiceFactory.FACTORY_INSTANCE_LABEL
 *
 * @see ODataServiceFactory#FACTORY_INSTANCE_LABEL
 *
 * @param req http servlet request
 * @return instance of a ODataServiceFactory
 */
private ODataServiceFactory getODataServiceFactoryInstance(HttpServletRequest req) {
  Object factory = req.getAttribute(ODataServiceFactory.FACTORY_INSTANCE_LABEL);
  if(factory == null) {
    return null;
  } else if(factory instanceof ODataServiceFactory) {
    return (ODataServiceFactory) factory;
  }
  throw new ODataRuntimeException("Invalid service factory instance of type " + factory.getClass());
}
 
Example #17
Source File: ODataServlet.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
/**
 * Get the service factory instance which is used for creation of the
 * <code>ODataService</code> which handles the processing of the request.
 *
 * @param request the http request which is processed as an OData request
 * @return an instance of an ODataServiceFactory
 */
protected ODataServiceFactory getServiceFactory(HttpServletRequest request) {
  try {
    ODataServiceFactory factoryInstance = getODataServiceFactoryInstance(request);
    if(factoryInstance == null) {
      return createODataServiceFactory(request);
    }
    return factoryInstance;

  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #18
Source File: EdmSimpleTypeFacadeImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static EdmSimpleType getInternalEdmSimpleTypeByString(final String edmSimpleType) {
  if ("Bit".equals(edmSimpleType)) {
    return Bit.getInstance();
  } else if ("Uint7".equals(edmSimpleType)) {
    return Uint7.getInstance();
  } else {
    throw new ODataRuntimeException("Invalid internal Type " + edmSimpleType);
  }
}
 
Example #19
Source File: EdmSimpleTypeFacadeImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static EdmSimpleType getEdmSimpleType(final EdmSimpleTypeKind typeKind) {

    switch (typeKind) {
    case Binary:
      return EdmBinary.getInstance();
    case Boolean:
      return EdmBoolean.getInstance();
    case Byte:
      return EdmByte.getInstance();
    case DateTime:
      return EdmDateTime.getInstance();
    case DateTimeOffset:
      return EdmDateTimeOffset.getInstance();
    case Decimal:
      return EdmDecimal.getInstance();
    case Double:
      return EdmDouble.getInstance();
    case Guid:
      return EdmGuid.getInstance();
    case Int16:
      return EdmInt16.getInstance();
    case Int32:
      return EdmInt32.getInstance();
    case Int64:
      return EdmInt64.getInstance();
    case SByte:
      return EdmSByte.getInstance();
    case Single:
      return EdmSingle.getInstance();
    case String:
      return EdmString.getInstance();
    case Time:
      return EdmTime.getInstance();
    case Null:
      return EdmNull.getInstance();
    default:
      throw new ODataRuntimeException("Invalid Type " + typeKind);
    }
  }
 
Example #20
Source File: ProviderFacadeImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public ODataResponse writeErrorDocument(final ODataErrorContext context) {
  try {
    return create(context.getContentType()).writeErrorDocument(context.getHttpStatus(), context.getErrorCode(),
        context.getMessage(), context.getLocale(), context.getInnerError());
  } catch (EntityProviderException e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #21
Source File: XmlMetadataProducer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private static void writeProperties(final Collection<Property> properties,
    final Map<String, String> predefinedNamespaces, final XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
  for (Property property : properties) {
    xmlStreamWriter.writeStartElement(XmlMetadataConstants.EDM_PROPERTY);
    xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_NAME, property.getName());
    if (property instanceof SimpleProperty) {
      xmlStreamWriter.writeAttribute(XmlMetadataConstants.EDM_TYPE, ((SimpleProperty) property).getType()
          .getFullQualifiedName().toString());
    } else if (property instanceof ComplexProperty) {
      xmlStreamWriter
          .writeAttribute(XmlMetadataConstants.EDM_TYPE, ((ComplexProperty) property).getType().toString());
    } else {
      throw new ODataRuntimeException();
    }

    writeFacets(xmlStreamWriter, property.getFacets());

    if (property.getMimeType() != null) {
      xmlStreamWriter.writeAttribute(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.M_MIMETYPE, property
          .getMimeType());
    }

    writeCustomizableFeedMappings(property.getCustomizableFeedMappings(), xmlStreamWriter);

    writeAnnotationAttributes(property.getAnnotationAttributes(), predefinedNamespaces, null, xmlStreamWriter);

    writeDocumentation(property.getDocumentation(), predefinedNamespaces, xmlStreamWriter);

    writeAnnotationElements(property.getAnnotationElements(), predefinedNamespaces, xmlStreamWriter);

    xmlStreamWriter.writeEndElement();
  }
}
 
Example #22
Source File: ProductsMap.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Iterator<Product> serviceIterator ()
{
   try
   {
      User u = Security.getCurrentUser();
      final List<fr.gael.dhus.database.object.Product> products =
         olingoManager.getProducts (u, filter, orderBy, skip, top);

      List<Product> prods = new ArrayList<> ();
      Iterator<fr.gael.dhus.database.object.Product> it =
         products.iterator ();
      while (it.hasNext ())
      {
         fr.gael.dhus.database.object.Product p = it.next ();
         if (p != null)
         {
            prods.add (new Product (p));
         }
      }

      return prods.iterator ();
   }
   catch (Exception e)
   {
      throw new ODataRuntimeException (e);
   }
}
 
Example #23
Source File: CollectionProductsMap.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected Iterator<Product> serviceIterator ()
{
   try
   {
      User u = Security.getCurrentUser();
      final List<fr.gael.dhus.database.object.Product> products =
         olingoManager.getProducts (u, collectionUUID, filter, orderBy, skip,
            top);

      List<Product> prods = new ArrayList<Product> ();
      Iterator<fr.gael.dhus.database.object.Product> it =
         products.iterator ();
      while (it.hasNext ())
      {
         fr.gael.dhus.database.object.Product p = it.next ();
         if (p != null)
         {
            prods.add (new Product (p));
         }
      }

      return prods.iterator ();
   }
   catch (Exception e)
   {
      throw new ODataRuntimeException (e);
   }
}
 
Example #24
Source File: Dispatcher.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected static Class<? extends ODataProcessor> mapUriTypeToProcessorFeature(final UriInfoImpl uriInfo) {
  Class<? extends ODataProcessor> feature;

  switch (uriInfo.getUriType()) {
  case URI0:
    feature = ServiceDocumentProcessor.class;
    break;
  case URI1:
  case URI6B:
  case URI15:
    feature = EntitySetProcessor.class;
    break;
  case URI2:
  case URI6A:
  case URI16:
    feature = EntityProcessor.class;
    break;
  case URI3:
    feature = EntityComplexPropertyProcessor.class;
    break;
  case URI4:
  case URI5:
    feature = uriInfo.isValue() ? EntitySimplePropertyValueProcessor.class : EntitySimplePropertyProcessor.class;
    break;
  case URI7A:
  case URI50A:
    feature = EntityLinkProcessor.class;
    break;
  case URI7B:
  case URI50B:
    feature = EntityLinksProcessor.class;
    break;
  case URI8:
    feature = MetadataProcessor.class;
    break;
  case URI9:
    feature = BatchProcessor.class;
    break;
  case URI10:
  case URI11:
  case URI12:
  case URI13:
    feature = FunctionImportProcessor.class;
    break;
  case URI14:
    feature = uriInfo.isValue() ? FunctionImportValueProcessor.class : FunctionImportProcessor.class;
    break;
  case URI17:
    feature = EntityMediaProcessor.class;
    break;
  default:
    throw new ODataRuntimeException("Unknown or not implemented URI type: " + uriInfo.getUriType());
  }

  return feature;
}
 
Example #25
Source File: ODataRequestHandler.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private static void validateUriMethod(final ODataHttpMethod method, final UriInfoImpl uriInfo) throws ODataException {
  switch (uriInfo.getUriType()) {
  case URI0:
  case URI8:
  case URI15:
  case URI16:
  case URI50A:
  case URI50B:
    if (method != ODataHttpMethod.GET) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI1:
  case URI6B:
  case URI7B:
    if (method != ODataHttpMethod.GET && method != ODataHttpMethod.POST) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI2:
  case URI6A:
  case URI7A:
    if (method != ODataHttpMethod.GET && method != ODataHttpMethod.PUT && method != ODataHttpMethod.DELETE
        && method != ODataHttpMethod.PATCH && method != ODataHttpMethod.MERGE) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI3:
    if (method != ODataHttpMethod.GET && method != ODataHttpMethod.PUT && method != ODataHttpMethod.PATCH
        && method != ODataHttpMethod.MERGE) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI4:
  case URI5:
    if (method != ODataHttpMethod.GET && method != ODataHttpMethod.PUT && method != ODataHttpMethod.DELETE
        && method != ODataHttpMethod.PATCH && method != ODataHttpMethod.MERGE) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    } else if (method == ODataHttpMethod.DELETE && !uriInfo.isValue()) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI9:
    if (method != ODataHttpMethod.POST) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    }
    break;

  case URI10:
  case URI11:
  case URI12:
  case URI13:
  case URI14:
    break;

  case URI17:
    if (method != ODataHttpMethod.GET && method != ODataHttpMethod.PUT && method != ODataHttpMethod.DELETE) {
      throw new ODataMethodNotAllowedException(ODataMethodNotAllowedException.DISPATCH);
    } else {
      if (uriInfo.getFormat() != null) {
        throw new ODataBadRequestException(ODataBadRequestException.INVALID_SYNTAX);
      }
    }
    break;

  default:
    throw new ODataRuntimeException("Unknown or not implemented URI type: " + uriInfo.getUriType());
  }
}
 
Example #26
Source File: JsonEntryDeepInsertEntryTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public void handleReadFeed(final ReadFeedResult context) {
  throw new ODataRuntimeException("No feed expected");
}
 
Example #27
Source File: JsonEntryDeepInsertFeedTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public void handleReadEntry(final ReadEntryResult context) {
  throw new ODataRuntimeException("No entry expected");
}
 
Example #28
Source File: ExpandSelectTreeNodeBuilderTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test(expected = ODataRuntimeException.class)
public void nullNodeInCustomExpandedProperty() throws Exception {
  EdmEntitySet roomsSet = edm.getDefaultEntityContainer().getEntitySet("Rooms");
  ExpandSelectTreeNode.entitySet(roomsSet).customExpandedLink("nr_Building", null).build();
}