Category Archives: Weblogic

Deploying a EJB 2.1 Stateful Bean on Weblogic 10.3

Hi,

Deploying an EJB2.1 Stateful bean is quite very easy in weblogic. First of all develop the Stateful bean and extract a jar out of it. I will show how to build and deploy the EJB in web logic 10.3 step by step.

There are five steps involved in EJB Session bean Development and deploy process.

1.       Create the Home Interface

2.       Create the Remote Interface

3.       Create the Session Bean

4.       Define the resources in DD

5.       Deploy on the server


1.       Create a Home Interface.


package
com.test.stf;

import java.rmi.RemoteException;

import javax.ejb.CreateException;

import javax.ejb.EJBHome;

public interface CounterHome extends EJBHome {

public Counter create(String name)throws CreateException, RemoteException;

}


2.       Create a Component Interface(Remote)

package com.test.stf;

import java.rmi.RemoteException;

import javax.ejb.EJBObject;

public interface Counter extends EJBObject {

public void startCounter() throws RemoteException;

public int getCounter() throws RemoteException;

}

3. Create Stateful session bean


package com.test.stf;

import java.io.Serializable;

import java.rmi.RemoteException;

import javax.ejb.EJBException;

import javax.ejb.SessionBean;

import javax.ejb.SessionContext;

public class HandleCounter implements SessionBean, Serializable {

private static final long serialVersionUID = 1L;

private String userName=””;

private SessionContext ctx;

private int counter=0;

public void ejbActivate() throws EJBException, RemoteException {

System.out.println(“Inside ejbActivate”);

}

public void ejbPassivate() throws EJBException, RemoteException {

System.out.println(“Inside ejbPassivate”);

}

public void ejbRemove() throws EJBException, RemoteException {

System.out.println(“Inside ejbRemove”);

}

public void setSessionContext(SessionContext arg0) throws EJBException,

RemoteException {

this.ctx=arg0;

}

public void startCounter() throws RemoteException{

counter=counter+1;

}

public int getCounter()throws RemoteException{

return counter;

}

public void ejbCreate(String name) throws RuntimeException{

userName=name;

}

}

Below is the list of some high Level rules which we have ensure while developing the EJB objects.

-> Rules for EJB Home Interface:

1.       Should must extend EJBHome Interface

2.       Must have atlest one createMethod

3.       The name of create method must begin with create e.g createClientPortfolio etc.

4.       The Create method should return the Component interface type(Remote interface)

5.       Create method should throw “CreateException, RemoteException”.

-> Rules for Remote Interface

1.       Should Must extends EJBObject Interface

2.       Should contains the business methods

3.       Every business method should throw RemoteException

-> Rules for SessionBeans

1.       Every SessionBean should extend SessionBean Interface

2.       In case of Stateless session bean there must be only one create method and that should must prefix with “ejbCreate”. And should be with no-arg approach.

3.       Every bean should save the SessionContext copy in the “setSessionContext” method, as this bean called only once when bean gets created; saving this reference is always useful.

4.       Incase of Stateful session bean, do not need to have no-arg create method. And also you can create as many as createMethod.
e.g  ejbCreate(), ejbCreate(String), createCustomerPortfolio(String) etc.

4.  Now let’s prepare the DD of EJB Component

<?xml version=“1.0” encoding=“UTF-8”?>

<ejb-jar id=“ejb-jar_ID” version=“2.1” xmlns=http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd&#8221;>

<display-name>

TestStateful</display-name>

<enterprise-beans>

<session>

<description>Test Stateful on Weblogic</description>

<ejb-name>TestStateful</ejb-name>

<home>com.test.stf.CounterHome</home>

<remote>com.test.stf.Counter</remote>

<ejb-class>com.test.stf.HandleCounter</ejb-class>

<session-type>Stateful</session-type>

<transaction-type>Container</transaction-type>

</session>

</enterprise-beans>

