| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| <section id="middle-tier.trying-it-out"> |
| <title>Trying out the JPA middle tier</title> |
| <para> |
| Open a Web browser and navigate to <ulink url="http://localhost:8080/greenpages">http://localhost:8080/greenpages</ulink>. |
| Click the <emphasis>Submit</emphasis> button. Unfortunately the search will not return any results |
| as the Web bundle is still using the stub <literal>Directory</literal> implementation provided by the |
| <literal>greenpages.app</literal> module, rather than the JPA-based implementation that is provided |
| by <literal>greenpages.jpa</literal>. |
| This can be confirmed by using the Equinox console or the web-based admin console to examine the services being used |
| by <literal>greenpages.web</literal>. |
| </para> |
| |
| <para> |
| The service which is being used by the Web bundle can be changed at runtime without having to restart the |
| application or the @webserv@. This can be achieved by changing <literal>greenpages.app</literal> so that it no longer |
| publishes its <literal>Directory</literal> implementation. As a result of this <literal>Directory</literal> |
| service no longer being available, the Web bundle will automatically switch to using the JPA-based |
| implementation. |
| </para> |
| |
| <para> |
| Open the <literal>osgi-context.xml</literal> file in the <literal>META-INF/spring</literal> folder of the |
| <literal>greenpages.app</literal> project and comment out the publication of the directory service: |
| <programlisting><![CDATA[<!-- <osgi:service interface="greenpages.Directory" ref="directory"/> -->]]> |
| </programlisting> |
| </para> |
| |
| <para> |
| Now save the updated file which will cause the application to be updated and refreshed on the server. |
| Switch back to the Web browser and click |
| <emphasis>Submit</emphasis> again. |
| </para> |
| |
| <para> |
| This time eight results should be returned. Clicking on any of the |
| <emphasis>View</emphasis> links will display the listing’s details. |
| The application is now working. |
| All that remains is to apply some best practices to the middle tier. |
| </para> |
| </section> |