Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!

tangara goh

Ranch Hand
+ Follow
since Dec 27, 2009
I am a beginner in Java and hope to pick up the trade secrets so that I can move on to Android development
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
111
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by tangara goh

Himai Minh wrote:You may find this tutorial helpful. You can create a repository class extending the CrudRepository .
https://www.concretepage.com/spring-5/spring-data-crudrepository-example



Hi Himai,

I need to further clarify with you as I am still very much confused with this RESTController.
While I am doing the various queries for all the methods now, I researched and ran into this article :


https://www.netsurfingzone.com/hibernate/temporal-annotation-example-in-hibernate-jpa-using-spring-boot-and-oracle/



Can I know why some people are using ResponseEntity and some use like this article return a book ?

Also, I noted alot of them do not use Service and ServiceImpl layer.

So, if I were to use ServiceImpl that has the implementation method whereas My service layer is an interface that contains the various methods without the implementation.
In the Controller, if I user service.method will it work ?

Because I compared this to the way I implemented using the servlet method, we will use a Factory to do service = new ServiceImpl

Please let me know what is the right ways of implementing a Rest Controller.

Thank you.

18 hours ago
Hi experts,

I refer to the project below:

https://projects.spring.io/spring-petclinic/#quick-start

And here's my database schema which I am abit uncertain if it is correct :



My question is
1) Is the above schema correct? Should I leave out reference foreign key in SpringBoot JPA web app?
2) do I need to use One-to-Many and Many-to-One to annotate the entities if the case applies? cos we can always us Join Column at the query in the Repository or Service layer for greater flexibity and perhaps 'optimization' ?
3) if the variables/attributes/fields and the names in my entity class are the same, I do not have to put @column right ?

Thank you for your help.

tangara goh wrote:

Himai Minh wrote:You may find this tutorial helpful. You can create a repository class extending the CrudRepository .
https://www.concretepage.com/spring-5/spring-data-crudrepository-example




Hi Himai,

I refer to the above recommended sample.

Now, I am facing problem in using Postman to test my SpringBoot, as it keeps giving me

CORS error : the request has been blocked because of CORS policy


and I have been trying for days how to resolve this without avail...I used annotations like @CrossOrigin at the Controller and a the method, removing all the security config files etc, etc..still cannot

So, now I tried out using RESTclient like what is is mentioned in this article.

But, I am not getting any result either.

How do I run this RESTClient ?

Futhermore, I am still trying to get SpringBoot to connect to MYSQL(fumbled till now...)

so I test out using hard-coded Status :



Hope you could share with me

1) what should I do to get rid of the CORS error by Postman
2) how to run the SpringBoot with the RestClientUitl to see the result ?

Thank you once again for your help.

6 days ago

Himai Minh wrote:Hi, Tangara,
For MediaType, you can use org.spring.framework.http.MediaType. There are different types in this class, such as APPLICATION_JSON, APPLICATION_ATOM_XML and etc.
If you choose to use Spring framework, then stick with it and don't need to use JEE for Restful.

If can return ResponseEntity with a status such as new ResponseEntity<>( message, HttpStatus.OK) or new ResposneEntity<>(message, HttpStatus.BAD_REQUEST) and etc.



Hi Himai,

I need further clarification as  I noted that I am mixing RequestContext request in this ResponseEntity and I am not sure if it is alright to do that.  I just want to make sure that everything is correct, since you said don't sue JAX-RS.

Here'a a snippet of code


You advice is greatly appreciate.

1 week ago

Tim Holloway wrote:

tangara goh wrote:I just want to take a small step to learn this shell script to build thing or automate stuff.

While it's hard to tell  for certain, it sounds like you're referring to a script developed in-house by your current employer for their own internal use. Once that employer has dumped you out on the streets, you'll likely never see that script again. So there's no point in trying to learn anything about it.

In the wider world, most Java apps are built using Maven, Ant or Gradle. Probably the most useful one to know at the moment is Maven, although that depends on what your next employer may prefer.

Beyond that, I don't know what CI CD means either, and Docker/containers are very different to build tools.

Oh. Come to think of it, I guess you mean Continuous Integration/Continous Deployment. That's a very broad topic and application building is only a very small part of it. Do try and avoid unexplained acronyms, though. IBM has at least one acronym I know of that has at least 4 different meanings and uses, depending on which of their products you're referring to and you probably wouldn't be able to guess any of them. And that's just in the IBM world.



Sorry about it...I thought CI CD is something that a developer would know ...I will avoid that.
I guess I have to prepare for the worse...and anyway my coding skill is really bad...even now I really think I am not cut out for it.....

Could you share with me abit more where do I pick up shell scripting meant for Continous Integration/Continous Deployment ?
1 week ago
I refer to this example :

https://stackabuse.com/uploading-files-with-spring-boot/



I would like to know if it is ok to follow the StringValidateEncodeUtils and filesource in the example code from :


https://www.programcreek.com/java-api-examples/?code=Unidata%2Ftds%2Ftds-master%2Ftds%2Fsrc%2Fmain%2Fjava%2Fthredds%2Futil%2Ffilesource%2FBasicDescendantFileSource.java#



The files look complicated I wonder if it is an overkill to have that to process the file ?
1 week ago

Stephan van Hulst wrote:Uhh for what? Why do you want to build a JRE?



Sorry Stephan, let me rephrase my question.

I just want to take a small step to learn this shell script to build thing or automate stuff.