</ejb-jar>

ejb-name : Give any name for the EJB
home: EJBHome class FQDN (Fully qualified defined name)
remote: Remote class FQDN (Fully qualified defined name)
ejb-class : Session bean class FQDN (Fully qualified defined name)
session-type: Stateful or Stateless (in our case Stateful)
transaction-type: Container | Bean (let container handle this)

As we are deploying on weblogic , we need weblogic-ejb-jar.xml so that weblogic can treat this as an EJB Component and set the configuration at deploy time(JNDI name, security related etc).

<?xml version=“1.0” encoding=“UTF-8”?>

<weblogic-ejb-jar

xmlns=http://www.bea.com/ns/weblogic/90&#8221; xmlns:j2ee=http://java.sun.com/xml/ns/j2ee&#8221; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd&#8221;>

<weblogic-enterprise-bean>

<ejb-name>TestStateful</ejb-name>

<jndi-name>TestStateful</jndi-name>

</weblogic-enterprise-bean>

</weblogic-ejb-jar>
ejb-name: make sure to use the same ejb-name defined in ejb-jar.xml
jndi-name: this is the name of the JNDI given the EJB component.

5 Deployment
To deploy simply extract the jar of the EJB classes and deploy in the admin console of weblogic.


Structure of the EJB Jar:
———————————————————————————–|
com
META-INF
– ejb-jar.xml
– weblogic-ejb-jar.xml
– manifest
————————————————————————————|

In case of stateless, keep everything same and change the bean create method to no-arg.

Client to test

public final static String JNDI_FACTORY = “weblogic.jndi.WLInitialContextFactory”;

public static void main(String[] args) throws Exception {

InitialContext ic = getInitialContext(“t3://localhost:7001”);

CounterHome home = (CounterHome) PortableRemoteObject.narrow(ic

.lookup(“TestStateful“), CounterHome.class);

Counter adv = home.create(“ejbMarathon“);

adv.startCounter();

adv.startCounter();

System.out.println(adv.getCounter());

}

private static InitialContext getInitialContext(String url)

throws NamingException {

Hashtable<String, String> env = new Hashtable<String, String>();

env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);

env.put(Context.PROVIDER_URL, url);

env.put(Context.SECURITY_PRINCIPAL, “ejbuser“);

env.put(Context.SECURITY_CREDENTIALS, “PASSWORD123“);

env.put(“weblogic.jndi.createIntermediateContexts”, “true”);

return new InitialContext(env);

}

Hope This helps.

Thanks
R Vashi

HermesJMS console to monitor JMS resources


HermesJMS is an
extensible console that helps you interact with JMS providers making it easy to browse or search queues and topics, copy messages around and delete them. It fully integrates with JNDI letting you discover administered objects stored, create JMS sessions from the connection factories and use any destinations found. Many providers include a plugin that uses the native API to do non-JMS things like getting queue depths (and other statistics) or finding queue and topic names.

The main advantage of the tool is the ability to work with many JMS Providers like JBOSS MQ, ActiveMQ,  OpenJMS, Weblogic, Webspehere etc etc. It also supports the FIX protocol messages which gives a full advantage to all financial vertical applications.

HermesJMS is a java swing based tool.

Follow the below steps to install and use the tool to monitor the JMS resources.

1.  Download Link.

http://sourceforge.net/projects/hermesjms/

2. Open Command Console and type the below command to run the execuatable installer jar.

java –jar hermes-installer-1.13.jar

now it will start the installation process. Follow the installation wizard and finsh.

3. Go to Start -> program files -> hermes -> hermesJms

4 Now it will open the GUI of HermesJMS.

5 On left side Under ” Sessions” -> right click on “session” -> new session

6 And configure the Screen with Weblogic JMS Provider info.  You will find tabs in the bottom i.e session, provider etc

-> First of all click on Provider Tab and add Weblogic jar.

