com.fasterxml.jackson.jr.ob.JSONObjectException Java Examples

The following examples show how to use com.fasterxml.jackson.jr.ob.JSONObjectException. 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: BasicRenameTest.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
public void testBasicRenameOnDeserialize() throws Exception
{
    final String json = a2q("{'firstName':'Bob','_last':'Burger'}");
    final JSON j = JSON.std
            .with(JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY);

    try {
        j.beanFrom(NameSimple.class, json);
        fail("Should not pass");
    } catch (JSONObjectException e) {
        verifyException(e, "Unrecognized JSON property \"firstName\"");
    }
    NameSimple result = JSON_WITH_ANNO.beanFrom(NameSimple.class, json);
    assertEquals("Bob", result._first);
    assertEquals("Burger", result._last);
}
 
Example #2
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeIn() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeIn";
    rrec = new RequestRecord(layer);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();

    logger.info(Markers.REQUEST_MARKER, rrec.toString());

    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.IN.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_SENT_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
}
 
Example #3
Source File: PreferencesUsageDataStoreTest.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void multipleIncrementUsageFor() throws JSONObjectException, IOException, InterruptedException {
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage = JSON.std.beanFrom(
            ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    victim.flush();
    Thread.sleep(1000);
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage2 = JSON.std.beanFrom(
            ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    assertEquals(2, usage2.getTotalUsed());
    assertTrue(usage.getLastSeen() != usage2.getLastSeen());
}
 
Example #4
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeOut() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeOut";
    rrec = new RequestRecord(layer, Direction.OUT);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();

    logger.info(Markers.REQUEST_MARKER, rrec.toString());

    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.OUT.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_SENT_AT), not(nullValue()));
    assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
}
 
Example #5
Source File: ArrayReader.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
@Override
public Object readNext(JSONReader r, JsonParser p) throws IOException {
    if (p.nextToken() != JsonToken.START_ARRAY) {
        if (p.hasToken(JsonToken.VALUE_NULL)) {
            return null;
        }
        throw JSONObjectException.from(p, "Unexpected token %s; should get START_ARRAY",
                p.currentToken());
    }
    CollectionBuilder b = r._collectionBuilder(null);
    if (p.nextToken() == JsonToken.END_ARRAY) {
        return b.emptyArray(_elementType);
    }
    Object value = _valueReader.read(r, p);
    if (p.nextToken() == JsonToken.END_ARRAY) {
        return b.singletonArray(_elementType, value);
    }
    b = b.start().add(value);
    do {
        b = b.add(_valueReader.read(r, p));
    } while (p.nextToken() != JsonToken.END_ARRAY);
    return b.buildArray(_elementType);
}
 
Example #6
Source File: CollectionReader.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
@Override
public Object readNext(JSONReader r, JsonParser p) throws IOException {
    if (p.nextToken() != JsonToken.START_ARRAY) {
        if (p.hasToken(JsonToken.VALUE_NULL)) {
            return null;
        }
        throw JSONObjectException.from(p, "Unexpected token %s; should get START_ARRAY",
                p.currentToken());
    }
    CollectionBuilder b = r._collectionBuilder(_collectionType);
    if (p.nextToken() == JsonToken.END_ARRAY) {
        return b.emptyCollection();
    }
    Object value = _valueReader.read(r, p);
    if (p.nextToken() == JsonToken.END_ARRAY) {
        return b.singletonCollection(value);
    }
    b = b.start().add(value);
    do {
        b = b.add(_valueReader.read(r, p));
    } while (p.nextToken() != JsonToken.END_ARRAY);
    return b.buildCollection();
}
 
Example #7
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeOut() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeOut";
    rrec = new RequestRecord(layer, Direction.OUT);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();
    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.OUT.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_SENT_AT), not(nullValue()));
}
 
Example #8
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeIn() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeIn";
    rrec = new RequestRecord(layer);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();
    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.IN.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_SENT_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_RECEIVED_AT), not(nullValue()));
}
 
Example #9
Source File: BeanPropertyWriter.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
public Object getValueFor(Object bean) throws IOException
{
    try {
        if (_getter == null) {
            return _field.get(bean);
        }
        return _getter.invoke(bean);
    } catch (Exception e) {
        final String accessorDesc = (_getter != null)
                ? String.format("method %s.%s()", _bean(), _getter.getName())
                : String.format("field %s.%s", _bean(), _field.getName());
        throw new JSONObjectException(String.format(
                "Failed to access property '%s' (using %s); exception (%s): %s",
                name, e.getClass().getName(), accessorDesc, e.getMessage()), e);
    }
}
 
