use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.
the class AttributeRemovalTest method removeAttributeTest.
@Test
public void removeAttributeTest() throws TransactionFailure {
HttpService httpService = Utils.instance.getHabitat(this).getService(HttpService.class);
VirtualServer vs = httpService.getVirtualServerByName("server");
ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
param.setDefaultWebModule("/context/bar");
return null;
}
}, vs);
// ensure it's here
org.junit.Assert.assertNotNull(vs.getDefaultWebModule());
ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
param.setDefaultWebModule(null);
return null;
}
}, vs);
// ensure it's removed
org.junit.Assert.assertNull(vs.getDefaultWebModule());
}
use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.
the class DuplicateKeyedElementTest method identicalKeyTest.
@Test(expected = TransactionFailure.class)
public void identicalKeyTest() throws TransactionFailure {
HttpService httpService = getHabitat().getService(HttpService.class);
assertNotNull(httpService);
// let's find a acceptable target.
VirtualServer target = null;
for (VirtualServer vs : httpService.getVirtualServer()) {
if (!vs.getProperty().isEmpty()) {
target = vs;
break;
}
}
assertNotNull(target);
Property newProp = (Property) ConfigSupport.apply(new SingleConfigCode<VirtualServer>() {
public Object run(VirtualServer param) throws PropertyVetoException, TransactionFailure {
// first one is fine...
Property firstProp = param.createChild(Property.class);
firstProp.setName("foo");
firstProp.setValue("bar");
param.getProperty().add(firstProp);
// this should fail...
Property secondProp = param.createChild(Property.class);
secondProp.setName("foo");
secondProp.setValue("bar");
param.getProperty().add(secondProp);
return secondProp;
}
}, target);
// if we arrive here, this is an error, we succeeded adding a property with
// the same key name.
assertTrue(false);
}
use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.
the class GetHostAndPortCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
ActionReport.MessagePart part = report.getTopMessagePart();
HttpService httpService = null;
HostAndPort hostAndPort = null;
try {
if (config == null) {
throw new Exception("No such target:" + target);
}
httpService = config.getHttpService();
if (httpService != null) {
hostAndPort = getHostAndPortForRequest(httpService);
}
} catch (Exception e) {
report.setMessage(e.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (hostAndPort != null) {
part.setMessage(hostAndPort.getHost() + ":" + hostAndPort.getPort());
// property for REST Access
part.addProperty("host", hostAndPort.getHost());
// property for REST Access
part.addProperty("port", "" + hostAndPort.getPort());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.
the class WarHandler method configureContextXmlAttribute.
protected void configureContextXmlAttribute(WebappClassLoader cloader, File base, DeploymentContext dc) throws XMLStreamException, IOException {
boolean consistent = true;
Boolean value = null;
File warContextXml = new File(base.getAbsolutePath(), WAR_CONTEXT_XML);
if (warContextXml.exists()) {
ContextXmlParser parser = new ContextXmlParser(warContextXml);
value = parser.getClearReferencesStatic();
}
if (value == null) {
Boolean domainCRS = null;
File defaultContextXml = new File(serverEnvironment.getInstanceRoot(), DEFAULT_CONTEXT_XML);
if (defaultContextXml.exists()) {
ContextXmlParser parser = new ContextXmlParser(defaultContextXml);
domainCRS = parser.getClearReferencesStatic();
}
List<Boolean> csrs = new ArrayList<Boolean>();
HttpService httpService = serverConfig.getHttpService();
DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
String vsIDs = params.virtualservers;
List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
if (httpService != null && vsList != null && !vsList.isEmpty()) {
for (VirtualServer vsBean : httpService.getVirtualServer()) {
if (vsList.contains(vsBean.getId())) {
Boolean csr = null;
Property prop = vsBean.getProperty("contextXmlDefault");
if (prop != null) {
File contextXml = new File(serverEnvironment.getInstanceRoot(), prop.getValue());
if (contextXml.exists()) {
// vs context.xml
ContextXmlParser parser = new ContextXmlParser(contextXml);
csr = parser.getClearReferencesStatic();
}
}
if (csr == null) {
csr = domainCRS;
}
csrs.add(csr);
}
}
// check that it is consistent
for (Boolean b : csrs) {
if (b != null) {
if (value != null && !b.equals(value)) {
consistent = false;
break;
}
value = b;
}
}
}
}
if (consistent) {
if (value != null) {
cloader.setClearReferencesStatic(value);
}
} else if (logger.isLoggable(Level.WARNING)) {
logger.log(Level.WARNING, LogFacade.INCONSISTENT_CLEAR_REFERENCE_STATIC);
}
}
use of com.sun.enterprise.config.serverbeans.HttpService in project Payara by payara.
the class CreateHttpListener 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) {
final ActionReport report = context.getActionReport();
if (!validateInputs(report)) {
return;
}
Target targetUtil = services.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
networkConfig = config.getNetworkConfig();
HttpService httpService = config.getHttpService();
if (!(verifyUniqueName(report, networkConfig) && verifyUniquePort(report, networkConfig) && verifyDefaultVirtualServer(report))) {
return;
}
VirtualServer vs = httpService.getVirtualServerByName(defaultVirtualServer);
boolean listener = false;
boolean protocol = false;
boolean transport = false;
try {
transport = createOrGetTransport(null);
protocol = createProtocol(context);
createHttp(context);
final ThreadPool threadPool = getThreadPool(networkConfig);
listener = createNetworkListener(networkConfig, transport, threadPool);
updateVirtualServer(vs);
} catch (TransactionFailure e) {
try {
if (listener) {
deleteListener(context);
}
if (protocol) {
deleteProtocol(context);
}
if (transport) {
deleteTransport(context);
}
} catch (Exception e1) {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, e.getMessage(), e);
}
throw new RuntimeException(e.getMessage());
}
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, e.getMessage(), e);
}
report.setMessage(MessageFormat.format(rb.getString(LogFacade.CREATE_HTTP_LISTENER_FAIL), listenerId, e.getMessage()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Aggregations