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

Mike Gosling

Ranch Hand
+ Follow
since May 19, 2016
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 Mike Gosling

The idea is to use some kind of (custom) design pattern (or any other Java constructs such as parametrized types etc) to make @Configuration and @Service classes more generic and general.

The problem:

Part of my Spring Boot application acts like a client, i.e. it uses some SOAP Web services. I'm using exactly seven (in future possibly more) services. Classes which I'm using to send request and receive response are generated by the Maven JAXB2 plugin based on WSDL. In this post, I'm gonna outline the simplest services:


Controller layer:

Configuration for service class

Service class

Now, as I mentioned I have seven more of these "triplets" for each service one triplet. As expected, other services in the getValue() are accepting different number of parametears (String, ints and BigDecimals).

The question is, is there some kind of design pattern or Spring "way" of making this more generic? Meaning, to write some kind of "template" @Serivce class, along with @Configuration class to facilitate the idea?

Something roughly like this:

I know this is wrong, but I don't have any idea on how to approach this. I know this is very broad question, but if anyone could give me any pointers where to look for, maybe a specific design pattern or something similar, that would be excellent.
1 week ago
So guys, I have a Spring Boot client application which is hitting some SOAP Web Services application. They have a whole cr*p load of exposed services. Two of them are and .

A colleague, which was working on this project before me, managed to generate source files in order to send request and receive responses from that service. They were having problem of hitting controllers of that application. Particular piece of code which was causing the issue was:

Beside this, we have also got:

P.S. This is practically all the code (not counting generated request/response source files) for communicating with that web service.

For 6 months they were getting 301 Moved Permanently. Then I took over and after couple of days I noticed that is overloaded. Then after researching on SOAP Action Header, I figured this header is mandatory so that request can conform to SOAP specification. Then, I did following:

In any case, this worked! I got the answer back!

I'm assuming that is just a controller of that soap service application?