Example #10
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaults() throws JSONObjectException, IOException {
    String layer = "testDefaults";
    rrec = new RequestRecord(layer);
    assertThat(getField(Fields.DIRECTION), is(Direction.IN.toString()));
    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.RESPONSE_SIZE_B), is("-1"));
    assertThat(getField(Fields.REQUEST_SIZE_B), is("-1"));
    assertThat(getField(Fields.REQUEST_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_RECEIVED_AT), not(nullValue()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)), greaterThan(new Double(0.0)));

    assertThat(getField(Fields.REQUEST), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.REMOTE_IP), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.REMOTE_HOST), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.PROTOCOL), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.METHOD), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.REMOTE_IP), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.REMOTE_HOST), is(Defaults.UNKNOWN));
    assertThat(getField(Fields.RESPONSE_CONTENT_TYPE), is(Defaults.UNKNOWN));

    assertThat(getField(Fields.REFERER), is(nullValue()));
    assertThat(getField(Fields.X_FORWARDED_FOR), is(nullValue()));
    assertThat(getField(Fields.REMOTE_PORT), is(nullValue()));

}
 
Example #11
Source File: CustomValueReadersTest.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
public void testCustomBeanReader() throws Exception
{
    // First: without handler, will fail to map
    try {
        JSON.std.beanFrom(CustomValue.class, "123");
        fail("Should not pass");
    } catch (JSONObjectException e) {
        verifyException(e, ".CustomValue");
        verifyException(e, "constructor to use");
    }

    // then with custom, should be fine
    JSON json = jsonWithProvider(new CustomReaders(0));
    CustomValue v = json.beanFrom(CustomValue.class, "123");
    assertEquals(124, v.value);

    // similarly with wrapper
    CustomValueBean bean = json.beanFrom(CustomValueBean.class,
            aposToQuotes("{ 'custom' : 137 }"));
    assertEquals(138, bean.custom.value);

    // but also ensure we can change registered handler(s)
    JSON json2 = jsonWithProvider(new CustomReaders(100));
    v = json2.beanFrom(CustomValue.class, "123");
    assertEquals(224, v.value);
}
 
Example #12
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeOut() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeOut";
    rrec = new RequestRecord(layer, Direction.OUT);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();

    logger.info(Markers.REQUEST_MARKER, rrec.toString());

    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.OUT.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_SENT_AT), not(nullValue()));
    assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
}
 
Example #13
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponseTimeIn() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testResponseTimeIn";
    rrec = new RequestRecord(layer);
    long start = rrec.start();
    doWait(150);
    long end = rrec.stop();

    logger.info(Markers.REQUEST_MARKER, rrec.toString());

    assertThat(getField(Fields.LAYER), is(layer));
    assertThat(getField(Fields.DIRECTION), is(Direction.IN.toString()));
    assertThat(Double.valueOf(getField(Fields.RESPONSE_TIME_MS)).longValue(), lessThanOrEqualTo(Double.valueOf(end -
                                                                                                               start)
                                                                                                      .longValue()));
    assertThat(getField(Fields.RESPONSE_SENT_AT), not(nullValue()));
    assertThat(getField(Fields.REQUEST_RECEIVED_AT), not(nullValue()));
    assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
}
 
Example #14
Source File: BeanReader.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
protected void handleUnknown(JSONReader reader, JsonParser parser, String fieldName) throws IOException {
        if (JSON.Feature.FAIL_ON_UNKNOWN_BEAN_PROPERTY.isEnabled(reader._features)) {
            // 20-Jan-2020, tatu: With optional annotation support, may have "known ignorable"
            //    that usually should behave as if safely ignorable
            if (!_ignorableNames.contains(fieldName)) {
                final StringBuilder sb = new StringBuilder(60);
                Iterator<String> it = new TreeSet<String>(_propsByName.keySet()).iterator();
                if (it.hasNext()) {
                    sb.append('"').append(it.next()).append('"');
                    while (it.hasNext()) {
                        sb.append(", \"").append(it.next()).append('"');
                    }
                }
                throw JSONObjectException.from(parser,
"Unrecognized JSON property \"%s\" for Bean type `%s` (known properties: [%s])",
                        fieldName, _valueType.getName(), sb.toString());
            }
        }
        parser.nextToken();
        parser.skipChildren();
    }
 
Example #15
Source File: CustomValueReadersTest.java    From jackson-jr with Apache License 2.0 6 votes vote down vote up
public void testCustomDelegatingReader() throws Exception
{
    // First: without handler, will fail to map
    final String doc = "{\"y\" : 3, \"x\": 2 }";
    try {
        JSON.std.beanFrom(Point.class, doc);
        fail("Should not pass");
    } catch (JSONObjectException e) {
        verifyException(e, "$Point");
        verifyException(e, "constructor to use");
    }

    // then with custom, should be fine
    JSON json = jsonWithProvider(new PointReaderProvider());
    Point v = json.beanFrom(Point.class, doc);
    assertEquals(2, v._x);
    assertEquals(3, v._y);
}
 
