Win a copy of Terraform in Action this week in the Cloud forum!

Ivan Leon

Greenhorn
+ Follow
since Jun 15, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ivan Leon

Hello everyone!

I'm having a problems regarding HTTP connections using SSL, using a self-signed certificate.

The subject is about Android, but I believe that I can find a very good answer here (JavaRanch), although there will be some caveats of Android that I have to keep in mind.

Many articles and topics from forums and blogs, instruct about creating an SSLSocket factory, and set it on the HttpsURLConnection before making connections. But until I just have found pieces of codes (the IntellJ IDE is always complaining: cannot resolve symbol...), and nothing complete.

Does anyone have a COMPLETE EXAMPLE (no missing parts) in Java (JSSE javax.net.ssl.*), about creating a SSLSocket factory for a self-signed certificate, accepting just my certificate, and finally, being able to perform HTTPS requests to my server?

P.S.: I have exported the certificate of my server and created a truststore .BKS.

Any help would be much appreciated.

Thank you very much!
That makes sense.

I'm not a Python expert but, I believe that for this approach, in order to keep specific libraries and their versions for a web app, it must be used the Virtual Env, which performs a kind of "chroot" for your application, totally isolating the app from the rest of the system.

I do believe that in Python, importing modules and libraries is much easier and straightforward, but maybe Java is more organized and correct about keeping the libraries in just one place, avoiding issues regarding library versions... ;)
5 years ago

I don't know about the Eclipse but, I went through the same problem, and one thing that I saw here during my searches for the answer, is that, in some cases, you have to throw an Exception in your method, or put a try/catch around your if/else, and here is the reason (taken from StackOverflow):

"Unchecked exceptions are those that extend RuntimeException class. Compiler will never force you to catch such exception or force you to declare it in the method using throws keyword. All other exception types (that do not extend RuntimeException) are checked and therefore must be declared to be thrown and/or catched."

The rule of thumb here is: for any exception (except RuntimeException), you must consider the usage of "throws Exception" or "try/catch". It depends on you.

Without a "try/catch" or "throw Exception", this could happen at Eclipse, for example:

"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
at FileReader.main(FileReader.java:10)"


Considering that the possible exception that can occur from trying to create a file is "IOException", the rule above applies to this scenario

Here is a code which I used "throw Excepetion":



Regards
Ivan Leon
@ivanleoncz
5 years ago

I know how it feels.. when I got the LPIC-1 certification, it's a pretty good feeling !

I don't know you but, congrats man !
5 years ago
I got no words. Both answers helped me.

I specified the .JAR and IT WORKED: $ javac -cp /usr/share/java/json-20160212.jar JsonParser.java

Thank you, guys!
Thank you, Code Ranch!

------------------------------------------------------
A brief (parentheses) here, just for reflection.

* In my opinion, Java Compiler could be more objective, not so trick, about this sort of situation.
Look at Google, and you will find thousands of Java developers (from beginners to not so beginners), having problems with this..
Thinking about Python: how many issues can you find in Google about module import, in comparison with Java.
For me that means something: maybe the approach of Java about compiling, could be revisited.


5 years ago
Hi guys! My first post here!

I downloaded the JSON library for Java from Maven Repo and installed the .JAR file at the Java library directory on UBuntu 14.04.
I tried compile a simple JAVA snippet for JSON parsing, but the compiler (javac) is telling me that the "org.json" library does not exist..

Here are some details:

$ echo $CLASSPATH
/usr/share/java

$ ll /usr/share/java/json*
-rw-r--r-- 1 root root 49176 Jun 12 22:31 /usr/share/java/json-20160212.jar

$ jar tf /usr/share/java/json-20160212.jar
META-INF/MANIFEST.MF
META-INF/
META-INF/maven/
META-INF/maven/org.json/
META-INF/maven/org.json/json/
META-INF/maven/org.json/json/pom.properties
META-INF/maven/org.json/json/pom.xml
org/
org/json/
org/json/CDL.class
org/json/Cookie.class
org/json/CookieList.class
org/json/HTTP.class
org/json/HTTPTokener.class
org/json/JSONArray.class
org/json/JSONException.class
org/json/JSONML.class
org/json/JSONObject$1.class
org/json/JSONObject$Null.class
org/json/JSONObject.class
org/json/JSONString.class
org/json/JSONStringer.class
org/json/JSONTokener.class
org/json/JSONWriter.class
org/json/Property.class
org/json/XML.class
org/json/XMLTokener.class

$ javac JsonParser.java
JsonParser.java:1: error: package org.json does not exist
import org.json.*;
^
1 error


** Please, forgive my ignorance but.. what is missing? I came from Python, where the import and code execution are pretty straightforward.

Thank you so much!

Kind Regards
5 years ago