Create a weather magnet using xml feed from weather.com
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.
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”
Step3:
Save the following image to your dist->images folder by right clicking on it. Make sure you don’t rename the 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(“
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
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
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!
Prakash.
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 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 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.
I am glad you tried it out but It should still work with port number specified in the url. If you try the following url in IE it returns XML data.
http://xoap.weather.com:80/weather/local/32779?cc=*&prod=xoap&par=1006383251&key=c1e3c6d7d69bcc41
Maybe somebody will try this in PHP. Thanks again.
Regards,
Prakash Singh
BSP: Create a weather magnet using xml feed from weather.com
I think the results are rather intersting in that JAVA and ABAP are similar in approach and functionality in creating this solution.
I also need those two *.jar files, could you email them to me (gesche.raabe@stud.fh-wilhelmshaven.de)?
Thanks a lot!
Regards,
Gesche
Sounds like a challenge for me 😉
VS
Very nice job. I am eager to get this on our Portal. I would appreciate if you could email the files to rrios@watsonpharm.com
(contentconverterapi.jar,contentconversionapi.jar)
Thanks
Rudy
Thank you for your kind feeback. I have sent you the jars.
Prakash
Can you please send me those 2 jar files to sathya.berigai@gmail.com.
Thanks,
Sathya
Could you kindly email me the two jars required for this iView, please?
contentconverterapi.jar,contentconversionapi.jar
Thank you,
umair.salam@gmail.com
Could you please email me the two jars required
for this iView, please?
contentconverterapi.jar,contentconversionapi.jar
Thank you,
evgenykl@gmail.com
Thanx,
Dheeram
Hi guys,Joerg Loechner
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
Your blog is very nice and cleary explain.
Please, Could you kindly email me the two jars required for this iView?
(contentconverterapi.jar,contentconversionapi.jar)
my email:mathiue2002@hotmail.com
Thank you,
Rasim
I need the two jars mailme to : mythu.vthluv@gmail.com.
Very interesting blog.
Regards,
Aksiti.