Working with XML service definitions through Java programming

Source: Internet
Author: User
Tags basic html page definition html page

Self-Service trends

For most service providers, self-service is evolving into a trend-especially for financially strapped ISPs. Therefore, if you need more bandwidth (to download or play online games), you can log on to the provider's Web site and automatically upgrade your connection to the provider through a Web page. Let's look at a concrete example: Listing 1 shows a simple xml-based User Service profile.

Listing 1. A simple xml-based service description

<ServiceInstance>
<Customer>Josephine Bloggs</Customer>
<Package>Internet</Package>
<Bandwidth>1mbps</Bandwidth>
<DownloadLimit>1Gbyte</DownloadLimit>
<Uptime>95</Uptime>
</ServiceInstance>

The code explains the user XML service model. The model includes:

A service instance

Customer Name

Name of the service pack

Configured amount of Bandwidth

allowable download limits for each month

Guarantee of the normal running time of the provider

Clearly, a service definition can be a lot more complicated than the example here. Other content may include customer address, billing details, round-trip latency, encryption, and service credit information. The point is that an increasing number of providers provide details of Web Access as shown in Listing 1. In a way, such attempts can reduce the cost and frequency of support calls. Interestingly, this web-based service allows users to feel that they are providing a more advanced provider for their services. This is achieved in a winning situation, as customers have better access to their service data, and providers can sell service packs that do not need their intervention. Authorized users can modify some of the service parameters shown in Listing 1-for example, the configured bandwidth. The user's monthly subscription fee is subsequently modified.

Therefore, the code in Listing 1 forms the basis of an xml-based service model. By simply interacting with online forms, users can modify the writable service elements (such as bandwidth). Modifications made through online forms are recorded and then reflected in back-end services that can be modified by user profiles. This is a standard way to implement self-service.

However, you will want to learn about another, more loosely coupled, self-service-a service that allows users to modify data by transferring the XML content in Listing 1 across the network. In this scenario, the transferred XML content can be modified by a Java client that runs on a desktop, laptop, or even a resource-constrained device, such as a cell phone, and then sends the data back to the network service provider. This mechanism transcends the basic HTML page model and incorporates SOA ideas.

Transfer service definition XML documents to clients that use Java technology

Java technology provides some really powerful tools for XML data processing (see Sidebar Java Technology and XML). If you view the content in Listing 1 as an xml-based rendering of a given dataset, you can also render it in other ways. The raw data that makes up the basic contents of Listing 1 is typically stored in the database. So how do you package this data into XML?

The contents of Listing 2 are extracted from the Java file Encodexml.java included with this article. (related files are available from the download section). The Encodexml.java class instantiates objects of the Xmlencoder class. As you can see, this object then creates a file named Xmldata.xml in the current directory. The next step is to insert the XML data value into the file, which can be implemented by invoking a series of WriteObject () methods (illustrated in Listing 2). Obviously, in a production environment, the hard-coded text string in Listing 2 will come from a persistent store such as a database. In any case, it is easy to see the creation of an XML data file.

Listing 2. encoding data using XML format

XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream("xmldata.xml")));
e.writeObject("Josephine Bloggs");
e.writeObject("Internet");
e.writeObject("1mbps");
e.writeObject("Gbyte");
e.writeObject("295");
e.close();

After the program in Listing 2 is executed, a file named Xmldata.xml appears in the execution directory of the program. Listing 3 explains what the newly created file contains.

Listing 3. The generated XML data

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_06" class="java.beans.XMLDecoder">
<string>Josephine Bloggs</string>
<string>Internet</string>
<string>1mbps</string>
<string>Gbyte</string>
<string>295</string>
</java>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.