Win a copy of Head First Android this week in the Android forum!

Raymond Holguin

Ranch Hand
+ Follow
since Aug 11, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
4
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 Raymond Holguin

In an attempt to debug this SSL issue that came up on one of our servers recently I wrote a very simple program to connect to an SSL site in our intranet.



This code fails with SSLHandshakeException on one of our servers, but the same exact code works without issue on another server. I ran the programs with SSL debugging enabled and here are results of each server

**WORKING SERVER - SLES 11.3, Java IBM 1.6.0 64-bit**



**NOT WORKING SERVER: Windows 7, Java JDK 1.6.0_39**



Does anyone have any ideas on what I can do to get this simple code working on my Windows 7 machine? I have been at this all day and pretty lost at this point. Thanks for any help!

Also, the URL for the server is accessible without issue when viewing from the web browser on both machines. It appears just when I try to connect over Java that I have issues.
7 years ago

Karthik Shiraly wrote:

When i run this code, c2.call() does not execute until c1.call() is completed.


I get the impression that you expect each of these call()s to spawn new threads. But that's not how the API is used.
In your current code, there is only *1* thread ever. In that thread, c1.call() puts that single thread to sleep for 5 seconds.
Only after 5 seconds have passed, the CPU starts executing anything further on this thread, which happens to be c2.call().
That's why c2.call() starts only after c1.call() is completed.

The correct way to spawn threads with Callable is using the Executors / ExecutorService class (see tutorial here)



Thanks, while you are correct that Executors are the way to go after doing some research on them...i believe you may incorrect about the single thread part. The only reason they were firing off sequentially is because I mistakenly had c1 sleep for 5 seconds. When i changed it to 1 second like I originally though I had it it worked identical to how my second example worked where I used Thread objects instead of Callable, which is what i was expecting. I think the Executors are just threadpool managers that make it easier to maintain the threads your running, but not a requirement to use Callables as a thread.
7 years ago
nevermind I'm an idiot. Copy and pasting error put my c1 and c2 at the same sleep delay so that was causing issues.
7 years ago
So my understanding is that Callable is just Runnable with some extra goodies, mainly the ability to return a result when completed. Now I have read that when you reference the callable.get() method, the execution of the calling thread will wait until the result is available. The issue is that even though I don't use the get() method, my program still seems to be waiting for completion before continuing on.



When i run this code, c2.call() does not execute until c1.call() is completed. I don't understand why this is happening, it should not be waiting for anything. Seems to defeat the purpose of a concurrent process when they actually run sequentially.

Using the same example but with Runnable's, it executes as expected



I get overlapping output messages and everything is great...but not when using Callable. any ideas?
7 years ago
well everyone has there own way of learning, you can stick with yours and ill stick with mine. I believe the pro's outweigh the con's, but again that was just my learning experience.
7 years ago
It appears your not using an IDE otherwise it would be screaming at you with the errors in your code as well as how to fix them (most IDE's at least). Similar to how your importing the class import java.util.Scanner; you also need to import Calculate and any other class you wish to use inside that particular class. I would suggest using some sort of IDE instead of a text editor, especially for beginners.
7 years ago
As yourself mentioned, there is a general lack of knowledge in regards to variable scope and object oriented programming expressed here. As mentioned above, we don't flat out fix your code but I can offer some general ideas

1) Those 3 classes are not tied together or related to each other in any way, they are there own separate entity. That being the case, declaring a variable in 1 class does not allow you to call that variable in another class.
2) If you want to access another variable or class instance from the method/function of another class, then you need to pass that data via the method parameters.
3) As mentioned, you don't need/want to declare an instance of your class inside your class...there is no need. For example, you don't need to declare an instance of Calculate inside the Calculate class in order to call c.setNums(total) from the addition method. You can delete the instance declaration and simply call setNums(total)
4) You really want to declare you class instances in your main and then go from there, passing the data around and such.

Hope that gets you going in the right direction.
7 years ago
I have a one-many relationship that when i access via the POJO Set, it is missing data. If i directly query for the Set then all the data is retrieved propertly.



