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();
}
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");
}
}
}
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);
}
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);
}
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();
}
Aggregations