<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
   <!ENTITY % BOOK_ENTITIES SYSTEM "../Reference_Guide.ent">
   %BOOK_ENTITIES;
   ]>
<chapter id="wsrp">
   <title>Web Services for Remote Portlets (WSRP)</title>

   <sect1 id="wsrp-Introduction">
      <title>Introduction</title>
      <para>The Web Services for Remote Portlets specification defines a web service interface for accessing and
         interacting with interactive presentation-oriented web services. It has been produced through the efforts of
         the Web Services for Remote Portlets (WSRP) OASIS Technical Committee. It is based on the requirements
         gathered and on the concrete proposals made to the committee.
      </para>

      <para>Scenarios that motivate WSRP functionality include:
         <itemizedlist>
            <listitem>
               <para>Content hosts, such as portal servers, providing Portlets as presentation-oriented web services
                  that can be used by aggregation engines.
               </para>
            </listitem>
            <listitem>
               <para>Aggregating frameworks, including portal servers, consuming presentation-oriented web services
                  offered by content providers and integrating them into the framework.
               </para>
            </listitem>
         </itemizedlist>
      </para>

      <para>More information on WSRP can be found on the
         <ulink url="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wsrp">official website for WSRP</ulink>.
         We suggest reading the
         <ulink url="http://www.oasis-open.org/committees/download.php/10539/wsrp-primer-1.0.html">primer</ulink>
         for a good, albeit technical, overview of WSRP.
      </para>
   </sect1>

   <sect1 id="wsrp_support">
      <title>Level of support in &PRODUCT;</title>
      <para>The WSRP Technical Committee defined
         <ulink url="http://www.oasis-open.org/committees/download.php/3073">WSRP Use Profiles</ulink>
         to help with WSRP interoperability. We will refer to terms defined in that document in
         this section.
      </para>

      <para>&PRODUCT_NAME; provides a Simple level of support for our WSRP Producer except that out-of-band registration
         is not currently handled. We support in-band registration and persistent local state (which are
         defined at the Complex level).
      </para>

      <para>On the Consumer side, &PRODUCT_NAME; provides a Medium level of support for WSRP, except that we only handle
         HTML markup (as &PRODUCT_NAME; itself doesn't handle other markup types). We do support explicit portlet
         cloning and
         we fully support the PortletManagement interface.
      </para>

      <para>As far as caching goes, we have Level 1 Producer and Consumer. We support Cookie handling properly on the
         Consumer and our Producer requires initialization of cookies (as we have found that it improved interoperabilty
         with some consumers). We don't support custom window states or modes, as Portal doesn't either. We do, however,
         support CSS on both the Producer (though it's more a function of the portlets than inherent Producer
         capability) and Consumer.
      </para>

      <para>While we provide a complete implementation of WSRP 1.0, we do need to go through the
         <ulink url="http://www.oasis-open.org/committees/download.php/6018">Conformance statements</ulink>
         and perform more interoperability testing (an area that needs to be better supported by the WSRP Technical
         Committee and Community at large).
      </para>

      <note>
         <para>As of version &PRODUCT_VERSION; of &PRODUCT_NAME;, WSRP is only activated and supported
            when &PRODUCT_NAME; is deployed on JBoss Application Server.
         </para>
      </note>
   </sect1>

   <sect1 id="wsrp-Deploy_GateIn_wsrp_services">
      <title>Deploying &PRODUCT_NAME;'s WSRP services</title>
      <para>
         &PRODUCT_NAME; provides a complete support of WSRP 1.0 standard interfaces and offers both consumer and
         producer services. WSRP support is provided by the following files, assuming
         <code>$GATEIN_HOME</code>
         is
         where &PRODUCT_NAME; has been installed,
         <code>$WSRP_VERSION</code>
         (at the time of the writing, it was &WSRP_VERSION;)
         is the version of the WSRP component and
         <code>$PORTAL_VERSION</code>
         (at the time of the writing, it was &PORTAL_VERSION;)
         is the current &PRODUCT_NAME; version:
         <itemizedlist>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/wsrp-admin-gui.war</filename>, which contains the WSRP Configuration portlet
                  with which you can configure consumers to access remote servers and how the WSRP producer is
                  configured.
               </para>
            </listitem>
            <listitem>
               <para><filename>$GATEIN_HOME/wsrp-producer.war</filename>, which contains the WSRP producer web
                  application.
               </para>
            </listitem>
            <listitem>
               <para><filename>$GATEIN_HOME/lib/wsrp-common-$WSRP_VERSION.jar</filename>, which contains common classes
                  needed by the different WSRP libraries.
               </para>
            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/wsrp-consumer-$WSRP_VERSION.jar</filename>, which contains the WSRP
                  consumer.
               </para>
            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/wsrp-integration-api-$WSRP_VERSION.jar</filename>, which contains the
                  API classes needed to integrate the WSRP component into portals.
               </para>

            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/wsrp-producer-lib-$WSRP_VERSION.jar</filename>, which contains the classes
                  needed by the WSRP producer.
               </para>
            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/wsrp-wsrp1-ws-$WSRP_VERSION.jar</filename>, which contains the generated
                  JAX-WS classes for WSRP version 1.
               </para>
            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/wsrp-wsrp2-ws-$WSRP_VERSION.jar</filename>, which contains the generated
                  JAX-WS classes for WSRP version 2.
               </para>
            </listitem>
            <listitem>
               <para>
                  <filename>$GATEIN_HOME/lib/gatein.portal.component.wsrp-$PORTAL_VERSION.jar</filename>, which
                  contains the code to integrate the WSRP service into &PRODUCT_NAME;.
               </para>
            </listitem>
         </itemizedlist>
         If you're not going to use WSRP in &PRODUCT_NAME;, you can remove
         <filename>$GATEIN_HOME/lib/gatein.portal.component.wsrp-$PORTAL_VERSION.jar</filename>
         from your &PRODUCT_NAME; distribution to easily deactivate WSRP support. Of course, if you want to trim your
         installation, you can also remove all the files mentioned above.
      </para>

      <sect2 id="wsrp-ports">
         <title>Considerations to use WSRP when running &PRODUCT_NAME; on a non-default port or hostname</title>
         <para>
            JBoss WS (the web service stack that &PRODUCT_NAME; uses) should take care of the details of updating the
            port and host name used in WSDL. See the
            <ulink url="http://community.jboss.org/wiki/JBossWS-UserGuide#Configuration">JBoss WS user guide on that
               subject
            </ulink>
            for more details.
         </para>
         <para>
            Of course, if you have modified you have modified the host name and port on which your server runs, you will
            need to
            update the configuration for the consumer used to consume &PRODUCT_NAME;'s 'self' producer. Please refer to
            the
            <xref linkend="consumer_configuration"/>
            to learn how to do so.
         </para>
      </sect2>

      <sect2 id="wsrp-Deploy_GateIn_wsrp_services-Considerations_to_use_wsrp_with_SSL">
         <title>Considerations to use WSRP with SSL</title>
         <para>It is possible to use WSRP over SSL for secure exchange of data. Please refer to the
            <ulink url="http://community.jboss.org/wiki/ConfiguringWSRPforuseoverSSL">instructions</ulink>
            on how to do so from
            <ulink url="http://community.jboss.org/wiki/GateIn">GateIn's wiki</ulink>.
         </para>
      </sect2>
   </sect1>

   <sect1 id="wsrp-Make_portlet_remotable">
      <title>Making a portlet remotable</title>
      <note>
         <para>
            Only JSR-286 (Portlet 2.0) portlets can be made remotable as the mechanism to expose a portlet to WSRP
            relies on a JSR-286-only functionality.
         </para>
      </note>
      <para>&PRODUCT_NAME; does
         <emphasis role="bold">NOT</emphasis>, by default, expose local portlets for consumption
         by remote WSRP consumers. In order to make a portlet remotely available, it must be made "remotable" by marking
         it as such in the associated
         <filename>portlet.xml</filename>. This is accomplished by using a specific
         <code>org.gatein.pc.remotable container-runtime-option</code>. Setting its value to
         <code>true</code>
         makes the portlet available for remote consumption, while setting its value to
         <code>false</code>
         will not publish it remotely. As specifying the remotable status for a portlet is optional, you do not need to
         do anything if you don't need your portlet to be available remotely.
      </para>
      <para>In the following example, the "BasicPortlet" portlet is specified as being remotable.
      </para>
      <example>
         <para>
            <programlisting><![CDATA[
<?xml version="1.0" standalone="yes"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             version="2.0">
<portlet-app>
   <portlet>
      <portlet-name>BasicPortlet</portlet-name>

      ...

      <container-runtime-option>
         <name>org.gatein.pc.remotable</name>
         <value>true</value>
      </container-runtime-option>
   </portlet>
</portlet-app>]]></programlisting>
         </para>

      </example>
      <para>
         It is also possible to specify that all the portlets declared within a given portlet application to be
         remotable by default. This is done by specifying the
         <code>
            container-runtime-option
         </code>
         at the
         <code>portlet-app</code>
         element level. Individual portlets can override that value to not be remotely exposed. Let's look at an
         example:
      </para>
      <example>
         <para>
            <programlisting><![CDATA[
<?xml version="1.0" standalone="yes"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
             version="2.0">
<portlet-app>

   <portlet>
      <portlet-name>RemotelyExposedPortlet</portlet-name>
      ...
   </portlet>
   <portlet>
      <portlet-name>NotRemotelyExposedPortlet</portlet-name>
      ...
      <container-runtime-option>
         <name>org.gatein.pc.remotable</name>
         <value>false</value>
      </container-runtime-option>
   </portlet>

   <container-runtime-option>
      <name>org.gatein.pc.remotable</name>
      <value>true</value>
   </container-runtime-option>
</portlet-app>]]>
            </programlisting>
         </para>

      </example>

      <para>
         In the example above, we defined two portlets. The
         <code>org.gatein.pc.remotable container-runtime-option</code>
         being set to
         <code>true</code>
         at the
         <code>portlet-app</code>
         level, all portlets defined in this particular portlet application are exposed remotely by &PRODUCT_NAME;'s
         WSRP
         producer.
         Note, however, that it is possible to override the default behavior: specifying a value for the
         <code>org.gatein.pc.remotable container-runtime-option</code>
         at the
         <code>portlet</code>
         level will take precedence over the default. In the example above, the
         <varname>RemotelyExposedPortlet</varname>
         inherits the remotable status defined at the
         <code>portlet-app</code>
         level since it does not specify a value for the<code>org.gatein.pc.remotable container-runtime-option</code>.
         The<varname>NotRemotelyExposedPortlet</varname>, however, overrides the default behavior and is not remotely
         exposed. Note that in the absence of a top-level
         <code>org.gatein.pc.remotable container-runtime-option</code>
         value set to<code>true</code>, portlets are NOT remotely exposed.
      </para>
   </sect1>

   <sect1 id="wsrp-Consume_GateIn_wsrp_portlets_from_remote_consumer">
      <title>Consuming &PRODUCT_NAME;'s WSRP portlets from a remote Consumer</title>
      <para>WSRP Consumers vary a lot as far as how they are configured. Most of them require that you specify
         the URL for the Producer's WSDL definition. Please refer to your Consumer's documentation for specific
         instructions. For instructions on how to do so in &PRODUCT_NAME;, please
         refer to
         <xref linkend="consumer_configuration"/>.
      </para>
      <para>
         &PRODUCT_NAME;'s Producer is automatically set up when you deploy a portal instance with the WSRP service.
         You can access the WSDL file at
         <filename>http://{hostname}:{port}/wsrp-producer/MarkupService?wsdl</filename>.
         The default hostname is
         <literal>localhost</literal>
         and the default port is 8080.
      </para>
   </sect1>

   <sect1 id="wsrp-consumer_configuration">
      <title>Consuming remote WSRP portlets in &PRODUCT_NAME;</title>
      <sect2 id="wsrp-consumer_configuration-Overview">
         <title>Overview</title>
         <para>
            To be able to consume WSRP portlets exposed by a remote producer, &PRODUCT_NAME;'s WSRP consumer needs to
            know how to access that remote producer. One can configure access to a remote producer using WSRP Producer
            descriptors. Alternatively, a portlet is provided to configure remote producers.
         </para>
         <para>
            Once a remote producer has been configured, the portlets that it exposes are then available in the
            Application Registry to be added to categories and then to pages.
         </para>
         <para>
            As a way to test the WSRP producer service and to check that the portlets that you want to expose remotely
            are correctly published via WSRP, a default consumer named
            <literal>self</literal>, that consumes the portlets exposed by &PRODUCT_NAME;'s producer,
            has been configured.
         </para>
      </sect2>

      <sect2 id="wsrp-consumer_configuration-Configure_remote_producer_walkthrough">
         <title>Configuring a remote producer walk-through</title>
         <para>
            Let's work through the steps of defining access to a remote producer so that its portlets can be
            consumed within &PRODUCT_NAME;. We will configure access to Oracle's public WSRP producer. We will first
            examine how to do so using the configuration portlet. We will then show how the same result can be
            accomplished with a producer descriptor, though it is far easier to do so via the configuration portlet.
         </para>

         <note>
            <para>
               Some WSRP producers do not support chunked encoding that is activated by default by JBoss WS. If your
               producer does not support chunked encoding, your consumer will not be able to properly connect to the
               producer. This will manifest itself with the following error:
               <code>Caused by: org.jboss.ws.WSException: Invalid HTTP server response [503] - Service Unavailable</code>.
               Please see this GateIn's
               <ulink url="http://community.jboss.org/wiki/Workaroundwhenchunkedencodingisnotsupported">wiki page</ulink>
               for more details.
            </para>
         </note>

         <sect3 id="consumer_gui">
            <title>Using the configuration portlet</title>
            <para>
               &PRODUCT_NAME; provides a portlet to configure access (among other functions) to remote WSRP Producers
               grahically. It isn't, however, installed by default, so the first thing we will need to do is to install
               the WSRP configuration portlet using the Application Registry.
            </para>

            <para>
               Use the usual procedure to log in as a Portal administrator and go to the Application Registry.
               With the default install, you can just go to
               <ulink
                  url="http://localhost:8080/portal/login?initialURI=%2Fportal%2Fprivate%2Fclassic%2Fadministration%2Fregistry&amp;username=root&amp;password=gtn">
                  http://localhost:8080/portal/login?initialURI=%2Fportal%2Fprivate%2Fclassic%2Fadministration%2Fregistry&amp;username=root&amp;password=gtn
               </ulink>
               Add the WSRP Configuration portlet to the Administration category. If you use the Import Applications
               functionality, the WSRP Configuration portlet will be automatically added to the Administration category.
            </para>
            <para>
               Now that the portlet is added to a category, it can be added to a page and used. We recommend adding it
               to the same page as the Application Registry as operations relating to WSRP and adding portlets to
               categories are somewhat related as we will see. Go ahead and add the WSRP Configuration portlet to the
               page using the standard procedure.
            </para>
            <para>
               If all went well, you should see something similar to this:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_init.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               This screen presents all the configured Consumers associated with their status and possible actions on
               them. A Consumer can be active or inactive. Activating a Consumer means that it is ready to act as a
               portlet provider. Note also that a Consumer can be marked as requiring refresh meaning that the
               information held about it might not be up to date and refreshing it from the remote Producer might be a
               good idea. This can happen for several reasons: the service description for that remote Producer has not
               been fetched yet, the cached version has expired or modifications have been made to the configuration
               that could potentially invalidate it, thus requiring re-validation of the information.
            </para>

            <para>
               Next, we create a new Consumer which we will call<literal>oracle</literal>. Type "<literal>
               oracle</literal>" in
               the "Create a consumer named:" field then click on "Create consumer":
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_create.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               You should now see a form allowing you to enter/modify the information about the Consumer.
               Set the cache expiration value to 300 seconds, leave the default timeout value for web services (WS)
               operations and enter the WSDL URL for the producer in the text field
               and press the "Refresh &amp; Save" button:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_wsdl.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               This will retrieve the service description associated with the Producer which WSRP interface is described
               by the WSDL file found at the URL you just entered. In our case, querying the service description will
               allow us to learn that the Producer requires registration but didn't request any registration property:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_refresh.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               The Consumer for the
               <literal>oracle</literal>
               Producer should now be available as a portlet provider and be ready to be used.
            </para>
            <para>
               Now, assuming that the producer required a value for an
               <literal>email</literal>
               registration property, &PRODUCT_NAME;'s WSRP consumer would have informed you that you were missing some
               information:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_missing.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               <note>
                  <para>At this point, there is no automated way to learn about which possible values (if any) are
                     expected by the remote Producer. Sometimes, the possible values will be indicated in the
                     registration
                     property description but this is not always the case... Please refer to the specific Producer's
                     documentation.
                  </para>

               </note>
               If you entered "<literal>example@example.com</literal>" as the value for the registration property and
               press "Save &amp;
               Refresh" once more, you would have seen something similar to:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_end.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
            </para>
         </sect3>

         <sect3 id="wsrp-consumer_configuration-Configure_remote_producer_walkthrough-Use_XML">
            <title>Using XML</title>

            <para>While we recommend you use the WSRP Configuration portlet to configure Consumers, we provide an
               alternative way to configure consumers by editing the XML file located at
               <filename>$GATEIN_HOME/lib/wsrp-consumer-$WSRP_VERSION.jar/conf/wsrp-consumers-config.xml</filename>.
            </para>
            <programlisting role="XML"><![CDATA[
<?xml version='1.0' encoding='UTF-8' ?>
<deployments xmlns="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0 http://www.jboss.org/portal/xsd/gatein_wsrp_consumer_1_0.xsd">
   <deployment>
      <wsrp-producer id="self" expiration-cache="300" ws-timeout="30000">
         <endpoint-wsdl-url>http://localhost:8080/wsrp-producer/MarkupService?wsdl</endpoint-wsdl-url>
         <registration-data>
            <property>
               <name>email</name>
               <lang>en</lang>
               <value>example@example.com</value>
            </property>
         </registration-data>
      </wsrp-producer>
   </deployment>
   <deployment>
      <wsrp-producer id="oracle" expiration-cache="300">
         <endpoint-wsdl-url>http://portalstandards.oracle.com/portletapp/portlets?WSDL</endpoint-wsdl-url>
         <registration-data/>
      </wsrp-producer>
   </deployment>
</deployments>]]></programlisting>
            <para>
               The file as shown above specifies access to two producers:
               <literal>self</literal>, which consumes &PRODUCT_NAME;'s own WSRP producer albeit in a version that
               assumes that the producer requires a value for an
               <literal>email</literal>
               registration property, and
               <literal>oracle</literal>, which consumes Oracle's public producer, both in configurations as shown in
               the walk-through above.
            </para>
            <para>We will look at the details of the meaning of elements later on.</para>
         </sect3>

         <sect3 id="wsrp-consumer_configuration-Configure_remote_producer_walkthrough-Configure_access_to_remote_portlet">
            <title>Configuring access to a remote portlet</title>
            <para>
               If we go back to the Application Registry and examine the available portlets by clicking on the
               Portlet link, you will now be able to see the remote portlets if you click on the REMOTE tab in the left
               column:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/remote_portlets.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
            </para>

            <para>
               These portlets are, of course, available to be used such as regular portlets: they can be used in
               categories and added to pages. If you use the Import Applications functionality, they will also be
               automatically imported in categories based on the keywords they define.
            </para>

            <para>
               More specifically, if you want to add a WSRP portlet to a category, you can access these portlets by
               selecting
               <literal>wsrp</literal>
               in the Application Type drop-down menu:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/remote_portlets_category.png" format="PNG" align="center"
                                valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
            </para>
         </sect3>
      </sect2>

      <sect2 id="wsrp-consumer_configuration-Configure_access_to_remote_producers_via_XML">
         <title>Configuring access to remote producers via XML</title>

         <para>While we recommend you use the WSRP Configuration portlet to configure Consumers, we provide an
            alternative way to configure consumers by editing the XML file located at
            <filename>$GATEIN_HOME/lib/wsrp-consumer-$WSRP_VERSION.jar/conf/wsrp-consumers-config.xml</filename>.
            <note>
               <para>An XML Schema defining which elements are available to configure Consumers via XML can be found
                  in
                  <filename>
                     $GATEIN_HOME/lib/wsrp-integration-api-$WSRP_VERSION.jar/xsd/gatein_wsrp_consumer_1_0.xsd
                  </filename>
               </para>
            </note>
            <note>
               <para>It is important to note how the XML consumers configuration file is processed. It is read the first
                  time the WSRP service starts and the associated information is then put under control of JCR (Java
                  Content Repository). Subsequent launches of the WSRP service will use the JCR-stored information for
                  all producers are already known to &PRODUCT_NAME;. More specifically,
                  <filename>wsrp-consumers-config.xml</filename>
                  file is scanned for producer identifiers.
                  Any identifier that is already known will be bypassed and the JCR information associated with this
                  remote producer will be used. The information defined at the XML level is only processed for producer
                  definition for which no information is already present in JCR. Therefore, if you wish to delete a
                  producer configuration, you need to delete the associated information in the database (this can be
                  accomplished using the configuration portlet as we saw in
                  <xref linkend="consumer_gui"/>)
                  <emphasis>AND</emphasis>
                  remove the associated information in
                  <filename>wsrp-consumers-config.xml</filename>
                  (if such information exists) as the producer will be re-created the next time the WSRP is launched if
                  that information is not removed.
               </para>
            </note>
         </para>

         <sect3 id="wsrp-consumer_configuration-Configure_access_to_remote_producers_via_XML-Required_configuration_information">
            <title>Required configuration information</title>

            <para>Let's now look at which information needs to be provided to configure access to a remote producer.
            </para>

            <para>First, we need to provide an identifier for the producer we are configuring so that we can refer to it
               afterwards. This is accomplished via the mandatory
               <literal>id</literal>
               attribute of the
               <literal>&lt;wsrp-producer&gt;</literal>
               element.
            </para>

            <para>&PRODUCT_NAME; also needs to learn about the remote producer's endpoints to be able to connect to the
               remote web services and perform WSRP invocations. This is accomplished by specifying the URL for the
               WSDL description for the remote WSRP service, using the
               <literal>&lt;endpoint-wsdl-url&gt;</literal>
               element.
            </para>

            <para>Both the
               <literal>id</literal>
               attribute and
               <literal>&lt;endpoint-wsdl-url&gt;</literal>
               elements are required for a functional remote producer configuration.
            </para>
         </sect3>

         <sect3 id="wsrp-consumer_configuration-Configure_access_to_remote_producers_via_XML-Optional_configuration">
            <title>Optional configuration</title>
            <para>It is also possible to provide addtional configuration, which, in some cases, might be important to
               establish a proper connection to the remote producer.
            </para>

            <para>One such optional configuration concerns caching. To prevent useless roundtrips between the local
               consumer and the remote producer, it is possible to cache some of the information sent by the producer
               (such as the list of offered portlets) for a given duration. The rate at which the information is
               refreshed is
               defined by the
               <literal>expiration-cache</literal>
               attribute of the
               <literal>&lt;wsrp-producer&gt;</literal>
               element which specifies the refreshing period in seconds. For example, providing a value of 120 for
               expiration-cache means that the producer information will not be refreshed for 2 minutes after it has
               been somehow accessed. If no value is provided, &PRODUCT_NAME; will always access the remote producer
               regardless of whether the remote information has changed or not. Since, in most instances, the
               information provided by the producer does not change often, we recommend that you use this caching
               facility to minimize bandwidth usage.
            </para>

            <para>It is also possible to define a timeout after which WS operations are considered as failed. This is
               helpful to avoid blocking the WSRP service, waiting forever on the service that doesn't answer. Use the
               <literal>ws-timeout</literal>
               attribute of the
               <literal>&lt;wsrp-producer&gt;</literal>
               element to specify how many milliseconds the WSRP service will wait for a response from the remote
               producer before timing out and giving up.
            </para>

            <para>Additionally, some producers require consumers to register with them before authorizing them to access
               their offered portlets. If you know that information beforehand, you can provide the required
               registration information in the producer configuration so that the consumer can register with the remote
               producer when required.
               <note>
                  <para>At this time, though, only simple String properties are supported and it is not possible to
                     configure complex registration data. This should, however, be sufficient for most cases.
                  </para>
               </note>
            </para>

            <para>Registration configuration is done via the
               <literal>&lt;registration-data&gt;</literal>
               element. Since &PRODUCT_NAME; can generate the mandatory information for you, if the remote producer does
               not require any registration properties, you only need to provide an empty
               <literal>&lt;registration-data&gt;</literal>
               element. Values for the registration properties
               required by the remote producer can be provided via
               <literal>&lt;property&gt;</literal>
               elements. See the example below for more details. Additionally, you can override the default consumer
               name automatically provided by &PRODUCT_NAME; via the
               <literal>&lt;consumer-name&gt;</literal>
               element. If you choose to provide a consumer name, please remember that this should uniquely identify
               your consumer.
            </para>
         </sect3>
      </sect2>

      <sect2 id="wsrp-consumer_configuration-Example">
         <title>Examples</title>

         <para>
            Here is the configuration of the
            <literal>self</literal>
            producer as found in
            <filename>default-wsrp.xml</filename>
            with a cache expiring every five minutes and with a 30 second timeout for web service operations.
         </para>

         <example>
            <para>
               <programlisting><![CDATA[
<?xml version='1.0' encoding='UTF-8' ?>
<deployments xmlns="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0 http://www.jboss.org/portal/xsd/gatein_wsrp_consumer_1_0.xsd">
   <deployment>
      <wsrp-producer id="self" expiration-cache="300" ws-timeout="30000">
         <endpoint-wsdl-url>http://localhost:8080/wsrp-producer/MarkupService?wsdl</endpoint-wsdl-url>
         <registration-data/>
      </wsrp-producer>
   </deployment>
</deployments>]]>
               </programlisting>
            </para>

         </example>

         <para>Here is an example of a WSRP descriptor with registration data and cache expiring every minute:
         </para>

         <example>
            <para>
               <programlisting><![CDATA[
<?xml version='1.0' encoding='UTF-8' ?>
<deployments xmlns="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_wsrp_consumer_1_0 http://www.jboss.org/portal/xsd/gatein_wsrp_consumer_1_0.xsd">
<deployments>
   <deployment>
      <wsrp-producer id="AnotherProducer" expiration-cache="60">
         <endpoint-wsdl-url>http://example.com/producer/producer?WSDL</endpoint-wsdl-url>
         <registration-data>
            <property>
               <name>property name</name>
               <lang>en</lang>
               <value>property value</value>
            </property>
         </registration-data>
      </wsrp-producer>
   </deployment>
</deployments>]]></programlisting>
            </para>
         </example>
      </sect2>
   </sect1>

   <sect1 id="wsrp-Consumers_maintenance">
      <title>Consumers maintenance</title>

      <sect2 id="wsrp-Consumers_maintenance-Modify_currently_held_registration">
         <title>Modifying a currently held registration</title>

         <sect3 id="wsrp-Consumers_maintenance-Modify_currently_held_registration-Registration_modification_for_service_upgrade">
            <title>Registration modification for service upgrade</title>
            <para>
               Producers often offer several levels of service depending on consumers' subscription levels (for
               example). This is implemented at the WSRP level with the registration concept: producers can assert which
               level of service to provide to consumers based on the values of given registration properties.
            </para>
            <para>
               There might also be cases where you just want to update the registration information because it has
               changed. For example, the producer required you to provide a valid email and the previously email
               address is not valid anymore and needs to be updated.
            </para>
            <para>
               It is therefore sometimes necessary to modify the registration that concretizes the service agreement
               between a consumer and a producer. Let's take the example of the producer requiring an email we
               configured in
               <xref linkend="consumer_gui"/>.
               If you recall, the producer was requiring registration and required a value to be provided for the
               <literal>email</literal>
               property.
            </para>
            <para>
               Suppose now that we would like to update the email address that we provided to the remote producer. We
               will need to tell the producer that our registration data has been modified. Let's see how to do this.
               Assuming you
               have configured access to the producer as previously described, please go to the configuration screen for
               the
               <literal>self</literal>
               producer and modify the value of
               <literal>email</literal>
               to
               <literal>foo@example.com</literal>
               instead of<literal>example@example.com</literal>:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/modify_reg_start.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
               Now click on "Update properties" to save the change. A "Modify registration" button should now appear to
               let you send this new data to the remote producer:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/modify_reg_modify.png" format="PNG" align="center"
                                valign="middle" scalefit="1"/>
                  </imageobject>
               </mediaobject>
               Click on this new button and, if everything went well and your updated registration has been accepted by
               the remote producer, you should see something similar to:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/modify_reg_end.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>
            </para>

         </sect3>

         <sect3 id="reg_mod_error">
            <title>Registration modification on producer error</title>

            <para>
               It can also happen that a producer administrator decided to change its requirement forregistered
               consumers. In this case, invoking operations on the producer will fail with an
               <exceptionname>OperationFailedFault</exceptionname>. &PRODUCT_NAME; will attempt to help you in this
               situation. Let's walk through an example using the
               <literal>self</literal>
               producer. Let's assume that
               registration is requiring a valid value for an
               <literal>email</literal>
               registration property (as we have seen so far). If you go to the configuration screen for this producer,
               you should see:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/config_self.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>

               Now suppose that the administrator of the producer now additionaly requires a value to be provided for a
               <literal>name</literal>
               registration property. We will actually see how to do perform this operation
               in &PRODUCT_NAME; when we examine how to configure &PRODUCT_NAME;'s producer in
               <xref linkend="producer_config"/>.
               Operations with this producer will now fail. If you suspect that a registration modification is required,
               you should go to the configuration screen for this remote producer and refresh the information held by
               the consumer by pressing "Refresh &amp; Save":
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/modify_reg_self.png" format="PNG" align="center" valign="middle"
                                scalefit="1"/>
                  </imageobject>
               </mediaobject>

               As you can see, the configuration screen now shows the currently held registration information and
               the expected information from the producer. Enter a value for the
               <literal>name</literal>
               property
               and then click on "Modify registration". If all went well and the producer accepted your new registration
               data, you should see something similar to:
               <mediaobject>
                  <imageobject>
                     <imagedata fileref="images/WSRP/modify_reg_self_end.png" format="PNG" align="center"
                                valign="middle" scalefit="1"/>
                  </imageobject>
               </mediaobject>

               <note>
                  <para>As of WSRP 1, it is rather difficult to ascertain for sure what caused an
                     <exceptionname>OperationFailedFault</exceptionname>
                     as it is the generic exception returned by
                     producers if something didn't quite happen as expected during a method invocation. This means that
                     <exceptionname>OperationFailedFault</exceptionname>
                     can be caused by several different reasons, one
                     of them being a request to modify the registration data. Please take a look at the log files to see
                     if you can gather more information as to what happened. WSRP 2 introduces an exception that is
                     specific to a request to modify registrations thus reducing the ambiguity that currently exists.
                  </para>

               </note>
            </para>
         </sect3>
      </sect2>

      <sect2 id="wsrp-Consumers_maintenance-Consumer_operations">
         <title>Consumer operations</title>
         <para>
            Several operations are available from the consumer list view of the WSRP configuration portlet:
            <mediaobject>
               <imageobject>
                  <imagedata fileref="images/WSRP/consumer_operations.png" format="PNG" align="center" valign="middle"
                             scalefit="1"/>
               </imageobject>
            </mediaobject>
         </para>
         <para>
            The available operations are:
            <itemizedlist>
               <listitem>
                  <para>Configure: displays the consumer details and allows user to edit them</para>
               </listitem>
               <listitem>
                  <para>Refresh: forces the consumer to retrieve the service description from the remote producer to
                     refresh
                     the local information (offered portlets, registration information, etc.)
                  </para>
               </listitem>
               <listitem>
                  <para>Activate/Deactivate: activates/deactivates a consumer, governing whether it will be available to
                     provide portlets and receive portlet invocations
                  </para>
               </listitem>
               <listitem>
                  <para>Register/Deregister: registers/deregisters a consumer based on whether registration is required
                     and/or acquired
                  </para>
               </listitem>
               <listitem>
                  <para>Delete: destroys the consumer, after deregisterting it if it was registered</para>
               </listitem>
            </itemizedlist>
         </para>
      </sect2>

      <sect2 id="wsrp-Consumers_maintenance-Erase_local_registration_data">
         <title>Erasing local registration data</title>
         <para>
            There are rare cases where it might be required to erase the local information without being able to
            deregister first. This is the case when a consumer is registered with a producer that has been modified by
            its administrator to not require registration anymore. If that ever was to happen (most likely, it won't),
            you can erase the local registration information from the consumer so that it can resume interacting with
            the remote producer. To do so, click on "Erase local registration" button next to the registration context
            information on the consumer configuration screen:
         </para>
         <mediaobject>
            <imageobject>
               <imagedata fileref="images/WSRP/erase_registration.png" format="PNG" align="center" valign="middle"/>
            </imageobject>
         </mediaobject>
         <para>
            <emphasis>Warning:</emphasis>
            This operation is dangerous as it can result in inability to interact with the remote producer if invoked
            when not required. A warning screen will be displayed to give you a chance to change your mind:
         </para>
         <mediaobject>
            <imageobject>
               <imagedata fileref="images/WSRP/erase_registration_warning.png" format="PNG" align="center"
                          valign="middle"/>
            </imageobject>
         </mediaobject>
      </sect2>
   </sect1>

   <sect1 id="producer_config">
      <title>Configuring &PRODUCT_NAME;'s WSRP Producer</title>
      <sect2 id="producer_config-Overview">
         <title>Overview</title>
         <para>
            You can configure the behavior of Portal's WSRP Producer by using the WSRP administration interface, which
            is the preferred way, or by editing the
            <filename>$GATEIN_HOME/wsrp-producer.war/WEB-INF/conf/producer/config.xml</filename>
            file. Several aspects can be modified with respects to whether registration is required for consumers to
            access the Producer's services. An XML Schema for the configuration format is available at
            <filename>
               $GATEIN_HOME/lib/wsrp-integration-api-$WSRP_VERSION.jar/xsd/gatein_wsrp_producer_1_0.xsd
            </filename>.
         </para>
      </sect2>
      <sect2 id="producer_config-Default_configuration">
         <title>Default configuration</title>
         <para>
            The default producer configuration is to require that consumers register with it before providing access its
            services but does not require any specific registration properties (apart from what is mandated by the
            WSRP standard). It does, however, require consumers to be registered before sending them a full service
            description. This means that our WSRP producer will not provide the list of offered portlets and other
            capabilities to unregistered consumers. The producer also uses the default
            <classname>RegistrationPolicy</classname>
            paired with the default
            <classname>RegistrationPropertyValidator</classname>. We will look into property
            validators in greater detail later in<xref linkend="registration-configuration"/>. Suffice to say for now
            that this allows users to customize how Portal's WSRP Producer decides whether a given registration property
            is valid or not.
         </para>
         <para>
            &PRODUCT_NAME; provides a web interface to configure the producer's behavior. You can access it
            by clicking on the "Producer Configuration" tab of the "WSRP" page of the "admin" portal. Here's what you
            should see with the default configuration:
            <mediaobject>
               <imageobject>
                  <imagedata fileref="images/WSRP/producer_default.png" format="PNG" align="center" valign="middle"
                             scalefit="1"/>
               </imageobject>
            </mediaobject>
            As would be expected, you can specify whether or not the producer will send the full service description to
            unregistered consumers, and, if it requires registration, which
            <classname>RegistrationPolicy</classname>
            to use (and, if needed, which
            <classname>RegistrationPropertyValidator</classname>), along with required
            registration property description for which consumers must provide acceptable values to successfully
            register.
         </para>
      </sect2>

      <sect2 id="registration-configuration">
         <title>Registration configuration</title>
         <para>
            In order to require consumers to register with Portal's producer before interacting with it, you need to
            configure Portal's behavior with respect to registration. Registration is optional, as are registration
            properties. The producer can require registration without requiring consumers to pass any registration
            properties as is the case in the default configuration. Let's configure our producer starting with a blank
            state:
            <mediaobject>
               <imageobject>
                  <imagedata fileref="images/WSRP/producer_blank.png" format="PNG" align="center" valign="middle"
                             scalefit="1"/>
               </imageobject>
            </mediaobject>
            We will allow unregistered consumers to see the list of offered portlets so we leave the first checkbox
            ("Access to full service description requires consumers to be registered.") unchecked. We will, however,
            specify that consumers will need to be registered to be able to interact with our producer. Check the second
            checkbox ("Requires registration. Modifying this information will trigger invalidation of consumer
            registrations."). The screen should now refresh and display:
            <mediaobject>
               <imageobject>
                  <imagedata fileref="images/WSRP/producer_registration.png" format="PNG" align="center"
                             valign="middle" scalefit="1"/>
               </imageobject>
            </mediaobject>
            You can specify the fully-qualified name for your
            <classname>RegistrationPolicy</classname>
            and
            <classname>RegistrationPropertyValidator</classname>
            there. We will keep the default value. See
            <xref linkend="custom_registration"/>
            for more details. Let's add, however, a registration property called
            <literal>email</literal>. Click "Add property" and enter the appropriate information in the fields,
            providing a description for the registration property that can be used by consumers to figure out its
            purpose:
            <mediaobject>
               <imageobject>
                  <imagedata fileref="images/WSRP/producer_email.png" format="PNG" align="center" valign="middle"
                             scalefit="1"/>
               </imageobject>
            </mediaobject>
            Press "Save" to record your modifications.

            <note>
               <para>At this time, only String (xsd:string) properties are supported. If your application requires more
                  complex properties, please let us know.
               </para>
            </note>

            <note>
               <para>If consumers are already registered with the producer, modifying the configuration of required
                  registration
                  information will trigger the invalidation of held registrations, requiring consumers to modify their
                  registration before being able to access the producer again. We saw the consumer side of that process
                  in
                  <xref linkend="reg_mod_error"/>.
               </para>

            </note>
         </para>

         <sect3 id="custom_registration">
            <title>Customization of Registration handling behavior</title>
            <para>
               Registration handling behavior can be customized by users to suit their Producer needs. This is
               accomplished by providing an implementation of the
               <classname>RegistrationPolicy</classname>
               interface. This interface defines methods that are called by Portal's Registration service so that
               decisions can be made appropriately. A default registration policy that provides basic
               behavior is provided and should be enough for most user needs.
            </para>
            <para>
               While the default registration policy provides default behavior for most registration-related aspects,
               there is still one aspect that requires configuration: whether a given value for a registration property
               is acceptable by the WSRP Producer. This is accomplished by plugging a
               <classname>RegistrationPropertyValidator</classname>
               in the default registration policy. This allows users to define their own validation mechanism.
            </para>
            <para>
               Please refer to the
               <trademark class="trade">Javadoc</trademark>
               for
               <classname>org.jboss.portal.registration.RegistrationPolicy</classname>
               and
               <classname>org.jboss.portal.Registration.policies.RegistrationPropertyValidator</classname>
               for more
               details on what is expected of each method.
            </para>
            <para>Defining a registration policy is required for the producer to be correctly configured. This is
               accomplished by specifying the qualified class name of the registration policy. Since we anticipate that
               most users will use the default registration policy, it is possible to provide the class
               name of your custom property validator instead to customize the default registration policy behavior.
               Note that property validators are only used by the default policy.

               <note>
                  <para>Since the policy or the validator are defined via their class name and dynamically loaded, it is
                     important that you make sure that the identified class is available to the application server. One
                     way
                     to accomplish that is to deploy your policy implementation as JAR file in your AS instance deploy
                     directory. Note also that, since both policies and validators are dynamically instantiated, they
                     must
                     provide a default, no-argument constructor.
                  </para>
               </note>
            </para>
         </sect3>
      </sect2>
      <sect2 id="strict-mode">
         <title>WSRP validation mode</title>
         <para>The lack of conformance kit and the wording of the WSRP specification leaves room for differing
            interpretations, resulting in interoperability issues. It is therefore possible to encounter issues when
            using consumers from different vendors. We have experienced such issues and have introduced a way to relax
            the validation that our WSRP producer performs on the data provided by consumers to help with
            interoperability by accepting data that would normally be invalid. Note that we only relax our validation
            algorithm on aspects of the specification that are deemed harmless such as invalid language codes.
         </para>
         <para>
            By default, the WSRP producer is configured in strict mode. If you experience issues with a given consumer,
            you might want to try to relax the validation mode. This is accomplished by unchecking the "Use strict WSRP
            compliance." checkbox on the Producer configuration screen.
         </para>
      </sect2>

   </sect1>
</chapter>
