use of org.glassfish.grizzly.config.dom.ProtocolFinder in project Payara by payara.
the class CreateProtocolFinder method execute.
@Override
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
report = context.getActionReport();
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
final Protocol target = protocols.findProtocol(targetName);
try {
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
validate(target, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, targetName);
final Class<?> finderClass = Thread.currentThread().getContextClassLoader().loadClass(classname);
if (!org.glassfish.grizzly.portunif.ProtocolFinder.class.isAssignableFrom(finderClass)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL_NOTFINDER), name, classname));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
PortUnification unif = (PortUnification) ConfigSupport.apply(new SingleConfigCode<Protocol>() {
@Override
public Object run(Protocol param) throws PropertyVetoException, TransactionFailure {
PortUnification pu = param.getPortUnification();
if (pu == null) {
pu = param.createChild(PortUnification.class);
param.setPortUnification(pu);
}
return pu;
}
}, protocol);
ConfigSupport.apply(new SingleConfigCode<PortUnification>() {
@Override
public Object run(PortUnification param) throws PropertyVetoException, TransactionFailure {
final List<ProtocolFinder> list = param.getProtocolFinder();
for (ProtocolFinder finder : list) {
if (name.equals(finder.getName())) {
throw new TransactionFailure(String.format("A protocol finder named %s already exists.", name));
}
}
final ProtocolFinder finder = param.createChild(ProtocolFinder.class);
finder.setName(name);
finder.setProtocol(targetName);
finder.setClassname(classname);
list.add(finder);
return null;
}
}, unif);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_PORTUNIF_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
use of org.glassfish.grizzly.config.dom.ProtocolFinder in project Payara by payara.
the class ListProtocolFinders method execute.
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
final ActionReport report = context.getActionReport();
Protocol protocol = config.getNetworkConfig().getProtocols().findProtocol(protocolName);
if (protocol != null) {
final PortUnification pu = protocol.getPortUnification();
if (pu != null) {
for (ProtocolFinder finder : pu.getProtocolFinder()) {
report.getTopMessagePart().addChild().setMessage(finder.getName());
}
}
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.grizzly.config.dom.ProtocolFinder in project Payara by payara.
the class CreateNetworkListener method findVirtualServer.
private VirtualServer findVirtualServer(Protocol protocol) {
String name = null;
final Http http = protocol.getHttp();
if (http != null) {
name = http.getDefaultVirtualServer();
} else {
final List<ProtocolFinder> finders = protocol.getPortUnification().getProtocolFinder();
for (ProtocolFinder finder : finders) {
if (name == null) {
final Protocol p = finder.findProtocol();
if (p.getHttp() != null) {
name = p.getHttp().getDefaultVirtualServer();
}
}
}
}
return config.getHttpService().getVirtualServerByName(name);
}
use of org.glassfish.grizzly.config.dom.ProtocolFinder in project Payara by payara.
the class DeleteProtocolFinder method execute.
@Override
public void execute(AdminCommandContext context) {
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
report = context.getActionReport();
try {
final Protocols protocols = config.getNetworkConfig().getProtocols();
final Protocol protocol = protocols.findProtocol(protocolName);
validate(protocol, LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND, protocolName);
PortUnification pu = getPortUnification(protocol);
ConfigSupport.apply(new ConfigCode() {
@Override
public Object run(ConfigBeanProxy... params) {
final Protocol prot = (Protocol) params[0];
final PortUnification portUnification = (PortUnification) params[1];
final List<ProtocolFinder> oldList = portUnification.getProtocolFinder();
List<ProtocolFinder> newList = new ArrayList<ProtocolFinder>();
for (final ProtocolFinder finder : oldList) {
if (!name.equals(finder.getName())) {
newList.add(finder);
}
}
if (oldList.size() == newList.size()) {
throw new RuntimeException(String.format("No finder named %s found for protocol %s", name, protocolName));
}
if (newList.isEmpty()) {
prot.setPortUnification(null);
} else {
portUnification.setProtocolFinder(newList);
}
return null;
}
}, protocol, pu);
cleanPortUnification(pu);
} catch (ValidationFailureException e) {
return;
} catch (Exception e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.DELETE_FAIL), name, e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
}
Aggregations