org.apache.olingo.commons.api.ex.ODataRuntimeException Java Examples

The following examples show how to use org.apache.olingo.commons.api.ex.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: DataRequest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private Object getRawValueFromClient() throws DeserializerException {
  InputStream input = getODataRequest().getBody();
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  if (input != null) {
    try {
      ByteBuffer inBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_SIZE);
      ReadableByteChannel ic = Channels.newChannel(input);
      WritableByteChannel oc = Channels.newChannel(buffer);
      while (ic.read(inBuffer) > 0) {
        inBuffer.flip();
        oc.write(inBuffer);
        inBuffer.rewind();
      }
      return buffer.toByteArray();
    } catch (IOException e) {
      throw new ODataRuntimeException("Error on reading content");
    }
  }
  return null;
}
 
Example #2
Source File: ODataNettyHandlerImpl.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/** 
 * Copy OData content to netty content
 * @param input
 * @param response
 */
static void copyContent(final ReadableByteChannel input, final HttpResponse response) {
  try (WritableByteChannel output = Channels.newChannel(new ByteBufOutputStream(((HttpContent)response).content()))){
      ByteBuffer inBuffer = ByteBuffer.allocate(COPY_BUFFER_SIZE);
      while (input.read(inBuffer) > 0) {
        inBuffer.flip();
        output.write(inBuffer);
        inBuffer.clear();
      }
      closeStream(output);
    } catch (IOException e) {
      throw new ODataRuntimeException("Error on reading request content", e);
    } finally {
      closeStream(input);
    }
}
 
Example #3
Source File: OData.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * Use this method to create a new OData instance. Each thread/request should keep its own instance.
 * @return a new OData instance
 */
public static OData newInstance() {
  try {
    final Class<?> clazz = Class.forName(OData.IMPLEMENTATION);

    /*
     * We explicitly do not use the singleton pattern to keep the server state free
     * and avoid class loading issues also during hot deployment.
     */
    final Object object = clazz.newInstance();

    return (OData) object;

  } catch (final Exception e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #4
Source File: ODataNetty.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
/**
 * Use this method to create a new OData instance. Each thread/request should keep its own instance.
 * @return a new OData instance
 */
public static ODataNetty newInstance() {
  try {
    final Class<?> clazz = Class.forName(ODataNetty.IMPLEMENTATION);

    
     /* We explicitly do not use the singleton pattern to keep the server state free
     * and avoid class loading issues also during hot deployment.*/
     
    final Object object = clazz.newInstance();

    return (ODataNetty) object;

  } catch (final Exception e) {
    throw new ODataRuntimeException(e);
  }
}
 
Example #5
Source File: TechnicalAsyncService.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
static void copy(final InputStream input, final OutputStream output) {
  if (output == null || input == null) {
    return;
  }

  try {
    ByteBuffer inBuffer = ByteBuffer.allocate(8192);
    ReadableByteChannel ic = Channels.newChannel(input);
    WritableByteChannel oc = Channels.newChannel(output);
    while (ic.read(inBuffer) > 0) {
      inBuffer.flip();
      oc.write(inBuffer);
      inBuffer.rewind();
    }
  } catch (IOException e) {
    throw new ODataRuntimeException("Error on reading request content");
  } finally {
    closeStream(input);
    closeStream(output);
  }
}
 
Example #6
Source File: AsyncProcessor.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
static InputStream copyRequestBody(ODataRequest request) {
  ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  InputStream input = request.getBody();
  if (input != null) {
    try {
      ByteBuffer inBuffer = ByteBuffer.allocate(8192);
      ReadableByteChannel ic = Channels.newChannel(input);
      WritableByteChannel oc = Channels.newChannel(buffer);
      while (ic.read(inBuffer) > 0) {
        inBuffer.flip();
        oc.write(inBuffer);
        inBuffer.rewind();
      }
      return new ByteArrayInputStream(buffer.toByteArray());
    } catch (IOException e) {
      throw new ODataRuntimeException("Error on reading request content");
    }
  }
  return null;
}
 
Example #7
Source File: SocketFactoryHttpClientFactory.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
      return true;
    }
  };

  final SchemeRegistry registry = new SchemeRegistry();
  try {
    final SSLSocketFactory ssf =
            new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }

  final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
 
Example #8
Source File: AbstractRequest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
protected void checkResponse(
        final ODataClient odataClient, final HttpResponse response, final String accept) {

  if (response.getStatusLine().getStatusCode() >= 400) {
    Header contentTypeHeader = response.getEntity() != null ? response.getEntity().getContentType() : null;
    try {
      final ODataRuntimeException exception = ODataErrorResponseChecker.checkResponse(
              odataClient,
              response.getStatusLine(),
              response.getEntity() == null ? null : response.getEntity().getContent(),
                  (contentTypeHeader != null && 
                  contentTypeHeader.getValue().contains(TEXT_CONTENT_TYPE)) ? TEXT_CONTENT_TYPE : accept);
      if (exception != null) {
        if (exception instanceof ODataClientErrorException) {
          ((ODataClientErrorException)exception).setHeaderInfo(response.getAllHeaders());
        }
        throw exception;
      }
    } catch (IOException e) {
      throw new ODataRuntimeException(
              "Received '" + response.getStatusLine() + "' but could not extract error body", e);
    }
  }
}
 
