With Swagger integration EJB injection fails in weblogic 12 env

329 views
Skip to first unread message

venkatesh g

unread,
Dec 22, 2013, 1:53:02 AM12/22/13
to swagger-sw...@googlegroups.com
Dear Team,

I was trying out the example from https://github.com/wordnik/swagger-core/tree/master/samples/java-jaxrs and deploying the same in Weblogic 12c + JDK 1.7 environment. With this EJB injection is failing. Any idea, please share.

Given below the slightly modified code in the example https://github.com/wordnik/swagger-core/tree/master/samples/java-jaxrs,

@Path("/pet")
@Api(value = "/pet", description = "Operations about pets")
@Produces({"application/json", "application/xml"})
@Stateless
public class PetResource {
  static PetData petData = new PetData();
  static JavaRestResourceUtil ru = new JavaRestResourceUtil();
  
  @EJB
private HelloWorld hWorld; // EJB injection
......
.......
  public Response getPetById(
      @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("petId") String petId)
      throws NotFoundException {
System.out.println("hWorld " + hWorld); // Returns null i.e injection does not happen


}


HelloWorld EJB:-
===============

package com.wordnik.swagger.sample.ejb;

import javax.ejb.Stateless;

@Stateless
public class HelloWorld {
public void hello(String name) {
System.out.println("Hello " + name);
}
}

tony tam

unread,
Dec 23, 2013, 12:04:35 AM12/23/13
to swagger-sw...@googlegroups.com
Hi, can you share more details?  Many people use swagger in an environment like this without issue.

venkatesh g

unread,
Dec 23, 2013, 10:00:50 AM12/23/13
to swagger-sw...@googlegroups.com
It will be great if someone can crack this puzzle. Sharing the additional details, please help.

Environment:-
Weblogic 12c (12.1.1) + JDK 1.7.0

Steps to reproduce the issue i.e EJB injection fails:-
1) Download the source code from Swagger github https://github.com/wordnik/swagger-core/tree/master/samples/java-jaxrs
2) Add the EJB injection as mentioned in the attached file PetResource.java or Replace the downloaded PetResource.java code in the above step with the attached PetResource.java file. Also include HelloWorld EJB under the folder com\wordnik\swagger\sample\ejb
3) Run the build mvn clean install
4) Rename swagger-java-sample-app_2.10-1.3.1.war to swagger-java-sample-app.war [For context path]
6) Run the Swagger code http://localhost:7001/swagger-java-sample-app/pet/1, which will give you Null pointer exception as EJB injection fails

@EJB 
  private HelloWorld hWorld; //EJB injection
  
  public Response getPetById(
      @ApiParam(value = "ID of pet that needs to be fetched", allowableValues = "range[1,5]", required = true) @PathParam("petId") String petId)
      throws NotFoundException {
System.out.println("petId " + petId);
System.out.println("hWorld " + hWorld); // This will return null in Weblogic 12c environment with JDK 1.7.0
hWorld.hello("Injection works"); // This will throw null pointer exception as EJB injection fails 


Regards
Venkatesh





--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/ja0nkivx2Co/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

PetResource.java
HelloWorld.java

venkatesh g

unread,
Dec 30, 2013, 4:56:53 AM12/30/13
to swagger-sw...@googlegroups.com
I was able to crack the puzzle. In the github example, I have changed the following line in the web.xml and EJB injection works.
 
 
Thanks. This thread is closed.
 
Regards
To unsubscribe from this group and all its topics, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages