Home > Products > SophiaFramework UNIVERSE > BREW Application for Amazon Web Service

BREW Application for Amazon Web Service using REST / SOAP API

Mobile2.0 on BREW ! : Access Web Services from BREW Phones

Web 2.0 software technologies such as blogs, SNS and RSS regard the web itself as a platform.

Amazon, Google and Yahoo! deliver information in XML format through their web services.

Standard XML data can be viewed, modified and operated freely. Therein lies the biggest strength of these Web services.

Now BREW enabled mobile phones are able to wirelessly access these Web services.

[ Aug. 8, 2006] SophiaFramework Latest Information

The C++ WSDL/SOAP/XML libraries have now been added to SophiaFramework 4.0.

The World's First XML Parser for BREW "pself"

"pself" is the world's first XML Parser for BREW to support DTD and XML schema. Its source code was developed using SophiaFramework UNIVERSE.

Its implementation is in keeping with the API of Microsoft's XML Parser for C++ ( Microsoft XML Core Services (MSXML) 4.0 ).

Therefore, pself allows Web service applications for BREW to be coded smoothly in C++, on Windows.

XML data acquired from Web servers is automatically processed by pself. ( No BREW programming is required )

"Bookshelf Application" using Web service from Amazon.co.jp

Amazon.co.jp offers functions that allow book searches and purchases to be performed online.

The "Bookshelf Application" presented here is a BREW application which uses pself to instantly display information about books available on Amazon.co.jp on a BREW enabled mobile phone.

Amazon Web Service

URL Used to Obtain Book Information from the Amazon Web Server.
http://webservices.amazon.co.jp/onca/xml?Service=AWSECommerceService
&Operation=ItemSearch
&SubscriptionId=[ Subscription ID ]
&SearchIndex=Books
&ResponseGroup=Large
&Power=isbn:0123456789X

  * URL should be written without line breaks.

Enter your Subscription ID in "[Subscription ID]". You can get your subscription ID when registering for Amazon Web services.

Enter the ISBN number in "Power = isbn: ".

The window below is displayed when the URL is accessed using a PC browser.

When viewed from PC Browser

Essential Parts of the XML Data Above
<ItemSearchResponse 
xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
    ...
    <Items>
        ...
        <Item>
            <ASIN>0123456789X</ASIN>
            <DetailPageURL>URL of the page product</DetailPageURL>
            ...
            <ItemAttributes>
                <Author>Author</Author>
                ...
                <Title>Title</Title>
            </ItemAttributes>
            ...
        </Item>
    </Items>
<ItemSearchResponse>

For instance, <Author> found in <ItemAttributes> represents the author's name and <Title> is the book's title.

Handling XML Data Using pself

HTTP communication with Amazon is achieved through the SFXHTTPConnection class of SophiaFramework UNIVERSE.

Before the inbound data can be delivered to pself, it is first saved to the file "amazondata.xml" using the SFXFile class of SophiaFramework UNIVERSE.

// Error handling is ommited.

SFXXMLDOMParser parser; // Parser class for handling XML data
parser.SetDoNamespaces(false); // Namespace function OFF

SFCError error = parser.Parse("amazondata.xml"); // Process XML data

// Save data like author, title, etc. (String Class) 
SFXAnsiString asin;
SFXAnsiString detailPageURL;
SFXAnsiString author;
SFXAnsiString title;

