我是编码竞赛的一部分,任务是创建一个RESTful在线市场,用户可以通过http发布买卖请求.
我需要构建一个接受并存储这些请求的前端Web服务.
技术要求包括Spring boot和CXF.据我所知,CXF和Spring启动都能够接受http请求.
在spring boot中,您使用如下控制器:
@Controller
@EnableAutoConfiguration
public class controller {
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello, World!";
}
}
Run Code Online (Sandbox Code Playgroud)
而对于CXF(使用javax.ws.rs),代码可能如下所示:
@WebService(serviceName = "MarketService", targetNamespace = "http://localhost:9005")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public interface MarketService {
@GET
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_JSON })
@Path("/sells/{id}")
public prod getProduct(@PathParam("id") int id);
Run Code Online (Sandbox Code Playgroud)
有人可以帮我理解这两种处理http请求的方法之间的根本区别吗?有没有办法在同一个应用程序中同时使用Spring Boot和CXF?
我想链接一个CompletableFuture,以便它在处理过程中呈扇形散开。我的意思是我对列表有一个开放的CompletableFuture,并且我想对列表中的每个项目应用计算。
第一步是调用m_myApi.getResponse(request,executor)发出异步调用。
该异步调用的结果具有getCandidates方法。我想同时解析所有这些候选人。
目前,我的代码按顺序解析它们
public CompletableFuture<List<DOMAIN_OBJECT>> parseAllCandidates(@Nonnull final REQUEST request, @Nonnull final Executor executor)
{
CompletableFuture<RESPONSE> candidates = m_myApi.getResponse(request, executor);
return candidates.thenApplyAsync(response -> response.getCandidates()
.stream()
.map(MyParser::ParseCandidates)
.collect(Collectors.toList()));
}
Run Code Online (Sandbox Code Playgroud)
我想要这样的东西:
public CompletableFuture<List<DOMAIN_OBJECT>> parseAllCandidates(@Nonnull final REQUEST request, @Nonnull final Executor executor)
{
CompletableFuture<RESPONSE> candidates = m_myApi.getResponse(request, executor);
return candidates.thenApplyAsync(response -> response.getCandidates()
.stream()
.PARSE_IN_PARALLEL_USING_EXECUTOR
}
Run Code Online (Sandbox Code Playgroud)