Can you let me know how do I start ?

Tks.
1 week ago

Himai Minh wrote:In Spring, your request is converted into Json by default.
You pass in a customized object type to a method, it will be converted into JSON by Spring.



Thanks Himai,

Could you advise me at what stage people start to test out or do they test out Rest Controller at all ?  Or do I just use the RestClient as per your recommend article to do it.

I have often heard people using Postman or Curl or even Swagger to test out the end point so I just hope to have some advice where to start ?

Furthermore, I have tried using that sample app and modified accordingly to use Spring library as suggested by you.

However, there is this pets.add(createPet) that I can't get into the RespondEntity and Request Context, I hope you can let me know if there is a better way to do it other than using the PetData.

Thanks again for your help.
2 weeks ago

Stephan van Hulst wrote:

Do you mean how to get a password from environment specific configuration? Usually continuous deployment systems allow you to set environment variables for the system that the application will deploy to. You could configure the path to a configuration file where the password is located (or even configure the password itself) and then read it from the Java application.

How to do it exactly depends on the CI/CD system you're using.



Yes.  My apologies I am abit fuzzy about this cos I have only like thought about this and then I was just told using CI/CD but I had no idea how it is done.

Also, today, I discovred about this which is something that I have seen another supervisor had done it but I really don't know where to pick up this skill.

https://www.eclipse.org/justj/


The build-jre.sh script is used by a Jenkins pipeline script which in turn is used by the build-jres job to produce the following downloads:



where can I start at beginner level to learn how to do build-jre.sh ?

2 weeks ago
I have problem understanding this question and I can not understand how 4 is derived since 2 and 1 inside the span of 1 is 3.





So far I have tried out traverse the array backward but really my mind is blank from what to do next.  Please give me some tips.
I hope someone can give me an estimate time for a person without CS degree to practise good enough to go for coding interview.
Is 2 months too long or too short consider I need to fulfull a temp job duty?

Tks.
2 weeks ago

Himai Minh wrote:Hi, Tangara,
For MediaType, you can use org.spring.framework.http.MediaType. There are different types in this class, such as APPLICATION_JSON, APPLICATION_ATOM_XML and etc.
If you choose to use Spring framework, then stick with it and don't need to use JEE for Restful.

If can return ResponseEntity with a status such as new ResponseEntity<>( message, HttpStatus.OK) or new ResposneEntity<>(message, HttpStatus.BAD_REQUEST) and etc.



Hi Himai,

That part is easy but the utility part if I were to use Spring HTTP headers I am afraid with my beginner level it is really tough to refactor.

I google abit and found this one at

https://stackoverflow.com/questions/62372402/spring-how-to-pass-automatically-https-header-between-microservices

Do you think this is the thing I should use or can you give me some hints how to refactor the utility part to accept json and xml using header request in Spring.
Tks.
2 weeks ago

Himai Minh wrote:Hi,Tanagara,
The PetController is not using any Spring's Restful features.
I am sure javax.ws.rs-api is from JEE,not Spring
In Spring , you can use ResponseEntity<>  to return the output.

You may want to use these as reference:
https://spring.io/guides/tutorials/rest/
https://www.baeldung.com/spring-response-entity



Thanks so much for the tutorial and I have used this guide and adapt accordingly.

But, another question came to my mind as I edit the PetController... cos for if I were to follow strictly the example in that swagger-petstore, I would just be getting a return in response as oppose to the traditional way of returning via GET, POST etc to return say an array of pets that has the same status for example.

I'd also want to clarify about java.ws.rs, cos in the utility of this petstore, they are also using import javax.ws.rs.core.MediaType so is it not advisable to use or it is ok to use?

Or ...I am sorry but I have problem in reading that swagger document...does it mean that I only need to return a response will do.  But then if it is just a response of ok or bad request, then what does this app serve the purpose then...so sorry but I really am not very good in this whole thing.

Thanks for your help in advance.
2 weeks ago
I have "seen" my supervisor using CI CD to inject passwords rather than hardcode in Java classess but I have no chance to learn from him cos he already made up his mind to ditch me for good and I am left with less than 3 months to get a job...and I still can't do the algorithm test within 5 mins....

So, I am hoping someone can tell me how to do it.

I tried to learn Docker but I still have yet to come across a tutorial like that.

Or should I look at Kubernete ?

I am really L..O..S..T...so really appreciate some helps here.

Tks.
2 weeks ago

Himai Minh wrote:Hi, Targara,
The CrudRepository can be used in Spring boot / Spring framework.
You can use Spring intializer to generate a Spring boot project and add some child classes for CrudRepository.



Hi Himai Minh,

I would like to further check with you cos I found out that there is this petstore that has very similar end points like what I am doing now but they are using ResponseContext to return the response.


https://github.com/swagger-api/swagger-petstore/blob/master/src/main/java/io/swagger/petstore/controller/PetController.java



Is this the right way to do a RPC web app?

Can I use javax.ws.rs-api to do it ?

And if I don't do the testing like what they do using Petdata, do I just use a public void main (String []) and then I just create an instance of Pet and do a getId, getName like that is it ok ?

Furthermore, I'd like to clarify should I use the below code for /store/order


cos I am not sure about this one...since I can't tell if a user is supposed to be able to place an order just by looking at this description : /store/order and should I included Store as entity ?

Really, I am so confused really hope can get some help here....really I feel that maybe coding is not for me...

Tks.

2 weeks ago