java

Best Practices for defining PatternLayout when using Log4j SyslogAppender

For those who are developing applications that are under PCI scope, where the guidance suggests that you should store your application logs on another tier, remoting to a syslog server elsewhere feels like a best practice. The question becomes, what should the PatternLayout look like that best enables folks to review their logs at least...

Referencing JAXB jars - best practice

My first post, so go easy on me. I'm looking for advice on organising and referencing third party jars for use in my j2ee web application. The jars I need to organise and reference are the JWSDP-2.0 JAXB api jars. I'm using Eclipse and Tomcat 5.5. My web app exchanges XML with a web service, and therefore needs to do some XML marshall...

detect power interruption from J2ME app

I'm involved in yet another application . this time, it's about developing a J2ME application. the mobile the application will run on is going to be connected to an electrical socket . and whenever the mobile is unplugged (interruption of electrical energy supply in the battery), the application should detect it and do some custom acti...

Java Web Start Driven Installation

Hey all, I'm trying to figure out the best way to install my Java app on client computers. The main guideline here is that these clients are computer illiterates - so the less fuss the better. I was thinking of using a model that would launch a Java Web Start app which would both take care of the registration and installation processes...

Get battery status from J2ME

How can I get battery status through J2ME ? ...

Guaranteed cache hits when retrieving data

Problem setting Entities arrive for processing and are taken through a series of steps which operate on those entities and possibly on other, related, entities and generate some results; Some of the entities are required to be processed in real-time, without any database access; Currently the implementation simply looks up entities in ...

how to create a JSON object in action class of JAVA

I want to create a JSON object. I have tried the following myString=new JSONObject().put("JSON", sampleClass).toString(); but mystring gives me {"SampleClass@170f98"}. I also tried the following XStream xsStream=new XStream(new JsonHierarchicalStreamDriver()); SampleClass sampleClass=new SampleClass(userset.getId(),userset.getUser...

Threads in java

int iThreadCount = 1; iThreadCount = GHMTreadUtil.getHygThreadCount(); arrHygThread = new Thread[iThreadCount]; for(int iCount=0;iCount<iThreadCount;iCount++) { LogMgr.logDebugInfo("spawning the HYG Thread"+iCount,objDebug); Job1 objJob1=new Job1 (); Job2 objJob2 =new Job2 (); Thread objHygThread = new Thread(objJob1,ob...

pack:tag does not work in websphere

I find the pack:tag very cool. It minifies javascripts, CSS and other stuff thereby reducing the network payload. It works quite fine on Tomcat. But when I run it on Websphere AS 6.1, it does not work. There are no errors reported in the logs, but it simply does not work. Anyone pointers/tips would be great. ...

Is there a Java bytecode optimizer that removes useless gotos?

Problem: I have a method that compiles to over 8000 bytes of Java bytecode. HotSpot has a magic limit that makes the JIT not kick in for methods that exceed 8000 bytes. (Yes, it is reasonable to have a huge method. This is a tokenizer loop.) The method is in a library and I don't want to require users of the library to have to configure ...

Java BitTorrent library

Are there any decent BitTorrent libraries for Java? I need to program a simple torrent client, but it would be great if I didn't have to write everything from scratch. ...

Can HTMLUnit enter data in password fields?

My HTMLUnit tests are failing, and I've got a feeling it's because I'm entering a password using the setValueAttribute() method and that for some reason doesn't work. Any ideas? Am I supposed to pass HTMLUnit the encrypted form of the password? EDIT: The code to set the pass: loginForm.getInputByName("loginPassword").setValueAttribute...

How do I access a config file inside the jar?

I'm using FlatPack to parse and load data from flat files. This requires loading a config file that stores mappings of the columns of the flat file. I have a constant to define the location of the mapping file: private static final String MAPPING_FILE = "src/com/company/config/Maping.pzmap.xml"; I have a parse(File dataFile) method ...

Does Java support variable variables?

Such as in PHP: <?php $a = 'hello'; $$a = 'world'; echo $hello; // Prints out "world" ?> I need to create an unknown number of HashMaps on the fly (which are each placed into an arraylist). Please say if there's an easier or more Java-centric way. Thanks. ...

Supplying credentials safely to a RESTFUL API

Hello, I've created a RESTful server app that sits and services requests at useful URLs such as www.site.com/get/someinfo. It's built in Spring. However, these accesses are password protected. I'm now building a client app that will connect to this RESTful app and request data via a URL. How can I pass the credentials across? Currently...

How to update the UserPrincipal with a new role without logging out and in?

Hi all, I am using form based authentication with tomcat. In a certain point in my site I allow the user to decide whether they want to add a role to their account. i.e. a user can decide to be an administrator as well. This request results in a new database entry. Now, in the site I show or hide certain links depending to what roles t...

PreparedStatement caching in Tomcat

I am looking for a way to achieve PreparedStatement caching, so as to save recreating the PreparedStatement objects for queries that were already executed in the past. Is there some built in way to achieve this using Tomcat? Or must I program this cache myself? ...

Visitor pattern implementation in java- How does this look?

Alrite, I am gonna jump straight to the code: public interface Visitor { public void visitInventory(); public void visitMaxCount(); public void visitCountry(); public void visitSomethingElse(); public void complete(); //the idea of this visitor is that when a validator would visit it, it would validate data //when a persister visits i...

Tomcat 6 freezes at startup

When I start tomcat 6 it freezes in certain point of the startup and stays there forever (I've waited 3 hours and nothing happened - not even an out of memory error). I don't have any clue of what could cause a behavior like that. I'm runnig tomcat with Jira and Confluence, and the problem seem to be when tomcat tries to load confluence...

Why does my servlet stacktrace show "Unknown Source" for my classes?

I'm currently using Apache Tomcat 5.5.16 to serve a Lucene-based search API. Lately I've been having some NullPointerExceptions inside my servlet class. The class is called com.my_company.search.servlet.SearchServlet. With certain types of input I can routinely create a NullPointerException, but I'm having trouble figuring out where e...