jax-rs

How to retrieve data from database using webservices (JAX - RS) in eclipse using Java

情到浓时终转凉″ 提交于 2020-01-29 05:21:29
问题 I have done inserting a record into database but I don't know how to retrieve it. My code is: Account.java: package com.fetch; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Id; public class Account implements Serializable { @Id private long id; @Column(name="NAME") private String name; public Account() { } public Account(int id, String name) { this.id = id; this.name = name; } public long getId() { return id; } public void setId(long id) { this.id = id

jackson - MessageBodyWriter Not Found when returning a JSON POJO from a GET Api

空扰寡人 提交于 2020-01-25 11:56:10
问题 I was trying to return a simple json response using jackson. @GET @Produces(MediaType.APPLICATION_JSON) public FMSResponseInfo test(){ System.out.println("Entered the function"); FMSResponseInfo fmsResponseInfo = new FMSResponseInfo(); List<SearchDetailsDTO> searchDetailsDtoList = new ArrayList<>(); for (int i = 0; i < 5; i++) { SearchDetailsDTO searchDetailsDto = new SearchDetailsDTO(); searchDetailsDto.setBarcode("barcode" + i); searchDetailsDto.setDocNo("docNo" + i); searchDetailsDto

Why am I getting a WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped exception?

戏子无情 提交于 2020-01-24 13:53:26
问题 I've looked at other questions relating to this error on the site but most of them are either about SessionScope or are unanswered. The only possibly helpful one is No active contexts for scope type javax.enterprise.context.RequestScoped when invoking a bean from a thread but it's not in the context I have. I'm running a JAX-RS endpoint on Wildfly 10.1 (Java ee 7). Looks something like this: @Path("") public class ServerResource { @Inject Order order; @Resource ManagedExecutorService mes;

HttpServletRequest injection on RequestScoped bean CDI

一曲冷凌霜 提交于 2020-01-24 10:38:19
问题 I'm looking for a way in order to inject a @RequestScoped custom class into my @Stateless JAX-RS endpoint: I want each time the application receives a request my custom class is injected in my JAX-RS endpoint. Custom class: @RequestScoped public class CurrentTransaction { private String user; private String token; @PersistenceContext(name="mysql") protected EntityManager em; @Inject HttpServletRequest request; public CurrentTransaction() { this.user = request.getHeader("user"); this.token =

HttpServletRequest injection on RequestScoped bean CDI

感情迁移 提交于 2020-01-24 10:38:06
问题 I'm looking for a way in order to inject a @RequestScoped custom class into my @Stateless JAX-RS endpoint: I want each time the application receives a request my custom class is injected in my JAX-RS endpoint. Custom class: @RequestScoped public class CurrentTransaction { private String user; private String token; @PersistenceContext(name="mysql") protected EntityManager em; @Inject HttpServletRequest request; public CurrentTransaction() { this.user = request.getHeader("user"); this.token =

Glassfish 5 ignores JAXB @XmlJavaTypeAdapter annotation?

谁说胖子不能爱 提交于 2020-01-24 09:06:32
问题 I just switched to Glassfish 5 from Glassfish 4 and I noticed that Glassfish no longer called the unmarshal method of my DateTimeAdapter class, it worked okay in Glassfish 4. The Web service class receives a json data and it should be converted automatically to the appropriate RegisterItemDTO object. I've tried putting the annotation on the getter method and it still didn't work. The unmarshal method was never called. I've made sure the json data was in the right format. Service class:

Glassfish 5 ignores JAXB @XmlJavaTypeAdapter annotation?

核能气质少年 提交于 2020-01-24 09:05:49
问题 I just switched to Glassfish 5 from Glassfish 4 and I noticed that Glassfish no longer called the unmarshal method of my DateTimeAdapter class, it worked okay in Glassfish 4. The Web service class receives a json data and it should be converted automatically to the appropriate RegisterItemDTO object. I've tried putting the annotation on the getter method and it still didn't work. The unmarshal method was never called. I've made sure the json data was in the right format. Service class:

How to securing programmatic resources in a jersey?

大憨熊 提交于 2020-01-23 12:05:47
问题 jersey JAX-RS resources can be secured with annotations like this. @RolesAllowed("user") @GET public String get() { return "GET"; } My requirement is securing dynamically created jersey resources which I have created like this @ApplicationPath("/") public class MyApp extends ResourceConfig { public MyApp() { packages("com.test.res"); Resource.Builder resourceBuilder = Resource.builder(); resourceBuilder.path("/myresource3"); final ResourceMethod.Builder methodBuilder = resourceBuilder

How to securing programmatic resources in a jersey?

删除回忆录丶 提交于 2020-01-23 12:05:36
问题 jersey JAX-RS resources can be secured with annotations like this. @RolesAllowed("user") @GET public String get() { return "GET"; } My requirement is securing dynamically created jersey resources which I have created like this @ApplicationPath("/") public class MyApp extends ResourceConfig { public MyApp() { packages("com.test.res"); Resource.Builder resourceBuilder = Resource.builder(); resourceBuilder.path("/myresource3"); final ResourceMethod.Builder methodBuilder = resourceBuilder

GSON - JsonSyntaxException - Expected name at line 7 column 4

末鹿安然 提交于 2020-01-22 17:50:06
问题 I have the following result class whose object is to be returned as JSON. public class Result { public String objectid; public String dtype; public String type; public String name; public String description; public Result() { this.objectid = ""; this.dtype= ""; this.type=""; this.name= ""; this.description = ""; } public String getObjectid() { return objectid; } public void setObjectid(String s) { this.objectid = s; } public String getDtype() { return dtype; } public void setDtype(String s) {