java


How to invoke Restful WebService in Spring Boot


I have a SB service that is being used to send email. I wanted to use that in my existing application , how can I do that? I am thinking to create a controller that handles incoming HttpRequest and HttpResponse. But still no idea on how my existing application will invoke it. I need some high level overview too on how exactly SB application will run independently with other application.
P.S.- there is no UI interface for the email service so i wont be mapping url like we do in controllers generally.
Here is my sample email service:
public class EmailService {
public HashMap<String, String> sendMessage(String emailFrom, String[] emailToList, String subject, Context ctx) {
...../*Business Logic*/
}
}
I created a controller like this earlier to test this out:
#RestController
public class CourseController {
#Autowired
private EmailService emailService;
#RequestMapping(value = "/sendEmail", method = RequestMethod.POST)
public void sendEmail() {
emailService.sendMessage("abc#gmail.com","{client#gmail.com}", "testSubject",new Context);
}
Context has some business data.
I have a jsp that I am using and posting my form through which it is mapping. It all works fine.
But now I want to integrate this with my existing application (its on struts 1)so there wont be any uri to map. There must be some kind of HttpRequest need to be created from the invoking application and my controller should be handling it. How can I achieve this?
You have already this service implemented? Then you need a RestController class that mapps the uri of your choice. In this class you need to inject the service class that realizes your email sending method. Is this class annotated with #Service? Quite difficult to explain without seeing your code. Here an example for a REST-Interface:
#RestController
#RequestMapping("/api/v1/email")
public class RestClass {
private EmailService emailService;
#Autowired
public RestClass(EmailService emailService){
this.emailService = emailService;
}
#RequestMapping(method = RequestMethod.POST)
public ResponseEntity<?> sendEmail(#RequestBody EmailDTO emailDTO){
String emailAdress = emailDTO.getEmail();
this.emailService.sendEmail(emailAdress);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
So in this case the emailService would be the class that has the method that sends your email. This class should be annotated with #Service. Hope that helps.
Here your existing class:
#Service
public class EmailService {
public HashMap<String, String> sendMessage(String emailFrom, String[] emailToList, String subject, Context ctx) {
...../*Business Logic*/
}
}
And in case the injection doesn't work you have to annotate your application class with #ComponentScan({"com.foo.dal.","com.foo.notification."}) replace this packages simply with the package of your service and resource class.
I am not sure about the problem. If I am right that you need to call a rest service from your application. In this case it is lot easier and convenient to use Spring's RestTemplate link
You can get some overview here

Related Links

Convert raw byte[] to best quality and resolution image possible java Apache POI
jvm crush with EXCEPTION_ACCESS_VIOLATION when executing writeUTF method [closed]
01 Knapsack using best first search algoithm
Java FXML Error Loading Anchor Pane [duplicate]
Is APPCDS available in OpenJdk?
Netty binary data not flush out until 0x0a
Error Making Payment with Stripe SDK
Issues calculating quartiles in Java
java UDP server client application
Android home screen widget
I want set a notification that it should ring when i receive a notification
Organize java imports in Eclipse IDE
Photo Uploaded is inverted - Android App
Why is ExecutorService.awaitTermination() succeeding before a submitted task has completed
java code looping through an array
Spring Controller fails my CRUD Operations what can be done about this?

Categories

HOME
zeromq
push-notification
tinymce
plot
stock
relayjs
q
sql-server-2016
ckeditor
ojdbc
ezpublish
flyway4
facebook-messenger-bot
python-unittest
facebook-php-sdk
tomcat6
postgres-xl
static-libraries
orchardcms
quickfix
hapi
clearcase-ucm
seaborn
pythonanywhere
karma-jasmine
tokenize
web-sql
restful-authentication
wpfdatagrid
intel-pin
ejabberd-module
ecto
yadcf
oracle-fusion-middleware
cloud-code
simplexml
scaffold
espeak
az-application-insights
sqlite2
temporary-files
azure-ml
quadratic-programming
skeleton-css-boilerplate
fault
network-flow
zip4j
dwscript
sonarlint-vs
gnome-shell-extensions
eventkit
pycaffe
jquery-filter
firmata
angular-cache
instant
httplistener
file-writing
whois
goose
revolution-r
xpath-1.0
wapiti
qtableview
mono-embedding
p2
project-planning
oracle-warehouse-builder
java.nio.file
mqx
http-unit
wsdl-2.0
distutils
path-separator
gdata-api
runas
frameset
subscript
mysql-error-1005
radcombobox
cxxtest
.nettiers
gamma
suppress
bespin
fixed-width
web-architecture
libs
caching-application-block

Resources

Encrypt Message