Java 类javax.json.stream.JsonParsingException 实例源码

项目:eplmp    文件:JWTokenFactory.java   
public static String validateEntityToken(Key key, String jwt) {

        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
                .setVerificationKey(key)
                .setRelaxVerificationKeyValidation()
                .build();

        try {
            JwtClaims jwtClaims = jwtConsumer.processToClaims(jwt);
            String subject = jwtClaims.getSubject();
            try (JsonReader reader = Json.createReader(new StringReader(subject))) {
                JsonObject subjectObject = reader.readObject(); // JsonParsingException
                return subjectObject.getString(ENTITY_KEY); // Npe
            }
        } catch (InvalidJwtException | MalformedClaimException | JsonParsingException | NullPointerException e) {
            LOGGER.log(Level.SEVERE, "Cannot validate jwt token", e);
        }

        return null;

    }
项目:step    文件:ReturnHandler.java   
private JsonObject resolveOutputJson(Return testArtefact) {
    String outputJson = testArtefact.getOutput().get();

    JsonObject outputJsonObject;
    try {
        if(outputJson!=null&&outputJson.trim().length()>0) {
            outputJsonObject = jprov.createReader(new StringReader(outputJson)).readObject();
        } else {
            outputJsonObject = jprov.createObjectBuilder().build();
        }
    } catch(JsonParsingException e) {
        throw new RuntimeException("Error while parsing argument (input): "+e.getMessage());
    }

    JsonObject outputJsonAfterResolving = dynamicJsonObjectResolver.evaluate(outputJsonObject, getBindings());
    return outputJsonAfterResolving;
}
项目:cookjson    文件:TextJsonConfigHandler.java   
public static CookJsonParser getJsonParser (InputStream is)
{
    PushbackInputStream pis = new PushbackInputStream (is, 3);
    Charset charset;
    try
    {
        charset = BOM.guessCharset (pis);
    }
    catch (IOException ex)
    {
        JsonLocationImpl location = new JsonLocationImpl ();
        location.m_streamOffset = 0;
        throw new JsonParsingException (ex.getMessage (), ex, location);
    }
    if (charset == BOM.utf8)
        return new UTF8TextJsonParser (pis);
    return new TextJsonParser (new InputStreamReader (pis, charset));
}
项目:cookjson    文件:CommentTest.java   
@Test
public void testError1 ()
{
    String json = "{\"a\" :\n//abc\u0000\n 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    TextJsonParser p = new TextJsonParser (new StringReader (json), 2);
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:cookjson    文件:CommentTest.java   
@Test
public void testError2 ()
{
    String json = "{\"a\" :\n/*abc\u0000\n*/ 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:cookjson    文件:CommentTest.java   
@Test
public void testError2_2 ()
{
    String json = "{\"a\" :\n/*abc\u0000\n*/ 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    TextJsonParser p = new TextJsonParser (new StringReader (json), 2);
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:cookjson    文件:CommentTest.java   
@Test
public void testError3 ()
{
    String json = "{\"a\" :\n/****\u0000\n*/ 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:cookjson    文件:UTF8CommentTest.java   
@Test
public void testError1 ()
{
    String json = "{\"a\" :\n//abc\u0000\n 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    UTF8TextJsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)), 2);
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:cookjson    文件:UTF8CommentTest.java   
@Test
public void testError3_2 ()
{
    String json = "{\"a\" :\n/****\u0000\n*/ 99e12 }";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 2, column 6, offset 12: unexpected character '\\u0000'");

    UTF8TextJsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)), 2);
    p.setAllowComments (true);
    while (p.hasNext ())
    {
        p.next ();
    }
    p.close ();
}
项目:sample-acmegifts    文件:Orchestrator.java   
private JsonObject stringToJsonObj(String input) {
  try {
    JsonReader jsonReader = Json.createReader(new StringReader(input));
    JsonObject output = jsonReader.readObject();
    jsonReader.close();
    return output;
  } catch (JsonParsingException e) {
    return null;
  }
}
项目:sample-acmegifts    文件:Group.java   
public static JsonObject stringToJsonObj(String input) {
  try {
    JsonReader jsonReader = Json.createReader(new StringReader(input));
    JsonObject output = jsonReader.readObject();
    jsonReader.close();
    return output;
  } catch (JsonParsingException e) {
    return null;
  }
}
项目:eplmp    文件:JWTokenFactory.java   
public static JWTokenUserGroupMapping validateAuthToken(Key key, String jwt) {

        JwtConsumer jwtConsumer = new JwtConsumerBuilder()
                .setVerificationKey(key)
                .setRelaxVerificationKeyValidation()
                .build();

        try {
            JwtClaims jwtClaims = jwtConsumer.processToClaims(jwt);
            String subject = jwtClaims.getSubject();

            try (JsonReader reader = Json.createReader(new StringReader(subject))) {
                JsonObject subjectObject = reader.readObject(); // JsonParsingException
                String login = subjectObject.getString(SUBJECT_LOGIN); // Npe
                String groupName = subjectObject.getString(SUBJECT_GROUP_NAME); // Npe

                if (login != null && !login.isEmpty() && groupName != null && !groupName.isEmpty()) {
                    return new JWTokenUserGroupMapping(jwtClaims, new UserGroupMapping(login, groupName));
                }
            }


        } catch (InvalidJwtException | MalformedClaimException | JsonParsingException | NullPointerException e) {
            LOGGER.log(Level.SEVERE, "Cannot validate jwt token", e);
        }

        return null;

    }
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testError6 ()
{
    String json = "\u0000{ \"a\" : 1 ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 1, offset 0: unexpected character '\\u0000'");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testIOError ()
{
    String json = "[{";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 3, offset 2: unexpected eof");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:yconnect-servlet-sdk    文件:JWTVerificationTest.java   
@Test(expected = JsonParsingException.class)
public void testInvalidHeader() throws DataFormatException {
  String clientSecret = "SECRET_KEY";
  String idTokenString =
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ.eyJpc3MiOiJodHRwczpcL1wvYXV0aC5sb2dpbi55YWhvby5jby5qcCIsInVzZXJfaWQiOiJVU0VSX0lEIiwiYXVkIjoiQVBQTElDQVRJT05fSUQiLCJleHAiOjE0MTE2NDcxMzksImlhdCI6MTQxMDQzNzU0MCwibm9uY2UiOiJhYmNkZWZnIn0.OLUFkAlp4BwwAxniMzXyoR5ZFC3Q5HCNHRvR6qDf-zY";
  JWTVerification verifier = new JWTVerification(clientSecret, idTokenString);
  boolean result = verifier.verifyJWT();
  assertFalse(result);
}
项目:yconnect-servlet-sdk    文件:JWTVerificationTest.java   
@Test(expected = JsonParsingException.class)
public void testInvalidPayload() throws DataFormatException {
  String clientSecret = "SECRET_KEY";
  String idTokenString =
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvYXV0aC5sb2dpbi55YWhvby5jby5qcCIsInVzZXJfaWQiOiJVU0VSX0lEIiwiYXVkIjoiQVBQTElDQVRJT05fSUQiLCJleHAiOjE0MTE2NDcxMzksImlhdCI6MTQxMDQzNzU0MCwibm9uY2UiOiJhYmNkZWZnIn.OLUFkAlp4BwwAxniMzXyoR5ZFC3Q5HCNHRvR6qDf-zY";
  JWTVerification verifier = new JWTVerification(clientSecret, idTokenString);
  boolean result = verifier.verifyJWT();
  assertFalse(result);
}
项目:aerodrome-for-jet    文件:APIResponse.java   
/**
 * Retrieve the response as a parsed JsonObject
 * @return response
 * @throws JsonException if a JSON object cannot
 *     be created due to i/o error (IOException would be
 *     cause of JsonException)
 * @throws javax.json.stream.JsonParsingException if a JSON object cannot
 *     be created due to incorrect representation
 */
@Override
public JsonObject getJsonObject()
  throws JsonException, JsonParsingException
{
  try ( final JsonReader reader = Json.createReader( 
    new StringReader( content ))) 
  {
    return reader.readObject();
  }
}
项目:hibiscus    文件:BasicJsonValidatorTest.java   
@Test(expected = JsonParsingException.class)
public void notWellFormed() throws IOException {
    JsonValidator validator = new BasicJsonValidator(personSchema());
    try (InputStream stream = newInputStream("person-not-well-formed.json")) {
        validator.validate(stream, StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw e;
    }
}
项目:hibiscus    文件:BasicJsonValidatorTest.java   
@Test(expected = JsonParsingException.class)
public void empty() throws IOException {
    JsonValidator validator = new BasicJsonValidator(personSchema());
    try (InputStream stream = newInputStream("empty.json")) {
        validator.validate(stream, StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw e;
    }
}
项目:hibiscus    文件:BasicJsonValidatorTest.java   
@Test
public void invalidRoot() throws IOException {
    JsonValidator validator = new BasicJsonValidator(schema(string()));
    ValidationResult result = null; 
    try (InputStream stream = newInputStream("invalid-root.json")) {
        result = validator.validate(stream, StandardCharsets.UTF_8);
        assertResultValid(result);
        assertFalse(result.hasProblems());
        assertTrue(result.getValue() instanceof JsonString);
    } catch (JsonParsingException e) {
        // We ignore the exception thrown by the reference implementation.
    }
}
项目:step    文件:CallFunctionHandler.java   
private JsonObject parseAndResolveJson(String functionStr) {
    JsonObject query;
    try {
        if(functionStr!=null&&functionStr.trim().length()>0) {
            query = jprov.createReader(new StringReader(functionStr)).readObject();
        } else {
            query = jprov.createObjectBuilder().build();
        }
    } catch(JsonParsingException e) {
        throw new RuntimeException("Error while parsing argument (input): "+e.getMessage());
    }
    return dynamicJsonObjectResolver.evaluate(query, getBindings());
}
项目:cookjson    文件:TextJsonParser.java   
private JsonParsingException ioError (String msg)
{
    JsonLocationImpl location = new JsonLocationImpl ();
    location.m_lineNumber = m_line;
    // -1 to back track the last read character.
    location.m_columnNumber = m_column -1;
    location.m_streamOffset = m_offset - 1;
    return new JsonParsingException ("Parsing error at " + location.toString () + ": " + msg, location);
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testError3 ()
{
    String json = "[ \u0000 ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 3, offset 2: unexpected character '\\u0000'");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParser.java   
private JsonParsingException ioError (String msg)
{
    JsonLocationImpl location = new JsonLocationImpl ();
    location.m_lineNumber = m_line;
    // -1 to back track the last read character.
    location.m_columnNumber = m_column -1;
    location.m_streamOffset = m_offset - 1;
    return new JsonParsingException ("Parsing error at " + location.toString () + ": " + msg, location);
}
项目:cookjson    文件:UTF8TextJsonParser.java   
@Override
public void close ()
{
    try
    {
        m_in.close ();
    }
    catch (IOException ex)
    {
        throw new JsonParsingException (ex.getMessage (), ex, getCurrentLocation ());
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testString4 ()
{
    String json = "[ \"\n\" ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 4, offset 3: unexpected character '\\n'");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testNumber4 ()
{
    String json = "[ -1e- ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 7, offset 6: unexpected character ' '");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testError5 ()
{
    String json = "{ \u0000\"a\" : 1 ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 3, offset 2: unexpected character '\\u0000'");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void test1 ()
{
    String json = "{[]}";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 2, offset 1: unexpected character '['");

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void test3 ()
{
    String json = "{{}}";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 2, offset 1: unexpected character '{'");

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testTrue1 ()
{
    String json = "[ t ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testTrue2 ()
{
    String json = "[ tr ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testTrue3 ()
{
    String json = "[ tru ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testError1 ()
{
    String json = "[ -\\ ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 4, offset 3: unexpected character '\\\\'");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testFalse1 ()
{
    String json = "[ f ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testFalse2 ()
{
    String json = "[ fa ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testFalse3 ()
{
    String json = "[ fal ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testFalse4 ()
{
    String json = "[ fals ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:UTF8TextJsonParserErrorTest.java   
@Test
@SuppressWarnings ("resource")
public void testNumber6_2 ()
{
    String json = "[ - ]";

    thrown.expect (JsonParsingException.class);
    thrown.expectMessage ("Parsing error at line 1, column 4, offset 3: unexpected character ' '");

    JsonParser p = new UTF8TextJsonParser (new ByteArrayInputStream (json.getBytes (BOM.utf8)), 2);
    for (;;)
    {
        p.next ();
    }
}
项目:cookjson    文件:TextJsonParserErrorTest.java   
@Test (expected = JsonParsingException.class)
@SuppressWarnings ("resource")
public void testNull1 ()
{
    String json = "[ n ]";

    TextJsonParser p = new TextJsonParser (new StringReader (json));
    for (;;)
    {
        p.next ();
    }
}