标签: spring-jersey

在春季靴子里打开球衣库的包装

我有一个带有球衣依赖项的项目春季启动:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

当我执行spring-boot:run所有操作时,所有上下文都将变得完美,一切正常。

当我使用打包该项目时mvn package,就会出现问题,因为requiresUnpack没有打开球衣的依赖关系。这是解决这个问题的必要条件:https : //github.com/spring-projects/spring-boot/issues/1468

在pom.xml中,我使用:

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <requiresUnpack>
                    <!-- dependencies that I want to unpack -->
                    </requiresUnpack>
                </configuration>
            </plugin>
        </plugins>          
    </build>
Run Code Online (Sandbox Code Playgroud)

然后,当我执行java -jar jarBoot.jar控制台输出为:

2019-05-02 15:02:46.218 ERROR 17476 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : StandardWrapper.Throwable

org.glassfish.hk2.api.MultiException: A MultiException has 1 exceptions.  They are:
1. org.glassfish.jersey.server.internal.scanning.ResourceFinderException: java.io.FileNotFoundException: C:\Users\Francesc\microservices git\sidecar-base\target\sidecar-base-0.0.1-SNAPSHOT.jar!\BOOT-INF\classes (El sistema no puede encontrar la ruta especificada)

        at org.jvnet.hk2.internal.Utilities.justCreate(Utilities.java:1009) ~[hk2-locator-2.5.0-b32.jar!/:na]
        at org.jvnet.hk2.internal.ServiceLocatorImpl.create(ServiceLocatorImpl.java:975) ~[hk2-locator-2.5.0-b32.jar!/:na] …
Run Code Online (Sandbox Code Playgroud)

java spring jersey spring-boot-maven-plugin spring-jersey

5
推荐指数
1
解决办法
170
查看次数

无法再从 HttpServletRequest SpringBoot 2.2、Jersey 2.29 获取表单数据

我们有一个 SpringBoot 应用程序,并使用 Jersey 来审核传入的 HTTP 请求。

我们实现了 Jersey ContainerRequestFilter来检索传入的HttpServletRequest 并使用 HttpServletRequest 的getParameterMap()方法来提取查询和表单数据并将其放入我们的审核中。

这与 getParameterMap() 的 javadoc 一致:

“请求参数是随请求发送的额外信息。对于 HTTP servlet,参数包含在查询字符串或发布的表单数据中。”

这是与过滤器相关的文档:

https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/user-guide.html#filters-and-interceptors

更新SpringBoot后,我们发现getParameterMap()不再返回表单数据,但仍然返回查询数据。

我们发现 SpringBoot 2.1 是支持我们代码的最后一个版本。在 SpringBoot 2.2 中,Jersey 的版本更新为 2.29,但在查看发行说明后,我们没有看到任何与此相关的内容。

发生了什么变化?我们需要改变什么来支持 SpringBoot 2.2 / Jersey 2.29?

这是我们代码的简化版本:

JerseyRequestFilter - 我们的过滤器

import javax.annotation.Priority;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
...

@Provider
@Priority(Priorities.AUTHORIZATION)
public class JerseyRequestFilter implements ContainerRequestFilter {

    @Context
    private ResourceInfo resourceInfo;

    @Context
    private …
Run Code Online (Sandbox Code Playgroud)

jax-rs jersey jersey-2.0 spring-boot spring-jersey

5
推荐指数
2
解决办法
1791
查看次数

从数据库下载文件而不将其保存在服务器上

我想使用 jersey api 从数据库中检索 pdf(存储为 BLOB)我使用 mybatis 作为数据库框架。我可以下载 pdf,但问题是我将输入流作为数据库获取,我将其另存为文件,然后在响应中传递它,但我不想将该文件保存在服务器中,我希望文件直接到下载给用户。

当前流程:

数据库----->输入流----->文件----------->添加到响应----->用户下载它

         retrieving        making file  passing file          user downloads
Run Code Online (Sandbox Code Playgroud)

我想要的是 :

DATABASE--------->输入流------------>添加到响应------->用户下载它

         retrieving         passing file              user downloads
Run Code Online (Sandbox Code Playgroud)

我想删除服务器中的文件制作,因为数据是机密的

资源接口

@GET
@Path("v1/download/{id}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(@PathParam("id") int id) throws IOException, SQLException;
Run Code Online (Sandbox Code Playgroud)

资源实施

@Override
public Response downloadFile(int id) throws IOException, SQLException {
    // TODO Auto-generated method stub
    File file = fileUploadService.downloadFile(id);

    ResponseBuilder response = Response.ok(file);
    response.header("Content-Disposition", "attachment;filename=aman.pdf");
    return response.build();
}
Run Code Online (Sandbox Code Playgroud)

服务方式

@Override
public File downloadFile(int id) throws IOException {
    // TODO Auto-generated method …
Run Code Online (Sandbox Code Playgroud)

java pdf jersey spring-mybatis spring-jersey

0
推荐指数
1
解决办法
1755
查看次数