use of org.glassfish.grizzly.config.dom.HttpRedirect in project Payara by payara.
the class CreateHttpRedirect method execute.
// ----------------------------------------------- Methods from AdminCommand
@Override
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
Protocols protocols = config.getNetworkConfig().getProtocols();
Protocol protocol = null;
for (Protocol p : protocols.getProtocol()) {
if (protocolName.equals(p.getName())) {
protocol = p;
}
}
if (protocol == null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_FAIL_PROTOCOL_NOT_FOUND), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (protocol.getHttpRedirect() != null) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL_DUPLICATE), protocolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<Protocol>() {
public Object run(Protocol param) throws TransactionFailure {
HttpRedirect httpRedirect = param.createChild(HttpRedirect.class);
httpRedirect.setPort(port);
httpRedirect.setSecure(secure);
param.setHttpRedirect(httpRedirect);
return httpRedirect;
}
}, protocol);
} catch (TransactionFailure e) {
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_REDIRECT_FAIL), protocolName) + (e.getMessage() == null ? "No reason given." : e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.grizzly.config.dom.HttpRedirect in project Payara by payara.
the class HttpRedirectFilter method configure.
// ----------------------------------------- Methods from ConfigAwareElement
/**
* Configuration for <http-redirect>.
*
* @param configuration filter configuration
*/
@Override
public void configure(ServiceLocator habitat, NetworkListener networkListener, ConfigBeanProxy configuration) {
if (configuration instanceof HttpRedirect) {
final HttpRedirect httpRedirectConfig = (HttpRedirect) configuration;
int port = Integer.parseInt(httpRedirectConfig.getPort());
redirectPort = port != -1 ? port : null;
secure = Boolean.parseBoolean(httpRedirectConfig.getSecure());
} else {
// Retained for backwards compatibility with legacy redirect declarations.
}
}
Aggregations