Example usage for org.json.simple JSONObject toJSONString

List of usage examples for org.json.simple JSONObject toJSONString

Introduction

In this page you can find the example usage for org.json.simple JSONObject toJSONString.

Prototype

public String toJSONString() 

Source Link

Usage

From source file:org.kitodo.data.index.elasticsearch.type.UserGroupType.java

@SuppressWarnings("unchecked")
@Override//from  www  . java 2s. com
public HttpEntity createDocument(UserGroup userGroup) {

    LinkedHashMap<String, String> orderedUserGroupMap = new LinkedHashMap<>();
    orderedUserGroupMap.put("title", userGroup.getTitle());
    orderedUserGroupMap.put("permission", userGroup.getPermission().toString());

    JSONArray users = new JSONArray();
    List<User> userGroupUsers = userGroup.getUsers();
    for (User user : userGroupUsers) {
        JSONObject userObject = new JSONObject();
        userObject.put("id", user.getId().toString());
        users.add(userObject);
    }

    JSONObject userGroupObject = new JSONObject(orderedUserGroupMap);
    userGroupObject.put("users", users);

    return new NStringEntity(userGroupObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:com.appzone.sim.services.handlers.SendMoServiceHandler.java

@Override
protected String doProcess(HttpServletRequest request) {

    String address = request.getParameter(KEY_ADDRESS);
    String message = request.getParameter(KEY_MESSAGE);
    String correlator = "" + ((int) (Math.random() * 10000000000000L));

    try {//ww  w. ja va  2 s.  c  om
        String queryString = String.format("version=1.0&address=%s&message=%s&correlator=%s", address,
                URLEncoder.encode(message, "UTF-8"), URLEncoder.encode(correlator, "UTF-8"));

        logger.info("sending MO request as: {}", queryString);
        String response = http.excutePost(application.getUrl(), queryString);
        logger.debug("getting response as: {}", response);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_RESULT, response);
        return json.toJSONString();

    } catch (Exception e) {

        logger.error("Error while sending http request", e);

        JSONObject json = new JSONObject();
        json.put(ServiceHandler.JSON_KEY_ERROR, e.getMessage());
        return json.toJSONString();
    }

}

From source file:i5.las2peer.services.two.Two.java

/**
 * //from ww w.  j ava2s .  c o  m
 * test
 * 
 *
 * 
 * @return HttpResponse  
 * 
 */
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "testJson") })
@ApiOperation(value = "test", notes = " ")
public HttpResponse test() {

    // testJson
    boolean testJson_condition = true;
    if (testJson_condition) {
        JSONObject testResult = new JSONObject();
        HttpResponse testJson = new HttpResponse(testResult.toJSONString(), HttpURLConnection.HTTP_OK);
        return testJson;
    }
    return null;
}

From source file:io.hawt.testing.env.builtin.NotFound.java

@Override
public void handle(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    resp.setContentType("application/json");
    resp.setCharacterEncoding("UTF-8");
    JSONObject r = new JSONObject();
    r.put("error", HttpServletResponse.SC_NOT_FOUND);
    r.put("message", "Environment not found");
    resp.getWriter().println(r.toJSONString());
    resp.getWriter().close();//from  w  w  w .  j a v a  2s.  co m
}

From source file:io.personium.test.jersey.box.odatacol.schema.property.PropertyUtils.java

/**
 * PropertyEntityType??NP??./*from   w w w.j  a  v a2s.co m*/
 * @param token 
 * @param cell ??
 * @param box ??
 * @param collection ??
 * @param entityTypeName EntityType??
 * @param propertyName Property??
 * @param type Property?Type
 * @param nullable Property?Nullable
 * @param defaultValue Property?DefaultValue
 * @param collectionKind Property?collectionKind
 * @param isKey Property?isKey
 * @param uniqueKey Property?UniqueKey
 * @param code ??
 * @return ?
 */
@SuppressWarnings("unchecked")
public static TResponse createViaPropertyNP(String token, String cell, String box, String collection,
        String entityTypeName, String propertyName, String type, Boolean nullable, String defaultValue,
        String collectionKind, Boolean isKey, String uniqueKey, int code) {

    // ???
    JSONObject body = new JSONObject();
    body.put("Name", propertyName);
    body.put("_EntityType.Name", entityTypeName);
    body.put("Type", type);
    body.put("Nullable", nullable);
    body.put("DefaultValue", defaultValue);
    body.put("CollectionKind", collectionKind);
    body.put("IsKey", isKey);
    body.put("UniqueKey", uniqueKey);

    TResponse res = Http.request("box/odatacol/schema/createViaNP.txt").with("cell", cell).with("box", box)
            .with("collection", collection).with("accept", MediaType.APPLICATION_JSON)
            .with("contentType", MediaType.APPLICATION_JSON).with("token", PersoniumUnitConfig.getMasterToken())
            .with("entityType", "EntityType").with("id", entityTypeName).with("navPropName", "_Property")
            .with("body", body.toJSONString()).returns().statusCode(code).debug();
    return res;
}

From source file:com.demandware.vulnapp.challenge.impl.CookieChallenge.java

@SuppressWarnings("unchecked")
private Cookie generateCookie() {
    JSONObject o = new JSONObject();
    o.put(ACCESS_KEY, "false");
    String value = new String(Base64.encodeBase64(o.toJSONString().getBytes()));
    Cookie c = new Cookie(COOKIE_NAME, value);
    c.setMaxAge(MAX_AGE);//from  w  w  w  .  j  ava  2 s .  c  om
    c.setPath("/");
    return c;
}

From source file:hoot.services.controllers.info.ErrorLogResource.java

@GET
@Path("/debuglog")
@Produces(MediaType.TEXT_PLAIN)/*from   w  w w.  ja va  2s .c o  m*/
public Response getDebugLog() {
    String logStr = null;

    try {
        ErrorLog logging = new ErrorLog();
        // 50k Length
        logStr = logging.getErrorlog(50000);
    } catch (Exception ex) {
        ResourceErrorHandler.handleError("Error getting error log: " + ex.toString(),
                Status.INTERNAL_SERVER_ERROR, log);
    }
    JSONObject res = new JSONObject();
    res.put("log", logStr);
    return Response.ok(res.toJSONString(), MediaType.APPLICATION_JSON).build();
}

From source file:i5.las2peer.services.test.Test.java

/**
 * //  w  w  w  .j a  v a2  s.c  om
 * test
 * 
 *
 * 
 * @return HttpResponse  
 * 
 */
@GET
@Path("/est")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "test") })
@ApiOperation(value = "test", notes = " ")
public HttpResponse test() {
    Serializable test = null;

    try {
        Object test = this.invokeServiceMethod("test", "test", test);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // test
    boolean test_condition = true;
    if (test_condition) {
        JSONObject etst2 = new JSONObject();
        HttpResponse test = new HttpResponse(etst2.toJSONString(), HttpURLConnection.HTTP_OK);
        return test;
    }
    return null;
}

From source file:org.kitodo.data.elasticsearch.index.type.DocketType.java

@SuppressWarnings("unchecked")
@Override//from  w  w w  .j a v a2s.c o m
public HttpEntity createDocument(Docket docket) {

    JSONObject docketObject = new JSONObject();
    docketObject.put("title", docket.getTitle());
    docketObject.put("file", docket.getFile());

    return new NStringEntity(docketObject.toJSONString(), ContentType.APPLICATION_JSON);
}

From source file:hudson.plugins.memegen.MemegeneratorResponseException.java

MemegeneratorResponseException(JSONObject obj) {
    super(obj.get("errorMessage") + ", full response: " + obj.toJSONString());
}