-> Click on Session Drop Down(on top) and type “Weblogic

-> Select the BEA Weblogic plugin from the drop down of plugin and add the properties.(you can skip the properites part as it will also work)

-> On Connection Factory drop down, select the hermes.JNDIConnectionFactory class and also select the loader “weblogic“, And then add the properties of the Connection factory. This is mandatory to discover the JMS resources of the selected provider.
(see the below screen shot for the high level information)

Now close the dialog box.

-> On the left side right click on your “weblogic” session and click “discover“. You get a meesage to add the resources into the session click “yes”.

-> now you will see all the topics and queues beaneth your cofigured session. Right click on any the resource and click “Browse”, you will notice the message details on the right side.

You can also view the configuration on the HermesJSM website.

http://www.hermesjms.com/confluence/display/HJMS/WebLogicMQ+9.X+Tutorial&#8221;.

Hope this helps.

Thanks
R Vashi

Building a Basic Web service using JAX-WS

Web Service: A web service is a service which runs over XML Data exchange in the form of SOAP Request and SOAP Response.  The advantage we got over web service is the communication with different language platforms e.g. Java, .net, C++, PHP   etc.  Web services are playing a crucial part in SOA (Service Oriented Architecture) which is again a very broad term and one of the successful architecture accepted by many enterprise level applications today. Let’s end the definition part here and move now to Web Service development part. (Hope the intro have made you clear the basic concept of Web Services if not please do Google more on web services 🙂 ).

Develop a Simple Web Service

To develop a web service there are 2 types of approaches we can follow.

1.       Contract First Approach.

2.       Code First Approach

Contract First Approach: This approach works on the basis of WSDL, and require a very good knowledge of WSDL, XML, XSD.  Once you expertise the web services then you can apply some hand on this approach. For this post I will describe how to build a web service using 2nd Approach.


Code First
Approach

This approach starts with the very core level of code writing. I mean by writing a Java Class and defining all the properties of web services i.e. ports, operation, endpoints etc.

Lets Develop a Ping Web Service: This web service will simply return a greeting message with Current date and time.

First of All write a Java Class:

package com.webservice.sample;

import javax.jws.WebMethod;

import javax.jws.WebService;

import javax.jws.soap.SOAPBinding;

import java.util.Date;

@WebService(name=”PingServer”, serviceName=”PingServer”,portName=”PingServerPort”, targetNamespace=”com.webservice.pingserver”)

@SOAPBinding(style=SOAPBinding.Style.DOCUMENT,use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED)

public class PingServer {

@WebMethod

public String getPingStatus(){

return “Hi!! I am active :” + new Date().getTime();

}

}

Description:

@WebService :

Name: This Defines a name of web service
serviceName: This Defines a name of web service Endpoint interface

portName: This defines the name of the port

targetNamespace: Define a namespace for your web service, if no name specified, Compiler will take a default name space in the reverse order of you package name.

@SOAPBinding

Style       =Defines a Soap Styel e.g SOAPBinding.Style.DOCUMENT,

Use     = Specify a SOAP Message format e.g SOAPBinding.Use.LITERAL, 

parameterStyle =defines how Web service request/reply messages are interpreted by a Web service provider/consumer. Quite simply, "wrapper" style tells the Web service provider that the root element of the message (also called "wrapper element") represents the name of the operation and it is not part of the payload. This also means that children of the root element must map directly to parameters of the operation's signature. The "non-wrapper" style (also sometimes called "bare"), does not make this assumption; in this case the entire message will be passed to the service operation. The reply message is handled in a similar way.

@WebMethod : This specify the method which is exposed to web service(operation)

[NOTE]
in case if you are passing any arguments to the web service method.
You can use @WebParam(name=”argumentName”) annotation to comply with the schema. Otherwise generic “in0”, “in1” names will be used in WSDL for input arguments.

Generating the Web Service Artifacts

