jersey

Jersey “Auto-Discoverable Features” 在 Maven 编译后失效

依然范特西╮ 提交于 2019-12-05 07:07:26
本文同步至 http://www.waylau.com/jersey-auto-discoverable-features-failed-in-maven/ 问题 原本 Jersey "Auto-Discoverable Features"(自动发现功能)中 JSON 解析在 eclipse 右键运行项目是正常的,但用 Maven 编译成 jar 后运行,就无法使用 JSON 解析了 <!-- more --> Jersey "Auto-Discoverable Features" Jersey "Auto-Discoverable Features"(自动发现功能)。默认情况下 Jersey 2.x 不隐式注册在 classpath 上可用的模块中的任何扩展功能,除非明确在扩展文档中进行说明。用户将明确注册的扩展 功能 来使用他们的 Application 子类。一小部分 Jersey 提供模块不需要显式注册他们的扩展功能,因为这些在 配置 (客户端/服务器)中将会被Jersey 运行时发现和注册,这些功能模块实现的这些特性将呈现在 JAX-RS 应用部署的 classpath 上。这些自动发现模块包括: 来自 jersey-media-moxy 的 JSON 绑定特性 jersey-media-json-processing jersey-bean-validation

Jersey+Spring:解决Jersey单实例问题

这一生的挚爱 提交于 2019-12-05 07:07:09
Jersey是一款优秀的webservice框架,它同时支持soap和rest两种协议,而且系出名门(oracle)。美中不足的是: Jersey是基于Servlet实现的,具有Servlet的单例特性,有线程安全问题的隐患 (这点跟Struts1.x很像)。 通过将Jersey与Spring整合,利用Spring托管Jersey服务实例的生成,即针对每一个客户端请求都生成一个服务实例,可以很好的解决Jersey的单实例问题。 本文不再赘述Jersey与Spring的整合,只讲解如何让Spring针对每一个请求(request)都生成新的Jersey服务实例, 具体方法有如下两种: (1) request scope: @Component @Scope("request") @Path("/WebServiceDemoImpl") public class WebServiceDemoImpl implements WebServiceDemo{ 加入@Scope("request")注解后,Spring会针对每一个request请求都生成新的Jersey服务类实例 (实际上spring并不是采用这种机制保障线程安全的,我这么说是为了便于理解) 。但使用request scope还要在web.xml文件中加入Spring RequsetContextListener的配置:

Exception starting application on webspere 8.5

徘徊边缘 提交于 2019-12-05 06:52:27
I'm getting this error starting web application on WebSphere 8.5. Application calls thru MyBatis stored procedures on DB2. User triggers calls using REST WS, implemented using Jersey framework. Spring glues everything together. The same application works fine on Tomcat 7. Did anyone see this error? Any help will be appreciated). It looks like it fails to initialize Context and Dependency Injection container for the application. The stacktrace: [26.11.13 10:20:36:339 MSK] 000000a3 BeansDeployer E BeansDeployer deploy java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException at org

@Context returns Proxy instead of HttpServletRequest (No thread local value in scope for proxy)

吃可爱长大的小学妹 提交于 2019-12-05 06:47:09
I have a bit of a problem with understanding why @Context dependency injection returns collection of $Proxy(random number) instances instead of HttpServletRequest or HttpServletResponse. I am using Glassfish 3.1.2.2 with it's version of Jersey(Jersey: 1.11.1) and my app is built as EAR application. I have simple @Remote interface where I annotate my methods and REST services work without any problems, but the moment I try to access HttpServletRequest information it just causes problems. I have annotated private fields in my session bean: @Context private HttpServletRequest request; @Context

Authorization with RolesAllowedDynamicFeature and Jersey

核能气质少年 提交于 2019-12-05 06:32:46
I'm trying to authenticate users with a JAX-RS filter what seems to work so far. This is the filter where I'm setting a new SecurityContext: @Provider public class AuthenticationFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) throws IOException { requestContext.setSecurityContext(new SecurityContext() { @Override public Principal getUserPrincipal() { return new Principal() { @Override public String getName() { return "Joe"; } }; } @Override public boolean isUserInRole(String string) { return false; } @Override public boolean

XMLAdapter for HashMap

て烟熏妆下的殇ゞ 提交于 2019-12-05 06:25:21
I want to convert a list of items inside of my payaload and convert them into a hashmap. Basically, what I have is an Item xml representation which have a list of ItemID. Each ItemID has an idType in it. However, inside my Item class, i want these ItemIDs to be represented as a Map. HashMap<ItemIDType, ItemID> The incoming payload will represent this as a list <Item>... <ItemIDs> <ItemID type="external" id="XYZ"/> <ItemID type="internal" id="20011"/> </ItemIDs> </Item> but I want an adapter that will convert this into a HashMap "external" => "xyz" "internal" => "20011" I am right now using a

“Access-Control-Allow-Origin:*” has no influence in REST Web Service

倖福魔咒の 提交于 2019-12-05 06:15:54
I make an AJAX call from JavaScript client (running on machine A) to Web server (running on machine B). Client tries to access a URL exposed by RESTful Web service (Jersey), and it is blocked with error: Origin http://localhost/ is not allowed by Access-Control-Allow-Origin In server I added 2 header parameters that allow access to any client. However it didn't help: @Context private HttpServletResponse servlerResponse; @POST @Path("testme") public void test(){ servlerResponse.addHeader("Access-Control-Allow-Origin", "*"); servlerResponse.addHeader("Access-Control-Allow-Credentials", "true");

create a Jax-RS RESTful service that accepts both POST and GET?

喜欢而已 提交于 2019-12-05 06:02:49
I'm converting one of my existing service to become RESTful and I've got the basic things working with RestEasy. Some of my client apps should be able to execute both GET and POST requests to several services. I'm just seeking if there is any easy way around jax-rs to specify that API should accept both GETs and POSTs. Following you can find a test method, let me know if you see any way around without duplicating this in another class with @GET and @QueryParam. @POST @Path("/add") public Response testREST(@FormParam("paraA") String paraA, @FormParam("paraB") int paraB) { return Response.status

JsonMappingException: No suitable constructor found for type — for an external object

瘦欲@ 提交于 2019-12-05 06:02:05
I have an object called GeoJsonPoint from spring framework, and it can't get deserialized by jackson mapper in my integration test. Additionally, I can't add a dummy constructor because it is an external object. So I am stuck. This is my main entity; @Document(collection = "foodTrucks") @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) public class FoodTruckEntity { @Id private ObjectId id; private String applicant; private Status status; private String[] foodItems; private Double longitude; private Double latitude; private GeoJsonPoint geoJsonPoint; public FoodTruckEntity() {}; //

Annotation based Spring / JAX-RS integration with no web.xml

…衆ロ難τιáo~ 提交于 2019-12-05 05:56:20
问题 I'm trying to make a Servlet 3.0 REST server with no web.xml, ie dependent on java classes and annotations only. I'm not exactly sure how I can simultaneously register a Resource class with Spring and with the servlet mappings. I currently have: public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class<?>[] getRootConfigClasses() { return new Class<?>[]{RootConfiguration.class}; } @Override protected Class<?>[]