use of jp.ossc.nimbus.service.context.Context in project nimbus by nimbus-org.
the class BeanFlowInvokerAccessImpl2 method invokeFlowInternal.
protected Object invokeFlowInternal(Object input, BeanFlowMonitor monitor, boolean isTranControl) throws Exception {
coverage.cover();
if (factoryCallBack.isManageExecBeanFlow()) {
factoryCallBack.addExcecFlow(monitor);
}
FlowContext flowContext = null;
Journal journal = getJournal(null);
try {
if (semaphore != null) {
if (!semaphore.getResource(timeout, maxWaitCount, forceFreeTimeout)) {
throw new UnavailableFlowException(flowName);
}
}
if (journal != null) {
journal.startJournal(JOURNAL_KEY_FLOW, factoryCallBack.getEditorFinder());
final Context threadContext = factoryCallBack.getThreadContext();
if (threadContext != null) {
final String requestId = (String) threadContext.get(ThreadContextKey.REQUEST_ID);
if (requestId != null) {
journal.setRequestId(requestId);
}
}
journal.addInfo(JOURNAL_KEY_FLOW_NAME, flowName);
journal.addInfo(JOURNAL_KEY_FLOW_INPUT, input);
}
ResourceManager rm = null;
if (resources != null) {
rm = factoryCallBack.createResourceManager();
for (Iterator ite = resources.keySet().iterator(); ite.hasNext(); ) {
String name = (String) ite.next();
ResourceInfo resourceInfo = (ResourceInfo) resources.get(name);
rm.addResource(name, resourceInfo.key, resourceInfo.serviceName, isTranControl ? resourceInfo.isTranControl : false, resourceInfo.isTranClose);
if (journal != null) {
journal.addInfo(JOURNAL_KEY_RESOURCE, name);
}
}
}
flowContext = new FlowContext(input, rm, monitor, stepNames);
if (inputDefs != null) {
Iterator entries = inputDefs.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String name = (String) entry.getKey();
Property property = (Property) entry.getValue();
Object inputDef = null;
if (property == null) {
inputDef = flowContext.input;
} else {
inputDef = property.getProperty(flowContext.input);
}
if (journal != null) {
journal.addInfo(JOURNAL_KEY_INPUT_DEF + name, inputDef);
}
flowContext.setInputDef(name, inputDef);
}
}
Throwable throwable = null;
try {
if (jobSteps != null) {
for (int i = 0, max = jobSteps.size(); i < max; i++) {
Step jobStep = (Step) jobSteps.get(i);
StepContext stepContext = jobStep.invokeStep(flowContext);
if (stepContext == null) {
break;
}
}
}
} catch (UnavailableFlowException e) {
throwable = e;
throw e;
} catch (BeanFlowMonitorStopException e) {
throwable = e;
throw e;
} catch (BeanFlowAsynchTimeoutException e) {
throwable = e;
throw e;
} catch (Exception e) {
Throwable th = e;
if (e instanceof InvocationTargetException) {
th = ((InvocationTargetException) e).getTargetException();
} else if (e instanceof BeanControlUncheckedException) {
th = ((BeanControlUncheckedException) e).getCause();
}
boolean isCatch = false;
if (catchSteps != null && th instanceof Exception) {
try {
for (int i = 0, imax = catchSteps.size(); i < imax; i++) {
final CatchMetaData catchStep = (CatchMetaData) catchSteps.get(i);
if (catchStep.isMatch(flowContext, (Exception) th)) {
catchStep.invokeStep(flowContext);
isCatch = true;
break;
}
}
} catch (Throwable th2) {
throwable = th2;
throwException(th2);
}
}
if (!isCatch) {
throwable = th;
throwException(th);
}
} catch (Error e) {
throwable = e;
throw e;
} finally {
if (finallyStep != null) {
try {
finallyStep.invokeStep(flowContext);
} catch (Throwable th) {
throwable = th;
endJob(th, rm, monitor, flowName);
throwException(th);
}
}
endJob(throwable, rm, monitor, flowName);
}
} catch (Throwable th) {
if (journal != null) {
Throwable th2 = th;
if (th2 instanceof InvocationTargetException) {
th2 = ((InvocationTargetException) th2).getTargetException();
} else if (th2 instanceof BeanControlUncheckedException) {
th2 = ((BeanControlUncheckedException) th2).getCause();
}
journal.addInfo(JOURNAL_KEY_FLOW_EXCEPTION, th2);
}
throwException(th);
} finally {
if (journal != null) {
journal.addInfo(JOURNAL_KEY_FLOW_OUTPUT, flowContext == null ? null : (flowContext.current == null ? null : flowContext.current.result));
journal.endJournal();
}
if (semaphore != null) {
semaphore.freeResource();
}
}
return flowContext.current == null ? null : flowContext.current.result;
}
use of jp.ossc.nimbus.service.context.Context in project nimbus by nimbus-org.
the class ThreadContextImportInterceptorService method invokeInternal.
protected Object invokeInternal(Object inputObj, jp.ossc.nimbus.service.aspect.interfaces.InterceptorChain interceptChain, jp.ossc.nimbus.service.aop.InterceptorChain chain) throws Throwable {
Object input = inputObj;
if (chain != null) {
input = ((MethodInvocationContext) input).getParameters()[0];
}
FacadeValue in = (FacadeValue) input;
if (threadContextServiceName != null) {
final Context context = (Context) ServiceManagerFactory.getServiceObject(threadContextServiceName);
if (headerKeys == null) {
final Iterator keys = in.getHederKeys().iterator();
while (keys.hasNext()) {
final String key = (String) keys.next();
context.put(key, in.getHeader(key));
}
} else {
for (int i = 0; i < headerKeys.length; i++) {
final String key = headerKeys[i];
context.put(key, in.getHeader(key));
}
}
}
if (interceptChain != null) {
return interceptChain.invokeChain(inputObj);
} else {
return chain.invokeNext((InvocationContext) inputObj);
}
}
use of jp.ossc.nimbus.service.context.Context in project nimbus by nimbus-org.
the class ContextSequenceVariable method getCurrent.
/**
* 現在値を取得する。<p>
* {@link Context}サービスから値を取得して現在値とする。
*
* @return 現在値
*/
public String getCurrent() {
if (contextServiceName == null) {
return EMPTY;
}
final Context context = (Context) ServiceManagerFactory.getServiceObject(contextServiceName);
final Object val = context.get(key);
return val == null ? EMPTY : val.toString();
}
use of jp.ossc.nimbus.service.context.Context in project nimbus by nimbus-org.
the class BeanFlowServlet method doService.
/**
* 検証BeanFlow及びアクションBeanFlowの呼び出しを制御する。<p>
*
* @param req HTTPリクエスト
* @param resp HTTPレスポンス
* @exception ServletException
* @exception IOException
*/
protected void doService(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String flowName = processSelectBeanFlow(req, resp);
if (flowName == null || flowName.length() == 0) {
handleNotFound(req, resp, flowName);
return;
}
final BeanFlowInvokerFactory beanFlowInvokerFactory = (BeanFlowInvokerFactory) ServiceManagerFactory.getServiceObject(beanFlowInvokerFactoryServiceName);
if (!beanFlowInvokerFactory.containsFlow(flowName)) {
handleNotFound(req, resp, flowName);
return;
}
Journal journal = null;
EditorFinder editorFinder = null;
EditorFinder validateEditorFinder = null;
EditorFinder actionEditorFinder = null;
String requestId = null;
if (journalServiceName != null) {
journal = (Journal) ServiceManagerFactory.getServiceObject(journalServiceName);
if (editorFinderServiceName != null) {
editorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(editorFinderServiceName);
}
if (validateEditorFinderServiceName != null) {
validateEditorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(validateEditorFinderServiceName);
}
if (actionEditorFinderServiceName != null) {
actionEditorFinder = (EditorFinder) ServiceManagerFactory.getServiceObject(actionEditorFinderServiceName);
}
if (contextServiceName != null) {
Context context = (Context) ServiceManagerFactory.getServiceObject(contextServiceName);
requestId = (String) context.get(ThreadContextKey.REQUEST_ID);
}
}
try {
if (journal != null) {
journal.startJournal(JOURNAL_KEY_PROCESS, editorFinder);
if (requestId != null) {
journal.setRequestId(requestId);
}
}
final BeanFlowServletContext context = new BeanFlowServletContext(req, resp, req.getAttribute(inputAttributeName));
if (validateFlowPrefix != null && isValidate) {
final String validateFlowName = validateFlowPrefix + flowName;
if (beanFlowInvokerFactory.containsFlow(validateFlowName)) {
final BeanFlowInvoker validateFlow = beanFlowInvokerFactory.createFlow(validateFlowName);
try {
if (journal != null) {
journal.addStartStep(JOURNAL_KEY_VALIDATE, validateEditorFinder);
journal.addInfo(JOURNAL_KEY_FLOW_NAME, validateFlowName);
}
if (!processValidate(req, resp, context, validateFlow, journal)) {
if (!handleValidateError(req, resp, context, journal)) {
return;
}
}
} finally {
if (journal != null) {
journal.addEndStep();
}
}
}
}
final BeanFlowInvoker flow = beanFlowInvokerFactory.createFlow(flowName);
try {
if (journal != null) {
journal.addStartStep(JOURNAL_KEY_ACTION, actionEditorFinder);
journal.addInfo(JOURNAL_KEY_FLOW_NAME, flowName);
}
processAction(req, resp, context, flow, journal);
} finally {
if (journal != null) {
journal.addEndStep();
}
}
} finally {
if (journal != null) {
journal.endJournal();
}
}
}
Aggregations