Wednesday, May 6, 2009

difference between keyentry and trustedcertentry

You can tell if a certificate includes a private key by the way keytool lists it. Signing certificates with private keys will be marked keyEntry. Authority certificates without private keys will be marked trustedCertEntry.

Monday, March 30, 2009

The Logging Saga

Took me a whole day, so was worth blogging it.
This is jboss-4.2.2 specific.
WAR files in JBoss are scoped by default.
EAR files are not.

Lets look into the two case:
1. WAR
In case of WAR file, you can have the log4j.xml in the conf folder and things would work out. But, you cannot control the logging levels at runtime using Log4jService. The reason being, Log4JService controls the Logger in the jboss lib folder. To achieve this, I guess you might need a EAR or sthg.
What we can do is write a JSP/Servlet and have it as part of your application logger. This gives you the reference of your logger and hence runtime control to configure logging level


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
String loggerName = (String) request.getParameter("loggerName");
String level = (String) request.getParameter("level");
String actionType = (String) request.getParameter("submit");
System.out.println("loggerName=" + loggerName + "/level=" + level);
if (loggerName != null && loggerName.trim().length() > 0) {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Level origLevelObj = Logger.getLogger(loggerName).getLevel();
String origLevel = "UNKNOWN";
if (origLevelObj == null) {
System.out.println(Logger.getRootLogger().getLevel());
origLevel = Logger.getRootLogger().getLevel().toString();
}

if (actionType.equalsIgnoreCase("getloggerlevel")) {
out.println("Log level for " + loggerName + " is <b>" + origLevel + "</b>");
} else if (actionType.equalsIgnoreCase("setloggerlevel")) {
setLogLevel(loggerName, level);
out.println("Log level for " + loggerName + " is changed from <b>" + origLevel + "</b> to <b>" + level
+ "</b>");
}

out.flush();
out.close();
}

}

private void setLogLevel(String loggerName, String level) {
if ("debug".equalsIgnoreCase(level)) {
Logger.getLogger(loggerName).setLevel(Level.DEBUG);
} else if ("info".equalsIgnoreCase(level)) {
Logger.getLogger(loggerName).setLevel(Level.INFO);
} else if ("error".equalsIgnoreCase(level)) {
Logger.getLogger(loggerName).setLevel(Level.ERROR);
} else if ("fatal".equalsIgnoreCase(level)) {
Logger.getLogger(loggerName).setLevel(Level.FATAL);
} else if ("warn".equalsIgnoreCase(level)) {
Logger.getLogger(loggerName).setLevel(Level.WARN);
}
}


<span style="font-weight:bold;">And this could be your JSP:</span>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<h2> Log Level Controller </h2>
<br>
<FORM METHOD=POST ACTION="logy">
<table border=1>
<th colspan=2 bgcolor="YELLOW">Get Logger level</th>
<tr><td> LoggerName </td><td><INPUT TYPE=TEXT NAME="loggerName" SIZE=20></td></tr>
<tr><td colspan=2 align=right><INPUT TYPE=SUBMIT name=submit value=getloggerlevel></td></tr>
</table>
<br><br>
<table border=1>
<th colspan=2 bgcolor="YELLOW">Set Logger level</th>
<tr>
<td> LoggerName </td><td><INPUT TYPE=TEXT NAME="loggerName" SIZE=20></td></tr>
<tr><td> LogLevel </td>
<td>
<select name="level">
<option value=DEBUG>DEBUG</option>
<option value=INFO>INFO</option>
<option value=WARN>WARN</option>
<option value=ERROR>ERROR</option>
<option value=FATAL>FATAL</option>
</select>
</td></tr>
<tr><td colspan=2 align=right><INPUT TYPE=SUBMIT name=submit value=setloggerlevel></td></tr>
</table>
</FORM>


2. EAR

Make changes in jboss-log4j.xml.

To have application specific logging:
1. Write an appender - You can give your application specific filename.
2. Write a logger and refer to that appender. You do -> Logger.getLogger(x.class); This takes the complete package name into the logger hierarchy. So you can name you logger in log4j as "com.apple". This will route all your requests to your selected appender's file. and then specify the additivity to false. When you specify the additivity to false, then you dont log into the root appenders. And also, dont add your appender into the root logger.

