Tag: resteasy

在ExceptionMapper创建响应时,不会遍历RestEasy Post Process Interceptor链

我正在使用RestEasy构建我的Restful Web服务。 我已经实现了ExceptionMappers来准备特定的exception响应。 我还实现了MessageBodyWriterInterceptors和一些PostProcessorInterceptors。 问题:当任何资源没有抛出任何exception时,一切正常。 我的实现按预期工作。 调用所有后处理器拦截器和消息体编写器拦截器。 但是,当从任何资源方法抛出exception时,将调用已注册的ExceptionMappers并创建响应。 但在这种情况下,不会遍历后处理器拦截器链。 他们没有被召唤。 在这种情况下我该怎么办 在我的exception映射器中写入该拦截器逻辑,或者是否有可用的解决方案?

将json对象解析为字符串

我有一个关于我正在构建的Web应用程序的问题,其中我有一个接收json字符串的REST服务。 Json字符串类似于: { “string” : “value”, “string” : “value”, “object” : { “string” : “value”, “string” : “value”, …. } } 我正在使用resteasy来解析使用下面的jackson的json字符串。 我有一个jaxb注释类,我想将“对象”完全解析为String变量。 我想这样做的原因是以后能够使用正确的解析器解析json(它取决于发送请求的应用程序,因此事先无法知道)。 我的jaxb注释类看起来像这样: @XmlRootElement @XmlAccessorType(XmlAccessType.PROPERTY) public class Test{ @XmlElement(type = String.class) private String object; //getter and setter … } 当我执行其余的调用并让jackson解析这段代码时,我得到了一个 Can not deserialize instance of java.lang.String out of START_OBJECT token 错误。 所以实际上我正在尝试将一个json字符串(一个json对象)解析为一个String。 我似乎找不到有类似问题的人。 […]

Resteasy ProxyFactory类的替代品是什么?

我刚刚意识到在RestEasy版本3.0.0中, ProxyFactory类被标记为已弃用。 遗憾的是,弃用此类的方法没有记录在任何地方。 我曾经以这种方式初始化我的服务,但新方法是什么? protected static final String URL = “http://localhost:12345″+”/api”; protected static final MyService myService = ProxyFactory.create(MyService.class, URL);

具有Resteasy的多个端点

我在一个应用程序中有两个单独的REST服务。 让我们说一个主要的“人”服务和一个辅助“管理”服务。 我想要的是在服务器上的不同路径中公开它们。 我正在使用JAX-RS,RESTEasy和Spring。 例: @Path(“/people”) public interface PeopleService { // Stuff } @Path(“/management”) public interface ManagementService { // Stuff } 在web.xml我目前有以下设置: org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap org.jboss.resteasy.plugins.spring.SpringContextLoaderListener resteasy.servlet.mapping.prefix /public Resteasy org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher Resteasy /public/* PeopleService和ManagementService实现只是Spring bean。 上面的web.xml配置会在/public上公开它们(所以分别使用/public/people和/public/management )。 我想要实现的是在/public上/public PeopleService ,以便完整路径将成为/public/people并在/internal上公开ManagementService ,以便其完整路径将成为/internal/management 。 不幸的是,我无法更改@Path注释的值。 我该怎么做?

如何将一些类的创建从Guice注入器委托给另一个工厂?

例如,RESTEasy的ResteasyWebTarget类有一个方法proxy(Class clazz) ,就像Injector的getInstance(Class clazz) 。 有没有办法告诉Guice应该将某些类的创建委托给某个实例? 我的目标是Guice的以下行为:当要求注入器获得A类的新实例时,尝试实例化它; 如果实例化是不可能的,请询问另一个对象(例如ResteasyWebTarget实例)来实例化该类。 我想写一个这样的模块: @Override protected void configure() { String apiUrl = “https://api.example.com”; Client client = new ResteasyClientBuilder().build(); target = (ResteasyWebTarget) client.target(apiUrl); onFailureToInstantiateClass(Matchers.annotatedWith(@Path.class)).delegateTo(target); } 代替 @Override protected void configure() { String apiUrl = “https://api.example.com”; Client client = new ResteasyClientBuilder().build(); target = (ResteasyWebTarget) client.target(apiUrl); bind(Service1.class).toProvider(() -> target.proxy(Service1.class); bind(Service2.class).toProvider(() -> target.proxy(Service2.class); bind(Service3.class).toProvider(() […]

Resteasy和fileupload:没有内容处理错误

我有一个可以上传文件的rest资源。 @Path(“/rest/input”) public class InputResourceBean { @POST @Path(“{directory: .*}”) @Consumes(“multipart/form-data”) public void post(final String directory, final MultipartFormDataInput input) { } 我已经使用SOAPUI,curl和HTML表单来测试这段代码,并且对于所有这些代码我都得到了同样的错误:在部分内部找不到Content-Disposition标头 12:55:19,739 WARN [org.jboss.resteasy.core.SynchronousDispatcher] Failed executing POST /rest/input/myDir: org.jboss.resteasy.spi.ReaderException: java.lang.RuntimeException: Could find no Content-Disposition header within part at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:123) [:6.0.0.Final] at org.jboss.resteasy.core.messagebody.ReaderUtility.doRead(ReaderUtility.java:93) [:6.0.0.Final] at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:146) [:6.0.0.Final] at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:114) [:6.0.0.Final] at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) [:6.0.0.Final] at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) [:6.0.0.Final] […]

