Problem
Having above exception after deploying WAR file.
Solution
Delete [Tomcat]\work\Catalina\localhost.
Cause
Tomcat’s got crazy with JSP compilation.
Not Professional Programmers. But Problematic Programmers.
Having above exception after deploying WAR file.
Delete [Tomcat]\work\Catalina\localhost.
Tomcat’s got crazy with JSP compilation.
Want to use a Spring bean as JSP Filter.
Use DelagatingFilterProxy from Spring libarry.
public class HeaderValidationFilter implements Filter{
……
}
<bean id="filterHeader” class=”com.proprogrammers.HeaderValidationFilter”>
……
</bean>
<filter>
<filter-name>filterHeader</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter><filter-mapping>
<filter-name>filterHeader</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping><servlet>
<servlet-name>Spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
Filter bean (at step-2) cannot be defined in Spring Servlet XML file; Spring-servlet.xml in the sample. It must be in other Spring XML file.
http://static.springsource.org/spring-security/site/docs/3.0.x/reference/security-filter-chain.html
Collin Yates
http://forum.springsource.org/showthread.php?20230-Howto-The-joy-that-is-DelegatingFilterProxy
I have a long-running method which I want to run asynchronously. I transform the method into asynchronous method by running it on separate thread.
Original Code:
public void mainMethod() throws InterruptedException{
System.out.println("Main Method start");
longRunningMethod("testing", new Object());
otherMethod();
}
public Integer longRunningMethod(String param1,Object parm2) throws InterruptedException{
System.out.println("Long running method");
Thread.sleep(5000);
//long process
return 1;
}
public void otherMethod(){
System.out.println("Other Method");
}
New Code:
public void mainMethod() throws InterruptedException{
System.out.println("Main Method start");
//longRunningMethod("testing", new Object());
asyncServiceMethod("testing",new Object());
otherMethod();
}
public Integer longRunningMethod(String param1,Object parm2) throws InterruptedException{
System.out.println("Long running method");
Thread.sleep(5000);
//long process
return 1;
}
public void otherMethod(){
System.out.println("Other Method");
}
public void asyncServiceMethod(final String parm1,final Object obj){
Runnable task = new Runnable() {@Override
public void run() {
try {
longRunningMethod(parm1,obj);
} catch (Exception ex) {
//handle error which cannot be thrown back
}
}
};
new Thread(task, "ServiceThread").start();
}
There are few things to consider wrapping a method into asynchronous call.
Other to read
CurrentDateTime
-----------------------
2011-05-10 11:18:54.857
CurrentDate
-----------------------
2011-05-10 00:00:00.000
CurrentStartDayOftheWeek
------------------------
2011-05-09 00:00:00.000
CurrentStartDayOftheMonth
-------------------------
2011-05-01 00:00:00.000
CurrentStartDayOftheYear
------------------------
2011-01-01 00:00:00.000
public int[] toIntArray(byte[] barr) {
//Pad the size to multiple of 4
int size = (barr.length / 4) + ((barr.length % 4 == 0) ? 0 : 1);ByteBuffer bb = ByteBuffer.allocate(size *4);
bb.put(barr);//Java uses Big Endian. Network program uses Little Endian.
bb.order(ByteOrder.LITTLE_ENDIAN);
int[] result = new int[size];
bb.rewind();
while (bb.remaining() > 0) {
result[bb.position()/4] =bb.getInt();
}return result;
}
Disappointed for not seeing shifting? Wanna complain about performance?
This is definitely not the most efficient method to convert byte array into int array yet it can be done with simple logic and a bit of knowledge in NIO.
Unless the program is to be used on 1K memory device, using ByteBuffer is acceptable I reckon.
(I tried to convert to IntBuffer but in vain. If anyone could point out, that’d be great.)
Peter has mentioned how to use with IntBuffer in comment section as follow:
public int[] toIntArray(byte[] barr) {
//Pad the size to multiple of 4
int size = (barr.length / 4) + ((barr.length % 4 == 0) ? 0 : 1);ByteBuffer bb = ByteBuffer.allocate(size *4);
bb.put(barr);//Java uses Big Endian. Network program uses Little Endian.
bb.order(ByteOrder.LITTLE_ENDIAN);
bb.rewind();
IntBuffer ib = bb.asIntBuffer();
int [] result = new int [size];
ib.get(result);return result;
}
BigDecimal class from java.lang.Math package is useful for scale manipulation. Be careful though when you want to compare two BigDecimal objects with equals() method since it tests not just the equality of value but also the scale as mentioned in the document as below:
…..this method considers two BigDecimals equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).
For the following code
BigDecimal a = new BigDecimal("2.0");
BigDecimal b = new BigDecimal("2.00");
if (a.equals(b)){
System.out.println("Equals");
}else{
System.out.println("Not Equals");
}
it will return "Not Equals” as the scales of the objects are different.
To compare values of the above two objects, compareTo method can be used as it implements Comparable interface like wrappers.
if (a.compareTo(b)==0)
{
System.out.println("They have same value");
}
If you change proxy setting in Chrome using Options->Under the Hood –> [Change Proxy Setting], it will use IE proxy setting and it will change proxy setting for all other browsers.
To avoid this, execute chrome.exe using the command line argument below:
--proxy-server=PROXYSERVER:PORT
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>….
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- An appender which writes to file -->
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
<param name="file" value="../logs/MyApp.log" />
<param name="datePattern" value="'.'yyyy-MM" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c{6} - %m%n"/>
</layout>
</appender><root>
<priority value ="info" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
According to WiKiPedia
Ping is a computer network administration utility used to test the reachability of a host on an Internet Protocol (IP) network and to measure the round-trip time for messages sent from the originating host to a destination computer.
The name comes from active sonar terminology.
Ping is used to test the hostname/IP address for DNS resolution.
Ping uses ICMP protocol while telnet uses TCP protocol on specific port.
Since Windows 2008, it is disabled by default. To enable it, Networking – Echo Request(ICMPv4In), from command prompt, enter following:
netsh firewall set icmpsetting 8
dbcc checkident( 'TABLENAME', RESEED, 200000000)
Details in: http://blogs.techrepublic.com.com/datacenter/?p=406 (Susan Harkins, 2008)
If you want the Spring container to perform initialization work on your bean after all the properties are set, you may implement InitializationBean and implements afterPropertiesSet() method.
But just as Spring documentation outlines, that approach will couple the code to Spring. You should use init-metod instead and call any public method from your bean. You could event pass parameters using constructor-arg.
http://static.springsource.org/spring/docs/2.0.x/reference/beans.html#beans-factory-lifecycle
If your Tomcat is running with Java 1.5 by default and want to upgrade to Java 1.6, double click TOMCAT\bin\tomcat5w.exe
Thanks to kellyohair http://forums.java.net/jive/message.jspa?messageID=155421 for step-2
I use Apache Commons DBCP for the above purpose
<bean id="poolDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="poolPreparedStatements" value="true"/>
<property name="maxActive" value="10"/>
<property name="maxIdle" value="10"/>
</bean>
Application Log files should
Note From Wikipedia
Chunked Transfer Encoding is a mechanism that allows HTTP messages to be split in several parts. This can be applied to both HTTP requests (from client to server) and HTTP responses (from server to client).
HTTP Chunked Transfer Encoding allows a server to maintain a HTTP persistent connection for dynamically generated content.
Problem
If HTTP Response has “Transfer-Encoding” header, it causes client to wait for closing the connection.
Cause
If there is no “Content-Length” is defined in HTTP response header, it will be chunked transmission. HTTP Response must have either “Transfer-Encoding” or “Content-Length” attribute.
Solution
Define “Content-Length” attribute if it can be done.
The above error is caught when NULL value in a database column is attempted to set to a setter in an Entity bean whose attribute mapped to that column type is of primitive type.
Never ever use primitive for attribute type in Entity Bean.
Since Java 5, with a feature called “Autoboxing”, we can seamlessly treat wrapper as primitive type as below
Integer deptId;
deptId = 5;
//deptId = new Integer(5);
int a;
a = deptId;
//a = deptId.intValue();
Compiler will handle it.
We have several ways to avoid getting NullPointerException caught such as a method returning empty array or List rather than NULL as following:
public String[] getNames(){
return new String[0];//return null
}
This code will have the method caller in peace who can just write code without having to worry about NULL value something like this:
for(String name:getNames()){
//Do Something
}
But there could be a scenario where we want to have empty value different from NULL in return, for instance:
public String getName(){
return null;
}
For that reason, we can never assume that a method could not return NULL. Whether a method returns NULL or empty value should be described in Javadoc I believe. Consider this code:
if(person.getName().equals("John")){
//Do Something
}
The above code will give NullPointerException when getName() returns NULL and it should be written as below if we know that NULL can be returned.
if ("John".equals(person.getName())){
//Do Something
}
The conditional clause above will yield false if getName() returns NULL.
| GZip | Zip |
|
|
|
|
|
|