use of org.jose4j.json.internal.json_simple.JSONObject in project service-proxy by membrane.
the class GenericJsonParserTest method testTextContent.
@Test
public void testTextContent() {
String want = "println(\"Hello, World!\")";
JSONObject spec = new JSONObject(new HashMap<String, Object>() {
{
put("src", want);
}
});
GroovyInterceptor gi = GenericJsonParser.parse(GroovyInterceptor.class, spec);
assertEquals(want, gi.getSrc());
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class GetAllTodosIT method testGetAllTodos.
@Test
public void testGetAllTodos() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "gettodos");
map.put("version", "0.1.0");
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class DeleteTodoIT method testDeleteTodo.
@Test
public void testDeleteTodo() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "delete");
map.put("version", "0.1.0");
Map<String, Object> data = new HashMap<>();
data.put("id", "101010");
map.put("data", data);
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project light-example-4j by networknt.
the class UpdateTodoIT method testUpdateTodo.
@Test
public void testUpdateTodo() throws ClientException, ApiException {
final Http2Client client = Http2Client.getInstance();
final CountDownLatch latch = new CountDownLatch(1);
final ClientConnection connection;
try {
connection = client.connect(new URI(url), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, enableHttp2 ? OptionMap.create(UndertowOptions.ENABLE_HTTP2, true) : OptionMap.EMPTY).get();
} catch (Exception e) {
throw new ClientException(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "lightapi.net");
map.put("service", "todo");
map.put("action", "update");
map.put("version", "0.1.0");
Map<String, Object> data = new HashMap<>();
data.put("id", "101010");
data.put("title", "create todo from hybrid service unit test");
data.put("completed", false);
data.put("order", 1);
map.put("data", data);
JSONObject json = new JSONObject();
json.putAll(map);
System.out.printf("JSON: %s", json.toString());
final AtomicReference<ClientResponse> reference = new AtomicReference<>();
try {
ClientRequest request = new ClientRequest().setPath("/api/json").setMethod(Methods.POST);
request.getRequestHeaders().put(Headers.CONTENT_TYPE, "application/json");
request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
connection.sendRequest(request, client.createClientCallback(reference, latch, json.toString()));
latch.await();
} catch (Exception e) {
logger.error("Exception: ", e);
throw new ClientException(e);
} finally {
IoUtils.safeClose(connection);
}
int statusCode = reference.get().getResponseCode();
String body = reference.get().getAttachment(Http2Client.RESPONSE_BODY);
Assert.assertEquals(200, statusCode);
Assert.assertNotNull(body);
}
use of org.jose4j.json.internal.json_simple.JSONObject in project open-ecard by ecsec.
the class VersionUpdateLoader method loadVersionUpdateList.
public VersionUpdateList loadVersionUpdateList() throws IllegalArgumentException {
try {
// load proxy if one is available
// make sure it is initialized
ProxySettings.getDefault();
List<Proxy> proxies = ProxySelector.getDefault().select(updateUrl.toURI());
Proxy p = Proxy.NO_PROXY;
for (Proxy next : proxies) {
if (next.type() != Proxy.Type.DIRECT) {
LOG.debug("Found a proxy for the update connection.");
p = next;
break;
}
}
LOG.info("Trying to load version list.");
URLConnection con = updateUrl.openConnection(p);
con.connect();
InputStream in = con.getInputStream();
Reader r = new InputStreamReader(in, StandardCharsets.UTF_8);
JSONObject rootObj = (JSONObject) new JSONParser().parse(r);
// get package specific download page
String downloadPageString = (String) rootObj.get(pkgType + "_download_page");
// access package specific list
JSONArray updatesRaw = (JSONArray) rootObj.get(pkgType);
ArrayList<VersionUpdate> updates = new ArrayList<>();
for (Object ur : updatesRaw) {
try {
VersionUpdate next = VersionUpdate.fromJson((JSONObject) ur);
updates.add(next);
} catch (InvalidUpdateDefinition ex) {
LOG.warn("Invalid version info contained in update list.", ex);
throw new IllegalArgumentException("Invalid version info contained in update list.", ex);
}
}
// make sure the versions are in the correct order
Collections.sort(updates);
VersionUpdateList list = new VersionUpdateList(updates, new URL(downloadPageString));
LOG.info("Successfully retrieved version update list.");
return list;
} catch (IOException ex) {
LOG.error("Failed to retrieve update list from server.", ex);
throw new IllegalArgumentException("Failed to retrieve update list from server.", ex);
} catch (NullPointerException ex) {
LOG.warn("Package type {} not supported in update list.", pkgType);
throw new IllegalArgumentException("Package type " + pkgType + " not supported in update list.", ex);
} catch (URISyntaxException ex) {
String msg = "Failed to convert Update URL to a URI.";
LOG.error(msg, ex);
throw new IllegalArgumentException(msg, ex);
} catch (ParseException ex) {
String msg = "Failed to deserialize JSON data.";
LOG.error(msg, ex);
throw new IllegalArgumentException(msg, ex);
}
}
Aggregations