<appender name="InfoAppender" class="org.apache.log4j.RollingFileAppender">
<errorHandler
class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/pos-server.log" />
<param name="Append" value="true" />
<param name="ImmediateFlush" value="true" />
<param name="MaxFileSize" value="200MB" />
<param name="MaxBackupIndex" value="10" />
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %X{SERVER_NAME} [%t] %-5p (%c{1}) - %m%n" />
</layout>
</appender>

And then do this: Very important
<logger name="com.boo" additivity="false">
<level value="DEBUG" />
<appender-ref ref="InfoAppender"/>
</logger>

Check out the root:
<root>

<priority value ="debug" />
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>

Monday, February 23, 2009

Yosemite









Mac is Mac is Mac. These are the pics from my camera ...modified

Tuesday, November 11, 2008

WSDL styles

Firstly, let me talk about RPC/literal and Document/Literal(Wrapped)

RPC/literal -- uses methodName in soap:body, and the input parameters.
For eg. if you had a method like

private void simpleMethod(int x, int y)

RPC/literal SOAP request would be like...
<simplemethod>(Method name)
<x>2</x>
<y>3</y>
</simplemethod>

A Document/Literal(Wrapped) would be -
<name_of_input_request_element_in_wsdl>
<x>2</x>
<y>3</y>
</name_of_input_request_element_in_wsdl>

RPC/encoded would be like
<simplemethod>(Method name)
<x type="int">2</x>
<y type="">3</y>
<simplemethod>

Document/Encoded would be like
<soap:body>
<x>2</x>
<y>3</y>
</soap:body>

Check that there is no method names or sthg. Just the input params.

Document/Literal (bare)
<input_element1>2</input_element1>
<input_element2>3</input_element2>

Good like to read
<a href="http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/">http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/</a></simplemethod></simplemethod>

Wednesday, November 5, 2008

Hard time

This has been a very very tough week. I have never had it so hard. I cant concentrate. I just wish there werent so many rules. I just wish we could do stuff what we want. Sometimes, something amazing can be missed just because there are rules. 

I hate rules. 

Tuesday, October 21, 2008

Class.getResource and ClassLoader.getResource

I better blog this down before I forget and do another couple of hours of research.
Class.getResource(): 
1. Resolves name you pass to it. If the name has a starting "/", then it takes it relative from the classpath. means.. "/config/x.txt" == in classpath, config/x.txt should be there
2. If you dont pass a starting "/" then it appends the package name to the file...so, if the name is "config/x.txt" and the class is com.xxx.MyClass, it will look for com/xxx/config/x.txt.
ClassLoader.getResource():
Doesnt do any name resolving. Delegates to parent classloader, if not found, looks in current classloader. 

This is my execution:
C:\workspace\CL\bin>java -cp .;CL-1.0.jar a.B
              
I have a config file called POS.properties in ./config folder.

I tried to read POS.properties in 3 ways.
(i) From main method, 
this.class.getResource(/config/POS.properties);
Will find it. From current path, it exists in config/
this.class.getResource(config/POS.properties);
Cant find it. From current path, Looks for in a/config/POS.properties. 
this.class.getClassLoader().getResource(/config/POS.properties);
Cant find it
this.class.getClassLoader().getResource(config/POS.properties);
Will find it.

Monday, September 15, 2008

el corte de madera creek, woodside , ca




Yup...hiking day. Somehow...Didnt have lot to blog these days..things went too fast or I wasnt in a mood.
It was totally amazing! For the first half, we were going down the hill...thru the mountains and just before entering the mountains ...we saw the sign that it was infested with rattle snakes and mountain lions...we were bloody shocked and looked at each other.. We were shit scared... Well, we went anyway...then almost one mile down the hill...we see no one...we were alone....we wud stop at every creaking sound. We wud be scared with rats making sound etc... we thought maybe we r at a wrong place and we shud go back.. then we were at a point when we were totally freaked out. and then we turned back and started to go....but then at the same nick of time...we see more hikers... phew..from then on we saw lot of bikers and people..so it was cool. Then while going back...GPS was taking us down the hill....only car can drive and there were edges of the mountain.... ..I was ultra cool....and then the unthinkable happened... another car came in the opposite direction!!!!!!! ...heheheheh...someone had to move back...and it was all edgey....I moved back..and the other car somehow managed to move.....phew phew phew...I still cant get over the excitment...hopefully we go to more hiking!!

Check more pictures here...