Search in sources :

Example 26 with JSONObject

use of net.sf.json.JSONObject in project zaproxy by zaproxy.

the class StructuralNodeModifier method getConfig.

public String getConfig() {
    JSONObject json = new JSONObject();
    json.put(CONFIG_TYPE, this.getType().name());
    json.put(CONFIG_NAME, this.getName());
    if (getPattern() != null) {
        json.put(CONFIG_PATTERN, this.getPattern().pattern());
    }
    return json.toString();
}
Also used : JSONObject(net.sf.json.JSONObject)

Example 27 with JSONObject

use of net.sf.json.JSONObject in project opennms by OpenNMS.

the class TestServlet method doPost.

/* (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    LOG.info("JUnit Test Request: {}", req.getRequestURI());
    LOG.info("JUnit Test Content Type: {}", req.getContentType());
    String requestContent = IOUtils.toString(req.getReader());
    if (req.getRequestURI().equals("/junit/test/sample")) {
        resp.getWriter().write("OK!");
    }
    if (req.getRequestURI().equals("/junit/test/post")) {
        if (req.getContentType().startsWith("application/xml")) {
            resp.setContentType("application/xml");
            Person p = JaxbUtils.unmarshal(Person.class, requestContent);
            SampleData data = new SampleData();
            data.addParameter("firstName", p.getFirstName());
            data.addParameter("lastName", p.getLastName());
            resp.getWriter().write(JaxbUtils.marshal(data));
        } else if (req.getContentType().startsWith("application/json")) {
            resp.setContentType("application/json");
            JSONObject object = JSONObject.fromObject(requestContent);
            SampleData data = new SampleData();
            data.addParameter("firstName", object.getJSONObject("person").getString("firstName"));
            data.addParameter("lastName", object.getJSONObject("person").getString("lastName"));
            resp.getWriter().write(JaxbUtils.marshal(data));
        } else if (req.getContentType().startsWith("application/x-www-form-urlencoded")) {
            resp.setContentType("application/xml");
            StringTokenizer st = new StringTokenizer(requestContent, "&");
            SampleData data = new SampleData();
            while (st.hasMoreTokens()) {
                String[] pair = ((String) st.nextToken()).split("=");
                data.addParameter(pair[0], pair[1]);
            }
            resp.getWriter().write(JaxbUtils.marshal(data));
        } else {
            resp.setContentType("text/plain");
            resp.getWriter().write("ERROR!");
        }
    }
    if (req.getRequestURI().equals("/junit/test/post-data")) {
        Person p = JaxbUtils.unmarshal(Person.class, requestContent);
        if ("Alejandro".equals(p.getFirstName()) && "Galue".equals(p.getLastName())) {
            SampleData data = new SampleData();
            data.addParameter("contributions", "500");
            data.addParameter("applications", "2");
            data.addParameter("frameworks", "25");
            resp.setContentType("application/xml");
            resp.getWriter().write(JaxbUtils.marshal(data));
        } else {
            resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid request");
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) JSONObject(net.sf.json.JSONObject) Person(org.opennms.protocols.xml.config.Person)

Example 28 with JSONObject

use of net.sf.json.JSONObject in project fastjson by alibaba.

the class BugTest2 method test_0.

public void test_0() throws Exception {
    JSONObject obj = new JSONObject();
    obj.put("a", new A());
    String text = obj.toString();
    System.out.println(text);
}
Also used : JSONObject(net.sf.json.JSONObject)

Example 29 with JSONObject

use of net.sf.json.JSONObject in project fastjson by alibaba.

the class JSONLibXmlTest method test_xml.

public void test_xml() throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    JSONObject json = new JSONObject();
    json.put("id", 123);
    json.put("name", "jobs");
    json.put("flag", true);
    JSONArray items = new JSONArray();
    items.add("x");
    items.add(234);
    items.add(false);
    json.put("items", items);
    String text = xmlSerializer.write(json);
    System.out.println(text);
}
Also used : XMLSerializer(net.sf.json.xml.XMLSerializer) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray)

Example 30 with JSONObject

use of net.sf.json.JSONObject in project hudson-2.x by hudson.

the class CascadingTriggersTest method testSetChildrenTriggerEmptyJSON.

/**
     * Tests if trigger property value is null if there is no json data.
     *
     * @throws Exception if any.
     */
@Test
public void testSetChildrenTriggerEmptyJSON() throws Exception {
    CascadingUtil.setChildrenTrigger(p1, descriptor, propertyKey, req, new JSONObject());
    assertNull(CascadingUtil.getTriggerProjectProperty(p1, propertyKey).getValue());
    verifyAll();
}
Also used : JSONObject(net.sf.json.JSONObject) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11