object.put("num_files", fileCnt); } catch (JSONException jse) { logger.info("Caught JSON Exception --> {}", jse.getMessage());
public XMLStreamReader createXMLStreamReader(JSONTokener tokener) throws XMLStreamException { try { JSONObject root = createJSONObject(tokener); return new MappedXMLStreamReader(root, convention); } catch (JSONException e) { int column = e.getColumn(); if (column == -1) { throw new XMLStreamException(e); } else { throw new XMLStreamException(e.getMessage(), new ErrorLocation(e.getLine(), e.getColumn()), e); } } }
public Response toResponse( JSONException exception ) { return Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build(); }
@Override public JSONObjectWrapper put(String key, Object value) { try{ super.put(key, value); return this; } catch (JSONException e) { throw new NullPointerException(e.getMessage()); } }
public PersistentJwt(String jwt) { try { load(jwt); } catch (JSONException e) { log.error(e.getMessage(), e); } }
@Override public void onConnect(SocketIOOutbound outbound) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(this + " connected."); this.outbound = outbound; try { send(new JSONObject().put("type", MessageType.ACK)); } catch (JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
public void setTags(Set<String> tags) { if (tags == null || tags.isEmpty()) { throw new IllegalArgumentException("tags can't be null or empty."); } try { JSONArray tagArray = new JSONArray(tags); schema.put(FIELD_SCHEMA_TAGS, tagArray); } catch (JSONException e) { Preconditions.checkState(false, e.getMessage()); throw new RuntimeException(e); } schemaJSON = schema.toString(); }
/** * Parse a raw bucket config string into a {@link Bucket} configuration. * * @param bucketJson the raw JSON. * @return the parsed configuration. * @throws ParseException if the JSON could not be parsed properly. */ public Bucket parseBucket(String bucketJson) throws ParseException { try { return parseBucketFromJSON(new JSONObject(bucketJson), null); } catch (JSONException e) { throw new ParseException(e.getMessage(), 0); } }
/** * Parse a raw bucket config and update an old bucket with the new infos. * * @param bucketJson the new JSON information. * @param currentBucket the current bucket to update. * @return the parsed configuration. * @throws ParseException if the JSON could not be parsed properly. */ public Bucket updateBucket(String bucketJson, Bucket currentBucket) throws ParseException { try { return parseBucketFromJSON(new JSONObject(bucketJson), currentBucket); } catch (JSONException e) { throw new ParseException(e.getMessage(), 0); } }
private void generateResults(MessageContext messageContext, boolean resultStatus) { ResultPayloadCreater resultPayload = new ResultPayloadCreater(); String responses = "<unzip><success>" + resultStatus + "</success></unzip>"; try { OMElement element = resultPayload.performSearchMessages(responses); resultPayload.preparePayload(messageContext, element); } catch (XMLStreamException e) { log.error(e.getMessage()); handleException(e.getMessage(), messageContext); } catch (IOException e) { log.error(e.getMessage()); handleException(e.getMessage(), messageContext); } catch (JSONException e) { log.error(e.getMessage()); handleException(e.getMessage(), messageContext); } } }
/** * Parses a given /pools/{pool} JSON for the buckets URI. * * @param pool the actual pool object to attach to. * @param poolsJson the raw JSON for the pool response. * @throws ParseException if the JSON could not be parsed properly. */ public void parsePool(final Pool pool, final String poolsJson) throws ParseException { try { JSONObject buckets = new JSONObject(poolsJson).getJSONObject("buckets"); URI bucketsUri = new URI(buckets.getString("uri")); pool.setBucketsUri(bucketsUri); } catch (JSONException e) { throw new ParseException(e.getMessage(), 0); } catch (URISyntaxException e) { throw new ParseException(e.getMessage(), 0); } }
void fire(String topic, String data) { for (Endpoint endpoint : endpoints.values()) try { endpoint.send(new JSONObject().put("type", MessageType.PUBLISH).put("topic", topic).put("data", data)); } catch (JSONException e) { throw new RuntimeException(e.getMessage(), e); } } }
public JSONObjectAsserter assertJsonObject() { try { return JSONObjectAsserter.of(new JSONObject(entity)); } catch (JSONException e) { fail(e.getMessage() + "\nResponse was: " + entity, e); throw new RuntimeException(e); } }
@Parameters({"jwksPath"}) @Test public void requestJwks(final String jwksPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + jwksPath).request(); request.header("Accept", MediaType.APPLICATION_JSON); Response response = request.get(); String entity = response.readEntity(String.class); showResponse("requestJwks", response, entity); assertEquals(response.getStatus(), 200, "Unexpected response code."); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has(JSON_WEB_KEY_SET), "Unexpected result: keys not found"); JSONArray keys = jsonObj.getJSONArray(JSON_WEB_KEY_SET); assertNotNull(keys, "Unexpected result: keys is null"); assertTrue(keys.length() > 0, "Unexpected result: keys is empty"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Parameters({"registerPath"}) @Test public void requestClientRegistrationFail3(final String registerPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request(); String registerRequestContent = null; try { RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", Arrays.asList("https://client.example.com/cb#fail_fragment")); registerRequestContent = registerRequest.getJSONParameters().toString(4); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage()); } Response response = request.post(Entity.json(registerRequestContent)); String entity = response.readEntity(String.class); showResponse("requestClientRegistrationFail3", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity); TestUtil.assertErrorResponse(entity); }
@Parameters({"registerPath"}) @Test public void requestClientRegistrationFail1(final String registerPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request(); String registerRequestContent = null; try { RegisterRequest registerRequest = new RegisterRequest(null, null, null); registerRequestContent = registerRequest.getJSONParameters().toString(4); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage()); } Response response = request.post(Entity.json(registerRequestContent)); String entity = response.readEntity(String.class); showResponse("requestClientRegistrationFail 1", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity); TestUtil.assertErrorResponse(entity); }
@Parameters({"endSessionPath"}) @Test(enabled = true) // switched off test : WebApplicationException seems to not translated correctly into response by container and results in 500 error. See org.xdi.oxauth.session.ws.rs.EndSessionRestWebServiceImpl.endSession() public void requestEndSessionFail1(final String endSessionPath) throws Exception { EndSessionRequest endSessionRequest = new EndSessionRequest(null, null, null); Builder request = ResteasyClientBuilder.newClient() .target(url.toString() + endSessionPath + "?" + endSessionRequest.getQueryString()).request(); request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED); Response response = request.get(); String entity = response.readEntity(String.class); showResponse("requestEndSessionFail1", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code."); assertNotNull(entity, "Unexpected result: " + entity); try { JSONObject jsonObj = new JSONObject(entity); assertTrue(jsonObj.has("error"), "The error type is null"); assertTrue(jsonObj.has("error_description"), "The error description is null"); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage() + "\nResponse was: " + entity); } }
@Parameters({"registerPath"}) @Test public void requestClientRegistrationFail2(final String registerPath) throws Exception { Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request(); String registerRequestContent = null; try { RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", null); // Missing // redirect // URIs registerRequestContent = registerRequest.getJSONParameters().toString(4); } catch (JSONException e) { e.printStackTrace(); fail(e.getMessage()); } Response response = request.post(Entity.json(registerRequestContent)); String entity = response.readEntity(String.class); showResponse("requestClientRegistrationFail 2", response, entity); assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity); TestUtil.assertErrorResponse(entity); }
public JsonHttpResult(HttpResult other) { super(other); if (other.getContent() == null) { setParsedJson(new JSONObject()); return; } try{ if (other.getContent() instanceof JSONObject) { setParsedJson((JSONObject) other.getContent()); } else { setParsedJson(new JSONObject(other.getContent().toString())); } } catch (JSONException e) { failedParsing = true; setParsedJson(createErrorJson(e.getMessage(), other)); } }
public JSONObject toJSONObject() { JSONObject obj = new JSONObject(); try { obj.put("title", title); obj.put("key", key); obj.put("noLink", noLink); obj.put("mode", mode); obj.put("expand", true); obj.put("children", getChildrenJSONArray()); } catch (JSONException e) { try { obj.put("error", e.getMessage()); } catch (JSONException e1) { } } return obj; }