when(...) thenReturn(...) makes a real method call just before it is mocked. So if the called method throws an Exception you have to deal with it / mock it etc. Of course you still get your result (what you define in thenReturn(...) )
doReturn(...) when(...) does not call the method at all.
Standard HTTP Headers
RFC 2616 Fielding, et al. - 14 Header Field Definitions
vi Quick Reference
Find Program running on a port
Sometimes you see errors like
How to find what's running/using that port
On Mac
lsof -i :80 # checks port 80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 42488 ut 6u IPv4 0x6ddd270 0t0 TCP *:gds_db (LISTEN)
Labels:
Mac,
Programming
Java - Read data from URL
Sample code snippet to read data from an HTTP(S) url.
public static void main(String[] args) throws Exception{ URL url = new URL("https://www.google.com"); URLConnection con = url.openConnection(); BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } If you are using https url, if you get the following error sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target It means that the certificate is not available. You may have to import the certificate to your JRE. Follow the below steps:
Subscribe to:
Posts (Atom)
|
|