use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class BeanFlowServlet method getServiceName.
protected ServiceName getServiceName(String paramName) {
final ServletConfig config = getServletConfig();
final String serviceNameStr = config.getInitParameter(paramName);
if (serviceNameStr == null) {
return null;
}
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setAsText(serviceNameStr);
return (ServiceName) editor.getValue();
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class TestRunner method main.
public static void main(String[] args) {
if (args.length != 0 && args[0].equals("-help")) {
usage();
return;
}
String runnerDefPath = null;
final List servicePaths = new ArrayList();
boolean validate = false;
boolean verbose = false;
String userId = null;
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-verbose")) {
verbose = true;
} else if (args[i].equals("-validate")) {
validate = true;
} else if (args[i].equals("-userId")) {
userId = args[++i];
} else if (runnerDefPath == null) {
runnerDefPath = args[i];
} else {
servicePaths.add(args[i]);
}
}
if (runnerDefPath == null || servicePaths.size() == 0) {
usage();
return;
}
if (userId == null) {
userId = System.getProperty("user.name");
}
try {
for (int i = 0, max = servicePaths.size(); i < max; i++) {
if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
System.exit(-1);
}
}
if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
System.exit(-1);
}
TestController testController = null;
List testReporterList = null;
String phase = null;
Map scenarioGroupMap = new HashMap();
boolean isTest = true;
try {
final InputSource inputSource = new InputSource(new FileInputStream(runnerDefPath));
final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(validate);
final DocumentBuilder builder = domFactory.newDocumentBuilder();
final NimbusEntityResolver resolver = new NimbusEntityResolver();
builder.setEntityResolver(resolver);
final MyErrorHandler handler = new MyErrorHandler();
builder.setErrorHandler(handler);
final Document doc = builder.parse(inputSource);
if (handler.isError()) {
ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath);
System.exit(-1);
}
final Element root = doc.getDocumentElement();
isTest = MetaData.getOptionalBooleanAttribute(root, "test", true);
final Element controllerElement = MetaData.getOptionalChild(root, "controller");
final String controllerServiceNameStr = controllerElement == null ? "Nimbus#TestController" : MetaData.getElementContent(controllerElement, "Nimbus#TestController");
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setAsText(controllerServiceNameStr);
final ServiceName controllerServiceName = (ServiceName) editor.getValue();
testController = (TestController) ServiceManagerFactory.getServiceObject(controllerServiceName);
final Iterator reporterElements = MetaData.getChildrenByTagName(root, "reporter");
testReporterList = new ArrayList();
if (reporterElements.hasNext()) {
while (reporterElements.hasNext()) {
final Element reporterElement = (Element) reporterElements.next();
final String reporterServiceNameStr = MetaData.getElementContent(reporterElement);
editor.setAsText(reporterServiceNameStr);
final ServiceName reporterServiceName = (ServiceName) editor.getValue();
TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
testReporterList.add(testReporter);
}
} else {
editor.setAsText("Nimbus#TestReporter");
final ServiceName reporterServiceName = (ServiceName) editor.getValue();
TestReporter testReporter = (TestReporter) ServiceManagerFactory.getServiceObject(reporterServiceName);
testReporterList.add(testReporter);
}
final Element phaseElement = MetaData.getOptionalChild(root, "phase");
if (phaseElement != null) {
phase = MetaData.getElementContent(phaseElement, null);
}
testController.setTestPhase(phase);
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00005", phase);
}
final Iterator includeElements = MetaData.getChildrenByTagName(root, "include");
if (includeElements.hasNext()) {
while (includeElements.hasNext()) {
final Element includeElement = (Element) includeElements.next();
final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(includeElement, "scenarioGroup");
while (scenarioGroupElements.hasNext()) {
final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
if (scenarioMap == null) {
scenarioMap = new HashMap();
scenarioGroupMap.put(scenarioGroupId, scenarioMap);
}
final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
if (scenarioElements.hasNext()) {
while (scenarioElements.hasNext()) {
final Element scenarioElement = (Element) scenarioElements.next();
final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
Set testCaseSet = (Set) scenarioMap.get(scenarioId);
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarioId, testCaseSet);
}
TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarioId);
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
} else {
TestScenario[] scenarios = testController.getScenarios(scenarioGroupId);
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
}
TestCase[] testCases = testController.getTestCases(scenarioGroupId, scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
}
}
}
} else {
TestScenarioGroup[] groups = testController.getScenarioGroups();
for (int i = 0; i < groups.length; i++) {
Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
if (scenarioMap == null) {
scenarioMap = new HashMap();
scenarioGroupMap.put(groups[i].getScenarioGroupId(), scenarioMap);
}
TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
testCaseSet = new HashSet();
scenarioMap.put(scenarios[j].getScenarioId(), testCaseSet);
}
TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
testCaseSet.add(testCases[k].getTestCaseId());
}
}
}
}
final Iterator excludeElements = MetaData.getChildrenByTagName(root, "exclude");
while (excludeElements.hasNext()) {
final Element excludeElement = (Element) excludeElements.next();
final Iterator scenarioGroupElements = MetaData.getChildrenByTagName(excludeElement, "scenarioGroup");
while (scenarioGroupElements.hasNext()) {
final Element scenarioGroupElement = (Element) scenarioGroupElements.next();
final String scenarioGroupId = MetaData.getUniqueAttribute(scenarioGroupElement, "id");
Map scenarioMap = (Map) scenarioGroupMap.get(scenarioGroupId);
if (scenarioMap == null) {
continue;
}
final Iterator scenarioElements = MetaData.getChildrenByTagName(scenarioGroupElement, "scenario");
if (scenarioElements.hasNext()) {
while (scenarioElements.hasNext()) {
final Element scenarioElement = (Element) scenarioElements.next();
final String scenarioId = MetaData.getUniqueAttribute(scenarioElement, "id");
scenarioMap.remove(scenarioId);
}
} else {
scenarioGroupMap.remove(scenarioGroupId);
}
}
}
} catch (Exception e) {
ServiceManagerFactory.getLogger().write("TR___00004", runnerDefPath, e);
System.exit(-1);
}
TestScenarioGroup[] groups = null;
try {
groups = testController.getScenarioGroups();
} catch (Exception e) {
// TODO
ServiceManagerFactory.getLogger().write("TR___00006", e);
System.exit(-1);
}
for (int i = 0; i < groups.length; i++) {
Map scenarioMap = (Map) scenarioGroupMap.get(groups[i].getScenarioGroupId());
if (scenarioMap == null) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00007", groups[i].getScenarioGroupId());
}
if (isTest) {
testController.startScenarioGroup(userId, groups[i].getScenarioGroupId());
if (!groups[i].getStatus().getResult()) {
continue;
}
} else {
testController.downloadTestScenarioGroupResource(groups[i].getScenarioGroupId());
}
TestScenario[] scenarios = testController.getScenarios(groups[i].getScenarioGroupId());
for (int j = 0; j < scenarios.length; j++) {
Set testCaseSet = (Set) scenarioMap.get(scenarios[j].getScenarioId());
if (testCaseSet == null) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00008", scenarios[j].getScenarioId());
}
if (isTest) {
testController.startScenario(userId, scenarios[j].getScenarioId());
if (!scenarios[j].getStatus().getResult()) {
testController.cancelScenario(scenarios[j].getScenarioId());
continue;
}
int defaultTestCaseErrorContinue = scenarios[j].getTestScenarioResource().getErrorContinue();
TestCase[] testCases = testController.getTestCases(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
for (int k = 0; k < testCases.length; k++) {
if (!testCaseSet.contains(testCases[k].getTestCaseId())) {
continue;
}
try {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00009", testCases[k].getTestCaseId());
}
testController.startTestCase(userId, scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
if (testCases[k].getStatus().getResult()) {
testController.endTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
} else {
testController.cancelTestCase(scenarios[j].getScenarioId(), testCases[k].getTestCaseId());
}
if (testCases[k].getStatus().getResult()) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00010", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
}
} else {
int ErrorContinue = testCases[k].getTestCaseResource().getErrorContinue();
if (!(ErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE || (ErrorContinue == TestResourceBase.CONTINUE_TYPE_DEFAULT && defaultTestCaseErrorContinue == TestResourceBase.CONTINUE_TYPE_TRUE))) {
break;
}
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00011", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() });
}
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00012", new Object[] { testCases[k].getTestCaseId(), testCases[k].getStatus() }, e);
}
continue;
}
}
testController.endScenario(scenarios[j].getScenarioId());
if (verbose) {
if (scenarios[j].getStatus().getResult()) {
ServiceManagerFactory.getLogger().write("TR___00013", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
} else {
ServiceManagerFactory.getLogger().write("TR___00014", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() });
}
}
} else {
testController.downloadTestScenarioResource(groups[i].getScenarioGroupId(), scenarios[j].getScenarioId());
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00015", new Object[] { scenarios[j].getScenarioId(), scenarios[j].getStatus() }, e);
}
continue;
}
}
if (isTest) {
testController.endScenarioGroup();
}
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00016", groups[i].getScenarioGroupId());
}
} catch (Exception e) {
if (verbose) {
ServiceManagerFactory.getLogger().write("TR___00017", groups[i].getScenarioGroupId(), e);
}
continue;
}
}
// レポート
if (testReporterList != null) {
for (int i = 0; i < testReporterList.size(); i++) {
((TestReporter) testReporterList.get(i)).report(testController);
}
}
} finally {
for (int i = servicePaths.size(); --i >= 0; ) {
ServiceManagerFactory.unloadManager((String) servicePaths.get(i));
}
}
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class BeanFlowInvokerAccessImpl2 method fillInstance.
public void fillInstance(Element element, BeanFlowInvokerFactoryCallBack callBack, String encoding) {
this.encoding = encoding;
try {
factoryCallBack = callBack;
flowName = MetaData.getUniqueAttribute(element, NAME_ATTRIBUTE);
coverage = new BeanFlowCoverageImpl("<flow name=\"" + flowName + "\">");
String maxThreadsStr = MetaData.getOptionalAttribute(element, MAX_RUN_THREADS_ATTRIBUTE);
if (maxThreadsStr != null) {
maxThreadsStr = factoryCallBack.replaceProperty(maxThreadsStr);
try {
int maxThreads = Integer.parseInt(maxThreadsStr);
semaphore = new MemorySemaphore();
semaphore.setResourceCapacity(maxThreads);
semaphore.accept();
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("maxThreads is number " + maxThreadsStr);
}
}
String timeoutStr = MetaData.getOptionalAttribute(element, TIMEOUT_ATTRIBUTE);
if (timeoutStr != null) {
timeoutStr = factoryCallBack.replaceProperty(timeoutStr);
try {
timeout = Long.parseLong(timeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("timeout is number " + timeoutStr);
}
}
String maxWaitCountStr = MetaData.getOptionalAttribute(element, MAX_WAIT_THREADS_ATTRIBUTE);
if (maxWaitCountStr != null) {
maxWaitCountStr = factoryCallBack.replaceProperty(maxWaitCountStr);
try {
maxWaitCount = Integer.parseInt(maxWaitCountStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("maxWaitThreads is number " + maxWaitCountStr);
}
}
String forceFreeTimeoutStr = MetaData.getOptionalAttribute(element, FORCE_FREE_TIMEOUT_ATTRIBUTE);
if (forceFreeTimeoutStr != null) {
forceFreeTimeoutStr = factoryCallBack.replaceProperty(forceFreeTimeoutStr);
try {
forceFreeTimeout = Long.parseLong(forceFreeTimeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("forceFreeTimeout is number " + forceFreeTimeoutStr);
}
}
final String transactionStr = MetaData.getOptionalAttribute(element, TRANSACTION_ATTRIBUTE);
if (transactionStr != null) {
if (REQUIRED.equals(transactionStr)) {
transactionType = REQUIRED_VALUE;
} else if (REQUIRESNEW.equals(transactionStr)) {
transactionType = REQUIRESNEW_VALUE;
} else if (SUPPORTS.equals(transactionStr)) {
transactionType = SUPPORTS_VALUE;
} else if (MANDATORY.equals(transactionStr)) {
transactionType = MANDATORY_VALUE;
} else if (NEVER.equals(transactionStr)) {
transactionType = NEVER_VALUE;
} else if (NOT_SUPPORTED.equals(transactionStr)) {
transactionType = NOT_SUPPORTED_VALUE;
} else {
throw new InvalidConfigurationException("Invalid transaction : " + transactionStr);
}
if (transactionType != SUPPORTS_VALUE) {
try {
TransactionManagerFactory tranMngFactory = factoryCallBack.getTransactionManagerFactory();
if (getTransactionManagerJndiName() != null && tranMngFactory instanceof JndiTransactionManagerFactoryService) {
((JndiTransactionManagerFactoryService) tranMngFactory).setTransactionManagerName(getTransactionManagerJndiName());
}
tranManager = tranMngFactory.getTransactionManager();
} catch (TransactionManagerFactoryException e) {
throw new DeploymentException(e);
}
}
}
final String transactionTimeoutStr = MetaData.getOptionalAttribute(element, TRANTIMEOUT_ATTRIBUTE);
if (transactionTimeoutStr != null) {
try {
transactionTimeout = Integer.parseInt(transactionTimeoutStr);
} catch (NumberFormatException e) {
throw new InvalidConfigurationException("trantimeout is number " + transactionTimeoutStr);
}
}
final String journalStr = MetaData.getOptionalAttribute(element, JOURNAL_ATTRIBUTE);
if (journalStr != null) {
isJournal = Boolean.valueOf(journalStr).booleanValue();
}
final String suspendStr = MetaData.getOptionalAttribute(element, SUSPEND_ATTRIBUTE);
if (suspendStr != null) {
isSuspend = Boolean.valueOf(suspendStr).booleanValue();
}
final String stopStr = MetaData.getOptionalAttribute(element, STOP_ATTRIBUTE);
if (stopStr != null) {
isStop = Boolean.valueOf(stopStr).booleanValue();
}
final Iterator aliasElements = MetaData.getChildrenByTagName(element, ALIAS_ELEMENT);
while (aliasElements.hasNext()) {
aliasNames.add(MetaData.getUniqueAttribute((Element) aliasElements.next(), NAME_ATTRIBUTE));
}
final Iterator owElements = getChildrenByTagName(element, OVERRIDE_ELEMENT);
List overrideNameList = null;
while (owElements.hasNext()) {
Element owElement = (Element) owElements.next();
String overrideName = getUniqueAttribute(owElement, NAME_ATTRIBUTE);
if (overrideNameList == null) {
overrideNameList = new ArrayList();
}
overrideNameList.add(overrideName);
}
if (overrideNameList != null) {
overrideNames = (String[]) overrideNameList.toArray(new String[overrideNameList.size()]);
}
final Iterator inputDefElements = MetaData.getChildrenByTagName(element, INPUT_DEF_ELEMENT);
while (inputDefElements.hasNext()) {
final Element inputDefElement = (Element) inputDefElements.next();
final String name = MetaData.getUniqueAttribute(inputDefElement, NAME_ATTRIBUTE);
final String nullCheckAttribute = MetaData.getOptionalAttribute(inputDefElement, NULLCHECK_ATTRIBUTE);
boolean nullCheck = false;
if (nullCheckAttribute != null) {
nullCheck = Boolean.valueOf(nullCheckAttribute).booleanValue();
}
String val = MetaData.getElementContent(inputDefElement);
Property property = null;
if (val != null && val.length() != 0) {
try {
property = PropertyFactory.createProperty(val);
if (!nullCheck) {
property.setIgnoreNullProperty(true);
}
} catch (Exception e) {
throw new DeploymentException(e);
}
}
if (inputDefs == null) {
inputDefs = new HashMap();
}
inputDefs.put(name, property);
}
final ServiceNameEditor editor = new ServiceNameEditor();
final Iterator resourceElements = MetaData.getChildrenByTagName(element, RESOURCE_ELEMENT);
while (resourceElements.hasNext()) {
final Element resourceElement = (Element) resourceElements.next();
final String name = MetaData.getUniqueAttribute(resourceElement, NAME_ATTRIBUTE);
final String key = MetaData.getOptionalAttribute(resourceElement, KEY_ATTRIBUTE);
final String serviceNameStr = MetaData.getUniqueAttribute(resourceElement, SERVICE_ATTRIBUTE);
editor.setAsText(factoryCallBack.replaceProperty(serviceNameStr));
final ServiceName serviceName = (ServiceName) editor.getValue();
final boolean isTranControl = MetaData.getOptionalBooleanAttribute(resourceElement, TRANCONTROL_ATTRIBUTE);
final boolean isTranClose = MetaData.getOptionalBooleanAttribute(resourceElement, TRANCLOSE_ATTRIBUTE, true);
ResourceInfo resourceInfo = new ResourceInfo();
resourceInfo.name = name;
resourceInfo.key = key;
resourceInfo.serviceName = serviceName;
resourceInfo.isTranControl = isTranControl;
resourceInfo.isTranClose = isTranClose;
if (resources == null) {
resources = new HashMap();
}
resources.put(name, resourceInfo);
}
Iterator children = MetaData.getChildrenWithoutTagName(element, new String[] { ALIAS_ELEMENT, OVERRIDE_ELEMENT, INPUT_DEF_ELEMENT, RESOURCE_ELEMENT, CATCH_ELEMENT, FINALLY_ELEMENT });
boolean isReturn = false;
while (children.hasNext()) {
final Element currentElement = (Element) children.next();
final String tagName = currentElement.getTagName();
if (isReturn) {
throw new DeploymentException("Unreachable element : " + tagName);
}
Step stepObj = null;
if (STEP_ELEMENT.equals(tagName)) {
StepMetaData step = new StepMetaData(this, coverage);
step.importXML(currentElement);
stepObj = step;
} else if (CALL_FLOW_ELEMENT.equals(tagName)) {
CallFlowMetaData callFlowData = new CallFlowMetaData(this, coverage);
callFlowData.importXML(currentElement);
stepObj = callFlowData;
} else if (REPLY_ELEMENT.equals(tagName)) {
GetAsynchReplyMetaData replyData = new GetAsynchReplyMetaData(this, coverage);
replyData.importXML(currentElement);
stepObj = replyData;
} else if (SWITCH_ELEMENT.equals(tagName)) {
SwitchMetaData sw = new SwitchMetaData(this, coverage);
sw.importXML(currentElement);
stepObj = sw;
} else if (IF_ELEMENT.equals(tagName)) {
IfMetaData ifData = new IfMetaData(this, coverage);
ifData.importXML(currentElement);
stepObj = ifData;
} else if (FOR_ELEMENT.equals(tagName)) {
ForMetaData forData = new ForMetaData(this, coverage);
forData.importXML(currentElement);
stepObj = forData;
} else if (WHILE_ELEMENT.equals(tagName)) {
WhileMetaData whileData = new WhileMetaData(this, coverage);
whileData.importXML(currentElement);
stepObj = whileData;
} else if (RETURN_ELEMENT.equals(tagName)) {
ReturnMetaData returnData = new ReturnMetaData(this, coverage);
returnData.importXML(currentElement);
stepObj = returnData;
isReturn = true;
} else {
throw new DeploymentException("Invalid child tag of flow tag : " + tagName);
}
if (stepObj != null) {
if (jobSteps == null) {
jobSteps = new ArrayList();
}
jobSteps.add(stepObj);
}
}
final Iterator catchElements = MetaData.getChildrenByTagName(element, CATCH_ELEMENT);
while (catchElements.hasNext()) {
final Element catchElement = (Element) catchElements.next();
CatchMetaData step = new CatchMetaData(this, coverage);
step.importXML(catchElement);
if (catchSteps == null) {
catchSteps = new ArrayList();
}
catchSteps.add(step);
}
final Element finallyElement = MetaData.getOptionalChild(element, FINALLY_ELEMENT);
if (finallyElement != null) {
FinallyMetaData step = new FinallyMetaData(this, coverage);
step.importXML(finallyElement);
finallyStep = step;
}
stepNames = new HashSet();
if (inputDefs != null) {
stepNames.addAll(inputDefs.keySet());
}
if (jobSteps != null) {
for (int i = 0, max = jobSteps.size(); i < max; i++) {
Step jobStep = (Step) jobSteps.get(i);
jobStep.setupStepNames(stepNames);
}
}
} catch (InvalidConfigurationException e) {
e.setResourceName("flowName=" + flowName);
throw e;
} catch (DeploymentException e) {
e.setResourceName("flowName=" + flowName);
throw new InvalidConfigurationException("Invalid flow." + flowName, e);
}
journal = factoryCallBack.getJournal(this);
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class TestSwingRunner method main.
public static void main(String[] args) throws Exception {
if (args.length != 0 && args[0].equals("-help")) {
usage();
return;
}
final List servicePaths = new ArrayList();
boolean validate = false;
for (int i = 0; i < args.length; i++) {
servicePaths.add(args[i]);
}
if (servicePaths.size() == 0) {
usage();
return;
}
for (int i = 0, max = servicePaths.size(); i < max; i++) {
if (!ServiceManagerFactory.loadManager((String) servicePaths.get(i), false, validate)) {
System.exit(-1);
}
}
if (!ServiceManagerFactory.checkLoadManagerCompleted()) {
System.exit(-1);
}
TestController testController = null;
try {
String controllerServiceNameStr = null;
// コントローラーのサービス名は、とりあえずテストで固定値
if (controllerServiceNameStr == null)
controllerServiceNameStr = "Nimbus#TestController";
final ServiceNameEditor editor = new ServiceNameEditor();
editor.setAsText(controllerServiceNameStr);
final ServiceName controllerServiceName = (ServiceName) editor.getValue();
testController = (TestController) ServiceManagerFactory.getServiceObject(controllerServiceName);
} catch (Exception e) {
ServiceManagerFactory.getLogger().write("TR___00004", e);
System.exit(-1);
}
// GUI を起動
final UserIdInputView view = new UserIdInputView(servicePaths);
view.setTestController(testController);
view.setVisible(true);
view.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
view.setWindowClosed(true);
}
});
while (!view.isWindowClosed()) {
synchronized (view) {
view.wait(1000);
}
}
}
use of jp.ossc.nimbus.core.ServiceName in project nimbus by nimbus-org.
the class DefaultEndpointService method onOpen.
@Override
public void onOpen(Session session, EndpointConfig config) {
try {
SessionProperties prop = (SessionProperties) config.getUserProperties().get(SessionProperties.SESSION_PROPERTY_KEY);
prop.setWebSocketSessionId(session.getId());
// Journal出力
if (accessJournal != null) {
accessJournal.startJournal(accessJournalKey, editorFinder);
accessJournal.setRequestId(sequence.increment());
accessJournal.addInfo(idJournalKey, prop.getId());
accessJournal.addInfo(ticketJournalKey, prop.getTicket());
accessJournal.addInfo(webSocketSessionIdJournalKey, prop.getWebSocketSessionId());
accessJournal.addInfo(httpSessionIdJournalKey, prop.getHttpSessionId());
accessJournal.addInfo(pathJournalKey, prop.getPath());
accessJournal.addInfo(ipJournalKey, prop.getIp());
accessJournal.addInfo(portJournalKey, prop.getPort());
accessJournal.addInfo(headerJournalKey, prop.getHeaders());
accessJournal.addInfo(parameterJournalKey, prop.getParameterMap());
}
// IDとチケットは必須
if (prop.getId() == null && prop.getTicket() == null) {
CloseReason reason = new CustomCloseReason(CustomCloseReason.CloseCodes.SERVER_ACCESS_DENIED, "Server access denied");
try {
session.close(reason);
} catch (IOException e) {
}
service.getLogger().write(illegalRequestMessageId, prop.getIp());
return;
}
// クライアント数チェック
if (maxClientSize != -1 && sessionSet.size() >= maxClientSize) {
CloseReason reason = new CustomCloseReason(CustomCloseReason.CloseCodes.MAX_CLIENT_SIZE_OVER, "MaxClientSizeOver");
try {
session.close(reason);
} catch (Exception e) {
}
service.getLogger().write(maxClientSizeOverMessageId, prop);
return;
}
// 認証処理
if (authenticator != null) {
boolean result = false;
try {
result = authenticator.handshake(prop.getId(), prop.getTicket());
} catch (AuthenticateException e) {
handleException(session, e);
}
if (!result) {
CloseReason reason = new CustomCloseReason(CustomCloseReason.CloseCodes.HANDSHAKE_AUTH_FAILED, "handshakeAuthFailed");
try {
session.close(reason);
} catch (Exception e) {
}
return;
}
}
SessionProperties.put(session, prop);
if (maxIdleTimeout != -1) {
session.setMaxIdleTimeout(maxIdleTimeout);
}
if (maxTextMessageBufferSize != -1) {
session.setMaxTextMessageBufferSize(maxTextMessageBufferSize);
}
if (maxBinaryMessageBufferSize != -1) {
session.setMaxBinaryMessageBufferSize(maxBinaryMessageBufferSize);
}
for (ServiceName handlerName : messageHandlerServiceNames) {
Object service = ServiceManagerFactory.getServiceObject(handlerName);
if (service instanceof MessageHandler) {
session.addMessageHandler((MessageHandler) service);
}
if (service instanceof SessionMessageHandler) {
((SessionMessageHandler) service).onOpen(session, config);
}
}
synchronized (sessionSet) {
sessionSet.add(session);
}
} finally {
if (accessJournal != null && accessJournal.isStartJournal()) {
accessJournal.endJournal();
}
}
}
Aggregations