Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/DBWS/AdvancedOSGi"

(Modifying Activator to implement javax.xml.ws.Provider)
(Modifying Activator to implement javax.xml.ws.Provider)
Line 91: Line 91:
 
In order to correct the error, the <b>SimpleTable</b> project needs to update its list of required bundles. Open the <tt>MANIFEST.MF</tt> file in the 'Plug-in Manifest Editor' and select the 'Dependencies' tab and add the following bundles:
 
In order to correct the error, the <b>SimpleTable</b> project needs to update its list of required bundles. Open the <tt>MANIFEST.MF</tt> file in the 'Plug-in Manifest Editor' and select the 'Dependencies' tab and add the following bundles:
 
[[Image:EclipseLink DBWS with OSGi Dependencies.png]]<br/>
 
[[Image:EclipseLink DBWS with OSGi Dependencies.png]]<br/>
Note: you do not have to directly reference the DBWS bundle since its 'host' bundle <tt>org.eclipse.persistence.core</tt> is included in the list of 'Required Plug-ins'
+
Note: you do not have to directly reference the DBWS bundle since its 'host' bundle <tt>org.eclipse.persistence.core</tt> is included in the list of 'Required Plug-ins'<br/>
 +
The Activator needs to be annotated to support a (dynamic) Web services Endpoint:
 +
<source lang="java5">
 +
public class Constants {
 +
   
 +
//JAX-WS properties
 +
    public static final String TEST_NAMESPACE =
 +
    "urn:" + TEST_PROJECT;
 +
    public static final String TEST_SERVICE =
 +
    TEST_PROJECT + "Service";
 +
    public static final String TEST_SERVICE_NAMESPACE =
 +
    "urn:" + TEST_SERVICE;
 +
    public static final String TEST_PORT =
 +
    TEST_SERVICE + "Port";
 +
    public static final String ENDPOINT_ADDRESS =
 +
    "http://localhost:9999/" + TEST_PROJECT;
 +
}
 +
package simpletable;
 +
 
 +
//java eXtension imports
 +
import javax.xml.namespace.QName;
 +
import javax.xml.soap.SOAPMessage;
 +
import javax.xml.ws.Endpoint;
 +
import javax.xml.ws.Provider;
 +
import javax.xml.ws.Service;
 +
import javax.xml.ws.WebServiceProvider;
 +
import javax.xml.ws.ServiceMode;
 +
import static javax.xml.ws.Service.Mode.MESSAGE;
 +
import static javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
 +
 
 +
//EclipseLink imports
 +
import org.eclipse.persistence.internal.dbws.ProviderHelper;
 +
import org.eclipse.persistence.sessions.Session;
 +
 
 +
//OSGi/PDE imports
 +
import org.osgi.framework.BundleActivator;
 +
import org.osgi.framework.BundleContext;
 +
 
 +
//test imports
 +
import static simpletable.Constants.ENDPOINT_ADDRESS;
 +
import static simpletable.Constants.TEST_PORT;
 +
import static simpletable.Constants.TEST_SERVICE_NAMESPACE;
 +
import static simpletable.Constants.TEST_SERVICE;
 +
import static simpletable.Constants.CREATE_TABLE;
 +
import static simpletable.Constants.INS1;
 +
import static simpletable.Constants.INS2;
 +
import static simpletable.Constants.INS3;
 +
 
 +
@WebServiceProvider(
 +
    targetNamespace = TEST_SERVICE_NAMESPACE,
 +
    serviceName = TEST_SERVICE,
 +
    portName = TEST_PORT
 +
)
 +
@ServiceMode(MESSAGE)
 +
public class Activator extends ProviderHelper implements BundleActivator, Provider<SOAPMessage> {
 +
 
 +
private static BundleContext context;
 +
private static Endpoint endpoint = null;
 +
private static QName portQName = null;
 +
private static Service testService = null;
 +
 
 +
static BundleContext getContext() {
 +
return context;
 +
}
 +
 
 +
/*
 +
* (non-Javadoc)
 +
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 +
*/
 +
public void start(BundleContext bundleContext) throws Exception {
 +
Activator.context = bundleContext;
 +
        super.init(getClass().getClassLoader(), null, false);
 +
        endpoint = Endpoint.create(this);
 +
        endpoint.publish(ENDPOINT_ADDRESS);
 +
        QName serviceQName = new QName(TEST_SERVICE_NAMESPACE, TEST_SERVICE);
 +
        portQName = new QName(TEST_SERVICE_NAMESPACE, TEST_PORT);
 +
        testService = Service.create(serviceQName);
 +
        testService.addPort(portQName, SOAP11HTTP_BINDING, ENDPOINT_ADDRESS);
 +
System.out.println("Hello, " + testService.toString());
 +
}
 +
 
 +
/*
 +
* (non-Javadoc)
 +
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
 +
*/
 +
public void stop(BundleContext bundleContext) throws Exception {
 +
Activator.context = null;
 +
        if (endpoint != null) {
 +
            endpoint.stop();
 +
        }
 +
        super.destroy();
 +
System.out.println("Goodbye");
 +
}
 +
}
 +
</source>

Revision as of 11:26, 12 August 2010


DBWS in an OSGi Environment

An Eclipselink DBWS service can be run in an OSGi environment using Javase 6's 'containerless' javax.xml.ws.Endpoint API.

Environment Setup

Download a version of the Eclipse IDE that includes the Plug-in Development Environment (PDE) (Eclipse IDE for Java EE Developers, Eclipse Classic 3.6.0 or
Eclipse for RCP and RAP Developers). Install an OSGi-friendly JDBC driver - use Derby bundle:

  • Download Apache Derby (org.apache.derby) bundle from Orbit.


