Christian Wansart

Ranch Hand
+ Follow
since Dec 31, 2015
Christian likes ...
Firefox Browser IntelliJ IDE Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christian Wansart

In my linked example the query may throw an exception. The other exceptions were examples from other projects I attended. Let's say we have a user who types in a wrong password, I used to check whether the password is correct or wrong and throw an exception. I would catch that in my resource class like I did with NoResultException.

So my issue is that the API kind of forces me to use Exceptions. I've learned to catch those and re-throw more meaningful exceptions and catch them in the resource.

@Carey Brown: so you use integers instead of exceptions to create handle different situations?
2 months ago
Thanks for all the interesting answers.

I prepared an example:

This is how I learned to deal with issues, like not finding elements in the database. In the Resource I catch the NoResultException.

In other projects we (me and other devs) threw a lot of Exceptions on services and repositores, like CustomerNotFoundException, WrongPasswordException, DefaultLanguageNotAvailableException which were caught on the resource to create error messages or default values.

After reading and thinking about those things, I'd say that's kind of flow-control. That is why I was wondering if this is a good idea.

2 months ago

I tried to find an answer online to find out, which performs better: Exception handling or using Optional instead? I have a real-world scenario from a Spring application:

Or using Exceptions:

After writing the code for Exceptions I thought that this is not a very good example. But just think of JavaEE instead where you don't just get Optional returned. This is not about the style itself, but rather on the performance, since I've heard people arguing Exceptions are better and some say Optionals are better.

Which ones may perform better?

Thanks and best regards
2 months ago
Okay, thank you for your recommendations. I'll try both solutions and then decide which I like most.
1 year ago
Yes, that is the issue.

I want it hidden because it should contain the access token of the bot. If I publish it to the git repository (e. g. GitHub) anybody can use it. So I need to make it somehow safe.
I am not sure how to add the token safely except for passing it as a program argument (args).

1 year ago

I am currently creating a little bot for Discord using Discord4j. It needs a token, but it should not be published to the git repository.

So I could create a properties file but put it on the ignore list. But I don't really like the idea not shipping files. Another way would be using a program argument, but this bot should run on a raspberry pi later on so I would need to put the token somewhere in a config file or so.

What do you recommend to do here? What is a good way to add properties but hide them from git?

Best regards,
1 year ago
Okay, but where does the property path come into account?

It doesn't matter if I add any propertyNode, in this example it will still read the message from the with the property name "my.custom.message".

I don't understand where the propertyNode does anything other than set a value. Where is it used?

I have this code:

According to the api the addPropertyNode method “Adds a property node to the path the ConstraintViolation will be associated to.
name describes a single property. In particular, dot (.) is not allowed.”

But whatever this value is, it still reads the my.custom.message from So, what does this do? When should I use it?

Thanks in advance.
I found something on StackOverflow:
He says, to use the JAX-RS annotations in the Boundary class. That's a way to go, I guess.
2 years ago
OK, perhaps my question is a bit bad expressed.

Let's take a Java EE application using the BCE pattern, we have:

  • So far I used JSF for the templates, so I created a posts.xhtml for the "/posts" url, but so far I cannot access it "RESTful". So here comes JAX-RS into play, to provide the RESTful urls.

    I am not sure if I should just show the html files through JAX-RS and don't provide any JSF files or if I should provide both and let JAX-RS return the data as needed through JAXB and create JSF pages to access.
    2 years ago
    I should add that Laravel is an model view controller framework like Ruby on Rails for php. You generate models, controllers and views. In the routes file you can define a controller as a resource, so the controller has to have methods for index, show, edit, destroy, update and post.

    So let's say I create a Posts controller, model and views I get the routes
  • /posts -- which lists all posts
    /posts/1 -- which lists the first post
    /posts/new -- which shows a form to create a post
    and so on...

  • This way you can browse through your entities. But with Java EE I'm not sure if this is the right way to go.

    I'm open for suggestions.

    (Sorry for double posting, there is no edit button...)
    2 years ago
    Hello there,

    I currently have a web application using the PHP framework Laravel. My models there have restful urls like:

  • [*]/categories
    [*]and so on...

  • Now I want to port this software to Java EE. But I'm not sure how to start.

    So, for the REST routes I would use JAX-RS, but what about the whole application behind the scenes, like the models? Should I just create JAX-RS routes to access/save/modify/destroy the data and use the BCE pattern for accessing the web site or should I just return the templates via JAX-RS? What is best practice here?

    Thank you in advance. :-)
    2 years ago

    paul wheaton wrote:The old view will be retired.

    This is a really good time to create a detailed list of desired changes for the new view.

    At present "new view" takes around 5x more time when compared to "old view" for loading in slow connections.

    That is possible.  In which case, we really need to figure that one out.   Any suggestions on what the cause might be?

    Okay, here you go. I think it would be great, if there was an easier overview for the categories and it's forums.

    Let's see what we have: 5 columns:
  • Categories -- which doesn't look like them. They look like some sort of advert or even settings. The focus in the new view is obviously in the center, where you have a higher contrast to the rest.
  • Best this year/month? You should add a side panel which contains stuff like that. Like WoltLab does it:
  • Most Recent is a nice feature for the front page. But you should seperate it from the Top Forums. You can use responsive grids which wrap if the screen is not wide enogh. Then it should move above or below the Most recent.

  • The categories on the left side are useful, but *please* provide a single page that solely contains them. I do like the idea of a portal as the front page, but a seperate categories page would make it much much easier. Like this:

    (Sorry for the WoltLab focus, it's a forum software I've used for years and I'm comfortable with )
    2 years ago

    I am trying to understand method injection. This is my code:

    I use Weld SE to use the injection in Java SE. But now I am stuck. How do I invoke this method? Is this even possible, or is a Java EE feature done by the Java EE server?

    Edit: It seems that it's not supposed to be done that way.

    2 years ago
    OK, thanks for the pointer. Now my classIndexer.getInterfaceFile(field.getType().getName()) method returns a ClassInfo (my own class that contains the name, path and file) instead of a File object. Now I can load my class files. Thanks!
    2 years ago