cancel
Showing results for 
Search instead for 
Did you mean: 

Using only one method in session bean to create web service

Former Member
0 Kudos

Hi all,

I hhave a scenario where i am inserting and retrieving data from dict table using web service.

For this i have created a session bean and a wrapper class.

The session bean has two methods: insertRecords(), and viewRec().

so while creating a web service i need to include two methods.

I want to have only one method where i can pass a parameter as operation and if it is "I", then i can call the insert method and if it is "S" i can call view method.

I tried doing that bt i am stuck up with the return type.

Insert method has return type as array of wrapper class and

view method has wrapper class as return type ...

Is this scenario possible..??

or is there any other way to do this???

Plz let me knw..

Thankls n regards,

Ankita

Accepted Solutions (0)

Answers (1)

Answers (1)

siddharth_jain
Active Contributor
0 Kudos

Hi Ankita,

According to my understanding of your problem ,

you can keep the return type of your wrapper method which is internally calling the view method as Array of Wrapper class objects.

When you will call the view method according to the passed parameter and when it will return the wrapper class object then you can again create an Array of that wrapper class which will hold only 1 object and return it.

And in case of insert method return type will be Array of Wrapper class, so by doing this you can use the same method with same return type.

Hope this helps.

Regards,

Siddharth

Former Member
0 Kudos

Hi Siddharth,

Im really sorry..

i cudnt get u ..

Actually these r methods:


public DemoDicModel[] viewRecords()
{
}

and


public DemoDicModel insertRecords(
		String title,
		String desc,
		String status)
{
}

and im trying this:


public DemoDicModel[] getMethods(String operation,String title,String desc, String st)
 {
 DemoDicModel[] demoModel =null;
 	
 DemoDicModel model = new DemoDicModel();
 	
 if(operation == "show")
 {
      demoModel = viewRecords();
 }
 	
 if(operation == "ins")
 {
      model = insertRecords(title,desc,st);
      model.setMsg("RECORDS GENERATED");
      demoModel=
 }
  
 return demoModel;
 }

im stuck up with insert operation.

can u plz explain me in detail.

thanks,

ankita

Former Member
0 Kudos

Hi,

Create an interface

Create two classes that implements this interface

Return the array based on your input parameter.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

1. No need to change insertRecords method (it returns DemoDicModel type)

2. No need to change viewRecords method (it returns DemoDicModel array)

3. Change the getMethods method as follow

public DemoDicModel[] getMethods(String operation,String title,String desc, String st)

{

DemoDicModel[] demoModel =null;

if(operation == "show")

{

demoModel = viewRecords();

}

if(operation == "ins")

{

demoModel = new DemoDicModel[1];

model = insertRecords(title,desc,st);

model.setMsg("RECORDS GENERATED");

demoModel[0] = model;

}

return demoModel;

}

Hope this will solve your problem.

Thanks

Former Member
0 Kudos

hi Tatayya,

Thanks for the reply...

i have used the code ..

it doesnt give any error..

but i m nt able to get the required values..

the web service returns null;

Regards,

ankita

Former Member
0 Kudos

Hi,

You have to make sure that connection to the db is correct.

Better to debug the application or you can write simple class, which writes log messages to some file.

Place the log messages in methods and execute.

You will come to where exactly the problem is coming.