Saturday, July 3, 2010

logging more information in http logs in weblogic

Till recently I had not had occasion to actually use the http access.log in weblogic. I usually am able to use ethereal or whatever to look at the bits across the wire or httwatch and recently have been using firebug
But if you want WL to generate more detailed http logs....
This is where I ran into a little block, its not as simple as changing the access log format to "extended" in the console. You need to do that first and also WRITE A CLASS to do the extended logging. crazy I wonder why they did that.

access.log in weblogic: by default logs the HTTP method URI the status code and not much else. I needed to see the cookies coming in with the request and this was a production machine so no possibility of attaching the debugger.

As you know its a W3C specified common logging format for HTTP requests across the web. If you are interested take a look at the spec.

For some reason Weblogic decided to limit their default to very little information and in order to provide extended logging, you have to write a Class ... ie., if you want to access anything from the incoming http request that is from the http header like referrer, cookies, browserid useragent etc.,

Its pretty straight-forward.
  • The Java class must implement weblogic.servlet.logging.CustomELFLogger, which has a logField(HttpAccountingInfo, FormatStringBuffer)
  • Put the class into some directory and update the startweblogic.cmd classpath
  • Then modify the config.xml to add the high-lighted xml to the server

<server>
<name>AdminServer</name>
<ssl>
<enabled>
true</enabled>
<listen-port>8843</listen-port>
</ssl>
<web-server>
<web-server-log>
<file-name>logs/modifiedaccess.log</file-name>
<elf-fields>date x-MyCustomField cs-uri time cs-method cs-uri sc-status</elf-fields>
<log-file-format>extended</log-file-format>
<log-time-in-gmt>true</log-time-in-gmt><br />
</web-server-log>
</web-server>
<listen-address></listen-address><br /></server>

Here is the class, I just put it in the default package

import weblogic.servlet.logging.CustomELFLogger;
import weblogic.servlet.logging.FormatStringBuffer;
import weblogic.servlet.logging.HttpAccountingInfo;

/* This example outputs the User-Agent field into a
custom field called MyCustomField
*/

public class MyCustomField implements CustomELFLogger{

public void logField(HttpAccountingInfo metrics,
FormatStringBuffer buff) {
buff.appendValueOrDash(metrics.getHeader("User-Agent"));
}

static {
System.out.println("HELLO!!!!! I am a custom efield logger being picked up!");
}
}

Friday, July 2, 2010

IPHONE!!!

I stood in line early in the morning, bleary eyed and with no caffeine. Still I made it to the front of the line and snagged an Iphone 4.
The initial impression has been a little disappointing. It is SLOW. I know its not the network- well at least not obviously so. There is a big latency in connecting to calls, there is a few seconds of silence before it starts ringing and also when I download apps it takes a very long time. I am going to the apple store to see if they can figure out what is wrong. I hope they fix it, I want to set it up and get ORGANIZED!!!

Saturday, July 14, 2007

Identify the manufacturer of a NIC

Enter the first 6 nibbles of the MAC address into the IEEE public registry of OUI or company_ids.

http://standards.ieee.org/regauth/oui/index.shtml

The cases where this wont work:
* If its a locally administered address, as evidenced by the 41st bit of the 48 bit MAC
* Its not spoofed and set to something else on the card
* is some reserved number such as 01:00:5e, which is meant for multicast addressing

All in all an interesting exercise...

Saturday, August 12, 2006

Sharing common libraries in Java EE

It has always been a bit of an annoyance to share libraries across applications in j2ee applications, involving mucking around with class-path in Manifest.mf files and restrictions etc.,
but with Java EE 5, it has been made easier.

If you want to share common classes and jars it can be put into an ear level directory.

By default this directory is called lib, but if you want a custom name for this directory you can specify it in meta-inf/application.xml, which is really optional for jee5 on
common

The ear level classloader picks up classes from this directory and can be accessed by all the webapps of that ear.

Quoting from the http://java.sun.com/xml/ns/javaee/application_5.xsd schema,

The library-directory element specifies the pathname
of a directory within the application package, relative
to the top level of the application package. All files
named "*.jar" in this directory must be made available
in the class path of all components included in this
application package. If this element isn't specified,
the directory named "lib" is searched. An empty element
may be used to disable searching.

The important thing is that the classes have to be in jars. All jars from lib directory will be automatically loaded.

You can also specify the jars to be loaded shared, via the tag in the application.xml