Thursday, January 15, 2015

How to display null as empty string with Apache Velocity

We used the following Syntax to display attribute's value in Apache Velocity.
$myValue


But the problem is that, we the value carried by the attribute is null.
Velocity is not displaying an empty string or "null",
it display the attribute name that is being used.

attribute: [ $myValue1, $myValue2, $myValue3, $myValue4 ]
value:      [ "First", null, "Third", "" ]
Output:   [ First, $myValue2, Third,  ]


To display the NULL value as an empty string. we just need to add "!" after "$"

attribute: [ $!myValue1, $!myValue2, $!myValue3, $!myValue4 ]
value:      [ "First", null, "Third", "" ]
Output:   [ First, , Third,  ]


Done!!

Tuesday, January 13, 2015

How to retrieve value in map with Apache Velocity

Assuming we have a HashMap with the following value

HashMap myMap = new HashMap();
myMap.put("k1", "v1");
myMap.put("k2", "v2");
myMap.put("k3", "v3");


put the HashMap into the VelocityContext.

VelocityContext context = new VelocityContext();
context.put("myMap", myMap);


To retrieve the map value in the Velocity template (.vm file),
Use the following syntax to retrieve map value with constant key.

$myMap.get("k1");
$myMap.get("k2");
$myMap.get("k3");


Use the following syntax to retrieve map value with dynamic key.

$myMap.get($mapKey1);
$myMap.get($mapKey2);
$myMap.get($mapKey3);


Done!!

Saturday, December 6, 2014

How to increase JBoss Server memory and heap size when running JBoss with Eclipse Server Plugin

1. in Server view, double click on the selected configured JBoss runtime

2. click on Open launch configuration

3. in the VM arguments section, change to the desired settings

4. Click OK when finish editing the VM arguments.


Done!!

Wednesday, December 3, 2014

How to increase Web Pool to handle more requests in JBoss AS7

Web Pool is important in an Application Server,
if it is not configure properly, the server performance would be affected when huge number of requests coming into the server.

By default, the web pool in JBoss is not created.
Below are the steps to create Web Pool in JBoss

Steps
1. open <JBoss_HOME>/standalone/configuration/standalone.xml

2. find subsystem for "urn:jboss:domain:threads:1.1"

3. add thread factory to the subsystem

<thread-factory name="http-connector-factory" thread-name-pattern="HTTP-%t" priority="9" group-name="uq-thread-pool"/>

4. create an executor in the subsystem

<unbounded-queue-thread-pool name="uq-thread-pool">
    <thread-factory name="http-connector-factory" />
    <max-threads count="10" />
    <keepalive-time time="30" unit="seconds" />
</unbounded-queue-thread-pool>

5. search for connector name="http"

6. bind the executor created in step 3 to the http connector

<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />

reference: https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.3/html/Administration_and_Configuration_Guide/sect-Connector_Configuration.html


Done!!


Monday, November 17, 2014

How to replace HTML tag with ant

To replace a word or character with Ant,
we can use the following command.

<replaceregexp file="{FILE_TO_REPLACE}"
    match="{WORD_TO_REPLACE}"
    replace="{WORD}" flags="g" byline="true" />

But the above command can use to replace words withouth xml/html reserved characters only.
To replace words with xml/html reserved characters,

Steps:
1. encode the xml/html reserved words before putting into the the <replaceregexp /> command.
eg, <a>link</link>  =>  &lt;a&gt;link&lt;/a&gt;

2. put the encoded words into <replaceregexp />
eg,

<replaceregexp file="{FILE_TO_REPLACE}"
    match="&lt;a&gt;link&lt;/a&gt;"
    replace="&lt;a&gt;new_link&lt;/a&gt;" flags="g" byline="true" />


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...