use of java.beans.PropertyVetoException 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 java.beans.PropertyVetoException in project Payara by payara.
the class CreateVirtualServer method execute.
/**
* Executes the command with the command parameters passed as Properties where the keys are the paramter names and
* the values the parameter values
*
* @param context information
*/
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();
if (networkListeners != null && httpListeners != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_BOTH_HTTP_NETWORK), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
// use the listener parameter provided by the user.
if (networkListeners == null) {
networkListeners = httpListeners;
}
HttpService httpService = config.getHttpService();
// ensure we don't already have one of this name
for (VirtualServer virtualServer : httpService.getVirtualServer()) {
if (virtualServer.getId().equals(virtualServerId)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_DUPLICATE), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<HttpService>() {
public Object run(HttpService param) throws PropertyVetoException, TransactionFailure {
// default
String docroot = "${com.sun.aas.instanceRoot}/docroot";
// default
String accessLog = "${com.sun.aas.instanceRoot}/logs/access";
VirtualServer newVirtualServer = param.createChild(VirtualServer.class);
newVirtualServer.setId(virtualServerId);
newVirtualServer.setHosts(hosts);
newVirtualServer.setNetworkListeners(networkListeners);
newVirtualServer.setDefaultWebModule(defaultWebModule);
newVirtualServer.setState(state);
newVirtualServer.setLogFile(logFile);
// values if the properties have not been specified.
if (properties != null) {
for (Map.Entry entry : properties.entrySet()) {
String pn = (String) entry.getKey();
String pv = (String) entry.getValue();
if ("docroot".equals(pn)) {
docroot = pv;
} else if ("accesslog".equals(pn)) {
accessLog = pv;
} else {
Property property = newVirtualServer.createChild(Property.class);
property.setName(pn);
property.setValue(pv);
newVirtualServer.getProperty().add(property);
}
}
}
newVirtualServer.setDocroot(docroot);
newVirtualServer.setAccessLog(accessLog);
param.getVirtualServer().add(newVirtualServer);
return newVirtualServer;
}
}, httpService);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_VIRTUAL_SERVER_FAIL), virtualServerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of java.beans.PropertyVetoException in project Payara by payara.
the class SetWebEnvEntryCommand method set.
private void set(final EnvEntry envEntry, final String name, final String value, final String envEntryType, final String description, final Boolean ignoreDescriptorItem) throws PropertyVetoException, TransactionFailure {
final String candidateFinalValue = (value == null) ? envEntry.getEnvEntryValue() : value;
final String candidateFinalType = (envEntryType == null) ? envEntry.getEnvEntryType() : envEntryType;
if (value != null || envEntryType != null) {
if (candidateFinalValue == null || candidateFinalType == null) {
final String fmt = localStrings.getLocalString("valueAndTypeRequired", "Both a valid --type and --value are required; one is missing");
throw new IllegalArgumentException(fmt);
}
try {
EnvEntry.Util.validateValue(candidateFinalType, candidateFinalValue);
} catch (IllegalArgumentException ex) {
final String fmt = localStrings.getLocalString("valueTypeMismatch", "Cannot assign value {0} to an env-entry of type {1}", candidateFinalValue, candidateFinalType);
final String valueOrType = (value != null ? "--value" : "--type");
throw new PropertyVetoException(fmt + " - " + ex.getLocalizedMessage(), new PropertyChangeEvent(envEntry, valueOrType, envEntry.getEnvEntryType(), envEntryType));
}
}
envEntry.setEnvEntryName(name);
if (envEntryType != null) {
envEntry.setEnvEntryType(envEntryType);
}
if (value != null) {
envEntry.setEnvEntryValue(value);
}
if (envEntryType != null) {
envEntry.setEnvEntryType(envEntryType);
}
if (description != null) {
envEntry.setDescription(description);
}
if (ignoreDescriptorItem != null) {
envEntry.setIgnoreDescriptorItem(ignoreDescriptorItem.toString());
}
}
use of java.beans.PropertyVetoException in project Payara by payara.
the class CreateNetworkListener method execute.
/**
* Executes the command with the command parameters passed as Properties where the keys are the paramter names and
* the values the parameter values
*
* @param context information
*/
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();
NetworkConfig networkConfig = config.getNetworkConfig();
NetworkListeners nls = networkConfig.getNetworkListeners();
// ensure we don't have one of this name already
for (NetworkListener networkListener : nls.getNetworkListener()) {
if (networkListener.getName().equals(listenerName)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_DUPLICATE), listenerName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
if (!verifyUniquePort(networkConfig)) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.PORT_IN_USE), port, address));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Protocol prot = networkConfig.findProtocol(protocol);
if (prot == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocol));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (prot.getHttp() == null && prot.getPortUnification() == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL_BAD_PROTOCOL), protocol));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new ConfigCode() {
public Object run(ConfigBeanProxy... params) throws TransactionFailure, PropertyVetoException {
NetworkListeners listeners = (NetworkListeners) params[0];
NetworkListener newNetworkListener = listeners.createChild(NetworkListener.class);
newNetworkListener.setProtocol(protocol);
newNetworkListener.setTransport(transport);
newNetworkListener.setEnabled(enabled.toString());
newNetworkListener.setJkEnabled(jkEnabled.toString());
newNetworkListener.setPort(port);
newNetworkListener.setThreadPool(threadPool);
newNetworkListener.setName(listenerName);
newNetworkListener.setAddress(address);
listeners.getNetworkListener().add(newNetworkListener);
((VirtualServer) params[1]).addNetworkListener(listenerName);
return newNetworkListener;
}
}, nls, findVirtualServer(prot));
} catch (TransactionFailure e) {
e.printStackTrace();
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_NETWORK_LISTENER_FAIL), listenerName) + (e.getMessage() == null ? "No reason given" : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of java.beans.PropertyVetoException in project Payara by payara.
the class CreateTransport method execute.
/**
* Executes the command with the command parameters passed as Properties where the keys are the paramter names and
* the values the parameter values
*
* @param context information
*/
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();
// check for duplicates
NetworkConfig networkConfig = config.getNetworkConfig();
Transports transports = networkConfig.getTransports();
for (Transport transport : transports.getTransport()) {
if (transportName != null && transportName.equalsIgnoreCase(transport.getName())) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_TRANSPORT_FAIL_DUPLICATE), transportName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Add to the <network-config>
try {
ConfigSupport.apply(new SingleConfigCode<Transports>() {
public Object run(Transports param) throws PropertyVetoException, TransactionFailure {
boolean docrootAdded = false;
boolean accessLogAdded = false;
Transport newTransport = param.createChild(Transport.class);
newTransport.setName(transportName);
newTransport.setAcceptorThreads(acceptorThreads);
newTransport.setBufferSizeBytes(bufferSizeBytes);
newTransport.setByteBufferType(byteBufferType);
newTransport.setClassname(className);
newTransport.setDisplayConfiguration(displayConfiguration.toString());
newTransport.setIdleKeyTimeoutSeconds(idleKeyTimeoutSeconds);
newTransport.setMaxConnectionsCount(maxConnectionsCount);
newTransport.setName(transportName);
newTransport.setReadTimeoutMillis(readTimeoutMillis);
newTransport.setSelectionKeyHandler(selectionKeyHandler);
newTransport.setSelectorPollTimeoutMillis(selectorPollTimeoutMillis);
newTransport.setWriteTimeoutMillis(writeTimeoutMillis);
newTransport.setTcpNoDelay(tcpNoDelay.toString());
param.getTransport().add(newTransport);
return newTransport;
}
}, transports);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_TRANSPORT_FAIL), transportName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations