2

I have to send an XML-file from one java Application to another.

Currently, it works like this: - Export to local XML-file from application 1 - Import local XML-file in application 2

Now I have to do this via web service(s). Is it possible to create a JAX-WS web service in application 1 that redirects to application 2 with the data needed?

I can send the data (object) as a serialized object, instead of a XML-file. But is this possible? And if so, how?

Both applications are written in Eclipse-Scout.

Thanks in advance.

Maarten
  • 23
  • 1
  • 5

2 Answers2

0

webservice is simple and usefull if your two apps run on different machines.

Sending server: use a library for http (post or get)

1 only keep your file. just use an HTTP / POST. works for text an binary

2 more simple: if your datas are little text, you can use HTTP / GET (beware of special characters: you can encode them).

3 if you can put all your datas in one structure (object), just serialize it, put the result in a String, and send it.

Receiving server:

if you use tomcat, extend HttpServlet, and get by doPost or doGet

Or you can use another light http server

Or soap library (no really need).

DOPOST/DOGET

Sending server: HttpURLConnection conn= (HttpURLConnection) url.openConnection(); // etc.

Receiving server:

public class MyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String one_parameter = request.getParameter("name_of_parameter");

See these links for more explanation:

Java - sending HTTP parameters via POST method easily

doGet and doPost in Servlets

Community
  • 1
  • 1
  • Thanks for this answer. But I don't have a lit of experience with this sort of stuff. Do you know of an example where they send a serialized object from one application to another, with automatically redirecting to the other application? – Maarten Dec 22 '15 at 07:56
  • I found a post where someone does exactly what I want to do. But he doesn't explain how he sends the object to the other application: http://stackoverflow.com/questions/13584646/transferring-a-java-class-between-applications-via-serialization – Maarten Dec 22 '15 at 08:41
  • Thanks. So instead of using php (as they do in the example you sent), I have to send a SOAP envelope by using HttpURLConnection (from the sending server)? Does this mean that I only need to build a web service (using wsdl) on the receiving server? Thanks. – Maarten Dec 22 '15 at 09:24
  • not at all: in the line of code I put: you only package your datas on sendind server, naming them "name_of_parameter", and you get them in receiving server/Myservlet with request.getParameter. No SOAP, no wsdl – guillaume girod-vitouchkina Dec 22 '15 at 09:30
  • Oh ok. But then, how would the url look like on the sending server? Since I'm not using PHP, I'm a bit confused about that part. – Maarten Dec 22 '15 at 09:36
0

(A bit long for a comment)

You may want to stay away from bloated things like JAX-WS and just use a standard Servlet and JAXB or XStream for de-/serialisation.

Also, do not ever use Java (binary) deserialisation or default XStream on unauthenticated inputs/transport (e.g. HTTP or untrusted clients even with HTTPS). It always leads to remote code execution exploits that cannot be migitated without redeveloping your webservice interface. Most recent instance...

billc.cn
  • 7,187
  • 3
  • 39
  • 79