cancel
Showing results for 
Search instead for 
Did you mean: 

Service is null @WebServiceRef : Null Pointer Exception

nagishetty
Explorer
0 Kudos

Hi Guys,

I am using @WebServiceRef in my EJB WebModule,

@WebServiceRef (name="DataBrowserOB") DataBrowserService service; 


When it is invoked from the same EJB it gets Executed, But when it is triggered from another EJB the "service" is null, Service is not getting Instantiated.

Could anyone let me know is there any other way we could Instantiate?


Thanks,

Nagishetty

Accepted Solutions (1)

Accepted Solutions (1)

christian_santej
Active Participant
0 Kudos

Hi,


@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

public String businessMethodFromOtherEJB(Strig someFancyInput){

    //TODO implement; call webServiceRef injected service

    return null

}

Regards,

Christian

nagishetty
Explorer
0 Kudos

Hi Christian,

Thanks for your reply,

How do we lookup Service via JNDI?

I have tried with @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) ,,, But still there exists a Null Pointer Exception.

Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

You have to lookup the name of the service in the JNDI Browser (JNDI Browser - Developing Java EE 5 Applications - SAP Library) the call itself can be done as described here: Looking up Objects - Developing Java EE 5 Applications - SAP Library

(Main Documentation: Naming and Directory Services (JNDI) - Developing Java EE 5 Applications - SAP Library)

Regards,

Christian

nagishetty
Explorer
0 Kudos

Hi Christian,

I have the below Logic,

@WebServiceRef(name = "dataBrowser_OB")

  private DataBrowserOBService dataBrowserOBService;

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

public void cedbCallPI(){

InitialContext ctx;

  try {

  ctx = new InitialContext();

  DataBrowserOBService dataBrowserOBService = (DataBrowserOBService) ctx

.lookup("java:comp/env/com.Sample.gmmd.databrowser.pi.ejb.DataBrowserPIBean/dataBrowserOBService");

  dataBrowserOBService.getPort(DataBrowserOB.class);

  dataBrowserOBService.getHTTP_Port().dataBrowserOB();

  } catch (NamingException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  }

}

But I get a NameNotFoundException.

Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

Hi again,

You're using all variants - stick to the JNDI approach.

  1. Remove the @ WebServiceRef(name="....) part
  2. Remove the @ TransactionAttribute(....) part

The remaining method should be correct.


public void cedbCallPI(){

InitialContext ctx;

  try {

  ctx = new InitialContext();

  DataBrowserOBService dataBrowserOBService = (DataBrowserOBService) ctx

.lookup("java:comp/env/com.Sample.gmmd.databrowser.pi.ejb.DataBrowserPIBean/dataBrowserOBService");

  dataBrowserOBService.getPort(DataBrowserOB.class);

  dataBrowserOBService.getHTTP_Port().dataBrowserOB();

  } catch (NamingException e) {

  // TODO Auto-generated catch block

  e.printStackTrace();

  }

}

The only thing i'm not sure is if your lookup value is correct. What does the JNDI Browser return if you search for "DataBrowserOBService"?

Regards,

Christian

nagishetty
Explorer
0 Kudos

Hi Christian,

As suggested i have removed all variants and used JNDI approach, But i get a NameNotFoundException.

Below are the lookup details in JNDI,

I have provided "java:comp/env/dataBrowser_OB" and also tried with complete Object Name in the lookup value.

Best Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

i see.

you say you've also tried it with the full object name (which should work) "ejbContexts/com.XXXXXXXXgmmd~databrowser~pi~ejb~app/com.XXXXXXXX~gmmd~databrowser~pi~ejb~ejbjar.jar/DataBrowserPIBean/java:comp/env/dataBrowser_OB" - what does the error message say? is it something like "com.sap.engine.services.jndi.persistent.exceptions720.NameNotFoundException: Path to object does not exist. First missing component is" or something else?

regars,

Christian

nagishetty
Explorer
0 Kudos

Yes

it is "com.sap.engine.services.jndi.persistent.exceptions720.NameNotFoundException: Path to object does not exist. First missing component is [env],".

Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

mhm mhm.

could you post your current lookup snippet again (like you did before)?

regards,

nagishetty
Explorer
0 Kudos

Yeah,

/**

* Session Bean implementation class DataBrowserPIBean

*/

@WebService(endpointInterface = "com.xxxxxx.gmmd.databrowser.pi.ejb.DataBrowserPIBeanLocal", portName = "DataBrowserPIBeanPort", serviceName = "DataBrowserPIService", targetNamespace = "http://xxxxxx.com/gmmd/databrowser/pi/ejb/")

@Stateless

public class DataBrowserPIBean implements DataBrowserPIBeanLocal {

/**

  * Default constructor.

  */

  public DataBrowserPIBean() {

  }

  @Override

  public void cedbCallPI(String fileName, String userID) {

  InitialContext ctx;

  try {

  ctx = new InitialContext();

  DataBrowserOBService dataBrowserOBService = (DataBrowserOBService) ctx

.lookup("ejbContexts/com.xxxxxx/gmmd~databrowser~pi~ejb~app/com.xxxxxx~gmmd~databrowser~pi~ejb~ejbjar.jar/DataBrowserPIBean/java:comp/env/dataBrowser_OB");

  dataBrowserOBService.getPort(DataBrowserOB.class);

  DataBrowser_UD dB = new DataBrowser_UD();

  UserDetails uD = new UserDetails();

  uD.setTableName(fileName);

  uD.setUserID(userID);

  dB.setUserDetails(uD);

  dataBrowserOBService.getDataBrowser_OB_Port().dataBrowserOB(dB);

  } catch (NamingException e) {

  // TODO Auto-generated catch block

  System.err.println("NameNotFoundException : " + e);

  }

}

}

Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

thanks for full snippet.

i can't see why this shouldn't work....

  1. are you able to call a different EJB with this method?
  2. is this ejb deployed in the same container or a different one (LOCAL vs. REMOTE call)?
  3. maybe it is a PI related issue (what pi version are you working on)?

regards

nagishetty
Explorer
0 Kudos

Hi Christian,

1. The method "cedbCallPI" is being called by another EJB method, I could able to call this method from different EJB method, But the only problem is with Service class object which is Null [Not Instantiated] when Invoked.

2. Both EJB's are deployed in the same Container.

3. Am working with 7.31 PI version.

And with @WebServiceRef  i could able to Execute Successfully from Web Service Navigator, But now with the JNDI approach i get Exception even from Web Service Navigator.

Thanks & Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

what does the exception say?

have you published your web service? i'm not working with SAP PI but SAP Portal and here we have to publish the WS first (otherwise the WS Navigator test fails) ref: Publishing Web Services from the SAP NetWeaver Administrator - Administration - SAP Library

regards,

Christian

nagishetty
Explorer
0 Kudos

Hi,

It works with @WebServiceRef along with JNDI lookup.

Thank You so Much Christian for Helping Me on this Issue.

Regards,

Nagishetty

christian_santej
Active Participant
0 Kudos

You're welcome

Regards,

Christian

Answers (1)

Answers (1)

former_member191044
Active Contributor
0 Kudos

Have you verified that your service is up and running. Maybe check if can finde and execute it in the WSNavigator.

nagishetty
Explorer
0 Kudos

Hi Tobias,

Thanks for your reply,

The Service is running Successfully through WebServiceNavigator, The Service is Null only when it is called from another EJB.

Regards,

Nagishetty