views:

122

answers:

2

I have a problem with web services. They are programed in Java and are running on a WASCE server ( both are on the same server). My problem that i want to solve: We have two Web services: App1 and App2

In App1 i want to call a function that is in App2. How can i do this? Is this even possible? I tried creating a soapClient inside the App1 so i can connect to the App2 but that doesn't work. exp: I have a client that calls app1 gets data from app1 and send it to app2 then get back the response data from app2 and send it to an other function into the app1.

What i want to do is to skip the client part and do it directly so that app1 can send directly the data to the app2 and then receive an answer do whatever it needs to do.

For the note: Both of the web services use the connection to the database.

Thank you in advance. (it has been edited with additional data)

+1  A: 

It's definitely possible, with differing levels of complexity and feasibility depending on exactly what it is you want, and the restrictions you place on it.

Probably one of the simplest ways to go about this, if you don't have a problem with the method in App2 being public, is to simply create a web service exposing that method and call if from App1.

If you want App2's method to be essentially "protected", so that it can be called by App1 but not by public clients, then there are several alternative options. Firstly, you could use firewalls or equivalent to prevent external requests to the service URL. Alternatively, you could expose the method through some form of interprocess communication; RMI would be the obvious native one for Java (set up an RMI method in App2 and export this through a manager, then obtain the reference in App1 and invoke the method remotely). Depending on exactly what it is you want to do, you may be better off with a framework that does all this under the covers; e.g. distributed objects through something like Terracotta.

You should give more detail in your question, though - currently the only thing you've really specified is that you want to call "a function" in App2 from App1. There are dozens (if not hundreds) of ways to go about this and the best one(s) will depend on the details of what you're trying to do.

EDIT (in light of comments): It's not the details of what you want to do that are lacking - I understand fine that you want to call some method in App2 from within App1. It's more the architectural details - what languages are both clients coded in, what libraries are you using to do the web services, are both clients on the same machine or separate ones (and if same machine, same JVM or not), are there any firewall issues that could inhibit certain kinds of connectivity, are there any office-political restrictions that could inhibit your options, are there any security restrictions that could do the same (such as whether you can expose the functionality of App2's method publically or not). All of these will shape what is possible and what is optimal - because at the end of the day, all networking is basically I want to use resources on that remote computer from here. Without more architectural specifics, there are literally dozens of ways that you could achieve this.

Regarding exposition: You would create a web service to expose App2's function in the same way you would create any other web service (with the details being dependent on the tool/framework you're using). As an example if you're using a tool that supports the JSR-181 annotations, you'd write a method in App2 that performs this function, and annotate it with @WebMethod. Then you'd ensure that if this method is not part of an existing webservice class you'd annotate its class with @WebService. I was presuming that since you already have a couple of web services, you'd know how to write/define them.

As for accessing the web service from App1, this can be done quite simply by a Java SOAP client. A tool such as WSDL2Java can create a stub class modelling the remote service that you can call; alternatively you can get a richer interface with something like CXF.

What WS library are you using currently, and what errors have you encountered when trying to use it to perform this interaction?

Andrzej Doyle
You are heading the right way. I will give you an example of what i want to do.I have 2 web services that can work alone or for optimization together. Now im working like this : I have a client that calls app1 gets data from app1 and send it to app2 then get back the response data from app2 and send it to an other function into the app1. What i want to do is to skip the client part and do it directly so that app1 can send directly the data to the app2 and then receive an answer do whatever it needs to do. Hope that this is enough. if you need more info say it please and thank you wery much.
Mesni
oh and a question about the exposing. How do i do that? how do i create an web service exposing that method? thank you in advance
Mesni
Thank you very much you were a great help!!!! I just have to check about the security.
Mesni
+1  A: 

What does "doesn't work" mean? Exactly what happens?

Start by generating some client code for App2. Can you use that from some simple Java environment, or say a Servlet. If that works, what happens when you try to call it from inside your App 1 Service implementation code?

However: if these are related services running in the same JVM can you not set up some simpler relationship using java libraries. My preferred way of developing a service is first to develop some useful Java code, and make sure that works, then "wrap" it as a Web Service. In which case I have a callable routine that can just be invoked as Java.

djna
the WASCE trows an error.I cant make java libraries because this functions access to the database and using this in a library isnt a good idea.Maybe i did something wrong when i added a the client into the App2 is that possible?? Hmm tomorrow i will try it again and will come back to you.Thank you for your anwser
Mesni
But what error? WAS itself throwing it, or your APP saying something in the log? You might get better help if you showed exactly the error and also told us what Web Service toolkits you're using.
djna
Now i will try to do it this way and will comment if it is working. Thank you !!
Mesni
Ok i tried it again and with an other metod Here is the tutorial:http://px.pats.no/px/Eclipse_tutorial.htmlAnd then i added the generated code into my service and it actualy worked!!! thank you very much for your help and support. I wold give you a million points but I'm not able to :( thank you!!!
Mesni
Very pleased that you got it going. Also nice that you have given that tutorial referecne.
djna