private void setRequiredSilent(boolean required) { this.required=required; try { object.put("required",required); } catch (JSONException e) { e.printStackTrace(); } }
private void setTypeSilent(String type) { this.type = type; try { object.put("type", type); } catch (JSONException e) { e.printStackTrace(); } }
@Override public String getQueryString() { String jsonQueryString = null; try { jsonQueryString = getJSONParameters().toString(4).replace("\\/", "/"); } catch (JSONException e) { e.printStackTrace(); } return jsonQueryString; } }
private void pass(JSONObject obj, JSONObject sch) { for( Iterator<?> iter = obj.keys() ; iter.hasNext() ; ){ Object o = iter.next() ; String propName = o.toString(); Object value; try { value = obj.get(propName); registerProperty(propName,value,sch); } catch (JSONException e) { e.printStackTrace(); } } }
public JSONObject getAuthTokenResponse() { JSONObject node = new JSONObject(); try { node.put("token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyVXVpZCI6IlVVSURPRlVTRVIxIiwiZXhwIjoxNDY5MTE3MjQ3LCJpYXQiOjE0NjkxMTM2NDd9.i1u4RMs4K7zBkGhmcpp1P79Wpz2UQYJkZKJTVdFp_iU="); } catch (JSONException e) { e.printStackTrace(); } return node; }
public static List<Map<String, String>> getPropertiesFromJson(String json) { List<Map<String, String>> properties = null; json = json.trim(); if (json.startsWith("{")) { properties = new ArrayList<Map<String, String>>(); properties.add(processJsonMap(json)); } else if (json.startsWith("[")) { try { properties = processJsonArray(new JSONArray(json)); } catch (JSONException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } else { throw new RuntimeException("The JSON string must start with { or ["); // i18n } return properties; }
public String getDecodedJwt() { String decodedJwt = null; try { decodedJwt = payloadToJSONObject().toString(4); } catch (JSONException e) { e.printStackTrace(); } return decodedJwt; }
@SuppressWarnings("unchecked") public JSONArray getChildrenJSONArray() { JSONArray ar = null; if (children != null) { ar = new JSONArray(); for (DynaTreeNode a : children.values()) { try { ar.put(a.toJSONObject()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return ar; } }
@SuppressWarnings("unchecked") public JSONArray getChildrenJSONArray() { JSONArray ar = null; if (children != null) { ar = new JSONArray(); for (DynaTreeNode a : children.values()) { try { ar.put(a.toJSONObject()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return ar; } }
public JSONObject getSearchQueryExample() { JSONObject node = new JSONObject(); try { JSONObject query = new JSONObject(); JSONObject queryString = new JSONObject(); queryString.put("query", "some name"); query.put("query_string", queryString); node.put("query", query); } catch (JSONException e) { e.printStackTrace(); } return node; }
@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); }
/** * Creates a JSON string representation from a given vertex. * * @param v vertex * @return JSON string representation */ @Override public String format(V v) { JSONObject json = new JSONObject(); try { json.put(JSONConstants.IDENTIFIER, v.getId()); json.put(JSONConstants.DATA, writeProperties(v)); json.put(JSONConstants.META, writeGraphElementMeta(v)); } catch (JSONException e) { e.printStackTrace(); } return json.toString(); } }
/** * Creates a JSON string representation of a given graph head object. * * @param g graph head * @return JSON string representation */ @Override public String format(G g) { JSONObject json = new JSONObject(); try { json.put(JSONConstants.IDENTIFIER, g.getId()); json.put(JSONConstants.DATA, writeProperties(g)); json.put(JSONConstants.META, writeGraphMeta(g)); } catch (JSONException ex) { ex.printStackTrace(); } return json.toString(); } }
/** * Creates a JSON string representation of a given graph head object. * * @param g graph head * @return JSON string representation */ @Override public String format(G g) { JSONObject json = new JSONObject(); try { json.put(JSONConstants.IDENTIFIER, g.getId()); json.put(JSONConstants.DATA, writeProperties(g)); json.put(JSONConstants.META, writeGraphMeta(g)); } catch (JSONException ex) { ex.printStackTrace(); } return json.toString(); } }
/** * Creates a JSON string representation from a given vertex. * * @param v vertex * @return JSON string representation */ @Override public String format(V v) { JSONObject json = new JSONObject(); try { json.put(JSONConstants.IDENTIFIER, v.getId()); json.put(JSONConstants.DATA, writeProperties(v)); json.put(JSONConstants.META, writeGraphElementMeta(v)); } catch (JSONException e) { e.printStackTrace(); } return json.toString(); } }