if (error == SFERR_NO_ERROR) { // Data successfully processed
    SFXXMLDocument* root = parser.GetDocument(); // Get root
    if (root != null) {
        SFXXMLNodePtr child;

        // Search for Item tag. (Result will be given in a form of a list)
        SFXList<SFXXMLNodePtr>* list = root->GetElementsByTagName("Item");
        // If Item tag is found
        if (list != null && list->GetSize() > 0) { 
            child = list->Get(0); // This time, there is only 1 Item tag

            // use "for" to access child element of tags one by one
            // Get child element by GetFirstChild 
            // Get next element of the same section by GetNextSibling

            for (child = child->GetFirstChild(); child != null;
                child = child->GetNextSibling()) {

                // If node name is ASIN
                if (SFXAnsiString(child->GetNodeName()) == "ASIN") {
                    // Put <ASIN> content in asin
                    // Converts "&lt;", "&gt;", ... into "<", ">", ...  
                    asin = DecodeHtml(child->GetText()); 
                         
                }

                // If node name is DetailPageURL,
                else if (SFXAnsiString(child->GetNodeName()) 
                                              == "DetailPageURL") {
                    detailPageURL = DecodeHtml(child->GetText());
                }

                // If node name is ItemAttributes,
                else if (SFXAnsiString(child->GetNodeName()) 
                                              == "ItemAttributes") {
                    SFXXMLNodePtr node;

                    // access child element of ItemAttributes one by one

                    for (node = child->GetFirstChild(); node != null;
                            node = node->GetNextSibling()) {

                        // If node name is Author,
                        if (SFXAnsiString(node->GetNodeName()) 
                                                     == "Author") {
                            author = DecodeHtml(node->GetText());
                        }
                        // If node name is Title,
                        else if (SFXAnsiString(node->GetNodeName()) 
                                                     == "Title") {
                            title = DecodeHtml(node->GetText());
                        }
                    }
                }
            }
        }
        else {
            error = SFERR_FAILED; // Failed
        }
    }
    else {
        error = SFERR_FAILED; // Failed
    }
}

// Results are in asin, detailPageURL, author, title

Development and the maintenance are both facilitated by the XML data structures being fed directly into the source code.

GUI of "Bookshelf Application"

BREW App by SophiaFramework UNIVERSE

A book's essential information like title, author, image, price, contents, summary, reviews can be presented clearly on a mobile phone display with the proper original GUI.

The development of this GUI will be significantly reduced thanks to SophiaFramework UNIVERSE's GUI framework. It provides an infrastructure specifically for BREW mobile phones that needs only to be customized for each application.

Key Handlers
// Code for key handlers
HANDLER_IMPLEMENT_BOOLEVENT(InformationWindow, OnKey, event)
{
    switch (event.GetP16()) {
        case AVK_UP:      // When the up key is pressed
            FocusUp();    // moves focus upwards (used to scroll)
            return true;
        case AVK_LEFT:    // When the left key is pressed
            FocusLeft();  // moves focus left (used to toggle tabs)
            return true;
        case AVK_DOWN:    // When the down key is pressed
            FocusDown();  // moves focus downwards (used to scroll)
            return true;
        case AVK_RIGHT:   // When the right key is pressed
            FocusRight(); // moves focus right (used to toggle tabs)
            return true;
        case AVK_CLR:     // When the clear key is pressed
            // Close window
            return Invoke(SFXEvent(SREVT_RESPONDER_TERMINATE,
                       SRP16_TERMINATE_INVOKE, true));
    }
    return false;
}
Tab Control
// Building tabs (not full code)

// Building tab controls
SFRTabControlPtr tab = new SFRTabControl
                   (this, SFXRectangle(0, 0, 150, 200));

// Build 1st tab page (for general information)
SFRTabPanePtr pane1 = new SFRTabPane(tab, "General Information");

// Build 2nd tab page
SFRTabPanePtr pane2 = new SFRTabPane(tab, "Detailed Information");

// Build 3rd tab page
SFRTabPanePtr pane3 = new SFRTabPane(tab, "Review");

...

// Display text in 1st tab.
new SFRLabelControl(pane1, SFXRectangle(5, 5, 100, 28), "Title:");
new SFRLabelControl(pane1, SFXRectangle(125, 5, 100, 28), title);
new SFRLabelControl(pane1, SFXRectangle(5, 45, 100, 28), "Author:");
new SFRLabelControl(pane1, SFXRectangle(125, 45, 100, 28), author);

...

By using pself and SophiaFramework UNIVERSE, the "bookshelf GUI application" with tab control was completed with a minimum amount of coding.