Combine Spring REST service with Wicket - java

So I am developing a REST API in an application that uses both Spring and Wicket at the same time.
If I annotate #RequestMapping(value="/exchange") at my Spring #Controller annotated class (the one that is acting as a webserver), how do I have to configure Wicket to "recognize" http://myserver.com/myapp/exchange or http://myserver.com/myapp/exchange/onemethod as a valid URL so I don't get a 404 ERROR when I try to call the webservice from a client?

Use the JAX-RS #Path annotation:
#Path("exchange")
#Component
public class ExchangeService {
#POST
#Path("onemethod")
public void oneMethod(...) {
...
}
}

Related

How to set base url and common rest URL from property file in Quarkus?

I am working on Quarkus application and what I want to do is to set the global path from application.properties file for all rest rest, my application is working but while calling rest request it is giving not found 404.
#ApplicationScoped
public class ABC {
#POST
#javax.ws.rs.Path("/callit")
public Uni<Response> deleteNoti()
{
//whatever logic
}
}
#ApplicationScoped
public class PAR {
#POST
#javax.ws.rs.Path("/callitPar")
public Uni<Response> addNoti()
{
//whatever logic
}
}
And in application.properties file I am configuring below properties:
quarkus.resteasy.path=/rest/*
quarkus.rest.path=/rest/*
quarkus.http.root-path=/myapp
but when I am calling rest request from front-end it is not working, my rest request should be as below:
http://localhost:8080/myapp/rest/callit
http://localhost:8080/myapp/rest/callitPar
What I want is every rest request should start with "/rest/*" and my application base URL should be "/myapp", Let me know how can we achieve it?
Try to annotate your resource classes with #Path("/") and set quarkus.resteasy.path=/rest.
This should result in your described behaviour.
quarkus.rest.path can be removed.

Set different context paths with configuration files

Set Context path differently for both Webservice and Rest
I have an application which contains both implementation of Webservices and Rest services and I am looking for an solution to set context path for both Webservices and Rest services differently using yml/properties file
How to configure servlet dispatcher to work properly?
I would like to have:
localhost:8080/ws/* - webservice
localhost:8080/web/* - MVC components
servlet:
context-path: "/ws"
It sets globally for both webservices and rest services , How to make it independent to each other with out programming?
Using Spring Boot (with Spring Starter Web) you could achive what are you asking for with the annotation #RequestMapping.
You could put #RequestMapping(value="/ws") on the class declaration of every rest controller and #RequestMapping(value="/web") for web controllers.
For both rest and web controller than you could use other annotations to specify method path, i.e #GetMapping(value="/methodPath").
#Controller
#RequestMapping(value="/web")
public class WebController{
#GetMapping(value="/method")
public String method(){
...
}
}
#RestController
#RequestMapping(value="/ws")
public class RestController{
#GetMapping(value="method")
public String method(){
...
}
}

Spring can not call Rest Endpoint get 404

I have setup a service with spring boot but I can't call my rest endpoint.
CODE:
#RestController
#RequestMapping("/route")
#SessionAttributes("session_userId")
public class RoutingController extends BaseController implements WebMvcConfigurer{
Endpoint:
#RequestMapping("/users/web")
public ModelAndView routeToUserInterfaceServiceWeb(HttpSession session,Device device) {
The service runs on port 8000. So when I do in my browser:
"localhost:8000/route/users/web" I expect a any answer of the server. But all I get is a 404.
Try removing the controller annotation:
#RequestMapping("/route")
Keep the original annotation on the method:
#RequestMapping("/route/users/web")
ModelAndView is a Spring MVC construction. I would expect a REST service to return a ResponseEntity.

SpringBoot: Control Async behaviour from #RequestMapping analogous to an AsyncWebServlet?

I am working with Spring Boot 2 and I would like my requests to be handled asynchronously.
In Java EE, one can use Asynchronous Processing for Asynchronous Servlets as in this link. The following is a related example:
#WebServlet(urlPatterns={"/asyncservlet"}, asyncSupported=true)
public class AsyncServlet extends HttpServlet { ... }
and the above allows to use AsyncContext.
But in Spring Boot, I have the following #RequestMapping. How do I make it handle requests in Asynchronous mode and also supporting AsyncContext? How do I leverage the use of an Asynchronous Web Servlet?
#RestController
public class myRestController {
#RequestMapping("{resource}/**")
public void resourceRequest (#PathVariable("resource") String resource) {
// example:
// ... some long running calls such as database communication
// ... convert request through AsyncContext ctx = req.startAsync();
// etc
}
}
Note that returning void is intentional.
I found the following SO answer How to register a servlet with enabled "async-supported" in Spring-Boot? saying that "Spring Boot will automatically register any Servlet beans in your application context with the servlet container. By default async supported is set to true so there's nothing for you to do beyond creating a bean for your Servlet." but I am not using any #WebServlet annotations anywhere in my program, just the #RestController annotation. So how do I ensure that I am benefitting from asyncSupported option?

How to avoid class level #path in web service to handle all web service calls

I am writing a web service like
#Path("/pathName")
public class LoginServiceComponent {
#GET
#Path("/methodPathName/{param}")
#Produces(MediaType.TEXT_HTML)
public String getVoterByVoterId( #PathParam("param") String param)
{
.................
}
}
Here my url to access web service is http://www.abc.com/pathName/methodPathName/1
Here i have 10 methods.Is there any possibility to remove class level #Path means i have only one web service class in my project.So i dont want to use class level #Param repeatedly.
Thanks in advance...
If you want to avoid the #Path on the class so your URL's don't have the "pathName" in the path, I don't think you can remove the #Path on the class entirely. But I have used the #Path class annotation of #Path("/") and was able to get just URL to be just http://www.abc.com/methodPathName/1 (if that's what you're trying to do).

Categories