Now we need to create the artifacts of the web services. There is tool called WSGEN, This tools reads the Service Endpoint interface   and generate the WSDL and XML Schema for the web service which needs to be published.

To Run the tool first of all compile the Web service which we have created above. And open the command console and move the compiled directory e.g “/bin” dir. And run the below command.

wsgen –cp .  com.webservice.sample -wsdl

Once you run the tool you will notice the creation of WSDL and XDS creation in the “/bin” directory.

Now Let’s publish the Web Service.

In this part we will use the EndPoint class to publish the web service using a lightweight web server.

public class TestPublisher {

public static void main(String[] args) {

Endpoint.publish(“http://localhost:8011/service/pingserver&#8221;, new PingServer());

}

Call the publish method to publish the web service using FQN of the web service URL and the Service endpoint interface.

Endpoint.publish(URL, Object);

Once you run the Publisher. Go to Run -> Internet Explorer

And open the URL


http://localhost:8011/service/pingserver

If you are able to see the WSDL, Time to cheer!!!!! now… As the Web service has been published successfully.

[Note] Quit the Publisher Class to stop that Lightweight Web Server.

I will explain how to write a web service client to test the web service in my Next Post. Please give your suggestions or feedback.


Thanks
R Vashi

JAXB. Unmarshalling strings XML’s

Hi,

In this article I will show how to unmarshall XML string using JAXB, Usually JAXB uses InputStreams and OutputStreams for the XML text input and output, respectively.

One of workaround by passing a ByteArrayInputStreams (java.io) or ByteArrayOutputStreams (java.io) for XML String  or Using StreamSource to read the input via StringReader.

You can simply read my previous article “Sample on JAXB” to get the complete instruction on building a sample project on JAXB with eclipse plugin.

Below is the method which we can use to perform the unmarshalling of XML String into Java JAXB objects.
1. Via ByteArrayInputStream

public List loadObjectFromXMLString(String xmlString){
try{
ByteArrayInputStream input = new ByteArrayInputStream (xmlString.getBytes());
Object jaxbObject = unmarshaller.unmarshal( input);
if(items == null) {
items = (ItemsType)(((JAXBElement)jaxbObject).getValue());
return(items.getItem());
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}

2 Via StreamSource

JAXBContext jc = JAXBContext.newInstance( “com.acme.foo” );
Unmarshaller u = jc.createUnmarshaller();
StringBuffer xmlStr = new StringBuffer( “<?xml version=”1.0″?>…” );
Object o = u.unmarshal( new StreamSource( new StringReader( xmlStr.toString() ) ) );

[NOTE] This example is totally based on my previous article “Sample on JAXB”. Simply add the above method/statements if your building the project on my previous article instructions. Even there are many ways to do the same thing mentioned in the article. please go through with the below URL.
http://download.oracle.com/javase/6/docs/api/javax/xml/bind/Unmarshaller.html#supportedProps


Thanks
R Vashi

Useful JVM tunings

Categories of Java HotSpot VM Options

Standard options recognized by the Java HotSpot VM are described on the Java Application Launcher reference pages for Windows, Solaris and Linux. This document deals exclusively with non-standard options recognized by the Java HotSpot VM:

* Options that begin with -X are non-standard (not guaranteed to be supported on all VM implementations), and are subject to change without notice in subsequent releases of the JDK.
* Options that are specified with -XX are not stable and are not recommended for casual use. These options are subject to change without notice.

Some Useful -XX Options

Default values are listed for Java SE 6 for Solaris Sparc with -server. Some options may vary per architecture/OS/JVM version. Platforms with a differing default value are listed in the description.

* Boolean options are turned on with -XX:+<option> and turned off with -XX:-<option>.
* Numeric options are set with -XX:<option>=<number>. Numbers can include ‘m’ or ‘M’ for megabytes, ‘k’ or ‘K’ for kilobytes, and ‘g’ or ‘G’ for gigabytes (for example, 32k is the same as 32768).
* String options are set with -XX:<option>=<string>, are usually used to specify a file, a path, or a list of commands

Flags marked as manageable are dynamically writeable through the JDK management interface (com.sun.management.HotSpotDiagnosticMXBean API) and also through JConsole. In Monitoring and Managing Java SE 6 Platform Applications, The manageable flags can also be set through jinfo -flag.

The options below are loosely grouped into three categories.

* Behavioral options change the basic behavior of the VM.
* Performance tuning options are knobs which can be used to tune VM performance.
* Debugging options generally enable tracing, printing, or output of VM information.

1. Behavioral Options

Option and Default Value

Description
-XX:-AllowUserSignalHandlers    Do not complain if the application installs signal handlers. (Relevant to Solaris and Linux only.)

-XX:AltStackSize=16384    Alternate signal stack size (in Kbytes). (Relevant to Solaris only, removed from 5.0.)

-XX:-DisableExplicitGC    Disable calls to System.gc(), JVM still performs garbage collection when necessary.

-XX:+FailOverToOldVerifier    Fail over to old verifier when the new type checker fails. (Introduced in 6.)

-XX:+HandlePromotionFailure    The youngest generation collection does not require a guarantee of full promotion of all live objects. (Introduced in 1.4.2 update 11) [5.0 and earlier: false.]

-XX:+MaxFDLimit    Bump the number of file descriptors to max. (Relevant  to Solaris only.)

-XX:PreBlockSpin=10    Spin count variable for use with -XX:+UseSpinning. Controls the maximum spin iterations allowed before entering operating system thread synchronization code. (Introduced in 1.4.2.)

-XX:-RelaxAccessControlCheck    Relax the access control checks in the verifier. (Introduced in 6.)

-XX:+ScavengeBeforeFullGC    Do young generation GC prior to a full GC. (Introduced in 1.4.1.)

-XX:+UseAltSigs    Use alternate signals instead of SIGUSR1 and SIGUSR2 for VM internal signals. (Introduced in 1.3.1 update 9, 1.4.1. Relevant to Solaris only.)

-XX:+UseBoundThreads    Bind user level threads to kernel threads. (Relevant to Solaris only.)

-XX:-UseConcMarkSweepGC    Use concurrent mark-sweep collection for the old generation. (Introduced in 1.4.1)

-XX:+UseGCOverheadLimit    Use a policy that limits the proportion of the VM’s time that is spent in GC before an OutOfMemory error is thrown. (Introduced in 6.)

-XX:+UseLWPSynchronization    Use LWP-based instead of thread based synchronization. (Introduced in 1.4.0. Relevant to Solaris only.)

-XX:-UseParallelGC    Use parallel garbage collection for scavenges. (Introduced in 1.4.1)

-XX:-UseParallelOldGC    Use parallel garbage collection for the full collections. Enabling this option automatically sets -XX:+UseParallelGC. (Introduced in 5.0 update 6.)

-XX:-UseSerialGC    Use serial garbage collection. (Introduced in 5.0.)

-XX:-UseSpinning    Enable naive spinning on Java monitor before entering operating system thread synchronizaton code. (Relevant to 1.4.2 and 5.0 only.) [1.4.2, multi-processor Windows platforms: true]

-XX:+UseTLAB    Use thread-local object allocation (Introduced in 1.4.0, known as UseTLE prior to that.) [1.4.2 and earlier, x86 or with -client: false]

-XX:+UseSplitVerifier    Use the new type checker with StackMapTable attributes. (Introduced in 5.0.)[5.0: false]

-XX:+UseThreadPriorities    Use native thread priorities.

-XX:+UseVMInterruptibleIO    Thread interrupt before or with EINTR for I/O operations results in OS_INTRPT. (Introduced in 6. Relevant to Solaris only.)

2. Performance Options

Option and Default Value
Description
-XX:+AggressiveOpts    Turn on point performance compiler optimizations that are expected to be default in upcoming releases. (Introduced in 5.0 update 6.)

-XX:CompileThreshold=10000    Number of method invocations/branches before compiling [-client: 1,500]

-XX:LargePageSizeInBytes=4m    Sets the large page size used for the Java heap. (Introduced in 1.4.0 update 1.) [amd64: 2m.]

-XX:MaxHeapFreeRatio=70    Maximum percentage of heap free after GC to avoid shrinking.

-XX:MaxNewSize=size    Maximum size of new generation (in bytes). Since 1.4, MaxNewSize is computed as a function of NewRatio. [1.3.1 Sparc: 32m; 1.3.1 x86: 2.5m.]

-XX:MaxPermSize=64m    Size of the Permanent Generation.  [5.0 and newer: 64 bit VMs are scaled 30% larger; 1.4 amd64: 96m; 1.3.1 -client: 32m.]

-XX:MinHeapFreeRatio=40    Minimum percentage of heap free after GC to avoid expansion.

-XX:NewRatio=2    Ratio of new/old generation sizes. [Sparc -client: 8; x86 -server: 8; x86 -client: 12.]-client: 4 (1.3) 8 (1.3.1+), x86: 12]

-XX:NewSize=2.125m    Default size of new generation (in bytes) [5.0 and newer: 64 bit VMs are scaled 30% larger; x86: 1m; x86, 5.0 and older: 640k]

-XX:ReservedCodeCacheSize=32m    Reserved code cache size (in bytes) – maximum code cache size. [Solaris 64-bit, amd64, and -server x86: 48m; in 1.5.0_06 and earlier, Solaris 64-bit and and64: 1024m.]

-XX:SurvivorRatio=8    Ratio of eden/survivor space size [Solaris amd64: 6; Sparc in 1.3.1: 25; other Solaris platforms in 5.0 and earlier: 32]

-XX:TargetSurvivorRatio=50    Desired percentage of survivor space used after scavenge.

-XX:ThreadStackSize=512    Thread Stack Size (in Kbytes). (0 means use default stack size) [Sparc: 512; Solaris x86: 320 (was 256 prior in 5.0 and earlier); Sparc 64 bit: 1024; Linux amd64: 1024 (was 0 in 5.0 and earlier); all others 0.]

-XX:+UseBiasedLocking    Enable biased locking. For more details, see this tuning example. (Introduced in 5.0 update 6.) [5.0: false]

-XX:+UseFastAccessorMethods    Use optimized versions of Get<Primitive>Field.

-XX:-UseISM    Use Intimate Shared Memory. [Not accepted for non-Solaris platforms.] For details, see Intimate Shared Memory.

-XX:+UseLargePages    Use large page memory. (Introduced in 5.0 update 5.) For details, see Java Support for Large Memory Pages.

-XX:+UseMPSS    Use Multiple Page Size Support w/4mb pages for the heap. Do not use with ISM as this replaces the need for ISM. (Introduced in 1.4.0 update 1, Relevant to Solaris 9 and newer.) [1.4.1 and earlier: false]

-XX:+StringCache    Enables caching of commonly allocated strings.

-XX:AllocatePrefetchLines=1    Number of cache lines to load after the last object allocation using prefetch instructions generated in JIT compiled code. Default values are 1 if the last allocated object was an instance and 3 if it was an array.

-XX:AllocatePrefetchStyle=1    Generated code style for prefetch instructions.
0 – no prefetch instructions are generate*d*,
1 – execute prefetch instructions after each allocation,
2 – use TLAB allocation watermark pointer to gate when prefetch instructions are executed.

3. Debugging Options

Option and Default Value
Description
-XX:-CITime    Prints time spent in JIT Compiler. (Introduced in 1.4.0.)

-XX:ErrorFile=./hs_err_pid<pid>.log    If an error occurs, save the error data to this file. (Introduced in 6.)

-XX:-ExtendedDTraceProbes    Enable performance-impacting dtrace probes. (Introduced in 6. Relevant to Solaris only.)

-XX:HeapDumpPath=./java_pid<pid>.hprof    Path to directory or filename for heap dump. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)

-XX:-HeapDumpOnOutOfMemoryError    Dump heap to file when java.lang.OutOfMemoryError is thrown. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)

-XX:OnError=”<cmd args>;<cmd args>”    Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.)

