Show TOC

Background documentationCalling Portal Applications from Java EE Applications Locate this document in the navigation structure

 

This section describes how Java EE applications can access portal components and portal services.

Procedure

  1. Specify the reference tag.

    The reference tag is specified in the application-j2ee-engine.xml. It has the following specifics:

    • Attribute: reference-type.

      Attribute value: hard or soft.

    References to portal applications are treated in a unique way. This means there is no difference if hard or weak reference type is used.

  2. Specify the reference-target tag.

    • Tag value: The name of the portal application or an alias defined for it:

      • Attribute: target-type. Attribute value: application.

      The value application identifies the reference target as the portal application:

      • Attribute: provider-name. Attribute value: sap.com.

    The value of this attribute should correspond to the property Vendor of the portalapp.xml. By default, if no Vendor is provided in the portal application descriptor of the referenced application, the provider-name in the application-j2ee-engine.xml is sap.com..

  3. Access the application.

    The application is accessed via JNDI. The lookup is made to the portal registry. There is currently no JNDI schema defined for the portal registry. Therefore, the object factory for the portal registry must be specified in the environment of JNDI through:

    • the environment variable: Context.INITIAL_CONTEXT_FACTORY. It must have the value: com.sapportals.portal.prt.registry.PortalRegistryFactory.

    • The lookup is made using the following JNDI path: /broker/services/<service name>, and you can use one of the following notations:

      <service name> is the key of the service as defined in its interface.

      <application name>.<service name> can be used as defined in the portalapp.xml file of the application which provides the service.

Example

The following is an example of a Web Dynpro application that uses the portal transformation service to transform an XML file into HTML. The XML file is in the RSS format, a common format for providing news on the Internet. The example shows how to read the current news from Yahoo and transform the XML to HTML using an XSL style sheet located in c:\temp.

Syntax Syntax

  1. importcom.sapportals.portal.prt.service.xsltransform.IXSLTransformService;
    importcom.sapportals.portal.prt.service.xsltransform.IWPXSLTransformer;
    
    public class HelloWorld {
        public void wdDoInit() {
            String output;
            String line;
            String rssStyleSheetFileName = "c:/temp/rsshtml20.xsl";
            String topStoriesURLName =
                "http://rss.news.yahoo.com/rss/topstories";
            URL rssStyleSheetURL = null;
            URL topStoriesURL = null;
            StringBuffer news = new StringBuffer();
            StringBuffer styleSheet = new StringBuffer();
    
            Hashtable env = new Hashtable();
    
            env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sapportals.portal.prt.registry.PortalRegistryFactory");
    
            InitialContext context = new InitialContext(env);
    
            IXSLTransformService xslTransformService =
                (IXSLTransformService) context.lookup(
                "/broker/services/" + IXSLTransformService.KEY);
    
            try {
                rssStyleSheetURL = new URL("file://localhost/" +
                    rssStyleSheetFileName);
    
                InputStreamReader iReader =
                    new InputStreamReader(rssStyleSheetURL.openStream());
                BufferedReader bReader = new BufferedReader(iReader);
    
                while ((line = bReader.readLine()) != null) {
                    styleSheet.append(line);
                }
    
                IWPXSLTransformer rssTransformer =
                    xslTransformService.getTransformer(
                    new StringReader(styleSheet.toString()));
    
                topStoriesURL = new URL(topStoriesURLName);
    
                iReader = new InputStreamReader(topStoriesURL.openStream());
                bReader = new BufferedReader(iReader);
    
                while ((line = bReader.readLine()) != null) {
                    news.append(line);
                }
                output = rssTransformer.transform(news.toString());
    
            } catch(IOException e) {
                e.printStackTrace();
            }
            catch (MalformedURLException e1) {
                e1.printStackTrace();
            }
        }
    }
    
End of the code.