marten koomen

Ranch Hand
+ Follow
since Feb 03, 2007
Merit badge: grant badges
For More
Melbourne, Victoria, Australia
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by marten koomen

Thanks! a huge conceptual error fixed, my environment is now working swimmingly. I wasn't getting System.out.println output in my console before, and now that's functioning.  Onwards and upwards.
4 months ago
Thanks Tim -  another case of a novice blaming the tools.

I checked the TOMCAT_HOME\lib folder and it had a newer version of the postgres driver than declared in the pom.xml and in the development lib folder. Once I updated my pom.xml to reflect the newer driver, as well as delete older drivers from my system, things started to work as expected.

Having said that, it took a bit to expunge the outdated driver as it kept popping up in places, that Netbeans deploys tomcat apps from an \.m2 folder in my windows/users folder is annoying, and I had to restart my machine to ensure everything was good after some search and destroy missions.

Debug is now working fine, and from trial and error I can report that my set up does not work if  the localDataSource="true" element is not in the Realm element, but the antiJARLocking element is redundant.
4 months ago
I use " java:/comp/env/foo/bar"  in the java code, as in


but not in in my context.xml in the Realm descriptor for the dataSourceName where I just use foo/bar, when I do use java:/comp/env/foo/bar it doesn't work according to my trial and error method.

However I'm not sure that Netbeans isn't the culprit (apols for double negative). In Netbeans the database connection and authentication realm work well when I Run my app, but when I try Debug it hangs then finishes with the message below.

------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time:  2.000 s
Finished at: 2024-09-22T19:51:43+10:00
------------------------------------------------------------------------
Deploying on Apache Tomcat or TomEE
   profile mode: false
   debug mode: true
   force redeploy: true
Checking data source definitions for missing JDBC drivers...
Stopping Tomcat process...
Waiting for Tomcat...
Stopping of Tomcat failed.



It seems to be having trouble picking up the drivers. Not having Debug is not a totally bad thing, as it forces me to code without mistakes.
4 months ago
Thanks Tim, very generous with an undeserved cow, as I'm not sure what solved it, but as you suggest I think it had something to do with JINDI, and I suspect it's a Netbeans  things.

I found the following line in the localhost log in Tomcat's log folder
SEVERE: Exception performing authentication
javax.naming.NameNotFoundException: Name [jdbc/...] is not bound in this Context. Unable to find [jdbc].


which I thought strange because a servlet in the same context was able to access the database with the same details. So I added antiJARLocking in the Context tag in the context xml as per below. I found it somewhere, it's bit mysterious but it makes sense.  I'm not sure what the solution was - the antilocking or the localDataSource

4 months ago
Thanks Tim

I did a bit of deep dive into the logging functionality, and while not much of what I did made sense, login is now working, with the only thing effectively change I made was to add the localDateSource value in the Realm, as per below.



on well, all fixed, thanks
5 months ago
Hi