-XX:OnOutOfMemoryError=”<cmd args>;
<cmd args>”     Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6)

-XX:-PrintClassHistogram    Print a histogram of class instances on Ctrl-Break. Manageable. (Introduced in 1.4.2.) The jmap -histo command provides equivalent functionality.

-XX:-PrintConcurrentLocks    Print java.util.concurrent locks in Ctrl-Break thread dump. Manageable. (Introduced in 6.) The jstack -l command provides equivalent functionality.

-XX:-PrintCommandLineFlags    Print flags that appeared on the command line. (Introduced in 5.0.)

-XX:-PrintCompilation    Print message when a method is compiled.

-XX:-PrintGC    Print messages at garbage collection. Manageable.

-XX:-PrintGCDetails    Print more details at garbage collection. Manageable. (Introduced in 1.4.0.)

-XX:-PrintGCTimeStamps    Print timestamps at garbage collection. Manageable (Introduced in 1.4.0.)

-XX:-PrintTenuringDistribution    Print tenuring age information.

-XX:-TraceClassLoading    Trace loading of classes.

-XX:-TraceClassLoadingPreorder    Trace all classes loaded in order referenced (not loaded). (Introduced in 1.4.2.)

-XX:-TraceClassResolution    Trace constant pool resolutions. (Introduced in 1.4.2.)

