use of org.glassfish.orb.admin.config.IiopListener in project Payara by payara.
the class CreateIiopListener method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final Target targetUtil = services.getService(Target.class);
final Config config = targetUtil.getConfig(target);
final ActionReport report = context.getActionReport();
IiopService iiopService = config.getExtensionByType(IiopService.class);
// check port uniqueness, only for same address
for (IiopListener listener : iiopService.getIiopListener()) {
if (listener.getId().equals(listener_id)) {
String ls = localStrings.getLocalString("create.iiop.listener.duplicate", "IIOP Listener named {0} already exists.", listener_id);
report.setMessage(ls);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (listener.getAddress().trim().equals(listeneraddress) && listener.getPort().trim().equals((iiopport))) {
String def = "Port [{0}] is already taken by another listener: " + "[{1}] for address [{2}], choose another port.";
String ls = localStrings.getLocalString("create.iiop.listener.port.occupied", def, iiopport, listener.getId(), listeneraddress);
report.setMessage(ls);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopService>() {
@Override
public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
IiopListener newListener = param.createChild(IiopListener.class);
newListener.setId(listener_id);
newListener.setAddress(listeneraddress);
newListener.setPort(iiopport);
newListener.setSecurityEnabled(securityenabled.toString());
newListener.setEnabled(enabled.toString());
newListener.setLazyInit(Boolean.toString(lazyInit));
// add properties
if (properties != null) {
for (java.util.Map.Entry entry : properties.entrySet()) {
Property property = newListener.createChild(Property.class);
property.setName((String) entry.getKey());
property.setValue((String) entry.getValue());
newListener.getProperty().add(property);
}
}
param.getIiopListener().add(newListener);
return newListener;
}
}, iiopService);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
String actual = e.getMessage();
String def = "Creation of: " + listener_id + "failed because of: " + actual;
String msg = localStrings.getLocalString("create.iiop.listener.fail", def, listener_id, actual);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.orb.admin.config.IiopListener in project Payara by payara.
the class ListIiopListeners method execute.
/**
* Executes the command
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Target targetUtil = services.getService(Target.class);
final Config config = targetUtil.getConfig(target);
final IiopService iiopService = config.getExtensionByType(IiopService.class);
try {
List<IiopListener> listenerList = iiopService.getIiopListener();
for (IiopListener listener : listenerList) {
final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
part.setMessage(listener.getId());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (Exception e) {
report.setMessage(localStrings.getLocalString("list.iiop.listener" + ".fail", "List IIOP listeners failed."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.orb.admin.config.IiopListener in project Payara by payara.
the class IiopSslConfigHandler method create.
@Override
public void create(final CreateSsl command, ActionReport report) {
IiopService iiopService = command.config.getExtensionByType(IiopService.class);
// ensure we have the specified listener
IiopListener iiopListener = null;
for (IiopListener listener : iiopService.getIiopListener()) {
if (listener.getId().equals(command.listenerId)) {
iiopListener = listener;
}
}
if (iiopListener == null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiop.notfound", "IIOP Listener named {0} to which this ssl element is " + "being added does not exist.", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (iiopListener.getSsl() != null) {
report.setMessage(localStrings.getLocalString("create.ssl.iiop.alreadyExists", "IIOP Listener named {0} to which this ssl element is " + "being added already has an ssl element.", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
public Object run(IiopListener param) throws PropertyVetoException, TransactionFailure {
Ssl newSsl = param.createChild(Ssl.class);
command.populateSslElement(newSsl);
param.setSsl(newSsl);
return newSsl;
}
}, iiopListener);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
command.reportSuccess(report);
}
use of org.glassfish.orb.admin.config.IiopListener in project Payara by payara.
the class IiopSslConfigHandler method delete.
@Override
public void delete(DeleteSsl command, ActionReport report) {
IiopService iiopService = command.config.getExtensionByType(IiopService.class);
IiopListener iiopListener = null;
for (IiopListener listener : iiopService.getIiopListener()) {
if (listener.getId().equals(command.listenerId)) {
iiopListener = listener;
}
}
if (iiopListener == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.iiop.listener.notfound", "Iiop Listener named {0} not found", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (iiopListener.getSsl() == null) {
report.setMessage(localStrings.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", command.listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<IiopListener>() {
public Object run(IiopListener param) throws PropertyVetoException {
param.setSsl(null);
return null;
}
}, iiopListener);
} catch (TransactionFailure e) {
command.reportError(report, e);
}
}
use of org.glassfish.orb.admin.config.IiopListener in project Payara by payara.
the class CreateIiopListenerTest method testExecuteSuccessDefaultValues.
/**
* Test of execute method, of class CreateIiopListener.
* asadmin create-iiop-listener --listeneraddress localhost
* --iiopport 4440 iiop_1
*/
@Test
public void testExecuteSuccessDefaultValues() {
parameters.set("listeneraddress", "localhost");
parameters.set("iiopport", "4440");
parameters.set("listener_id", "iiop_1");
CreateIiopListener command = services.getService(CreateIiopListener.class);
cr.getCommandInvocation("create-iiop-listener", context.getActionReport(), adminSubject()).parameters(parameters).execute(command);
checkActionReport(context.getActionReport());
boolean isCreated = false;
List<IiopListener> listenerList = iiopService.getIiopListener();
for (IiopListener listener : listenerList) {
if (listener.getId().equals("iiop_1")) {
assertEquals("localhost", listener.getAddress());
assertEquals("4440", listener.getPort());
isCreated = true;
logger.fine("IIOPListener name iiop_1 is created.");
break;
}
}
assertTrue(isCreated);
logger.fine("msg: " + context.getActionReport().getMessage());
}
Aggregations