use of com.fasterxml.jackson.databind.JsonMappingException in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method testSerializeMultipleObjects.
@Test
public void testSerializeMultipleObjects() throws IOException {
final Collection<Comment> allComments = new ArrayList<Comment>();
Comment aComment = new Comment();
aComment.setContent("<b>There it is</b>");
allComments.add(aComment);
aComment = new Comment();
aComment.setContent("<p>I agree with the author</p>");
allComments.add(aComment);
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
FilterProvider fp = new SimpleFilterProvider().addFilter(JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, allComments);
}
});
assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
use of com.fasterxml.jackson.databind.JsonMappingException in project alfresco-remote-api by Alfresco.
the class SerializeTests method writeResponse.
private String writeResponse(final Object respons) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
objectMapper.writeValue(generator, respons);
}
});
System.out.println(out.toString());
return out.toString();
}
use of com.fasterxml.jackson.databind.JsonMappingException in project alfresco-remote-api by Alfresco.
the class WebScriptOptionsMetaData method writeMetaData.
@Override
public void writeMetaData(OutputStream out, ResourceWithMetadata resource, Map<String, ResourceWithMetadata> allApiResources) throws IOException {
final Object result = processResult(resource, allApiResources);
assistant.getJsonHelper().withWriter(out, new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
objectMapper.writeValue(generator, result);
}
});
}
use of com.fasterxml.jackson.databind.JsonMappingException in project qpid-broker-j by apache.
the class CompressedResponsesTest method doCompressionTest.
private void doCompressionTest(final boolean allowCompression, final boolean acceptCompressed) throws Exception {
final boolean expectCompression = allowCompression && acceptCompressed;
getHelper().submitRequest("plugin/httpManagement", "POST", Collections.singletonMap("compressResponses", expectCompression), SC_OK);
HttpURLConnection conn = getHelper().openManagementConnection("/service/metadata", "GET");
try {
if (acceptCompressed) {
conn.setRequestProperty("Accept-Encoding", "gzip");
}
conn.connect();
String contentEncoding = conn.getHeaderField("Content-Encoding");
if (expectCompression) {
assertEquals("gzip", contentEncoding);
} else {
if (contentEncoding != null) {
assertEquals("identity", contentEncoding);
}
}
byte[] bytes;
try (ByteArrayOutputStream contentBuffer = new ByteArrayOutputStream()) {
ByteStreams.copy(conn.getInputStream(), contentBuffer);
bytes = contentBuffer.toByteArray();
}
try (InputStream jsonStream = expectCompression ? new GZIPInputStream(new ByteArrayInputStream(bytes)) : new ByteArrayInputStream(bytes)) {
ObjectMapper mapper = new ObjectMapper();
try {
mapper.readValue(jsonStream, LinkedHashMap.class);
} catch (JsonParseException | JsonMappingException e) {
fail("Message was not in correct format");
}
}
} finally {
conn.disconnect();
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project bamboobsc by billchen198318.
the class CxfServerBean method shutdownOrReloadCallOneSystem.
@SuppressWarnings("unchecked")
public static Map<String, Object> shutdownOrReloadCallOneSystem(HttpServletRequest request, String system, String type) throws ServiceException, Exception {
if (StringUtils.isBlank(system) || StringUtils.isBlank(type)) {
throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
}
String urlStr = ApplicationSiteUtils.getBasePath(system, request) + "config-services?type=" + type + "&value=" + createParamValue();
logger.info("shutdownOrReloadCallSystem , url=" + urlStr);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(urlStr);
client.executeMethod(method);
byte[] responseBody = method.getResponseBody();
if (null == responseBody) {
throw new Exception("no response!");
}
String content = new String(responseBody, Constants.BASE_ENCODING);
logger.info("shutdownOrReloadCallSystem , system=" + system + " , type=" + type + " , response=" + content);
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> dataMap = null;
try {
dataMap = (Map<String, Object>) mapper.readValue(content, HashMap.class);
} catch (JsonParseException e) {
logger.error(e.getMessage().toString());
} catch (JsonMappingException e) {
logger.error(e.getMessage().toString());
}
if (null == dataMap) {
throw new Exception("response content error!");
}
return dataMap;
}
Aggregations