java

What is the best free plugin for Eclipse that allows for formatting/indenting/cleanup of JSP code?

I know that IntelliJ has an option to select all the code in a JSP file, right click, and select "format". This nicely formats all HTML, CSS, scriptlets and JSTL tags in a JSP file. Can Eclipse do this? If not, what is the best free Eclipse plugin that does the same? ...

How to map multiple records using SqlMap in Ibatis

I am just getting into ibatis with SqlMap for the first time and I have run into a problem. I have figured out how to insert, delete, update, and select single records. Now however I am trying to write a select statement that will bring back more than a single record and I am getting mapping errors. How do I specify that the result sh...

Custom Error Pages in JBoss

Hey all, This is my first question here! I'm trying to setup custom error pages in my JBoss RESTful web service. I'm starting with the 400 error, so in my web.xml I've added <error-page> <error-code>400</error-code> <location>/400.html</location> </error-page> and I've placed 400.html at the root of my war file (I've also tried pl...

How to convert string result of enum with overridden toString() back to enum?

Given the following java enum: public enum AgeRange { A18TO23 { public String toString() { return "18 - 23"; } }, A24TO29 { public String toString() { return "24 - 29"; } }, A30TO35 { public String toString() { return "30 - 35"; } }, } Is th...

Corrupt form data: premature ending (Resolved)

I am trying to upload files using the FileReference class. Files >2MB all work correctly but files <2MB cause this error: "java.io.IOException: Corrupt form data: premature ending" On the server I am using the com.oreilly.servlet package to handle the request. I have used this package many times to successfully handle file uploads from...

Getting Invalid Address with javax.mail when the addresses are fine

Hi All, I'm using the javax.mail system, and having problems with "Invalid Address" exceptions. Here's the basics of the code: // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", m_sending_host); // Get session Session session = Session.getDefaultInstance(props, ...

Given a Java InputStream, how can I determine the current offset in the stream?

I'd like something like a generic, re-usable getPosition() method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources. Does such a beast exist? If not, c...

How can I wrap a method so that I can kill its execution if it exceeds a specified timeout?

I have a method that I would like to call. However, I'm looking for a clean, simple way to kill it or force it to return if it is taking too long to execute. I'm using Java. to illusrate: logger.info("sequentially executing all batches..."); for (TestExecutor executor : builder.getExecutors()) { logger.info("executing batch....

Convert a string to GregorianCalendar.

I have a string from an email header, like Date: Mon, 27 Oct 2008 08:33:29 -0700. What I need is an instance of GregorianCalendar, that will represent the same moment. As easy as that -- how do I do it? And for the fastest ones -- this is not going to work properly: SimpleDateFormat format = ... // whatever you want Date date = format....

Patterns : Java class conversion from axis objects.

I use a axis to auto-generate webservice artifacts which I then convert into objects used within our application. Is there a sensible pattern for doing this ? We have written transform methods to output our objects from the axis created objects, at other times we have written an intermediate set of transformer classes that transform the ...

Removing HTML from a Java String

Is there a good way to remove HTML from a Java string? A simple regex like replaceAll("\\<.*?>","") will work, but things like &amp; wont be converted correctly and non-HTML between the two angle brackets will be removed (ie the .*? in the regex will disappear). ...

Regex to find static (non final) variables

I am trying to do a search in my Eclipse (Java) workspace to find all instances of static variables that are not final. I tried various regex's but they do not result in any matches. Can someone suggest a regex that will match all lines containing 'static' and not containing 'final', and not ending in a '{' The last part about not endi...

Download xml.gz file with HttpsURLConnection

Hello. I am trying to download an xml.gz file from a remote server with HttpsURLConnection in java, but I am getting an empty response. Here is a sample of my code: URL server = new URL("https://www.myurl.com/path/sample_file.xml.gz"); HttpsURLConnection connection = (HttpsURLConnection)server.openConnection(); connection.connect(); ...

Making a custom Sin() function in Java

I have to create the sin function from scratch in my Comp Sci class, and I think I got it down. But it still has some problems. If I put in a value of .5PI or less it works. Otherwise it doesn't. Any help would be greatly appreciated. double i=1; double sinSoFar = 0; int term = 1; while(i >= .000001) { i = pow(-1, term + 1) * pow(sinOf...

Mandatory cloneable interface in Java

Hi everybody, I'm having a small problem in Java. I have an interface called Modifiable. Objects implementing this interface are Modifiable. I also have a ModifyCommand class (with the Command pattern) that receive two Modifiable objects (to swap them in a list further on - that's not my question, I designed that solution already). Th...

autoboxing and performance

I have an application where I perform hundreds of thousands of calculations. Currently all of our values are Doubles. I am utilizing JFormula engine for most of the calculations, and have noticed the api takes a double parameter, so there is some autoboxing taking place when I pass in a Double. I have read some articles, and created s...

How to get a value from the last inserted row?

Is there some way to get a value from the last inserted row? I am inserting a row where the PK will automatically increase, and I would like to get this PK. Only the PK is guaranteed to be unique in the table. I am using Java with a JDBC and PostgreSQL. ...

How to remotely shutdown a Java RMI Server

I have a very simple Java RMI Server that looks like the following: import java.rmi.*; import java.rmi.server.*; public class CalculatorImpl extends UnicastRemoteObject implements Calculator { private String mServerName; public CalculatorImpl(String serverName) throws RemoteException { ...

What do curly braces by themselves mean in java?

for example, I have the following code (generated, not written) if(node.getId() != null) { node.getId().apply(this); } { List<PExp> copy = new ArrayList<PExp>(node.getArgs()); for(PExp e : copy) { e.apply(this); } } outAMethodExp(node); What do those extra curly...

How to nest Spring JMS MessageConverters

I'd like to write a MessageConverter class that can wrap another MessageConverter. This MessageConverter would call the child converter, which is assumed to generate a TextMessage. It would take the payload and GZIP compress it, creating a BytesMessage which is ultimately returned to the sender. The problem is in writing fromMessage(). ...