public void commit (long id, Serializable o) { Context ctx = (Context) o; ctx.log ("TestPausedParticipant commit has been called, id: " + id); } public void abort (long id, Serializable o) {
public void abort (long id, Serializable o) { Context ctx = (Context) o; ctx.log ("TestPausedParticipant abort has been called, id:" + id); } public void setTransactionManager (TransactionManager txnmgr) {
@Override public void failed(Exception ex) { ctx.log(ex); ctx.resume(); }
private void sendResponse (Context ctx, ChannelHandlerContext ch, FullHttpRequest request, FullHttpResponse response) { boolean keepAlive = HttpUtil.isKeepAlive(request); HttpHeaders headers = response.headers(); if (keepAlive) headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); if (contentType != null) headers.set(HttpHeaderNames.CONTENT_TYPE, contentType); headers.set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); ChannelFuture cf = ch.writeAndFlush(response); ctx.log(cf); if (!keepAlive) ch.close(); }
@Override public void completed(HttpResponse result) { ctx.log (result.getStatusLine()); int sc = result.getStatusLine().getStatusCode(); if (sc == HttpStatus.SC_CREATED || sc == HttpStatus.SC_OK) { try { ctx.put (responseName, EntityUtils.toString(result.getEntity())); } catch (IOException e) { ctx.log (e); } } ctx.put (statusName, sc); ctx.resume(); }
private void invokeNoResult (String functionName, long id, Serializable context) { try { js.invokeFunction(functionName, id, context); } catch (Exception e) { if (context instanceof Context) { Context ctx = (Context) context; ctx.log(e); } else { warn(id, e); } } } }
private int invokeWithResult (String functionName, long id, Serializable context) { try { return (Integer) js.invokeFunction(functionName, id, context); } catch (Exception e) { if (context instanceof Context) { Context ctx = (Context) context; ctx.log(e); } else { warn(id, e); } return ABORTED; } } private void invokeNoResult (String functionName, long id, Serializable context) {
public int prepare (long id, Serializable o) { Context ctx = (Context) o; try { return doPrepare (id, ctx); } catch (BLException e) { setResultCode (ctx, e.getMessage(), e.getDetail()); } catch (Throwable t) { ctx.log ("prepare exception in " + this.getClass().getName()); ctx.log (t); setResultCode (ctx, t.getMessage()); } finally { checkPoint (ctx); } return ABORTED; }
private HttpUriRequest getHttpUriRequest (Context ctx) { String url = getURL(ctx); switch (ctx.getString(methodName)) { case "POST": HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(ctx.getString(requestName), getContentType(ctx))); return post; case "PUT": HttpPut put = new HttpPut(url); put.setEntity(new StringEntity(ctx.getString(requestName), getContentType(ctx))); return put; case "GET": return new HttpGet(url); } ctx.log ("Invalid request method"); return null; }
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; FullHttpRequest request = ctx.get(REQUEST); try { String jsonStr = request.content().toString(CharsetUtil.UTF_8); ctx.log (jsonStr); @SuppressWarnings("unchecked") Map<String,String> m = (Map<String,String>) mapper.readValue(jsonStr, Map.class); SecureData sd = cs.aesEncrypt(m.get("text").getBytes()); Map<String, Object> r = new LinkedHashMap<>(); r.put ("kid", sd.getId()); r.put ("cryptogram", encoder.encodeToString(sd.getEncoded())); Response response = new Response(HttpResponseStatus.OK, r); ctx.put(RESPONSE, response); } catch (Exception e) { ctx.log(e); return FAIL; } return PREPARED | NO_JOIN | READONLY; }
public String select (long id, Serializable ser) { Context ctx = (Context) ser; String type = ctx.getString (txnNameEntry); String groups = null; if (type != null) groups = cfg.get (type, null); if (groups == null) groups = cfg.get ("unknown", ""); ctx.log ("SWITCH " + type + " (" + groups + ")"); return groups; } public int prepare (long id, Serializable o) {
public int prepareForAbort (long id, Serializable o) { // TxnSupport does not implement AbortParticipant on purpose, // but participants willing to implement it will benefit from // this method. Context ctx = (Context) o; try { return doPrepareForAbort (id, ctx); } catch (BLException e) { setResultCode (ctx, e.getMessage(), e.getDetail()); } catch (Throwable t) { ctx.log ("prepare exception in " + this.getClass().getName()); ctx.log (t); setResultCode (ctx, t.getMessage()); } finally { checkPoint (ctx); } return ABORTED; }
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; DB db = (DB) ctx.get(TxnConstants.DB); Session session = db.session(); SessionStatistics statistics = session.getStatistics(); Set<EntityKey> entityKeys = statistics.getEntityKeys(); ctx.log (String.format ("ENTITIES: (%d)", statistics.getEntityCount())); for (EntityKey ek : entityKeys) { Object obj = session.get(ek.getEntityName(), ek.getIdentifier()); LockMode lockMode = session.getCurrentLockMode(obj); ctx.log(String.format("[%s] %s %s", ek.getIdentifier(), ek.getEntityName(), lockMode)); } ctx.log ("==== COLLECTIONS ===="); Set<CollectionKey> collectionKeys = statistics.getCollectionKeys(); for (CollectionKey ck : collectionKeys) { ctx.log(String.format("[%s] %s", ck.getKey(), ck.getRole())); } ctx.log("====================="); return PREPARED | READONLY | NO_JOIN; }
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; if (cs.isLocked()) { ctx.put (RESPONSE, new Response(HttpResponseStatus.SERVICE_UNAVAILABLE, "Service unavailable - unlock required")); return FAIL; } FullHttpRequest request = ctx.get(REQUEST); try { String jsonStr = request.content().toString(CharsetUtil.UTF_8); ctx.log (jsonStr); @SuppressWarnings("unchecked") Map<String,String> m = (Map<String,String>) mapper.readValue(jsonStr, Map.class); UUID keyId = UUID.fromString(m.get("kid")); byte[] encoded = decoder.decode(m.get("cryptogram")); byte[] b = cs.aesDecrypt(jobId, keyId, encoded); Map<String, Object> r = new LinkedHashMap<>(); r.put ("text", new String(b)); Response response = new Response(HttpResponseStatus.OK, r); ctx.put(RESPONSE, response); } catch (Exception e) { ctx.log(e); return FAIL; } return PREPARED | NO_JOIN | READONLY; }
public int prepare (long id, Serializable o) { Context ctx = (Context) o; Integer ii = (Integer) ctx.get ("RETRY"); if (ii != null) { if (ii.intValue() > 0) { ctx.log ("retry " + ii.intValue()); ctx.put ("RETRY", Integer.valueOf(ii.intValue()-1)); return PREPARED | RETRY; } } return PREPARED | READONLY | NO_JOIN; } public void commit (long id, Serializable o) { }
private boolean checkMandatoryJson (Context ctx) { ctx.log ("Mandatory JSON: " + mandatoryJson); for (Map.Entry<String,JsonSchema> entry : mandatoryJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; ctx.log ("Checking " + entry.getKey() + " value=" + value); if (value != null) { try { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); } catch(Exception ex) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), ex.toString()); return false; } if (!report.isSuccess()) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); return false; } } } return true; }
@Override public String select(long id, Serializable context) { Context ctx = (Context) context; FullHttpRequest request = ctx.get(REQUEST); ctx.log ("Method: " + request.method().name()); ctx.log ("Routes: " + routes); List<Route<String>> routesByMethod = routes.get(request.method().name()); QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); if (!decoder.parameters().isEmpty()) ctx.put(QUERYPARAMS, decoder.parameters()); if (routesByMethod != null) { Optional<Route<String>> route = routesByMethod.stream().filter(r -> r.matches(decoder.uri())).findFirst(); String path = URI.create(decoder.uri()).getPath(); if (route.isPresent()) { Map m = route.get().parameters(path); if (m != null) ctx.put(PATHPARAMS, m); return route.get().apply(route.get(), path); } } return null; }
@Test public void testLog1() throws Throwable { new Context().log(""); assertTrue("Test completed without Exception", true); }
public int prepare (long id, Serializable context) { Context ctx = (Context) context; Result rc = ctx.getResult(); try { ISOMsg m = (ISOMsg) ctx.get (request); if (m == null) { ctx.getResult().fail(CMF.INVALID_TRANSACTION, Caller.info(), "'%s' not available in Context", request); return ABORTED | NO_JOIN | READONLY; } Set<String> validFields = new HashSet<>(); assertFields (ctx, m, cfg.get ("mandatory", ""), true, validFields, rc); assertFields (ctx, m, cfg.get ("optional", ""), false, validFields, rc); assertNoExtraFields (m, validFields, rc); } catch (Throwable t) { rc.fail(CMF.SYSTEM_ERROR, Caller.info(), t.getMessage()); ctx.log(t); } return (rc.hasFailures() ? ABORTED : PREPARED) | NO_JOIN | READONLY; }
@Test public void testLog() throws Throwable { Context context = new Context(); context.getPausedTransaction(); context.log("testString"); assertTrue("Test completed without Exception", true); }