Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Java Jersey PUT-Method and Client(Implementation of a PUT-Method and its client in Java with Jersey.)
Java Jersey PUT-Method and Client [message #1574914] Tue, 20 January 2015 14:10 Go to next message
Lukas Leuenberger is currently offline Lukas LeuenbergerFriend
Messages: 3
Registered: December 2014
Junior Member
I am developing an Dynamic Web Application with Eclipse. I have e working MySQL-Database which is connected over a class called 'Data Access Object' (=DAO) that works with JDBC. I want to create entries into this database. The functions are ready. With ready I mean tested and OK. On the same application I implemented Java Jersey's RESTful WebService. It is working well, I can call the service and it returns my desired information. But now to my question:

How can I send a String containing XML? The String has to be parsed in the WebMethod to build and execute the query.

My WebService looks as follows:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

@Path("/input")
public class Input {
    //DAO instance to have connection to the database.
    //Not used yet.
    //private DAO dao = new DAO();

    @PUT
    @Consumes(MediaType.TEXT_XML)
    @Path("/result")
    public void putIntoDAO(InputStream xml) {
        String line = "";
        StringBuilder sb = new  StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(xml));
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(sb.toString());
    }
}



As you see I tried to print the incoming Stream to the console. I repeat the most important things:
•I know how to parse XML.
•I know my DAO works properly.
•I know my WebService works as well.

What I would like to know:
•How do I send an XML-String to my WebService?
•How do I access this String in my PUT-method?

Thank you for your attention and try to help me. I appreciate even every try to.

Kind regards

L.
Re: Java Jersey PUT-Method and Client [message #1575241 is a reply to message #1574914] Tue, 20 January 2015 18:14 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
This isn't really a question about Eclipse; I suggest asking on a Jersey forum or a general programming forum like StackOverflow.
Previous Topic:Any help plz
Next Topic:j2me , text box String
Goto Forum:
  


Current Time: Fri Apr 26 01:36:32 GMT 2024

Powered by FUDForum. Page generated in 0.08103 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top