Cedric Bosch

Ranch Hand
+ Follow
since Nov 15, 2013
Cows and Likes
Cows
Total received
5
In last 30 days
0
Total given
0
Likes
Total received
11
Received in last 30 days
0
Total given
8
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Cedric Bosch

Would LocalTime.now(ZoneId.of("GMT")).getMinute() yield the same result in different applications ?

I would like to store online members on redis. To do so I create a set with a key like this : "online_members:minute", where minute is the minute the server is at. When User A wants to know if one of his friend is online at 15:04, I can go in the set "online_users:04" and check if his friend ID is in there. The potential problem with this is that if I have two instances of the server accessing the database and those instances are not geographically close, I'm wondering if I'll have accuracy with this ?
11 months ago

praveen kumaar wrote:
i will recommend you read the description in the link,that's a good tutorial.



I've already read it and I also read some of the spec on expression, but the answer wasn't clear to me ence why I posted here.
1 year ago
I would like to make a summary of what I learned about the java.io package. It's something I've an hard time with so hopefully some other people will chime in as well.

1. Writer/Readers vs OutputStream/InputStream

For reading or writing to a file there is two group of abstract classes from which the others descend. The streams, InputStream and OutputStream are used for binary data, while the Reader and Writer are used to deal with characters. Readers and Writers use streams internally, but make working with characters easier.

Low level vs High Level

We can divide the classes used to read / write data from files into two groups.

- Low level: FileInputStream, FileOutputStream, FileReader, FileWriter

- High level: BufferedInputStream, BufferedReader, ObjectInputStream and their accompanying output classes.

So we have this diagram for input which all have accompanying output class:



I think that's all the ones we need to know for the exam, but I'm not sure.



The low level take a file or a string as constructor argument. while the high level take another input stream. This means that to read from a file we will have a combination of high and low level
:




However it also means that we can have non-sensical things like this :



The buffered classes

Those classes are for reading data in chunks instead of a per byte basis. They greatly improve performance.

( Personal rant: While java designers could have abstracted this low level mess, they decided it would be more in line with the rest of the language if the programming interface was badly designed. I'm serious, this is monstruosity. Hopefully I'll learn they fixed it in the chapter on java.nio)


ObjectOutputStream 

Used for serialization of objects. What is should be known is this:

-  Object fields can be marked as transient to not be serialized.
-  Static fields are not part of the object, thus not serialized.
-  Constructor and static initialization are not called upon deserialization.
-  Serialization will try to serialize child objects, thus those child objects must also be serializable.

Jesper de Jong wrote:

Cedric Bosch wrote:I'd like to know what is an expression exactly and does it return a value always ?


Yes, an expression always evaluates to a value.



No it does not, calling a method returning void does not return anything.

Anyway I'm caught up in trying to understand what "returning a value" actually means. I mean on a low level what does it actually mean ?

this code:



will compile to this (if you prevent weird optimizations):



There is nothing in the bytecode that hints to a returned value. I don't get it. What am I  not understanding here ?
1 year ago
Ahh thanks, I guess it's not worth it, I just wanted to see if I could make something run that doesn't compile but I think should.

But if I have to download libs and such it's not worth it (yeah I'm lazy like that). Thanks anyway.
1 year ago
I've logged the byte code from a simple class into the command prompt via the command javap. It looks like that:




I'd like to change the instructions a bit and execute it the new byte code. However I don't know how to do that, if I open the .class file in notepad, it doesn't look anything like this.

Any help ?
1 year ago
I'd like to know what is an expression exactly and does it return a value always ?

Mainly I'd like to know if this :

int i = a; is an expression ?
1 year ago
I'd like to define my datasource + mysql connector inside my project instead of inside standalone.xml.

Is this possible ?
1 year ago
Thanks.

The past few days I learned about JNDI, RMI, (LDAP very, very roughly, I don't intend to use it since I felt it was a bit complicated), POM multimodule packaging under maven and I implemented SSO via keycloak (awesome, the doc not so much). Quite a lot huh ? I'm beggining to do a massive refactoring of the app, thanks to EJB's but I'm still learning. I was using EJB annotations before but to me it was just about injection lol. Now I see how powerful it can be, especially for remote accesses. During those past few days I felt a bit overwhelmed at this whole new set of information I didn't know; I even briefly thought I should give it all up and go sell sandwiches on the beach instead since I've been programming for over a year and I still didn't know all that. Don't get me wrong, I feel like I learned a ton during that time span and I know the lifecycle of learning: think you are good, realize you know barely anything, learn, repeat.
Having said that, I think I'm beginning to understand architecture a bit, and my goal is to divide my app in a lot of individual mini-apps that can be addressed independently without breaking the whole thing. It's a whole new world for me :). Especially EJB and remote calls. Still a bit confused on the implementation but the core idea is here and I see the light at the end of the tunnel :p.


However, I'm a bit skeptical of the fact that I based my whole app around JSF. Now in retrospect I feel that it might have been a mistake and a restful app could have been better suited (I had no idea what that was when I started). Do you think JSF is a thing of the past ? Since I intend to divide my app in a lot of micro services I think restful is more suited for that. A reason for it is that I'd like to open source some of those mini app, to users who want to contribute and more people know .js than JSF. Idk, I guess I'll have to go more in depth with rest to see what I'll lose with it.