Example #16
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
/**
 * Method for reading a JSON Object from input and building a {@link java.util.Map}
 * out of it, binding values into specified {@code type}.
 * Note that if input does NOT contain a JSON Object, {@link JSONObjectException} will be thrown.
 */
@SuppressWarnings("unchecked")
public <T> Map<String, T> readMapOf(Class<T> type) throws IOException
{
    if (_parser.isExpectedStartObjectToken()) {
        return (Map<String, T>) new MapReader(Map.class, _readerLocator.findReader(type))
                .read(this, _parser);
    }
    if (_parser.hasToken(JsonToken.VALUE_NULL)) {
        return null;
    }
    throw JSONObjectException.from(_parser,
            "Can not read a Map: expect to see START_OBJECT ('{'), instead got: "+ValueReader._tokenDesc(_parser));
}
 
Example #17
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
/**
 * Method for reading a JSON Array from input and building a {@link java.util.List}
 * out of it, binding values into specified {@code type}.
 * Note that if input does NOT contain a JSON Array, {@link JSONObjectException} will be thrown.
 */
@SuppressWarnings("unchecked")
public <T> List<T> readListOf(Class<T> type) throws IOException
{
    if (_parser.isExpectedStartArrayToken()) {
        return (List<T>) new CollectionReader(List.class, _readerLocator.findReader(type))
                .read(this, _parser);
    }
    if (_parser.hasToken(JsonToken.VALUE_NULL)) {
        return null;
    }
    throw JSONObjectException.from(_parser,
            "Can not read a List: expect to see START_ARRAY ('['), instead got: "+ValueReader._tokenDesc(_parser));
}
 
Example #18
Source File: PreferencesUsageDataStoreTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void incrementUsageFor() throws JSONObjectException, IOException {
    victim.incrementUsageFor("moduleId");
    ModuleUsage usage = JSON.std.beanFrom(
            ModuleUsage.class,
            Preferences.userRoot().node(PreferencesUsageDataStore.USAGE_PATH).node("moduleId")
                    .get(PreferencesUsageDataStore.MODULE_USAGE_KEY, ""));
    assertEquals(1, usage.getTotalUsed());
    assertTrue(usage.getLastSeen() != 0);
}
 
Example #19
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T> T[] readArrayOf(Class<T> type) throws IOException {
    if (_parser.isExpectedStartArrayToken()) {
        // NOTE: "array type" we give is incorrect, but should usually not matter
        // -- to fix would need to instantiate 0-element array, get that type
        return (T[]) new ArrayReader(type, type,
            _readerLocator.findReader(type))
                .read(this, _parser);
    }
    if (_parser.hasToken(JsonToken.VALUE_NULL)) {
        return null;
    }
    throw JSONObjectException.from(_parser,
            "Can not read an array: expect to see START_ARRAY ('['), instead got: "+ValueReader._tokenDesc(_parser));
}
 
Example #20
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
/**
 * Method for reading a JSON Object from input and building a {@link java.util.Map}
 * out of it. Note that if input does NOT contain a
 * JSON Object, {@link JSONObjectException} will be thrown.
 */
public Map<String,Object> readMap() throws IOException {
    if (_parser.isExpectedStartObjectToken()) {
        return (Map<String,Object>) AnyReader.std.readFromObject(this, _parser, _mapBuilder);
    }
    if (_parser.hasToken(JsonToken.VALUE_NULL)) {
        return null;
    }
    throw JSONObjectException.from(_parser,
            "Can not read a Map: expect to see START_OBJECT ('{'), instead got: "+ValueReader._tokenDesc(_parser));
}
 
Example #21
Source File: MapReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(JSONReader r, JsonParser p) throws IOException {
    MapBuilder b = r._mapBuilder(_mapType);
    String propName0 = p.nextFieldName();
    if (propName0 == null) {
        if (p.hasToken(JsonToken.END_OBJECT)) {
            return b.emptyMap();
        }
        throw _reportWrongToken(p);
    }
    Object value = _valueReader.readNext(r, p);
    String propName = p.nextFieldName();
    if (propName == null) {
        if (p.hasToken(JsonToken.END_OBJECT)) {
            return b.singletonMap(propName0, value);
        }
        throw _reportWrongToken(p);
    }
    try {
        b = b.start().put(propName0, value);
        while (true) {
            b = b.put(propName, _valueReader.readNext(r, p));
            propName = p.nextFieldName();
            if (propName == null) {
                if (p.hasToken(JsonToken.END_OBJECT)) {
                    return b.build();
                }
                throw _reportWrongToken(p);
            }
        }
    } catch (IllegalArgumentException e) {
        throw JSONObjectException.from(p, e.getMessage());
    }
}
 
