Saturday, October 23, 2010

Configure Java logging file handler

http://download.oracle.com/javase/6/docs/api/java/util/logging/package-summary.html


java.util.logging.config.file defines file used
by LogManager to configure root logger

FileHandler

%g the generation number to distinguish rotated logs

java.util.logging.FileHandler.count specifies how many output files to cycle through (defaults to 1).

http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ317_021.htm

FileHandlers for non-root logger must be specified using Java.

FileHandler fh = null;
try {
fh = new FileHandler("dave." + System.getenv("serverName")+ "%g.log",
500000,
10
);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

lgr2.addHandler(fh);

Wednesday, September 8, 2010

JDK Tools and Utilities

JDK Tools and Utilities

Monitoring and Management

Java Troubleshooting, Profiling, Monitoring and Management Tools

Java VisualVM


jvisualvm

A graphical tool that provides detailed information about the Java technology-based applications (Java applications) while they are running in a Java Virtual Machine. Java VisualVM provides memory and CPU profiling, heap dump analysis, memory leak detection, access to MBeans, and garbage collection.

jconsole A JMX-compliant graphical tool for monitoring a Java virtual machine. It can monitor both local and remote JVMs. It can also monitor and manage an application.

Monitoring Tools

jps JVM Process Status Tool - Lists instrumented HotSpot Java virtual machines on a target system.

jstat JVM Statistics Monitoring Tool - Attaches to an instrumented HotSpot Java virtual machine and collects and logs performance statistics as specified by the command line options.

Troubleshooting Tools

jinfo Configuration Info for Java - Prints configuration information for a given process or core file or a remote debug server.

jhat Heap Dump Browser - Starts a web server on a heap dump file (eg, produced by jmap -dump), allowing the heap to be browsed.

jmap Memory Map for Java - Prints shared object memory maps or heap memory details of a given process or core file or a remote debug server.

jsadebugd Serviceability Agent Debug Daemon for Java - Attaches to a process or core file and acts as a debug server.

jstack Stack Trace for Java - Prints a stack trace of threads for a given process or core file or remote debug server.

Tuesday, June 15, 2010

Override Weblogic config.xml values with weblogic.Server JVM property

Oracle® Fusion Middleware Command Reference for Oracle WebLogic Server
11g Release 1 (10.3.1)
weblogic.Server Command-Line Reference

When you use a startup option to override a configuration value, the server instance uses this value for the duration of its life cycle

http://download.oracle.com/docs/cd/E12839_01/web.1111/e13749/weblogicserver.htm#i1031832

For to override listen address stored in config.xml add in start script
-Dweblogic.ListenAddress=host

This startup option overrides any listen address value specified in the config.xml file. The override applies to the current server instantiation; it does not modify the value in the config.xml file. Use the Administration Console or WLST to modify the config.xml file.

Wednesday, June 9, 2010

Eclipse Weblogic OEPE split and exploded deployment

Oracle Enterprise Pack for Eclipse 11gR1 (11.1.1.5)
http://www.oracle.com/technology/software/products/oepe/oepe_11115.html

allows split and exploded deployment directory structure.

For existing projects use linked files to create projects deployable through OEPE.


Forum: Enterprise Pack for Eclipse

http://forums.oracle.com/forums/forum.jspa?forumID=578&start=0

Thursday, June 3, 2010

Encrypt Weblogic boot.properties using weblogic.security.Encrypt

# directory must be created for managed servers because it does not exist yet
mkdir -p ${DOMAIN_HOME}/servers/${SERVER_NAME}/security

echo "username=${ADMIN_USER}\npassword=\c" > ${DOMAIN_HOME}/servers/${SERVER_NAME}/security/boot.properties

${JAVA_HOME=}/bin/java -Dweblogic.RootDirectory=${DOMAIN_HOME} weblogic.security.Encrypt ${ADMIN_PASSWORD} >> ${DOMAIN_HOME}/servers/${SERVER_NAME}/security/boot.properties




weblogic.security.Encrypt documentation
http://download.oracle.com/docs/cd/E13222_01/wls/docs81/admin_ref/utils17.html

Wednesday, May 26, 2010

Start and stop Weblogic server using boot.properties

Starting and Stopping Weblogic Server
http://download.oracle.com/docs/cd/E12839_01/web.1111/e13708/overview.htm#i1068520


Specify location of boot.properties file using -Dweblogic.system.BootIdentityFile=filename

connect(url='t3://localhost:7001')
shutdown('AdminServer','Server')
exit()



connect command

connect([username, password], [url], [timeout])
connect([userConfigFile, userKeyFile], [url], [timeout])
connect([url], [adminServerName], [timeout])

adminServerName parameter (Name of the domain's Administration Server. ) is not needed.
Causes the connect command to use the credentials that are stored in the Administration Server's boot.properties file. If the Administration Server's boot.properties file is located in the domain directory, then you do not need to specify this argument.
http://download.oracle.com/docs/cd/E12839_01/web.1111/e13708/overview.htm#i1068520

Saturday, May 22, 2010

Foreign JNDI provider - call remote EJB

Create two domains - base_domain and remote_domain.


Setup Foreign JNDI provider on base_domain pointing to remote_domain.


http://download.oracle.com/docs/cd/E12840_01/wls/docs103/ConsoleHelp/taskhelp/jndi/ConfigureForeignJNDIProvider.html






Create session EJB calling remote session EJB and deploy to base_domain.
package testEAR;

import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import remoteEAR.RemoteEJBRemote;

/**
* Session Bean implementation class CallRemoteBean
*/
@Stateless
public class CallRemoteBean implements CallRemoteBeanLocal {

public CallRemoteBean() {
}


public void callRemoteBean(){


RemoteEJBRemote remoteEJB = null;
try {
remoteEJB = (RemoteEJBRemote)new InitialContext().lookup("RemoteEJB");
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("Calling remote");
String response = remoteEJB.hello();

System.out.println("Response remote=" + response);

}

}


Create session bean on remote_domain

package remoteEAR;

import javax.ejb.Stateless;

/**
* Session Bean implementation class RemoteEJB
*/
@Stateless(mappedName = "RemoteEJB")
public class RemoteEJB implements RemoteEJBRemote {

/**
* Default constructor.
*/
public RemoteEJB() {
}

public String hello(){
System.out.println("In remote");
return "Hello from remote";
}

}


All projects created in Eclipse 3.5


EJB3 reference injection problems
http://forums.oracle.com/forums/thread.jspa?messageID=4030853

http://msikora.typepad.com/michael_sikora_on_java_ee/page/2/

http://m-button.blogspot.com/2008/07/reminder-on-how-to-use-ejb3-with.html

http://biese.wordpress.com/2008/02/20/how-to-call-ejb3-from-jsp-servlet-and-stand-alone-application/