This string ( could have been found in .wsdl file. And I'm saying this "could" because when I first got to the project I was able to open WSDL schema from browser by opening opening this link .Strangely, WSDL schemas usually ends in .?wsdl (or something like). But now, this link is not working. Perhaps they changed WSDL? To make things more interesting, this link I'm also using in SoapUI, and SoapUI actually created all the services which were and are exposed in WSDL. If I hit any service from SoapUI now, I get back desired response.

Regarding other services, such us InsertInvoiceAndCustomer, I'm still able to hit it, that is I get back 200, but I am not able to actually insert new invoice and customer in their system. When I was making object InsertInvoiceAndCustomer as a request to pass to the marshalSendAndReceive(), I really make sure to set fields which are marked with required.

These three objects contains bunch of fields and I make sure to set all of those. This contains only three fields. Like credentials, username, password etc. Our client gave us these so we can "talk" to that web service.

Here is response (from Swagger) from that service I got:

I'm confused why that service is not "letting me in"? Messages from this response like: "value": "Authentication failed" or "value": "Missing user object" are not clear to me because I can engage this service via SoapUI without any problems.

Only there I write strings within xml tags and here I build objects.

Anyone any idea?

My next step is to try to see the actual string body of the request to see whether is the same as in SoapUI. For that I'm planning to use Interceptor Filter of some sort and loggers. Guys, any suggestions? I apologize for a bit longer post. Just I'm hitting wall here...

3 weeks ago
Well, to be honest I'm not yet confident enough to use Jpql. that's why Im using plain sql..But as you see..I need to generate some custom DTO, so using SqlMapper (Im not aure about annotation's name) is more convenient for me in this case. Hope anyone can help me with this 🙏
3 weeks ago
I have this method in JpaRepository interface:

I make sure I'm not passing nulls. Im just passing empty or non-empty strings.

This is my query which referenced by findInvoices:

I'm getting:

I've also tried writing symptomatic part in the query like this:

No luck.

I was able to make this (a bit modified) query work in MySQL Workbench. Any suggestions?
3 weeks ago

My boos gave me this link. I'm supposed to use this service (something for invoicing and administration in different mid-size companies), if I may call it that, and get some response from them from within Spring Boot app.
Now in Attachement 1, I used Soap UI, to test this service. If I understood correctly this Soap UI program acts basically like Swagger, of course it can do many other things. As you can see I send "Hello Ranchers" and got back some response. On the left hand side as you can see there a lot of those services, I just want to make HelloWorld service to work for now

Now, my assignment is to create simple service in Spring Boot, which will use these services. More specifically, I need to pass simple string to the HelloWorld (I marked it on the image) service and get back a response. In my understanding I will need to use maven-jaxb2-plugin in order to generate source code (i.e. Java Classes) for request and response objects.

I'm not exactly sure about steps, but for now I managed by using SoapUI tool to generate .xsd files from WSDL file (which is basically that link I provided above). I generated about 10 of those .xsd files with some random names.

Now, any idea or suggestions on how to create those Java classes which will represent request and response objects?

1 month ago
At University, I had email client type of project assignment and I was the best in my class, as professor pointed out. However, I was using bunch of tutorials and blogs on how to use and persist data using Hibernate.

Since we all know that Hibernate is an implementation of JPA, my question for you is, can a beginner using your book, understand JPA well enough so he/she can further deep dive into Hibernate.

In what style do you teach and display usage of JPA (or Hibernate)?

And maybe a bit broader question, what would be your tip or strategy on how to tackle "the beast" (not counting buying your book haha just kidding)

2 months ago
I'm building small TODO project using JavaScript, Ajax and Spring Boot. I did make all CRUD operations, tested them and they work.

Now I blend in pagination using Spring Boot, like so:

I have following data:

Exactly six TODO records with their title from do a to do f, with indexes from 1 to 6.

The UI in the browser once the page first time loads (attachment 1).

Now, in JavaScript, I made some constructor function called Page, so I can keep reference on current page. Kinda to mimic static in Java.

It looks like this:

Now, once the page first time loads, I set property of prototype called pageNumber, as I explaind above. The first time loading of a page will bring me two TODOs object, along with information whether it is the last page or not.

Each time I click Load more todos button, "static" pageNumber variable increases and I get following two entities. Increasing of variable looks like this:

Here is the problem:

Once I click second time, on my UI I have do a, do b, do c and do d. Next I delete do b and do c. I do remove the from UI and logically delete the from database, like so:

Now in UI, I have do a and do d. Here comes the problem. In my database I'm sure I have do e and do f not deleted, but once I click for the second time on Load more button, the pageNumber is equal to 2 (which is okey) and in my response I get that the page is last, but I get an EMPTY Json array! Drives me nuts!

Next, if I load page one more time, those last two elements do e and do f get fetched from db.

Here is how my Ajax GET request looks like:

These is the function which gets called on button click:

2 months ago

In my code I had:

It should have been

like I actually posted...
2 months ago
Absolutely. Test it with Postman as well, again 405.
2 months ago
I sincerely hope that I'm in appropriate forum.

My question is related with JavaScript (AJAX) and Spring Boot. So here it goes:

I'm getting 405 in console, when I send PUT request.

Here is my ajax call, which is part of bigger function:

I have a Promise object to handle asynchronous nature of ajax:

Now on the server side I have following, I have simple Task model object with omitted non relevant fields:

My controller class in Spring Boot and endpoint method for updating look like this:

I keep getting in the browser console 405. And on the console on server, I have following message:

I don't have SpringSecurity dependency...

I also asked on SO, but no luck..I really want to make PUT do the actual updating of the object, don't want to use POST, but that will be my last resort.
Thank you Tim once again. I'll get my hands on some quality book on Spring and Hibernate, so I can learn all that sh** Tnx
Yes Tim, you are right. But I cannot make your idea work.

In my repository if I do like this (what you suggested):

I get error 500, saying:

If I ommit nativeQuery = true:

I get

Now, I don't see a way how to get around this, and to get Entity directly as a record? I'll be sending these as JSON to andorid and will have to eventually create Folder object there anyway...

Wooo, my 100th post LOL Thank you Code Ranch very much, planning on at least couple of hundred posts more
I got what I need, that is, name of the folder and its Id. I did it with following query:

   @Query(value = "Select folder_id, name, parent From folders f Where f.parent = ?1", nativeQuery = true)

If I were to left out nativeQuery = true, I got:

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: folders is not mapped [Select folder_id, name, parent From folders f Where f.parent = ?1]

Thanks Tim, I'll look it up. For now, I was I able to get what I need in MySQL Workbench. But there is no way to tell that to Hibernate.

I have these query I it gets me what I need:

But when I type this:

in Hibernate, I get error saying:

In model I just placed Lazy instead of Eager and set @JsonIgnore on parent.

To be honest, I still haven't looked up about native queries yet, I think I saw it somewhere in TA's project and I just copy-paste it..Not very nice of me