jersey

Securing a REST API in Java [closed]

泄露秘密 提交于 2019-12-10 04:37:03
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am building a REST API in Java - using Jersey. I want to secure sensitive API calls with an API token security scheme, but I don't have any idea where to start. Is there a framework that will do this for me out of the box? Or do I have to implement my own security scheme? 回答1: There are several frameworks to do

Accessing Spring beans in JerseyTest

谁说我不能喝 提交于 2019-12-10 04:11:47
问题 I'm trying to figure out how to access Spring beans from a subclass of JerseyTest. Extending JerseyTest I've managed to load the Spring context in my tests, but I haven't figured out how to access the spring context. My setup looks like this: public abstract class SpringJerseyTest extends JerseyTest { public SpringJerseyTest() throws Exception { super(new WebAppDescriptor.Builder("com.acme.resources") .contextPath("/") .contextParam("contextConfigLocation", "classpath:applicationContext.xml")

What is the Jersey 2.0 equivalent of GZIPContentEncodingFilter

我的未来我决定 提交于 2019-12-10 04:09:59
问题 I am in the progress to migrate a Jerset 1.x client project to Jersey 2.0. I found that GZIPContentEncodingFilter does not exist any longer. Is there something similar? I stumbled over GZIPEncoder but am not sure how to plug it in. In Jersey 1.17 I use: WebResource r = ... r.register(new GZIPContentEncodingFilter()); In Jersey 2.0 I search for somethink like: WebTarget r = ... r.register(new GZIPContentEncodingFilter()); 回答1: Use WebTarget r = ... r.register(GZIPEncoder.class); 回答2: Most of

How to properly handle a JWT refresh?

十年热恋 提交于 2019-12-10 03:39:48
问题 I have an android app. It connects with a REST API developed with Jersey . My REST End points are secured with Tokens. Below is how I generate them. Algorithm algorithm = Algorithm.HMAC256(secret); String token = JWT.create() .withClaim("userName","myusername) .withExpiresAt(expirationDate) .sign(algorithm); Below is how I validate the token public boolean validateTokenHMAC256(String token, String secret) throws UnsupportedEncodingException, JWTVerificationException { Algorithm algorithm =

Want to Add @JsonIgnore property on Password in response Json

主宰稳场 提交于 2019-12-10 02:54:01
问题 I want to add @JsonIgnore of Jackson On the Password property of User domain such that I must be able to send the Json With password and It saves my data in Database but in response I don't want to show the password. How can I acheive this please help me. I tried to use it at the Domain level of the User where the properties are defined but it Totally Ignore the property in the getter and setter methods. I have tried this private String password; @JsonIgnore public String getPassword() {

How to log JSON responses in Dropwizard (Jersey)

久未见 提交于 2019-12-10 02:43:54
问题 I would like to know how one would configure Dropwizard to log the JSON response. 回答1: In dropwizard 0.8.1 (also tried in 0.9.0-SNAPSHOT), add to Application.run(...) : import java.util.logging.Logger; import org.glassfish.jersey.filter.LoggingFilter; ... public void run(MyApplicationConfiguration conf, Environment env) throws Exception { // do your stuff and then add LoggingFilter env.jersey().register(new LoggingFilter( Logger.getLogger(LoggingFilter.class.getName()), true) ); } To

A message body writer for Java type, class net.sf.json.JSONObject, and MIME media type, application/json, was not found

回眸只為那壹抹淺笑 提交于 2019-12-10 02:33:08
问题 I am using jersey client for making call to rest webservice. My webservice is consuming the json, so i need to put json in making call to my webservice provider. I am doing it in below way. JSONObject object=new JSONObject(); object.put("name", employee.getName()); object.put("empId", employee.getEmpId()); object.put("organizationName", employee.getOrganizationName()); ClientResponse response = service.path("rest").path("vtn").path("addEmplyee") .type(MediaType.APPLICATION_JSON_TYPE).post

JAX-RS (Jersey) ExceptionMapper - @Context injection into static/singleton class - it works, but why?

落花浮王杯 提交于 2019-12-10 02:17:20
问题 I have a single-instance class, implementing ExceptionMapper. It's not a static class, but it's a class for which I know only single instance is created (I checked - constructor is called only once). My class uses @Context HttpServletRequest , and I can clearly observe that when my ExceptionMapper.toResponse() method is called, the @Context 'request' parameter has a value which is relevant for a request where the exception is thrown. The doc says this is indeed by-design supported feature and

Returning JSON or XML for Exceptions in Jersey

隐身守侯 提交于 2019-12-10 01:52:22
问题 My goal is to have an error bean returned on a 404 with a descriptive message when a object is not found, and return the same MIME type that was requested. I have a look up resource, which will return the specified object in XML or JSON based on the URI (I have setup the com.sun.jersey.config.property.resourceConfigClass servlet parameter so I dont need the Accept header. My JAXBContextResolver has the ErrorBean.class in its list of types, and the correct JAXBContext is returned for this

Jersey 2.0 and Moxy Internal Server Error But No Server Log

為{幸葍}努か 提交于 2019-12-10 01:38:32
问题 I followed the Jersey 2.0 document (https://jersey.java.net/documentation/latest/user-guide.html#json.moxy), modified pom.xml, included jersey-media-moxy artifact, compiled and installed. I could get basic POJO to JSON mapping work for both Produces and Consumes cases. However, when I tried with some POJO with complex data type as resource return type, I got a lot Status 500 Internal Server Error but without any server log. It is very annoying. Does anybody know if it is a bug or I missed