EclipseLinkExamplesOSGiDeveloping with EclipseLink OSGi in PDE-2v2.png

  • Place the org.apache.derby bundle into your $ECLIPSE_HOME/dropins folder.
  • Install the EclipseLink and Jetty target Components:


EclipseLink DBWS with OSGi in PDE.png

EclipseLink DBWS with OSGi in PDE2.png
Accept the license and proceed through the prompts for re-starting Eclipse ...
{NB - later, a set of updated EclipseLink bundles will be required}
Under 'Preferences' -> 'Plug-in Development' -> 'Target Platform', reload the Running Platform (Active) EclipseLink DBWS with OSGi Target Platform.png

Create a new Plug-in project

From the 'Plug-in Development' Perspective, create a new Plug-in project SimpleTable:
{Note the choice of 'standard' for OSGi framework}
EclipseLink DBWS with OSGi SimpleTable.png
Proceed to the next panel of the wizard where the (OSGi bundle) Activator for SimpleTable is defined:
EclipseLink DBWS with OSGi SimpleTableActivator.png
Click 'Finish' and open the generated Activator:

package simpletable;
 
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
public class Activator implements BundleActivator {
 
	private static BundleContext context;
 
	static BundleContext getContext() {
		return context;
	}
 
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
	}
 
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}
}

Modifying Activator to implement javax.xml.ws.Provider

In order for our Activator to 'provide' Web service, we need to update the EclipseLink bundles. Builds after 2.1.1.v20100805-r7986 have EclipseLink DBWS packaged as a 'fragment' bundle that extends the core org.eclipse.persistence bundle. Download the updated bundles and extract the following 6 bundles: directory:

$ ls updatedBundles/
org.eclipse.persistence.asm.source_2.1.1.v20100805-r7986.jar
org.eclipse.persistence.asm_2.1.1.v20100805-r7986.jar
org.eclipse.persistence.core.source_2.1.1.v20100805-r7986.jar
org.eclipse.persistence.core_2.1.1.v20100805-r7986.jar
org.eclipse.persistence.dbws.source_2.1.1.v20100805-r7986.jar
org.eclipse.persistence.dbws_2.1.1.v20100805-r7986.jar

Edit the Target Platform, adding the directory with the above bundles:
EclipseLink DBWS with OSGi UpdatedBundles1.png
EclipseLink DBWS with OSGi UpdatedBundles2.png

Change the Activator to extend org.eclipse.persistence.internal.dbws.ProviderHelper (NB - will show error):
EclipseLink DBWS with OSGi ProviderHelperwavy.png
In order to correct the error, the SimpleTable project needs to update its list of required bundles. Open the MANIFEST.MF file in the 'Plug-in Manifest Editor' and select the 'Dependencies' tab and add the following bundles: EclipseLink DBWS with OSGi Dependencies.png
Note: you do not have to directly reference the DBWS bundle since its 'host' bundle org.eclipse.persistence.core is included in the list of 'Required Plug-ins'
The Activator needs to be annotated to support a (dynamic) Web services Endpoint:

public class Constants {
 
	//JAX-WS properties
    public static final String TEST_NAMESPACE = 
    	"urn:" + TEST_PROJECT;
    public static final String TEST_SERVICE = 
    	TEST_PROJECT + "Service";
    public static final String TEST_SERVICE_NAMESPACE = 
    	"urn:" + TEST_SERVICE;
    public static final String TEST_PORT = 
    	TEST_SERVICE + "Port";
    public static final String ENDPOINT_ADDRESS = 
    	"http://localhost:9999/" + TEST_PROJECT;
}
package simpletable;
 
//java eXtension imports
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Endpoint;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.ServiceMode;
import static javax.xml.ws.Service.Mode.MESSAGE;
import static javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING;
 
//EclipseLink imports
import org.eclipse.persistence.internal.dbws.ProviderHelper;
import org.eclipse.persistence.sessions.Session;
 
//OSGi/PDE imports
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
 
//test imports
import static simpletable.Constants.ENDPOINT_ADDRESS;
import static simpletable.Constants.TEST_PORT;
import static simpletable.Constants.TEST_SERVICE_NAMESPACE;
import static simpletable.Constants.TEST_SERVICE;
import static simpletable.Constants.CREATE_TABLE;
import static simpletable.Constants.INS1;
import static simpletable.Constants.INS2;
import static simpletable.Constants.INS3;
 
@WebServiceProvider(
    targetNamespace = TEST_SERVICE_NAMESPACE,
    serviceName = TEST_SERVICE,
    portName = TEST_PORT
)
@ServiceMode(MESSAGE)
public class Activator extends ProviderHelper implements BundleActivator, Provider<SOAPMessage> {
 
	private static BundleContext context;
	private static Endpoint endpoint = null;
	private static QName portQName = null;
	private static Service testService = null;
 
	static BundleContext getContext() {
		return context;
	}
 
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
        super.init(getClass().getClassLoader(), null, false);
        endpoint = Endpoint.create(this);
        endpoint.publish(ENDPOINT_ADDRESS);
        QName serviceQName = new QName(TEST_SERVICE_NAMESPACE, TEST_SERVICE);
        portQName = new QName(TEST_SERVICE_NAMESPACE, TEST_PORT);
        testService = Service.create(serviceQName);
        testService.addPort(portQName, SOAP11HTTP_BINDING, ENDPOINT_ADDRESS);
	System.out.println("Hello, " + testService.toString());
	}
 
	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
        if (endpoint != null) {
            endpoint.stop();
        }
        super.destroy();
		System.out.println("Goodbye");
	}
}

Back to the top