Example #22
Source File: DupFieldNameInTree51Test.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
public void testFailOnDupMapKeys() throws Exception
{
    JSON j = JSON.builder()
            .enable(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS)
            .build();
    assertTrue(j.isEnabled(JSON.Feature.FAIL_ON_DUPLICATE_MAP_KEYS));
    final String json = "{\"a\":1,\"b\":2,\"b\":3,\"c\":4}";
    try {
        /*TreeNode node =*/ treeJSON.treeFrom(json);
        fail("Should not pass");
    } catch (JSONObjectException e) {
        verifyException(e, "Duplicate key");
    }
}
 
Example #23
Source File: DefaultStageServiceTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void save() throws JSONObjectException, IOException {
    StageStatus status = new StageStatus(10, 20, 100, 200);
    victim.save(status);
    StageStatus storedStatus = JSON.std.beanFrom(StageStatus.class, Preferences.userRoot()
            .node(DefaultStageService.STAGE_PATH).get(DefaultStageService.STAGE_STATUS_KEY, ""));
    assertEquals(status, storedStatus);
}
 
Example #24
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
/**
 * @since 2.11
 */
public TreeNode readTree() throws IOException {
    if (_treeCodec == null) {
        throw new JSONObjectException("No `TreeCodec` specified: can not bind JSON into `TreeNode` types");
    }
    return _treeCodec.readTree(_parser);
}
 
Example #25
Source File: JSONReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
/**
 * Method for reading a JSON Array from input and building a <code>Object[]</code>
 * out of it. Note that if input does NOT contain a
 * JSON Array, {@link JSONObjectException} will be thrown.
 */
public Object[] readArray() throws IOException
{
    if (_parser.isExpectedStartArrayToken()) {
        return AnyReader.std.readArrayFromArray(this, _parser, _collectionBuilder);
    }
    if (_parser.hasToken(JsonToken.VALUE_NULL)) {
        return null;
    }
    throw JSONObjectException.from(_parser,
            "Can not read an array: expect to see START_ARRAY ('['), instead got: "+ValueReader._tokenDesc(_parser));
}
 
Example #26
Source File: JSONWriter.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
protected void _checkUnknown(Object value) throws IOException
{
    if (JSON.Feature.FAIL_ON_UNKNOWN_TYPE_WRITE.isEnabled(_features)) {
        throw new JSONObjectException("Unrecognized type ("+value.getClass().getName()
                +"), don't know how to write (disable "+JSON.Feature.FAIL_ON_UNKNOWN_TYPE_WRITE
                +" to avoid exception)");
    }
}
 
Example #27
Source File: EnumReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
@Override
public Object read(JSONReader reader, JsonParser p) throws IOException {
    if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
        int ix = p.getIntValue();
        if (ix < 0 || ix >= _byIndex.length) {
            throw new JSONObjectException("Failed to bind Enum "+desc()+" with index "+ix
                    +" (has "+_byIndex.length+" values)");
        }
        return _byIndex[ix];
    }
    return _enum(p.getValueAsString().trim());
}
 
Example #28
Source File: EnumReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
private Object _enum(String id) throws IOException
{
    Object e = _byName.get(id);
    if (e == null) {
        throw new JSONObjectException("Failed to find Enum of type "+desc()+" for value '"+id+"'");
    }
    return e;
}
 
Example #29
Source File: BeanPropertyReader.java    From jackson-jr with Apache License 2.0 5 votes vote down vote up
private void _reportProblem(Exception e) throws IOException
{
    Throwable t = e;
    if (t instanceof InvocationTargetException) {
        t = t.getCause();
    }
    throw new JSONObjectException("Failed to set property '"+_name+"'; exception "+e.getClass().getName()+"): "
            +t.getMessage(), t);
}
 
Example #30
Source File: TestRequestRecord.java    From cf-java-logging-support with Apache License 2.0 5 votes vote down vote up
@Test
public void testContext() throws JSONObjectException, IOException {
    MDC.clear();
    String layer = "testContext";
    String reqId = "1-2-3-4";

    rrec = new RequestRecord(layer);
    rrec.addContextTag(Fields.REQUEST_ID, reqId);

    logger.info(Markers.REQUEST_MARKER, rrec.toString());

    assertThat(getField(Fields.REQUEST_ID), is(reqId));
    assertThat(getField(Fields.WRITTEN_TS), is(notNullValue()));
}