Hello,
I am new to Java and I am trying to create my first web service. I am using Eclipse, Java and Axis2 to do so. I have the service up an running but now I want to ensure that my business logic and so on "lives" in the right place.
I have created a new project, added a new package and to that a new class called MyService.java
package pkg; public class MyService{ public MyService() {} public String SayHello(String name){ return "Hello " + name; } public int CalcStuff(int first, int second){ return first + second; } }
And thats it. It works and I can call the web service from another application.
Now I want to learn the proper way to do the above, assuming that it is incorrect. I think that I should change the MyService Class to not contain the "business logic" but instead have something like this:
public class MyService { public MyService() {} public String SayHello(String name){ return Hello.getHello(name); //calls a class that has business logic } public int AddNumbers(int first, int second){ return Numbers.AddNumbers(first, second); //calls a class that has business logic } }
Is the second way better? Is there a third way that is way better? Or is the first way I did it ok?
I know these are small methods, but I want to understand the way it should be before I start making actual web services.
Thanks