Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:05:01+00:00 2026-06-05T00:05:01+00:00

UPDATE I have almost been able to complete my RESTful communication, though I have

  • 0

UPDATE

I have almost been able to complete my RESTful communication, though I have to questions remaining:

1 – How do I assign my XML to the connection (the code below will give an example of my situation)?

Calling the Web Service

public Person getByAccount(Account account) {   
    URL url = new URL(uri);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Accept", "application/xml");

    XStream xstream = new XStream();
    String xmlIn = xstream.toXML(account);

    // Put the xmlIn into the connection

    BufferedReader br = new BufferedReader(new InputStreamReader(
        (connection.getInputStream())));

    StringBuilder sb = new StringBuilder();
    String line;
    while((line = br.readLine()) != null)
        sb.append(line);
    String xmlOut = sb.toString();

    connection.disconnect();
    return (Person) xstream.fromXML(xmlOut);
}

2 – Will the class below result in a valid XML-output, considering the last code example (the Web Service)?

Class to send using RESTful

@XmlRootElement(name="people")
public class People {
    @XmlElement(name="person")
    public List<Person> people;

    public People() {
        people.add(new Person(1, "Jan"));
        people.add(new Person(2, "Hans"));
        people.add(new Person(3, "Sjaak"));
    }

    public List<Person> all() {
        return people;
    }

    public Person byName(String name) {
        for(Person person : people)
            if(person.name.equals(name))
                return person;

        return null;
    }

    public void add(Person person) {
        people.add(person);
    }

    public Person update(Person person) {
        for(int i = 0; i < people.size(); i++)
            if(person.id == people.get(i).id) {
                people.set(i, person);
                return person;
            }

        return null;
    }

    public void remove(Person person) {
        people.remove(person);
    }
}

Web Service

@GET
@Path("/byAccount")
@Consumes("application/xml")
@Produces("application/xml")
public Person getByAccount(Account account) {
    // business logic
    return person;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:05:02+00:00Added an answer on June 5, 2026 at 12:05 am

    Try this:

    conn.setDoOutput(true);
    OutputStream output = conn.getOutputStream();
    // And write your xml to output stream.
    

    Check this link for using REST with standard URL: http://rest.elkstein.org/2008/02/using-rest-in-java.html

    EDIT

    First of all, you need to change your getByAccount request to POST request, because GET request doesn’t allow to pass any information in body, it uses only request parameters in url. But you send XML, so use POST.

    Try following version of your send method:

    public Person getByAccount(Account account) {   
        URL url = new URL(uri);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Accept", "application/xml");
        connection.setOutput(true);
    
        XStream xstream = new XStream();
        xstream.toXML(account, connection.getOutputStream());
    
        Person person = (Person) xstream.fromXML(connection.getInputStream());   
        connection.disconnect();
        return person;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know similar questions have been asked before. I am starting with a set
Almost all of the applications I've ever written have been GUIs of one form
UPDATE #2: I have solved almost all my issues bar the one major one.
I have been looking at the WF Wizard examples on endpoint.tv and here: http://stevenalexander.posterous.com/integrating-a-persisted-wf40-workflow-with-mv
We have been using Perl's Net:Twitter CPAN module (version 3.12) and basic authentication (not
I have been consuming a service for some time in development, and have been
I have some code that allows users to upload file attachments into a varbinary(max)
I have been spending the last hours trying to figure this out and now
I have a JScrollPane with a JTextArea set as its view port. I update
We have a very strange problem which we have yet to be able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.