Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.arquillian.container;
import static org.jboss.as.controller.client.helpers.ClientConstants.CONTROLLER_PROCESS_STATE_STARTING;
import static org.jboss.as.controller.client.helpers.ClientConstants.CONTROLLER_PROCESS_STATE_STOPPING;
import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT;
import static org.jboss.as.controller.client.helpers.ClientConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.client.helpers.ClientConstants.OP;
import static org.jboss.as.controller.client.helpers.ClientConstants.OP_ADDR;
import static org.jboss.as.controller.client.helpers.ClientConstants.OUTCOME;
import static org.jboss.as.controller.client.helpers.ClientConstants.READ_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.READ_RESOURCE_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.RECURSIVE;
import static org.jboss.as.controller.client.helpers.ClientConstants.RESULT;
import static org.jboss.as.controller.client.helpers.ClientConstants.SUBSYSTEM;
import static org.jboss.as.controller.client.helpers.ClientConstants.SUCCESS;
import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServerConnection;
import javax.management.NotCompliantMBeanException;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.security.auth.callback.CallbackHandler;
import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.logging.Logger;
import org.wildfly.common.Assert;
/**
* A helper class to join management related operations, like extract sub system ip/port (web/jmx)
* and deployment introspection.
*
*
* Instances of this type are not thread-safe.
*
* @author Aslak Knutsen
*/
public class ManagementClient implements Closeable {
private static final Logger logger = Logger.getLogger(ManagementClient.class);
private static final String SUBDEPLOYMENT = "subdeployment";
private static final String UNDERTOW = "undertow";
private static final String NAME = "name";
private static final String SERVLET = "servlet";
private static final String POSTFIX_WEB = ".war";
private static final String POSTFIX_EAR = ".ear";
private static final ModelNode UNDERTOW_SUBSYSTEM_ADDRESS = new ModelNode().add("subsystem", UNDERTOW);
private final String mgmtAddress;
private final int mgmtPort;
private final String mgmtProtocol;
private final ModelControllerClient client;
private final CommonContainerConfiguration config;
private boolean initialized = false;
private URI webUri;
private URI ejbUri;
private ModelNode undertowSubsystem = null;
private MBeanServerConnection connection;
private JMXConnector connector;
private boolean undertowSubsystemPresent = false;
private boolean closed = false;
public ManagementClient(ModelControllerClient client, final String mgmtAddress, final int managementPort, final String protocol) {
if (client == null) {
throw new IllegalArgumentException("Client must be specified");
}
this.client = client;
this.mgmtAddress = mgmtAddress;
this.mgmtPort = managementPort;
this.mgmtProtocol = protocol;
this.config = null;
}
public ManagementClient(ModelControllerClient client, final CommonContainerConfiguration config) {
if (client == null) {
throw new IllegalArgumentException("Client must be specified");
}
Assert.checkNotNullParam("config", config);
this.client = client;
this.mgmtAddress = config.getManagementAddress();
this.mgmtPort = config.getManagementPort();
this.mgmtProtocol = config.getManagementProtocol();
this.config = config;
}
//-------------------------------------------------------------------------------------||
// Public API -------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
* Returns the client used to connect to the server.
*
* @return the client
*
* @throws IllegalStateException if this has been {@linkplain #close() closed}
*/
public ModelControllerClient getControllerClient() {
checkState();
return client;
}
/**
* Resets the client. {@linkplain #close() Closes} open resources and resets flags so that the client itself can be
* reinitialized later if desired.
*/
void reset() {
close();
initialized = false;
closed = false;
}
/**
* Checks whether or not the Undertow subsystem is present and sets the internal state if it is. An invocation of
* this should happen after the server has been started.
*
* @throws IllegalStateException if this has been {@linkplain #close() closed}
*/
private void init() {
AccessController.doPrivileged(new PrivilegedAction