javax.ws.rs.core.NoContentException Java Examples

The following examples show how to use javax.ws.rs.core.NoContentException. 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: JsonObjectReader.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public JsonObject readFrom(Class<JsonObject> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    byte[] bytes = getBytes(entityStream);
    if (bytes.length == 0) {
        throw new NoContentException("Cannot create JsonObject");
    }
    return new JsonObject(Buffer.buffer(bytes));
}
 
Example #2
Source File: JsonArrayReader.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public JsonArray readFrom(Class<JsonArray> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    byte[] bytes = getBytes(entityStream);
    if (bytes.length == 0) {
        throw new NoContentException("Cannot create JsonArray");
    }
    return new JsonArray(Buffer.buffer(bytes));
}
 
Example #3
Source File: MoshiMessageBodyReader.java    From jax-rs-moshi with Apache License 2.0 5 votes vote down vote up
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations,
    MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
    throws IOException, WebApplicationException {
  JsonAdapter<Object> adapter = moshi.adapter(genericType);
  BufferedSource source = Okio.buffer(Okio.source(entityStream));
  if (!source.request(1)) {
    throw new NoContentException("Stream is empty");
  }
  return adapter.fromJson(source);
  // Note: we do not close the InputStream per the interface documentation.
}
 
Example #4
Source File: MoshiMessageBodyReaderTest.java    From jax-rs-moshi with Apache License 2.0 5 votes vote down vote up
@Test public void emptyReadThrows() throws IOException {
  Buffer data = new Buffer();
  Class<Object> type = (Class) String.class;
  try {
    reader.readFrom(type, type, new Annotation[0], APPLICATION_JSON_TYPE,
        new MultivaluedHashMap<>(),
        data.inputStream());
    fail();
  } catch (NoContentException ignored) {
  }
}
 
Example #5
Source File: PrimitiveTextProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({
    "unchecked", "rawtypes"
})
@Test(expected = NoContentException.class)
public void testReadEmptyByte() throws Exception {
    MessageBodyReader<?> p = new PrimitiveTextProvider<>();

    p.readFrom((Class)Byte.TYPE, null, null,
                                      null,
                                      null,
                                      new ByteArrayInputStream("".getBytes()));


}
 
Example #6
Source File: AbstractConfigurableProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void reportEmptyContentLength() throws NoContentException {
    String message = new org.apache.cxf.common.i18n.Message("EMPTY_BODY", BUNDLE).toString();
    LOG.warning(message);
    throw new NoContentException(message);
}