The StudentCourses Set in the StudentUser POJO is always missing the same rows, so its not randomly choosing rows to remove. Most, but not all of the StudentUser's experience this behavior.

As mentioned, a direct query works as shows here vs the incorrect data method



So there is something with the relationship in the mapping file because the data is there and is correctly displayed when i query the StudentCourses table directly. This is a huge database yet this is the only table/relationship that is experiencing this type of issue, so I really have no clue what the problem is as all the data looks correct.

I am using Hibernate 3.5.3. Sorry if i have not provided enough info, but since I'm so lost on this issue I don't know where to start or whats important to talk about. Please ask for whatever information you may need to assist me.

Thanks!

If it helps, here is the mapping for the StudentCourses table

I have a client-server type of application. My dilemma is trying to figure out how to access the server data from the client application. I have read about the con's of using JDBC connections in the client in that you hardcode credentials, you have to expose your server DB to the public, etc.

My environment has it such that this application will only be deployed at certain computers, so its not a situation where anyone in the world will be downloading this app. Though those specific computers could be potentially used by all sorts of people. So at the firewall level and DB level I can only allow access to those specific IP's (Yes I know IP's can be spoofed). So for me, a work around would that I could use JDBC, but just limit the access that user account has at the DB level by explicitly specifying read/write access to the various tables.

The other options is to have some webservices at the server level and the client can just call those services to read/write data. My issue is that I don't necessarily see a difference in security, since I am still going to have to hardcode some sort of credentials into the client to authenticate access to the web service. So if anyone tries to breakdown the code they will be able to access my webservice read/write calls. So I appear to be back at square one.

For me I am not sure I see a difference in one method being better/worse than the other security wise. At the end of the day I am still hard coding some login credentials that can potentially be compromised. Implementation wise, JDBC would be easier I think so I don't have to build the whole web service infrastructure. Can anyone give me some more insight about this topic and perhaps fill me in on some issues I may be overlooking?
7 years ago
Ok this topic can be closed. Turns out its a load balanced LDAP server so depending on when i ran my app i was getting different servers which i didn't have the certificates installed for. Stupid....
7 years ago
While this isn't resolved, I realized I am using the Eclipse built-in JDK so maybe there is some refreshing or something happening that is invalidating the cacerts file. So I just switched to a JDK i have installed on my system to see if that fixes it somehow.

Had no effect, issue still persists...fml
7 years ago
So I am using the InstallCert.java file from http://nodsw.com/blog/leeland/2006/12/06-no-more-unable-find-valid-certification-path-requested-target to grab the certs from a SSL enabled server so i can connect via LDAP. The issue is that when i run the program, it generates the jssecacerts file just fine. I copy that to my JAVA_HOME security folder and I am able to connect great, everything works. Then after about 20 minutes it doesn't work anymore and i start getting this execption again



So if I re-copy the same exact cacerts file from before back into my security folder and it works...but again it seems to expire after a few minutes and I get the exceptions again. I am not changing or modifying anything that would cause it to not work. I am literally leaving the computer and coming back to find it no longer works and I need to reinstall.

I have tried adding this to my code to expllicity point to the certs file but i get a "the trustAnchors parameter must be non-empty]" exception which from what i have read means it cannot find the file


*NOTE that using the "javax.net.ssl.trustStore" doesn't work no matter when i try using it, i always get the same error.


what could be the problem?
7 years ago
Just for an update on this situation. I messed around a bit with the web start and certificates and you can indeed bypass the security warning. What I did was import the certificate that i signed my JAR file with into the "Signer CA" trusted certificates via the Java control panel. The first time I ran my app it gave a prompt if i Always wanted to trust apps from this cert. i said yes, and I don't get prompted anymore. If the user is prompted once every time i update the cert every couple years, I believe this will be acceptable for us.
7 years ago
While the previous posters are absolutely correct about using the Calendar class to do that for you, might I suggest instead of using the built-in Calendar class maybe take a look at a third party calendar library called Joda Time. I have personally found it more useful and easier to use than Calendar class for many situations.
7 years ago