I'm hoping to get some help on how to debug failing to login using the DataSourceRealm, my context.xml and web.xml are below.
  • I've tested the database connection, that's working, and I can return usernames and passwords through that connection
  • I've tried turning the form-error-page off, but tomcat doesn't provide any futher details on why it's failing
  • I've tried to look in the log file, but the catalina log is telling me WARNING [http-nio-8080-exec-440] org.apache.tomcat.util.digester.SetPropertiesRule.begin Match [Context/Realm] failed to set property [debug] to [99]


  • I've been poking around all day, but haven't be able to make any progress, and tips would be welcomed.

    Thanks

    Marten

    note the userTable and userRoleTable are the same because a user can only be in one role in this application.





    5 months ago
    Thanks again, this advice has been so helpful. I can see that war file in the target directory as you  Next learning goal for me is to figure out how Netbeans interacts with Maven and Tomcat, and I'll read up a bit more on that.
    Cheers
    Marten
    5 months ago
    Thanks Tim!

    All solved for the time being, but it was a painful learning curve, and I'm not sure what actually fixed it.

    Key candidate for the solution was changing plug in versions in the pom.xml to
  • maven-compiler-plugin -> 3.10.1
  • maven-war-plugin -> 3.3.2

  • courtesy stack overflow post

    I also encountered issues when
  • trying to figure it out using the Windows command line, I needed to put all parameters in quotes (this was not stated in my book)
  • the 2008 book I have is out of date, as it shows starting a project using archetypes:create rather than archetypes:generate
  • given I had started using jakarta, the pom was getting confused with some javax plugins, and removing reference to javax fixed an exception in tomcat the output.


  • I'm too skeptical of the 'endorsed' things, particularly as for me System.getProperty("java.endorsed.dirs") returns null. I don't think I need it therefore I'll try and remove reference to the endorsed directory in the POM, and now that I have Netbeans, Java, Tomcat, Git/GitHum, PostGres and Maven all talking to each I feel a bit more confident to play around. I'm still not sure how Maven moves things around.

    Thanks again for your help.

    FYI - I removed references to the endorsed folder, and all still works. My working POM is below.


    5 months ago
    I can't get Netbeans to 'Clean and Build' or 'Build', I get the same error, so deployment is not the current issue, the POM is not making the war

    There seems to be an issue with org.apache.maven.plugins

    the error states

    Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war)



    the POM includes


    The book said I'd develop and interest in plugins, I suppose it starts here. I have a look around, any clues would be welcome.
    5 months ago
    Thanks, below is the POM.xml, it's all straight out of the Netbeans box, including the servlet. The only thing I have changed in the POM is set the source and target to 22, I'm finding it difficult to decipher the messages.


    5 months ago
    Thanks Stephan and Tim

    So I've started again in Maven, and started reading its definitive guide from 2008 which I happened to have found on my bookshelf. Maven does sound like the better idea for me, however, I can't even get a simple servlet to run in Maven.

    Below is part of my output, of which lines 6-30 are in red.

    I had an earlier issue with source and target being version 7, where it needed to be 8 or higher, and this seemed fixed when I changed <source> and <target> to 22 for the compiler plugin in the pom.xml, as 22 matched my javac version.

    Any suggestions?

    Thanks







    5 months ago
    Thanks Stephan, given I'm in the early stages of my project rerun I'll start again in Maven and try and learn that, fingers crossed.
    5 months ago
    Apologies for this basic question, I'm just returning to Java after a number of years away from it.

    I have successfully installed a new suite of netbeans, java, tomcat, git and postgres on a new machine, and created a basic servlet app that 'Builds Successfully' and runs when I run it, but fails when I do a clean and build. I can't find any error messages? See below.

    Any suggestions appreciated, even how I might go about debugging.

    Thanks

    Marten



    5 months ago
    Thanks Stephan

    You need to remove the type parameter R from Resource, because you're not using it anywhere (except in the self-referential type bound on R itself). You must leave it on your Manager class, because you actually use it there.


    yes, carry over from my first prototype, don't know why I did it then.

    Don't use integers for IDs.


    I've changed the key to a String, Although I can't for the moment figure out how to abstract a Key into a class, will work on it.

    Don't expose fields. Sub-classes may access private fields though protected accessors.


    Will tidy up

    What Java version are you on?


    from eclipse -> C:/Program Files/Java/jdk1.8.0_102/jre/bin\server\jvm.dll

    Don't do database stuff from constructors. Constructors must be lightweight. Let factory methods retrieve properties from a database and make the constructor accept the properties you want to set.


    In principle I agree here, but for my first prototype I got into all sorts of problems abstracting out the database from the objects. In this design the only way a Resource object is instantiated is when it's read from the database, so it somehow makes sense to pass the Result Set into the constructor. But I'll contemplate this. This project is for a very relational domain, so the objects doing the work all represent complete rows in a database table. Also in my first prototype I got into all sorts of problems creating unmodifiable Resources and other objects containing Resource state. I got into a big mess. I'm trying to avoid that here by encapsulating everything in a manager.


    Instead of returning defensive copies from methods, return unmodifiable views


    will do, but for the moment I know my clients will want to sort a list and present it.

    What is a TTException?


    Probably not the best solution, but this is a custom made exception that I use to swallow exceptions thrown by database interactions etc along with a severity indicator. TTException is then thrown so that it can propagate to the dispatcher/controller Servlet can then decide what to do and how - e.g. terminate the session or inform the client that a transaction has not been completed.  I understand this is not ideal, but I don't know how else to treat database exceptions elegantly for the browser based client.

    Return an Optional from methods instead of null


    I've been working to Joshua Bloch's Item 54, to not return nulls but empty collections, I'll need to double check that.

    Use upper type bounds when accepting a collection from which to retrieve elements.


    Will do, I think I know what this means, it sounds similar Joshua Bloch Item 31, of using bounded wildcards, so I'm understanding accept a Collection when that will do, rather an List.

    I don't understand why Resource needs a reference to the Manager, as it is the Manager that initiates and coordinates mutations to the Resource along with informing any other involved resources. I'll need to get my head around this.


    5 years ago

    Thing's generic type parameter T is unused. Remove it.
    You have public and protected members in a package private class.
    Your constructors are redundant.
    ConcreteThingManager's name can be shortened to Manager, because ConcreteThing already provides a separate namespace for it.
    ConcreteThingManager's class header doesn't do what you think it does. Instead of using the class ConcreteThing, you introduced a new type variable named ConcreteThing.


    When I look at these concerns in my actual code where my Thing (hereafter called Resource) class is over 1000 lines long, I can't find a way of getting around the type headers. Below are some snippets from the actual code, now called Resource to avoid transcription errors.

    I trust this gives a flavour. I'm keen to get this right because my first subclass is also ~800 lines. The Resource class crosses the nexus of MC of my MVC, where client classes are responsible for generating the view.
    The code now looks great (from my perspective) without any warnings, and where type wildcards<?> make sense.

    So I've shorten the name to Manager, but when I play around with the Type headers Eclipse becomes a sea of red.

    Just using the word singleton should send shivers up your spine


    okay, I understand this (I think), thanks
    5 years ago