Ejemplo n.º 1
0
 @Override
 public PluginTransportItem encode(CallingContext ctx, String uri) {
   try {
     Object o = getReflectionObject(ctx, uri);
     MessageDigest md = MessageDigest.getInstance("MD5");
     PluginTransportItem item = new PluginTransportItem();
     item.setContent(JacksonUtil.bytesJsonFromObject(o));
     md.update(item.getContent());
     item.setHash(Hex.encodeHexString(md.digest()));
     item.setUri(uri);
     return item;
   } catch (NoSuchAlgorithmException e) {
     throw RaptureExceptionFactory.create(
         HttpURLConnection.HTTP_INTERNAL_ERROR, "Error encoding item", e);
   }
 }
Ejemplo n.º 2
0
 private PluginTransportItem encodeRaw(CallingContext context, RaptureURI uri) {
   String uriString = uri.toString();
   PluginTransportItem result = new PluginTransportItem();
   RaptureScript script = Kernel.getScript().getScript(context, uriString);
   if (script == null) return null;
   String text = script.getScript();
   result.setContent(text.getBytes(Charsets.UTF_8));
   result.setUri(uriString);
   try {
     MessageDigest md = MessageDigest.getInstance("MD5");
     md.update(text.getBytes("UTF-8"));
     result.setHash(Hex.encodeHexString(md.digest()));
   } catch (NoSuchAlgorithmException e) {
     throw RaptureExceptionFactory.create("JRE does not support MD5");
   } catch (UnsupportedEncodingException e) {
     throw RaptureExceptionFactory.create("JRE does not support UTF-8");
   }
   return result;
 }