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

  • Home
  • SEARCH
  • 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 5980613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:49:33+00:00 2026-05-22T21:49:33+00:00

I am trying to provide a REST/XML Api programmed in Java. The application is

  • 0

I am trying to provide a REST/XML Api programmed in Java. The application is given a parameter and will then return XML content via HTTP.

In PHP the way I would solve it by having a rest_api.php file which is provided the parameter &string=helloworld by the application using my api, then I read this string, do calculations or searches with it, modify the data to meet my XML schema and reply this data an echo which sends it back with the HTTP response.

How do I do this properly with Java?

  • 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-05-22T21:49:34+00:00Added an answer on May 22, 2026 at 9:49 pm

    Two Java extensions work wonderfully in concert to this end:

    • JAX-RS (reference implementation Jersey)
    • JAXB (reference implementation Metro)

    Both are included with the Glassfish Java EE 5 and 6 reference implementation.

    In short, JAX-RS lets you declare a plain method as a web service by adding one of the @GET, @POST, @PUT or @DELETE annotations. JAX-RS also has annotations for automatic parsing of path and URL query parameters, and it takes care of constructing the proper response objects in most cases.

    JAXB automatically translates plain objects (POJOs) to and from XML by adding @XmlRootElement, @XmlElement, @XmlID, etc. When combined with JAX-RS, marshalling and unmarshalling is done transparently.

    For example:

    // POJO with JAXB annotations
    
    @XmlRootElement(name = "sensor")
    public class MyObject {
        @XmlID
        @XmlElement
        private String id;
    
        @XmlAttribute
        private String name;
    
        @XmlElement(name = "sensor-value")
        private Integer value;
    
        @XmlTransient // don't translate to XML
        private Double computedValue;
    
        // ...getters and setters
    }
    
    
    // POJO with REST interface
    
    @Path("/mywebservice")
    public class MyWebService {
        @EJB
        MySensorController controller;
    
        @GET
        @Produces("application/xml")
        public MyObject getCurrentSensorValue(@QueryParam("ID") String id) {
            // automatic unmarshalling from MyObject to XML
            return controller.getSensorValue(id);
        }
    }
    

    The resulting XML will look something like this:

    <sensor name="foo">
        <id>123</id>
        <sensor-value>42</sensor-value>
    </sensor>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vaadin application and I am trying to provide some REST Urls
I'm trying to develop an application server that will deliver content to a core
I am trying to provide a simple RESTful API to my ASP MVC project.
Trying to use an excpetion class which could provide location reference for XML parsing,
I'm trying to write a plugin system to provide some extensibility to an application
I'm trying to create a generic class in PHP that will provide a way
I am trying to send an URL-encoded post to a REST API implemented in
Hi I'm trying to build up a rest Service which provide JSON response. Yesterday
I'm trying to use Bing's REST api to geocode. But my 'y' value is
I'm trying to provide a link to my company's website from a Windows Form.

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.