ClientRequestFactory RestEasy已弃用……任何其他RestEasy替代方案?

我需要创建rest-easy客户端,使用其他人创建的RestService的de接口……这样做很好,除了一件事…… 当我从rest-easy 2.3.5.Final更新到rest-easy 3.0.x时,ClientRequestFactory类看起来像@Deprecated。 实际代码是: ClientRequestFactory crf = new ClientRequestFactory(UriBuilder.fromUri(“http://url-of-service”).build()); SomeRestInterface client = crf.createProxy(SomeRestInterface.class); client.theMethod(); 任何一个,现在什么是版本3.0.x的ClientRequestFactory的rest-easy的替代方案?

在javax.xml.bind中创建一个通用集合

在我编写的REST服务器中,我有几个集合类来包装要从我的服务返回的单个项目: @XmlAccessorType(XmlAccessType.NONE) @XmlRootElement(name = “person_collection”) public final class PersonCollection { @XmlElement(name = “person”) protected final List collection = new ArrayList(); public List getCollection() { return collection; } } 我想重构这些以使用generics,因此样板代码可以在超类中实现: public abstract class AbstractCollection { protected final List collection = new ArrayList(); public List getCollection() { return collection; } } @XmlAccessorType(XmlAccessType.NONE) @XmlRootElement(name = “person_collection”) public final […]

如何在不向用户显示堆栈跟踪的情况下处理servletfilter中的错误状态?

我正在开发一个Jetty / RESTEasy应用程序。 如果我从我的一个REST端点抛出WebApplicationException(myResponse) ,它会将给定的响应发送到客户端。 当filter检测到错误时,我想要相同的行为: 它应该停止执行,并且 它应该给用户一个明确的,JSON格式的错误,不包括堆栈跟踪。 显然,只需写入响应流并从doFilter方法中return工作。 但这对doFilter调用的其他方法不起作用。 抛出任何exception将满足条件#1,但我还没有想出一个理智的方式来满足条件#2。 (你可以在底部看到我最好的尝试。) 正如Perception在他的回答中解释的那样, WebApplicationException被视为Filter的上下文中的任何其他exception,因此为用户提供了一个很好的丑陋堆栈跟踪。 那么,总结一下我的问题: serveltt容器是否具有throw new WebApplicationException(Response)等价物? 也许更重要的是,其他java项目如何处理这个? 我在一个filter中有这个代码,它可以工作,但我更喜欢一个更优雅的解决方案,它自动应用于所有filter: public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { try { doFilterOrThrow(request, response, chain); } catch (WebApplicationException e) { Response res = e.getResponse(); ((HttpServletResponse) response).sendError(res.getStatus(), (String) res.getEntity()); } }

如何使Spring Security应用程序在代理后面运行?

我们有一个基于Spring 1.6.3的Java 1.6上的应用程序,它使用Spring Security 3.0.5并使用Spring Web和RestEasy 2.1.0实现REST API。 我需要将此应用程序(服务器)置于代理之后,该代理将HTTPS请求流量从REST API客户端应用程序转换为HTTP流量。 此更改为登录请求创建“跨域”方案:客户端发送HTTPS登录请求,服务器使用HTTP的重定向URL进行应答。 目前它回复: ”http://192.168.0.10:8090/index.html;jsessionid=64FD79…86D” , 我需要的是: ”/index.html;jsessionid=64FD79…86D” 我们提供了解决方案,使服务器响应“相对”URL而不是“绝对”URL。 所以我尝试在这里实现与描述情况类似的东西: forum.spring.io上的主题 我已经使用contextRelative =“true”设置RedirectStrategy bean并从LoginSuccessHandler扩展类中的AbstractAuthenticationTargetUrlRequestHandler覆盖redirectStrategy setter,我看到HttpServletResponse对象的redirectStrategy属性按预期设置为true。 仍然没有解决问题。 此外,当使用encodeRedirectURL(“otherLogin”)更改HttpServletResponse对象的redirectURLCC属性时,设置类似于 ”http://192.168.0.10:8090/otherLogin” 而这不是我需要的。 我需要删除URL的整个协议+ ipaddress部分。 响应对象的URL属性无法进行更改,因为它由Filter和FilterChain接口实现包装。 请提出任何想法。 我想这种事情应该在web.xml或auth-AplicationContext.xml文件中解决,而不是在代码中。 最好的祝福。