/** * Get a clone of a SeqContinuationState * * @param oriSeqContinuationState original SeqContinuationState * @return cloned SeqContinuationState */ public static SeqContinuationState getClonedSeqContinuationState( SeqContinuationState oriSeqContinuationState) { SeqContinuationState clone = new SeqContinuationState( oriSeqContinuationState.getSeqType(), oriSeqContinuationState.getSeqName()); clone.setPosition(oriSeqContinuationState.getPosition()); if (oriSeqContinuationState.hasChild()) { clone.setChildContState( getClonedReliantContState(oriSeqContinuationState.getChildContState())); } return clone; }
/** * Retrieve the sequence from Continuation state which message should be injected to. * * @param seqContState SeqContinuationState which contain the sequence information * @param synCtx message context * @return sequence which message should be injected to */ public static SequenceMediator retrieveSequence( MessageContext synCtx, SeqContinuationState seqContState) { SequenceMediator sequence = null; switch (seqContState.getSeqType()) { case NAMED: { sequence = (SequenceMediator) synCtx.getSequence(seqContState.getSeqName()); if (sequence == null) { // This can happen only if someone delete the sequence while running handleException("Sequence : " + seqContState.getSeqName() + " not found"); } break; } case PROXY_INSEQ: { String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE); ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName); if (proxyService != null) { sequence = proxyService.getTargetInLineInSequence(); } else { handleException("Proxy Service :" + proxyName + " not found"); } break; } case API_INSEQ: { String apiName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_REST_API); String resourceName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_RESOURCE); API api = synCtx.getEnvironment().getSynapseConfiguration().getAPI(apiName); if (api != null) { Resource resource = api.getResource(resourceName); if (resource != null) { sequence = resource.getInSequence(); } else { handleException("Resource : " + resourceName + " not found"); } } else { handleException("REST API : " + apiName + " not found"); } break; } case PROXY_OUTSEQ: { String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE); ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName); if (proxyService != null) { sequence = proxyService.getTargetInLineOutSequence(); } else { handleException("Proxy Service :" + proxyName + " not found"); } break; } case API_OUTSEQ: { String apiName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_REST_API); String resourceName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_RESOURCE); API api = synCtx.getEnvironment().getSynapseConfiguration().getAPI(apiName); if (api != null) { Resource resource = api.getResource(resourceName); if (resource != null) { sequence = resource.getOutSequence(); } else { handleException("Resource : " + resourceName + " not found"); } } else { handleException("REST API : " + apiName + " not found"); } break; } case PROXY_FAULTSEQ: { String proxyName = (String) synCtx.getProperty(SynapseConstants.PROXY_SERVICE); ProxyService proxyService = synCtx.getConfiguration().getProxyService(proxyName); if (proxyService != null) { sequence = proxyService.getTargetInLineFaultSequence(); } else { handleException("Proxy Service :" + proxyName + " not found"); } break; } case API_FAULTSEQ: { String apiName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_REST_API); String resourceName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_RESOURCE); API api = synCtx.getEnvironment().getSynapseConfiguration().getAPI(apiName); if (api != null) { Resource resource = api.getResource(resourceName); if (resource != null) { sequence = resource.getFaultSequence(); } else { handleException("Resource : " + resourceName + " not found"); } } else { handleException("REST API : " + apiName + " not found"); } break; } } return sequence; }