James Adams

Ranch Hand
+ Follow
since Sep 12, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by James Adams

Thanks, Rob. I don't see a way in either library to set the protocol level that the client instance should use, however both of these libraries support SSL 2.0 so I don't think that that is the issue. In any event I've resorted to a brute force approach running ssh and scp commands using Runtime.exec() in order to move on and get some work done. It's not elegant but it's working fine for now.

--James
I have written two methods for issuing an ssh command -- one using jsch version 0.1.31 and another using j2ssh-core version 0.2.9 -- and neither of them get past the connect step so I assume it's not an authentication problem since I don't even get to that step. With the code which uses the jsch library I get a JSchException: Algorithm negotiation fail, and with the code which uses the sshtools library I get an IOException: Socket is EOF. I have no clue as to what either of these exceptions indicate, and have found nothing so far using Google, amiling list archives, etc. However if I try the same ssh command at command line I have no errors. So it seems that my error is somehow related to running the Java code and not with the ssh configuration, but I'm not certain and hoping that someone reading this can guide me to a way of determining whether or not that's the case, and if so how to fix things.

When I run 'ssh -V' on both the local machine where I am running my Java codes as well as on the remote machine where I am trying to run the ssh commands I get the following result:

Sun_SSH_1.3, SSH protocols 1.5/2.0, OpenSSL 0x0090801f

Is there a way to determine whether or not this version of OpenSSL is compatible with either or both of the ssh libraries I'm using for this task?

Below are snippets of the code I have written -- I think they're OK but maybe I've done something wrong at the Java level and if so then please point it out to me:



Thanks in advance for any suggestions or ideas.

--James
Thanks, Rob, for the suggestion of making Worker.exit volatile, good catch.

--James
15 years ago
Thanks Paul and Rob. The referenced JavaWorld article was helpful in that 1) I think it shows that you should always consume the output and error streams from the command whether or not you want them displayed, 2) it provides a good "StreamGobbler" class for consuming and displaying the output and error streams, and 3) it gives some good code examples on how to handle Windows commands (although I'm not planning to run my code on Windows, it's good to realize that this approach is not platform independent and should be coded accordingly). One thing I discovered as a result of tackling this problem is that the destroy() method is deprecated and was probably never even implemented, so I ended up not trying the approach described by Rob (but thanks for the suggestions nevertheless!).

What I did end up doing is described in the crosspost over on Stack Overflow: http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec

In summary I used a worker thread which executes the command and to which I join my thread for the timeout period. If the worker thread completes within the timeout period then I return the result code, otherwise I assume that it has timed out.

--James

15 years ago


I have a method I am using to execute a command on the local host. I'd like to add a timeout parameter to the method so that if the command being called doesn't finish in a reasonable amount of time the method will return with an error code. Here's what it looks like so far, without the ability to timeout:


Can anyone suggest a good way for me to implement a timeout parameter?

Thanks in advance for any suggestions!

