java

How to read response from Https urls ?

Hi I am using following code to retrieve response code from https based urls, but when i run a prog it just hangs cont. code: import java.net.; import javax.net.ssl.; import java.io.*; class Https2 { public static void main(String args[]) throws Exception { URL u = new URL("https://myurl"); HttpsURLConnection ...

How can I send a command to a running Java program?

I have a Java program and I want to send a command from my Win32 application. Normally I'd use WM_COPYDATA but what options do I have with Java? ...

Best way to mock java web service

I have to mock quite complicated java web service and I'm searching for the right solution. One way to do it would be to use Soap UI, but I need something that would be able to modify server state ie. one request would affect future requests. In this particular case it could be done quickly by saving serialized objects to disk and some...

Retrieving the inherited attribute names/values using Java Reflection

I've a Java object 'ChildObj' which is extended from 'ParentObj'. Now, if it is possible to retrieve all the attribute names and values of ChildObj, including the inherited attributes too, using Java reflection mechanism? Class.getFields gives me the array of public attributes, and Class.getDeclaredFields gives me the array of all field...

Most elegant way to generate prime numbers

What is the most elegant way to implement this function: ArrayList generatePrimes(int n) This function generates the first n primes (edit: where n>1), so generatePrimes(5) will return an ArrayList with {2, 3, 5, 7, 11}. (I'm doing this in C#, but I'm happy with a Java implementation - or any other similar language for that matter (so ...

Opening a password-protected website from servlet

Hi All, The scenario is intended user will access the servlet (e.g http://someip/myservlet) which in turn authenticates a password protected website (e.g. mysite.com - which is hosted on IIS server with Use Windows authentication enabled) implicitly and then opens that mysite.com – so that: target users will not get prompt for usernam...

How to run an external tool in Eclipse in debug mode

For various reasons my project can only be run as a finished and packaged JAR (some magic happens at assembly), so I run it as an external tool in Eclipse. What I'm missing is debugging functionality. Is there any way of running an external tool in debug mode in Eclipse? ...

org.xml.sax.SAXParseException: The character reference must end with the ';' delimiter. Workaround Needed

I am trying to use DOM Parser in Java to parse a small XML file I pull off the net from its uri but receive an error complaining about missing semicolon. Here's link 108: Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("url_to_the_xml_file.xml"); Here's the error: [Fatal Error] A01.xml:6:53: The charac...

Why can't JAXB find my jaxb.index when running inside Apache Felix?

It's right there, in the package that it should be indexing. Still, when I call JAXBContext jc = JAXBContext.newInstance("my.package.name"); I get a JAXBException saying that "my.package.name" doesnt contain ObjectFactory.class or jaxb.index although it does contain both. What does work, but isn't quite what I want, is JAXBCo...

Can someone explain the conversion from byte array to hex string?

I recently started looking at MD5 hashing (in Java) and while I've found algorithms and methods to help me accomplish that, I'm left wondering how it actually works. For one, I found the following from this URL: private static String convertToHex(byte[] data) { StringBuffer buf = new StringBuffer(); for (int i = 0; i < data.len...

Access Request object from REST

Is it possible to access the Request object in a REST method under JAX-RS? I just found out [@Context][1] Request request; ...

Print full call stack on printStackTrace()?

I need to write small a log analyzer application to process some log files generated by a 3rd party closed source library (having custom logger inside) used in my project. In case of an exception entry in the log I need to collect aggregated information about the methods involved along the stack trace from the top to the actual place o...

Hibernate dynamic instantiations with collections, is it possible?

I would like to write a hql query using a dynamic instantiation with a list as one of it's parameters. Simplified example: A HQL query with a dynamic instantiation: select new x.y.UserDto(u.name, u.contacts) from User u where u.xyz=:param1 ... and my dto class constructor is: public class UserDto { private String name; privat...

How tomcat is able to locate a class that is not part of any of the jars in app libs

In our application(applet) I want to enable export functionality if one of the required jars is found. I do not want to add this jar applet references to avoid download size. I am using Class.forName with one of the classed to check whether particular is available. In local machine Class.forName call retruns an instance although the jar...

How to test HQL queries?

I'm searching for a fast (really fast) way to test changes to hibernate queries. I have a huge application with thousands of different HQL queries (in XML files) and 100+ mapped classes and i dont want to redeploy the whole application to just test one tiny change to a query. How would a good setup look like to free me from redeployment...

Java IOException: No buffer space available while sending UDP packets on Linux

I have a third party component which tries to send too many UDP messages to too many separate addresses in a certain situation. This is a burst which happens when the software is started and the situation is temporary. I'm actually not sure is it the plain amount of the messages or the fact that each of them go to a separate IP address. ...

Failure to start program from java (using ProcessBuilder)

I am trying to call cleartool from an java application, but cleartool hangs even for a simple "-version" argument. Running cleardiff instead of cleartool works fine, so apparently there is something specific with the cleartool program (which I assume is related to its interactive capabilities). The following program import java.io.*; i...

Counting Line Numbers in Eclipse

I have a Java project in Eclipse with ~10 packages and ~10 class files per package. Is there a way to determine total lines of code for the whole project from within Eclipse? I am familiar with other tools (e.g., Code Analyzer, wc, etc.) but I want to know if there is a way to do this within Eclipse (or get confirmation that there is n...

Swing application problem

I'm developing Swing application, and everything works fine usually. But I have an GUI issue. When I run the application, and for example minimize some other window, my application is still working, but the central part of JFrame is invisible or hidden. After finishing some part of program logic the GUI repaints and is visible again. ...

In TestNG in @AfterMethod how can I know the test result?

Hi! I have a number of TestNG test classes that all extend one base class AbstractIntegrationTest. In the superclass I have a mehod commonAfterMethod which is invoked after each test method and performs some clean-up. What I want is to do in this method something depending on the test result, e.g. if the test fails, I want to dump the ...