java-ee-7

Java EE 7: How-to inject an EJB into a WebSocket ServerEndpoint?

孤人 提交于 2019-11-28 18:47:43
To sum up my failing project: My @ServerEndpoint class is packaged in a WAR together with the beans.xml file. My WAR in turn is packaged in a EAR and this EAR file is what gets deployed to a GlassFish 4 server that internally use Tyrus. Should it be possible? The WebSocket specification says: Websocket endpoints running in the Java EE platform must have full dependency injection support as described in the CDI specification. Websocket implementations part of the Java EE platform are required to support field, method, and constructor injection using the javax.inject. Inject annotation into all

How to get a method's annotation value from a ProceedingJoinPoint?

核能气质少年 提交于 2019-11-28 16:11:45
I have below annotation. MyAnnotation.java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { } SomeAspect.java public class SomeAspect{ @Around("execution(public * *(..)) && @annotation(com.mycompany.MyAnnotation)") public Object procede(ProceedingJoinPoint call) throws Throwable { //Some logic } } SomeOther.java public class SomeOther{ @MyAnnotation("ABC") public String someMethod(String name){ } } In above class am passing " ABC " with in @MyAnnotation . Now how can i access " ABC " value in procede method of SomeAspect.java class? Thanks! You

Alternate docroot not working on glassfish 4

拟墨画扇 提交于 2019-11-28 12:52:46
Im trying to set-up an alternate docroot in order to serve uploaded documents from. I have included the following in my glassfish web xml <context-root>/dom</context-root> <property description="Uploaded Images" name="alternatedocroot_1" value="from=/uploads/* dir=C:/Test" /> I have then stored a test pdf in the Test folder called cars.pdf. To access it i am typing the following into my browser http://localhost:8080/uploads/cars.pdf This however simply gives me a 404 error, ive tried googling and searching about here but nothing seems to work. Can some tell me what im doing wrong? Thanks Steve

What is the significance of @javax.persistence.Lob annotation in JPA?

妖精的绣舞 提交于 2019-11-28 08:08:34
When should I use @javax.persistence.Lob annotation in JPA? What datatypes can be annotated by this annotation? Zielu @javax.persistence.Lob signifies that the annotated field should be represented as BLOB (binary data) in the DataBase. You can annotate any Serializable data type with this annotation. In JPA, upon persisting (retrieval) the field content will be serialized (deserialized) using standard Java serialization. Common use of @Lob is to annotate a HashMap field inside your Entity to store some of the object properties which are not mapped into DB columns. That way all the unmapped

How to convert Gregorian string to Gregorian Calendar?

余生长醉 提交于 2019-11-28 05:19:15
问题 I have to compute something based on the Calendar's date, but I am receiving the complete Gregorian Calendar's String value. Eg i/p received {may be - "new GregorianCalendar().toString()"} as String :- java.util.GregorianCalendar[time=1410521241348,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/London",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/London,offset=0,dstSavings=3600000

Getting a reference to EntityManager in Java EE applications using CDI

天涯浪子 提交于 2019-11-28 03:59:51
I'm using Java EE 7. I would like to know what is the proper way to inject a JPA EntityManager into an application scoped CDI bean. You can't just inject it using @PersistanceContext annotation, because EntityManager instances are not thread safe. Let's assume that we want our EntityManager to be created at the beginnig of every HTTP request processing and closed after the HTTP request is processed. Two options come into my mind: 1. Create a request scoped CDI bean which has a reference to an EntityManager and then inject the bean into an application scoped CDI bean. import javax.enterprise

Required jars for RestEasy Client

半城伤御伤魂 提交于 2019-11-28 00:23:15
I need to provide a java REST client, which should contain all required jars in one bundle. I chose RestEasy as REST framwork, since the server application is done on a JBoss. Nearly all examples I found so far use either an application container environment, where those libs are provided and thus only the Java EE API is needed during compile or are build with Maven and thus dependencies are resolved automatically, which maybe be a good idea and the current standard way to do it, but for project-related reasons I need the jars in a lib folder and be able to include during the build and wihtin

Java EE 7: How-to inject an EJB into a WebSocket ServerEndpoint?

末鹿安然 提交于 2019-11-27 11:39:44
问题 To sum up my failing project: My @ServerEndpoint class is packaged in a WAR together with the beans.xml file. My WAR in turn is packaged in a EAR and this EAR file is what gets deployed to a GlassFish 4 server that internally use Tyrus. Should it be possible? The WebSocket specification says: Websocket endpoints running in the Java EE platform must have full dependency injection support as described in the CDI specification. Websocket implementations part of the Java EE platform are required

How to get a method's annotation value from a ProceedingJoinPoint?

半腔热情 提交于 2019-11-27 09:40:22
问题 I have below annotation. MyAnnotation.java @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface MyAnnotation { } SomeAspect.java public class SomeAspect{ @Around("execution(public * *(..)) && @annotation(com.mycompany.MyAnnotation)") public Object procede(ProceedingJoinPoint call) throws Throwable { //Some logic } } SomeOther.java public class SomeOther{ @MyAnnotation("ABC") public String someMethod(String name){ } } In above class am passing " ABC " with in

Notify only specific user(s) through WebSockets, when something is modified in the database

混江龙づ霸主 提交于 2019-11-27 08:43:54
In order to notify all users through WebSockets, when something is modified in selected JPA entities, I use the following basic approach. @ServerEndpoint("/Push") public class Push { private static final Set<Session> sessions = new LinkedHashSet<Session>(); @OnOpen public void onOpen(Session session) { sessions.add(session); } @OnClose public void onClose(Session session) { sessions.remove(session); } private static JsonObject createJsonMessage(String message) { return JsonProvider.provider().createObjectBuilder().add("jsonMessage", message).build(); } public static void sendAll(String text) {