Say that i want my application to behave differently when running in debug mode in WebLogic - is there a flag that i can check?
ie:
if (weblogic.DEBUG) Console.writeline("running in debug mode in weblogic");
Say that i want my application to behave differently when running in debug mode in WebLogic - is there a flag that i can check?
ie:
if (weblogic.DEBUG) Console.writeline("running in debug mode in weblogic");
You can add arguments to your weblogic server to allow you to debug it remotely, specifically by setting the -Xdebug
option in your startWebLogic
script.
You can see a full example in the Oracle docs here
And in a similar question here: How to debug Java EE application using WebLogic 10.3
Once you have debug turned on you could pull it out of the JVM args/system properties like shown here: How to get vm arguments from inside of java application?
If you're not asking about debug but instead asking how to tell if your server is in production mode vs development mode, you can also access isProductionModeEnabled()
via JMX, as described here
You can also edit the logging levels for your servers to turn debug on...
You can use the DomainRuntimeServiceMBean and ServerRuntimeMBean provided by weblogic. There is an example on the oracle website of invoking these 2 MBeans to get the status of the server. I've pasted it below. Source can be found here
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
public class PrintServerState {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;
// Initializing the object name for DomainRuntimeServiceMBean
// so it can be used throughout the class.
static {
try {
service = new ObjectName(
"com.bea:Name=DomainRuntimeService,Type=weblogic.management.
mbeanservers.domainruntime.DomainRuntimeServiceMBean");
}catch (MalformedObjectNameException e) {
throw new AssertionError(e.getMessage());
}
}
/*
* Initialize connection to the Domain Runtime MBean Server
*/
public static void initConnection(String hostname, String portString,
String username, String password) throws IOException,
MalformedURLException {
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.domainruntime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,
port, jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();
}
/*
* Print an array of ServerRuntimeMBeans.
* This MBean is the root of the runtime MBean hierarchy, and
* each server in the domain hosts its own instance.
*/
public static ObjectName[] getServerRuntimes() throws Exception {
return (ObjectName[]) connection.getAttribute(service,
"ServerRuntimes");
}
/*
* Iterate through ServerRuntimeMBeans and get the name and state
*/
public void printNameAndState() throws Exception {
ObjectName[] serverRT = getServerRuntimes();
System.out.println("got server runtimes");
int length = (int) serverRT.length;
for (int i = 0; i < length; i++) {
String name = (String) connection.getAttribute(serverRT[i],
"Name");
String state = (String) connection.getAttribute(serverRT[i],
"State");
System.out.println("Server name: " + name + ". Server state: "
+ state);
}
}
public static void main(String[] args) throws Exception {
String hostname = args[0];
String portString = args[1];
String username = args[2];
String password = args[3];
PrintServerState s = new PrintServerState();
initConnection(hostname, portString, username, password);
s.printNameAndState();
connector.close();
}
}
You can the see debug socket log in the weblogic console like below,
Listening for transport dt_socket at address: xxxx
where xxxx is port number. By default the port number would be 8453