My guess: 
  - JSF templating is quite useful
  - I think pretty much anything that is done in a managed bean, and even around it with conversion and validation, can be implemented with rest. The nice thing with JSF is that everything is automatically done, the input values directly go into bean fields. But I suppose that there is also a mechanism to do that with jax-rs.
  - The biggest loss I think is the viewscope that I'm an heavy user of.
1 year ago
JSF
I've tried keycloak and it's awesome. If anyone was in the same case as I was, there are tons of things it does  more than a simple 2 line codes I had. TONS
1 year ago
Hello everyone,

I've a jaas authentication system that I did based on things I read online on owasp and such. However I'm currently reading about picketlink which is a security framework. I'm wondering if there is any use for me to even use that.

Can you guys take a look and tell me if what I do is insecure / if I would benefit from using picketlink ?

That's how I do authentication:



What confuses me is tht there doesn't seem to be a need for a framework for basically 3 lines of code. So I'm assuming I'm doing something wrong.
1 year ago
As always, thank you for your valuable input.

Tim Holloway wrote:EARs don't work in Tomcat (or jeTTY), only in full-stack JEE servers.





I'm definitely not using Tomcat. Maybe you thought I did because of my last post ? I'm just in the process of trying out multiple web server to find what suits me the bests. However I read a comparison where Tomcat was performing the worst, so it gave me a bad taste in the mouth.
I'm mostly hesitating between the undertow embedded API or a Full wildfly (quite the 2 extrems of the spectrum lol).


Tim Holloway wrote:
Alternatively, you might not actually need shared J2EE sessions if the only thing in common was just letting each app know that the user had logged into the system. A Single Signon (SSO) security Realm shared between the apps would be enough for that.

If you design the 3 apps to operate as full-blown microservices, you can even deploy them on separate server machines and get all elastic-y and cloud-y!



That is exactly what I was thinking about. If some of those services require more horse power I can scale them horizontally more easily this way!


Tim Holloway wrote:
There are several possibilities here. One, simplifying things from a maintenance standpoint would be to take the 3 parts of your app and build each of them into discrete JARs that go in the master WEB-INF/lib along with your JPA class jar(s), assorted other support libraries, and so forth.


I'm not a fan of that. It seems to me that doing so would make the development process a pain in the ass. Each time I make a change in one of the service, I'd have to convert it to a JAR and get it back into my WEB-INF/lib folder. Doesn't sound practical.


Tim Holloway wrote:
You could isolate things further by making each of the 3 subsystems be an independent webapp. However, if you do that, you have to get creative. By default, each webapp has its own unique set of user sessions. So you'd either have to configure Tomcat for shared sessions or make the login session be a JPA object. And, incidentally, set up JPA so that cache is shared between the 3 webapps. By the way, once you reach that stage, EJBs start to look better than straight JPA, since EJBs were designed from the beginning to be shareable between webapps. But straight Tomcat doesn't support EJBs, so you might have to step up to a full-stack server.


I'm not fully understanding this, so... I'll pass :p.


So about the single signon: I made a quick research and found out that it uses the LDAP that I kept reading here and there but know nothing about. I also read about 0Auth2 (and some security issues on wikipedia). However it's getting late, so I'm gonna do my research tomorrow. Could you be so kind and tell me a few buzzwords I can look up tomorrow to go in the right direction from the get go (the technology you would use I mean) ?

Thanks Tim !
1 year ago
JSF
Hello, I've made my first big web application that is mainly using JSF as technology but there is also some services on the side.
JSF is used to serve the page content, while websocket together with a rest service are used mainly for chatting with friends.
Everything is packed into a single WAR file that is quite big and messy. I'd like to divide that war file into independent app that can run on their own without having the others running.
Since I don't know much about application architecture I'd like some help trying to figure out what I have to do to reach my goals. Here is a little diagram I made representing how the app works.


Link: https://s32.postimg.org/7w84dbrcl/arch.png

As you can see in brown there is a CDI injection of the SessionBean. That is used so only valid and logged in users can access those service. For instance the Jax-rs service gives to the user his online friends :



Also they all use the same JPA package.


How can I divide this so I can have apps that can run independently (when others are not deployed in the web server ) ? Is it what EAR are used for ? If so do I have to create 3 war that are into one EAR ? I'm totally lost...


Thanks
1 year ago
JSF


Edit: I found the file under catalina_root/logging.properties and set everything to ALL instead of info.

I'm new to tomcat and I've been previously been using wildfly. I'm trying to launch a JSF project in tomcat without the required libraries (on purpose to test things out). However I can't manage to get the console output to show me ClassDefNotFoundError, or whatever the error is. It's just a test project with one index.xhtml.

IntelliJ basically opens 4 logs when running the server. There is : The server console output, Tomcat Localhost Log, Tomcat catalina Log, Tomcat local host access log, tomcat manager log, tomcat manager access log. In none of these is my error to be found. What's happening ? Why is there no error ?
1 year ago
Thanks for the kind answers .

Mikalai Zaikin wrote:
Yeah, "protected" prevents access from other packages, however your B still has access to "int i" via inheritance. Here is an example:


Yup, However with the way you changed the code you can access it directly as well . You can do :



(because they are in the same package). The thing that threw me off at first is that protected means it is accessible in subclasses. So one would assume it would be accessible in the class B since B extends A. And it is! but not like this.