--James
15 years ago
I have started working on a new application which uses Spring and Hibernate for the data layer. I want to enforce business rules on my entity objects before they are saved in order to ensure that my database stays free of invalid data. On a previous project I worked on (different employer so I can't reuse the code) there was a mechanism in place in which you could write business rules for entity objects and before an entity object was saved, updated, or deleted it was checked against the applicable business rules before the operation was allowed to proceed. This business rule processing system was not trivial and I'm afraid that I'm not up to the task of writing such a system myself so I'm hoping that something exists which will do this for me. (I'm not even sure what the term for such a system would be, which makes it difficult to find something appropriate using Google!)

As an example of what I'm talking about let's say I have an entity class representing a machine on a network, and one of its fields is a String for the machine's IP address. What I'd like to have is a business rule that is run against the entity before it is saved or updated which checks the IP address field to make sure that it's a valid IP address. So if I create a new machine entity and give the IP address field a value of "345.4567.2.35" then a save would fail since the IP address field is not in a valid IP address format.

Can anyone suggest the best practice for handling this sort of problem? Are there any open source solutions available that I could take advantage of or will I have to cook up something myself? Thanks in advance for any suggestions!

--James
Thanks Jeanne. At first I was thinking that it's a bad thing to mix the meaning of an override and an implementation into a single annotation, but I can get used to it. I'm starting to see how it's helpful to have @Override on a method which implements a method from the classes' interface, since if the method is removed from the interface then you will get a warning or error from the IDE telling you that the method is no longer an implementation of an interface method. Without the @Override annotation you could remove the method from the interface and still have the implementation hanging around in the class where it probably is never used, and if it is you have to remove the @Override, making you pay a little more attention to what you're doing.

--James
15 years ago
Thanks for your suggestion Javid. I have implemented a solution which takes this approach and it's working well. I appreciate your help!

--James
I want to keep a counter in a database which I can use for computing a value in my Java code. Each time I use the counter value I want to have it auto-incremented, that way if another thread reads the counter value it will be sure to be unique. I want to use Hibernate to do this, but it's not obvious to me how I would go about setting it up. Can anyone give me some suggestions on how I would go about it?

My first thoughts are to have an entity class which has a single field "counter", and a corresponding DAO class which has a single method getCounterValue() which will return the current counter value which will be incremented in the corresponding table. Does this seem reasonable?

Thanks in advance for any suggestions.

--James
I usually add @Override to methods which override super class methods since Eclipse issues a warning about its absence. It seems like a reasonable thing to have in place and I've always assumed that if Eclipse warns about its absence then it must have some good reason for being there. I like it because its a good indicator right in the code which eliminates me having to look into super classes to see if there is another method implementation. However I have recently become aware that in Java 1.6 it no longer has the original meaning of "this method overrides a method already implemented in a super class" (at least that was always my understanding), and now I've read somewhere that it has additional meanings attached to it related to the method being an implementation of a method from the interface (it seems like an @Implementation annotation or something similar would be more accurate in this case), but it's not clear from the API what the actual updated meaning of @Override really is.

What made me start thinking about this is that NetBeans will expect @Override on any method which implements a method declared in the interface of the class, and in my opinion that's not an override but a normal implementation which shouldn't take an @Override. Eclipse doesn't seem to do this, and only warns you when a truly overriding method is not annotated as such, which is what I expect. Of course you can eliminate the warnings about @Override altogether but I like the warnings since I want to have the annotations in my code, I just want to be using them correctly.

Does anyone know more about this than I do? Please enlighten me if so. Thanks in advance for your insight!

--James
15 years ago
My troubles went away once I added the below CascadeType setting to the collection field:

@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)

I hope this helps someone facing this issue in the future.

--James
This new forum software is really nice. Hats off to you guys, I know it must have taken lots of work. Kudos!

--James
15 years ago
I think I may have the answer, which I'll confirm tomorrow once I'm back at work -- I think I was mistaken in my thinking that CascadeType.PERSIST works for any operation that persists an entity, such as a save() call, but it probably only cascades the effect of calling persist(). The CascadeType I need to be using is Hibernate's CascadeType.SAVE_UPDATE, which will cascade the effects of calling save() or saveOrUpdate(). I'll follow up this post with my findings...

--James
I have an entity class A with a one-to-many relationship to another entity class B. The column which specifies this relationship specifies CascadeType.PERSIST and CascadeType.MERGE. My understanding was that if I create a new object of type A, create a new object of type B, and insert the object B into object A then when I save object A I will also have object saved as well by virtue of having configured cascading save for the object B collection field within A.

For example:



So if I have some code which does something like this:



then I am expecting for both a and b to be persisted since cascading saves have been configured on A's bList field. However this isn't happening, I get an exception from Hibernate telling me that I need to first save the transient instance of B:



Can anyone explain why this happens and why I am mistaken? Obviously I have misunderstood how cascading saves are supposed to work, or how to configure it correctly, etc.

Thanks in advance for any suggestions!

--James