-XX:-TraceClassUnloading    Trace unloading of classes.

-XX:-TraceLoaderConstraints    Trace recording of loader constraints. (Introduced in 6.)

-XX:+PerfSaveDataToFile    Saves jvmstat binary data on exit.

source http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html


Thanks
R Vashi

Viewing JNDI Objects on Weblogic

Hi All,

You can monitor your deployments by viewing the JNDI tree from the WebLogic Server Administration Console. The JNDI tree will open in a separate browser window when you perform the following steps:

  1. Click the Servers node to expand it and expose the names of the servers currently being administered through the console.
  2. Click the name of the server whose JNDI tree you want to view.
  3. Scroll down to the bottom of the Configuration pane, and
  4. Click the “View JNDI Tree” link.

The JNDI tree will appear in a new browser window. You can click on an individual object name to view information about its bind name and hash code.

[Note] Sometime we face issues like JNDI NameNotFound, in that case try to re-target the JNDI resource on the Admin server or Managed Nodes on Weblogic.

Hope this helps.


Thanks
R Vashi

Download a file using Response headers

Hi All,

We sometime struggle implementing a functionality to download a file through browser download dialog window.

The below example will demonstrate the way we can download a file using response headers.

There are few steps you need to follow:

Step 1: First of all set the Content Type, for example if you want to set the file extension to Excel then.

response.setContentType(“application/vnd.ms-excel”);

Step 2: Now in this step we will set the response headers so that the browser can display the save and open prompt for the file.
Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file.When Internet Explorer/Mozilla/any browser receives the header, it raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header.

response.setHeader(“Content-Disposition”, “attachment;filename=” + MYFILE+”_TEST”+version_no+”.xls”)

Step 3: In this step we will add the data to the file which we are going to download.

response.getOutputStream().print(myData); // here my data is CSV formatted data

Step 4: Now access the servlet/jsp, the moment it loads you will see download window asking for save/open a file.

e.g http://localhost:8080/myapp/downlodReport

Hope this helps.


Thanks
R Vashis