Skip to Content

Introduction

In this weblog i am going to present code to build a nice weather magnet for you portal. The code uses xml feed from weather.com and transforms the feed into a nice display using XSLT.

image

Required Jars

contentconverterapi.jar,contentconversionapi.jar

Step1:

Get an account from weather.com for your xml feed. Weather.com will send you a partner id and account key. You will see this info to retrieve the xml feed.

[http://www.weather.com/services/xmloap.html | http://www.weather.com/services/xmloap.html]

Step2:

Create a portal project(com.ust.weather) in NWDS or eclipse. Add a Dynpage class called

“Display”

image

Step3:

Save the following image to your dist->images folder by right clicking on it. Make sure you don’t rename the image.

!http://image.weather.com/web/common/wxicons/31/0.gif!

!http://image.weather.com/web/common/wxicons/31/1.gif!

!http://image.weather.com/web/common/wxicons/31/2.gif!

!http://image.weather.com/web/common/wxicons/31/3.gif!

!http://image.weather.com/web/common/wxicons/31/5.gif!

!http://image.weather.com/web/common/wxicons/31/5.gif!

!http://image.weather.com/web/common/wxicons/31/6.gif!

!http://image.weather.com/web/common/wxicons/31/7.gif!

!http://image.weather.com/web/common/wxicons/31/8.gif!

!http://image.weather.com/web/common/wxicons/31/9.gif!

!http://image.weather.com/web/common/wxicons/31/10.gif!

!http://image.weather.com/web/common/wxicons/31/11.gif!

!http://image.weather.com/web/common/wxicons/31/12.gif!

!http://image.weather.com/web/common/wxicons/31/13.gif!

!http://image.weather.com/web/common/wxicons/31/14.gif!

!http://image.weather.com/web/common/wxicons/31/15.gif!

!http://image.weather.com/web/common/wxicons/31/16.gif!

!http://image.weather.com/web/common/wxicons/31/17.gif!

!http://image.weather.com/web/common/wxicons/31/18.gif!

!http://image.weather.com/web/common/wxicons/31/19.gif!

!http://image.weather.com/web/common/wxicons/31/20.gif!

!http://image.weather.com/web/common/wxicons/31/21.gif!

!http://image.weather.com/web/common/wxicons/31/22.gif!

!http://image.weather.com/web/common/wxicons/31/23.gif!

!http://image.weather.com/web/common/wxicons/31/24.gif!

!http://image.weather.com/web/common/wxicons/31/25.gif!

!http://image.weather.com/web/common/wxicons/31/26.gif!

!http://image.weather.com/web/common/wxicons/31/27.gif!

!http://image.weather.com/web/common/wxicons/31/28.gif!

!http://image.weather.com/web/common/wxicons/31/29.gif!

!http://image.weather.com/web/common/wxicons/31/30.gif!

!http://image.weather.com/web/common/wxicons/31/31.gif!

!http://image.weather.com/web/common/wxicons/31/32.gif!

!http://image.weather.com/web/common/wxicons/31/33.gif!

!http://image.weather.com/web/common/wxicons/31/34.gif!

!http://image.weather.com/web/common/wxicons/31/35.gif!

!http://image.weather.com/web/common/wxicons/31/36.gif!

!http://image.weather.com/web/common/wxicons/31/37.gif!

!http://image.weather.com/web/common/wxicons/31/38.gif!

!http://image.weather.com/web/common/wxicons/31/39.gif!

!http://image.weather.com/web/common/wxicons/31/40.gif!

!http://image.weather.com/web/common/wxicons/31/41.gif!

!http://image.weather.com/web/common/wxicons/31/42.gif!

!http://image.weather.com/web/common/wxicons/31/43.gif!

!http://image.weather.com/web/common/wxicons/31/44.gif!

!http://image.weather.com/web/common/wxicons/31/45.gif!

!http://image.weather.com/web/common/wxicons/31/46.gif!

!http://image.weather.com/web/common/wxicons/31/47.gif!

!http://image.weather.com/web/common/wxicons/31/na.gif!

!https://weblogs.sdn.sap.com/weblogs/images/11062/transparent_orange_go.gif|height=19|alt=image|width=28|src=https://weblogs.sdn.sap.com/weblogs/images/11062/transparent_orange_go.gif|border=0!

!https://weblogs.sdn.sap.com/weblogs/images/11062/TWClogo_32px.gif|height=32|alt=image|width=43|src=https://weblogs.sdn.sap.com/weblogs/images/11062/TWClogo_32px.gif|border=0!

image

Step4:

Modify your Display.java to add the following code.

Make sure you change the code to use your partner id and key sent to you by weather.com. This code will not work till you update your information in it.

/* Built By: Prakash Singh

  • Technical Consultant

  • Universal System Technologies, Inc

  • 2500 W. Lake Mary Blvd., Ste 212-A

  • Lake Mary, FL 32746 USA

  • M 407-474-2216

*/

package com.ust.weather;

import java.io.BufferedInputStream;

import java.io.BufferedReader;

import java.io.ByteArrayInputStream;

import java.io.File;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import java.net.URL;

import com.sapportals.htmlb.DropdownListBox;

import com.sapportals.htmlb.Form;

import com.sapportals.htmlb.GridLayout;

import com.sapportals.htmlb.GridLayoutCell;

import com.sapportals.htmlb.Link;

import com.sapportals.htmlb.enum.CellHAlign;

import com.sapportals.htmlb.enum.DropdownListBoxDesign;

import com.sapportals.htmlb.event.Event;

import com.sapportals.htmlb.htmlcontainer.NonIsolatedHtmlContainer;

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

import com.sapportals.portal.prt.component.IPortalComponentInitContext;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.PortalComponentException;

import com.sapportals.portal.prt.contentconversion.XSLConverter;

import com.sapportals.portal.prt.logger.ILogger;

import com.sapportals.portal.prt.runtime.IPortalConstants;

import com.sapportals.portal.prt.runtime.PortalRuntime;

/**

  • @author Prakash Singh

*/

public class display extends PageProcessorComponent {

     /* (non-Javadoc)

     

  • @see com.sapportals.portal.htmlb.page.PageProcessorComponent#getPage()

      */

     public DynPage getPage() {

          return new RSSDynPage();

     }

     /* (non-Javadoc)

     

  • @see com.sapportals.portal.prt.component.IPortalComponentInit#init(com.sapportals.portal.prt.component.IPortalComponentInitContext)

      */

     public void init(IPortalComponentInitContext arg0)

          throws PortalComponentException {

          // TODO Auto-generated method stub

          super.init(arg0);

     }

     public class RSSDynPage extends DynPage {

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doInitialization()

          */

          private String location = “”;

          private String center = “”;

          private String tendayurl = “”;

          public void doInitialization() throws PageException {

               // TODO Auto-generated method stub

               location = “”;

          }

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doProcessAfterInput()

           */

          public void doProcessAfterInput() throws PageException {

               // TODO Auto-generated method stub

          }

          

          public void onSelect(Event vent) throws PageException {

               DropdownListBox centerfld =

                                   (DropdownListBox) getComponentByName(“DDLocation”);

             location = centerfld.getValueAsDataType().toString();

                    }

          /* (non-Javadoc)

          

  • @see com.sapportals.htmlb.page.DynPage#doProcessBeforeOutput()

           */

          public void doProcessBeforeOutput() throws PageException {

               ILogger logger =

                    PortalRuntime.getLogger(IPortalConstants.IVIEW_LOGGER);

               BufferedReader reader = null;

               try {

                    IPortalComponentRequest request =

                         (IPortalComponentRequest) this.getRequest();

                    URL url = getURL();

                    reader =

                         new BufferedReader(

                              new InputStreamReader(

                                   new BufferedInputStream(url.openStream())));

                    StringBuffer buff = new StringBuffer();

                    for (int i = reader.read(); i != -1; i = reader.read()) {

                         buff.append((char) i);

                    }

                    reader.close();

                    String rssString = buff.toString();

                    //get rss stylesheet

                    File file = getRssStyleSheet(request);

                    XSLConverter converter = new XSLConverter(file, null);

                    String result = converter.convert(rssString, request);

                    NonIsolatedHtmlContainer container =

                         new NonIsolatedHtmlContainer(

                              new ByteArrayInputStream(result.getBytes()));

                    Form form = this.getForm();

                    form.addRawText(“

Deploy your component and run it. BAM! you got yourself a nice weather magnet.

image

To report this post you need to login first.

27 Comments

You must be Logged on to comment or reply to a post.

  1. Raghu G
    Prakesh

    Excellent. This is what I am looking for. Where can I get contentconverterapi.jar,contentconversionapi.jar files. I would appreciate if you can email them to r_basis@yahoo.com

    Thanks
    Raghu

    (0) 
  2. Gopinath Venkatesan
    Hi Prakash,
      That was an interseting work.I just wanted to try the same.How to find the XSLConverter in the display program.Where can i find the contentconverterapi.jar.

    regards
    Gopi

    (0) 
  3. Ken Miller
    Your blog is perhaps one of the most useful blogs for content developers.  Lots of good stuff!

    Where can I find the two jar files in my Portals distribution?  I saw a note on SDN where you pointed someone to the portal for the files, but for the life of me, I can’t find them.  Or, if it’s easier, you can mail them to ‘ken.miller at huskyenergy.com’.

    Keep up the good work!

    (0) 
    1. Prakash Singh Post author
      Thank you Ken. I have sent you the jar files. Sorry i haven’t had a chance to respond to your email about message broadcaster. Did you finally figure it out? Let me know if you have still have a question on it.

      Prakash.

      (0) 
  4. Thomas Jung
    I was going to recreate your example in BSP.  I have ran into a little problem and I thought I might post it here in case anyone else tries. 

    The problem is that I can’t get the call to xoap.weather.com come to return correctly either with an RFC HTTP Connection or by coding the Client call itself with cl_http_client.  It appears that my request keeps being sent to http://www.weather.com instead.

    Doing some research on line it appears that weather.com is using a Name-Based Virtual Hosting scheme.  They are running on Apache with HTTP version 1.0.  It appears that with this setup, the client must make sure that the host request header field is properly formed because that is what the server will use to direct to the correct virtual host.  I verified that this was the problem using a website called web-sniffer.net.  I was able to recreate the same problem by sending a HTTP/1.0 request wihtout the host header to the xoap.weather.com address with this website. 

    So I did a trace on the ICM call out of SAP to see what the problem was.  SAP properly included the host header, except they always include the service port number.  So what I saw in the trace was host:xoap.weather.com:80.  I checked on the http://www.w3.org and it doesn’t say you shouldn’t include the port if it is the default.  It mearly says if you don’t include the port, the server will assume the default port:
    “A “host” without any trailing port information implies the default port for the service requested (e.g., “80” for an HTTP URL). “

    However Weather.com’s server can’t seem to handle port 80 being on the end of the host header.  To verify this I debugged down into the HTTP client and changed the value of the port in memory before it makes the call. Sure enough, the proper XML was returned.

    However there apprears to be no way to specify no Port in the ABAP coding of the HTTP Client.  The following code shows that No Port leads to 80 being defaulted in.
    if service is initial.
        if scheme = schemetype_http.
          service = ’80’.
        else.
          service = ‘443’.
        endif.
      else.

    I’m afraid that without changing SAP’s ABAP code in the HTTP Client Class, there isn’t a way to easily replicate this example in BSP. 

    (0) 
      1. Thomas Jung
        Yes, but just because you put the port in the URL in IE doesn’t mean that IE is inserting that into the host field of the HTTP header.  You would need a tool that snifs the HTTP header request to see that.  When I tested with my tool, IE does not include the port in the header field value if it is port 80.
        (0) 
      2. Prakash Singh Post author
        You are correct. I just tried it on my firefox and it does goes to weather.com. Looks like IE erases the port 80 and weather.com can’t handle port 80 in the url( i am repeating your words).
        (0) 
          1. Thomas Jung
            The HTTP Client problem with the ports should soon be offically fixed.  Have a look at OSS note 858970 for the details.  Thanks goes to Brian McKellar for keeping on top of this.
            (0) 
    1. Ravi Kumar Kuntala
      Hi Prakash,

      Great job ! Very usefull blog to many professional. Thanks.

      But, when I deploy the application I get foll error :

      Portal Runtime Error

      An exception occurred while processing a request for :
      iView : com.ust.weather.display
      Component Name : com.ust.weather.display

      xoap.weather.com.
      Exception id: 03:27_03/03/07_0766_1198650
      See the details for the exception ID in the log file

            Please, kindly let me know where iam going wrong.

      Appreciate your valuable inputs.

      Thanks in advance,
      Ravi Kumar

      (0) 

Leave a Reply