Example #9
Source File: AbstractODataResponse.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
public final ODataResponse initFromHttpResponse(final HttpResponse res) {
  try {
    this.payload = res.getEntity() == null ? null : res.getEntity().getContent();
    this.inputContent = null;
  } catch (final IllegalStateException | IOException e) {
    HttpClientUtils.closeQuietly(res);
    LOG.error("Error retrieving payload", e);
    throw new ODataRuntimeException(e);
  }
  for (Header header : res.getAllHeaders()) {
    final Collection<String> headerValues;
    if (headers.containsKey(header.getName())) {
      headerValues = headers.get(header.getName());
    } else {
      headerValues = new HashSet<>();
      headers.put(header.getName(), headerValues);
    }

    headerValues.add(header.getValue());
  }

  statusCode = res.getStatusLine().getStatusCode();
  statusMessage = res.getStatusLine().getReasonPhrase();

  hasBeenInitialized = true;
  return this;
}
 
Example #10
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #11
Source File: ErrorTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithNull() throws Exception {
  ODataClient odataClient = ODataClientFactory.getClient();
  StatusLine statusLine = mock(StatusLine.class);
  when(statusLine.getStatusCode()).thenReturn(500);
  when(statusLine.toString()).thenReturn("Internal Server Error");
      
  ODataRuntimeException exp = ODataErrorResponseChecker.
      checkResponse(odataClient, statusLine, null, "Json");
  assertTrue(exp.getMessage().startsWith("Internal Server Error"));
}
 
Example #12
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
	try {
		return new URI(entitySetName + "(" + String.valueOf(id) + ")");
	} catch (URISyntaxException e) {
		throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
	}
}
 
Example #13
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
	try {
		return new URI(entitySetName + "(" + String.valueOf(id) + ")");
	} catch (URISyntaxException e) {
		throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
	}
}
 
Example #14
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #15
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
	try {
		return new URI(entitySetName + "(" + String.valueOf(id) + ")");
	} catch (URISyntaxException e) {
		throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
	}
}
 
Example #16
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #17
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if (navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #18
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #19
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #20
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
	try {
		return new URI(entitySetName + "(" + String.valueOf(id) + ")");
	} catch (URISyntaxException e) {
		throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
	}
}
 
Example #21
Source File: DemoEntityCollectionProcessor.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
  try {
    return new URI(entitySetName + "(" + String.valueOf(id) + ")");
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
  }
}
 
Example #22
Source File: UriInfoImplTest.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Test(expected = ODataRuntimeException.class)
public void doubleAlias() {
  final AliasQueryOption alias = (AliasQueryOption) new AliasQueryOptionImpl().setName("A");
  new UriInfoImpl()
      .addAlias(alias)
      .addAlias(alias);
}
 
Example #23
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
  try {
    return new URI(entitySetName + "(" + String.valueOf(id) + ")");
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
  }
}
 
Example #24
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #25
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName, String sourceId) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(sourceId).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
      sb.append("(").append(property.asPrimitive()).append(")");
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #26
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(Entity entity, String idPropertyName, String navigationName) {
  try {
    StringBuilder sb = new StringBuilder(getEntitySetName(entity)).append("(");
    final Property property = entity.getProperty(idPropertyName);
    sb.append(property.asPrimitive()).append(")");
    if(navigationName != null) {
      sb.append("/").append(navigationName);
    }
    return new URI(sb.toString());
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create (Atom) id for entity: " + entity, e);
  }
}
 
Example #27
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
	try {
		return new URI(entitySetName + "(" + String.valueOf(id) + ")");
	} catch (URISyntaxException e) {
		throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
	}
}
 
Example #28
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
  try {
    return new URI(entitySetName + "(" + String.valueOf(id) + ")");
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
  }
}
 
Example #29
Source File: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
  try {
    return new URI(entitySetName + "(" + String.valueOf(id) + ")");
  } catch (URISyntaxException e) {
    throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
  }
}
 
Example #30
Source File: DemoEntityCollectionProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private URI createId(String entitySetName, Object id) {
    try {
        return new URI(entitySetName + "(" + String.valueOf(id) + ")");
    } catch (URISyntaxException e) {
        throw new ODataRuntimeException("Unable to create id for entity: " + entitySetName, e);
    }
}