SP - Advanced API Samples - Mediator, Web Services, and DSP Controls
This page last changed on Jun 19, 2008.
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2/3.01 Documentation
Getting Started with Advanced API Samples
This advanced topic supplements existing documentation that describes the invocation of ALDSP operations from Mediator API, web service, and DSP Control clients. Specifically this topic introduces the sample and provides links to the instructions necessary to download, build, and test the samples. Topic MapRequirementsDownload the SampleYou can install and work with the advanced API samples on any system with ALDSP 3.2 (server 10.1) or ALDSP 3.01 (server 9.2) installed, including the Sample Retail Application provided with ALDSP. The advanced API samples are available as a ZIP file from: It is recommended that the ZIP file be extracted into an ALDSP directory such as: <ALDSP_HOME>/user_projects/workspaces/default/AdvancedAPISamples
Install Workshop 10.2In order to run the ALDSP Control samples you need to install Workshop 10.2 into the BEA_HOME where your ALDSP server resides. You can download WebLogic Workshop 10.2 from: http://commerce.bea.com/showproduct.jsp?family=WLW&major=10.2&minor=0 Useful References
IntroductionALDSP enables you to create client projects that invoke data service operations. These client projects can include the following, among others:
Exploring the Sample ProjectsALDSP includes a set of four sample dataspace projects, based on the Retail Dataspace example provided with ALDSP, that shows how to call ALDSP from client applications using the following:
The sample dataspace projects highlight several aspects of the client development process including calling data service operations with different types of arguments and returning different return types. The sample dataspace projects also demonstrate how to use out-of-band settings (RequestConfig), and show how to perform create, read, update, and delete operations on the data returned.
Related TopicsConceptsHow TosReference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation Understanding the Advanced Static Mediator API SampleThis topic describes how to use the static mediator API to call a data service operation with a complex argument.
Topic Map![]() Importing PackagesThe first segment of the sample project imports several required packages including the DASResult package which represents the result of invoking an operation on a data service. import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.bea.dsp.das.DASResult; import weblogic.jndi.Environment; import java.io.StringWriter; Note that you could also choose to import the following classes that appear in the generated mediator client JAR file: import das.ws.retailapplication.customermanagement.ProfileServiceDAS import das.ejb.retailapplication.customermanagement.ProfileServiceDAS import retailer.CASE_SERVICE The ProfileServiceDAS classes (for web services and Java respectively) are the generated DataAccessService classes for the data service. These classes contains type-safe methods that map to the actual data service operations. The CASE_SERVICE class provides the SDO interface for manipulating DataObjects returned from the data service. Obtaining a Data Access Service HandleYou use a DataAccessService object to call methods (operations) on a data service. For the static mediator API, the DataAccessService (DAS) classes have a factory method named getInstance() which return the handle. The getInstance() method requires two parameters to return the handle:
The ALDSP web service client identifies the DataAccessService class using the URL of the WSDL file. The ALDSP Java client, on the other hand, identifies the DataAccessService class using the dataspace name.
das.ws.retailapplication.customermanagement.ProfileServiceDAS wsDas = null; das.ejb.retailapplication.customermanagement.ProfileServiceDAS ejbDas = null; DASResult<retailer.CASE_SERVICE> dasResult = null; ... if(isWebServiceClient()){ contextCacheKey=locator; wsDas=das.ws.retailapplication.customermanagement.ProfileServiceDAS.getInstance( new java.util.Hashtable(), contextCacheKey); } else { splitLocator(locator); Context ctx = getInitialContext(uri, username, password); ejbDas=das.ejb.retailapplication.customermanagement.ProfileServiceDAS.getInstance(ctx, contextCacheKey); } The sample uses a helper method, getInitialContext(), to get the initial context. public static InitialContext getInitialContext(String url, String username, String password) throws NamingException { Environment env = new Environment(); env.setProviderUrl(url); env.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory"); env.setSecurityPrincipal(username); env.setSecurityCredentials(password); return new InitialContext(env.getInitialContext().getEnvironment()); } Creating the SDO DataFactoryThe following code segment shows the use of the HelperContext to create a new DataFactory which you can later use to create new DataObjects. commonj.sdo.helper.HelperContext hc=com.bea.dsp.das.HelperContextCache.get(contextCacheKey); commonj.sdo.helper.XMLHelper xh = hc.getXMLHelper(); commonj.sdo.helper.DataFactory factory = hc.getDataFactory();
Retrieving Data from the ServiceThe generated DataAccessService method getServiceCase(profileService) retrieves the result set from the data service. This method returns all CASE objects corresponding to the specified profile from the data service. retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class ); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); if(isWebServiceClient()){ dasResult = wsDas.getServiceCase(profileService); } else { dasResult = ejbDas.getServiceCase(profileService); } Note that the argument for the setElementName() method must include the namespace URI along with the name of the type of the argument. You can determine the namespace URI by doing the following:
The method getServiceCase() is mapped directly from the original data service operation of the same name. The operation definition as specified in the data service file appears as follows: (::pragma function <f:function kind="navigate" roleName="ServiceCase" visibility="public" xmlns:f="urn:annotations.ld.bea.com"/>::) declare function tns:getServiceCase($profile as element(ns5:PROFILE)) as element(ns7:CASE)*{ for $b in ns8:getServiceCaseByCustID($profile/ns2:PROFILE/CustomerID) return $b }; Obtaining a DataObject from the ResultThe return type of the DataAccessService method is a dasResult object, which operates as an iterator. This means that you can use the DASResult.next() method similar to the way you would use the Java method Iterator.next(). The DASResult.next() method returns the next CASE, which is an SDO DataObject. SDO is a Java-based data programming model (API) and architecture for accessing and updating data. The sample iterates through the dasResult object and outputs the data. while( dasResult.hasNext()){ out("DataObject : " + dataObjectToString(xh,(retailer.CASE_SERVICE)dasResult.next())); } Disposing the dasResult ObjectYou must call the DASResult.dispose() method whenever you are finished iterating through a result object. The sample project uses the following code segment to dispose the object: try { if(dasResult!=null) dasResult.dispose(); } catch(Exception e){e.printStackTrace();}
ClientComplex.Arg.java ListingThe following lists the code for the ClientComplexArg.java sample project. ClientComplex.Arg.java Sample Project Codepackage client.java_and_ws.static0; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.bea.dsp.das.DASResult; import weblogic.jndi.Environment; import java.io.StringWriter; public class ClientComplexArg { String locator="http://localhost:7001/RetailDataspace/RetailApplication/CustomerManagement/ProfileService.ws?WSDL"; String dsLocator=null; String uri=null; String username= "weblogic"; String password="weblogic"; java.io.Writer out=new java.io.PrintWriter(System.out); String className=this.getClass().getName().substring(this.getClass().getName().lastIndexOf('.')+1); String runningIn=this.getClass().getClassLoader().equals(com.bea.dsp.das.DASResult.class.getClassLoader()) ? "standalone" : "webapp"; String contextCacheKey=null; enum ClientType {java, webservice, control}; ClientType clientType=ClientType.java; enum ClassloaderType { noclassloader, currentthread, other}; ClassloaderType classloaderType=ClassloaderType.noclassloader; public ClientComplexArg(){ this((String)null,(String)null,(String)null, (String)null, null, null); } public ClientComplexArg(java.io.Writer out){ this((String)null,(String)null,(String)null, (String)null, out, null); } public ClientComplexArg(String locator){ this(locator,(String)null,(String)null, (String)null, null, null); } public ClientComplexArg(String locator, java.io.Writer out, String classloadertypeStr){ this(locator,(String)null,(String)null, (String)null, out, classloadertypeStr); } public ClientComplexArg(String cType, String locator, String username, String password, java.io.Writer out, String classloadertypeStr){ if(cType != null) this.clientType=ClientType.valueOf(cType); if(locator!=null) this.locator=locator; if(username!=null) this.username=username; if(password!=null)this.password=password; if(out!=null) this.out=out; if(classloadertypeStr != null) this.classloaderType=ClassloaderType.valueOf(classloadertypeStr); } public static void main(String[] args) { String locator=args.length > 0 ? args[0] : null; String uri=args.length > 1 ? args[1] : null; String username=args.length > 2 ? args[2] : null; String password=args.length > 3 ? args[3] : null; String classloadertypeStr=args.length > 4 ? args[4] : null; ClientComplexArg c=new ClientComplexArg(locator, uri, username, password, null, classloadertypeStr); c.run(); } public void run(){ if (! locator.startsWith("http://") ){ out("locator must be http://... (wsdl URL)"); return; } das.ws.retailapplication.customermanagement.ProfileServiceDAS wsDas = null; das.ejb.retailapplication.customermanagement.ProfileServiceDAS ejbDas = null; DASResult<retailer.CASE_SERVICE> dasResult = null; try { if (isWebServiceClient()){ contextCacheKey=locator; wsDas=das.ws.retailapplication.customermanagement.ProfileServiceDAS.getInstance(new java.util.Hashtable(), contextCacheKey); } else { splitLocator(locator); Context ctx = getInitialContext(uri, username,password); ejbDas = das.ejb.retailapplication.customermanagement.ProfileServiceDAS.getInstance(ctx, contextCacheKey); } commonj.sdo.helper.HelperContext hc=com.bea.dsp.das.HelperContextCache.get(contextCacheKey); commonj.sdo.helper.XMLHelper xh = hc.getXMLHelper(); commonj.sdo.helper.DataFactory factory = hc.getDataFactory(); retailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class ); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); if (isWebServiceClient()){ dasResult = wsDas.getServiceCase(profileService); } else { dasResult = ejbDas.getServiceCase(profileService); } while( dasResult.hasNext()){ out("DataObject : " + dataObjectToString(xh,(retailer.CASE_SERVICE)dasResult.next())); } } catch (Exception e) { e.printStackTrace(); } finally { try { if(dasResult!=null) dasResult.dispose(); } catch(Exception e){e.printStackTrace();} } } public void out(String s){ try{ if(out instanceof javax.servlet.jsp.JspWriter) s = s.replace("&","&").replace("<", "<").replace(">", ">"); out.write(className+"/"+runningIn+"/"+clientType+"/"+classloaderType+" "+s+"\n"); out.flush(); }catch (Exception e){ e.printStackTrace(); } } public static InitialContext getInitialContext(String url, String username, String password) throws NamingException { Environment env = new Environment(); env.setProviderUrl(url); env.setInitialContextFactory("weblogic.jndi.WLInitialContextFactory"); env.setSecurityPrincipal(username); env.setSecurityCredentials(password); return new InitialContext(env.getInitialContext().getEnvironment()); } static String dataObjectToString(commonj.sdo.helper.XMLHelper xh, commonj.sdo.DataObject dObj) { try { com.bea.sdo.PropertyXML element = ((com.bea.sdo.DataObjectXML) dObj).getContainmentPropertyXML(); String elementName = element.getXMLName(); String elementURI = element.getXMLNamespaceURI(); commonj.sdo.helper.XMLDocument xmlDocument = xh.createDocument(dObj, elementURI, elementName); StringWriter outputWriter = new StringWriter(); xh.save(xmlDocument, outputWriter, null); return outputWriter.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } boolean isWebServiceClient(){ return clientType==ClientType.webservice; } void splitLocator(String locator) throws Exception { uri=null; contextCacheKey=null; dsLocator=null; for(int i=0, j=0, last=0;i<locator.length(); i++) { if(locator.charAt(i) == '/') { j++; if(j==2) last=i; if(j==3) { uri="t3://"+locator.substring(last+1,i); last=i; } if(j==4) { contextCacheKey=locator.substring(last+1,i); dsLocator="ld:"+locator.substring(i+1).replace(".ws?WSDL", ""); break; } } } if(uri==null || contextCacheKey== null || dsLocator==null) throw new Exception("locator not valid : "+locator); return; } } Related TopicsConceptsHow TosReference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation How To Set Up the Advanced API Sample ProjectsThis topic describes how to set up the ALDSP sample projects which illustrate how to call ALDSP data service operations from client applications. Topic Map
![]() Installing the ALDSP Retail Dataspace Sample
Adding Functions to the Dataspace ProjectTo add the sample functions to the RetailDataspace project:
Updating the SchemaTo update the schema file to support the new functions in the ProfileService.ds data service follow these steps:
Exporting the Mediator Client JAR FilesBefore exporting the Mediator Client JAR files, you need to create a web service map. To create the web service map:
Exporting the Java Mediator Client JAR FileTo export the Java Mediator Client JAR file for the project:
A message indicating that your have successfully exported the mediator JAR file and its location should appear. Exporting the Java Web Services Mediator Client JAR FileTo export the Java Web Services Mediator Client JAR File:
A message indicating that your have successfully exported the web services mediator JAR file and its location should appear. Creating the Sample DataspacesThe sample provides four dataspaces:
The dynamic and static client samples illustrate use of the Java and Web Services Mediator APIs. The control dynamic and static samples, illustrate use of ALDSP Control APIs. You can create the four sample dataspaces by dowloading and importing the advanced samples ZIP file.
Adding the Mediator Client JAR FilesTo add your mediator client JAR files to the projects:
Setting the Java Build PathsYou need to set the Java build paths to include the specific JAR files required by the projects.
To set the Java build path:
Configuring the Build Path
The following table identifies the necessary JAR files and their location for each advanced sample dataspace project. (The ld-client.jar file is needed by all four projects.) Project, Required JAR Files, and Location
Setting the Run ConfigurationsYou need to create a run configuration for the following projects:
Setting the Run Configuration for DSPClientSamplesDynamic1To set the run configuration for DSPClientSamplesDynamic1:
Configuring the Run Configuration Classpath
Setting the Run Configuration for DSPClientSamplesStatic1To set the run configuration for DSPClientSamplesStatic1:
Related TopicsHow Tos
Reference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation How To Run the Mediator API Sample ProjectsThis topic describes how to run the Mediator API sample projects. Topic Map![]() Running the Standalone Samples Using the Custom Run ConfigurationYou can run the following standalone Mediator API sample projects using a custom configuration:
You can run the DSPClientSamplesDynamic1 sample using the steps shown above. Selecting the Run ConfigurationThe sample project includes an optional parameter enabling you to choose the following client types:
The parameter can be specified in the Arguments tab as a program argument such as: webservice Specifying an ArgumentThe results appear in the Console Window. Console After Running Static Mediator Sample with webservice ParameterRunning the Sample Controls Using "Run on Server"You can run the Mediator API sample controls using the "Run on Server" option.
To run the sample projects:
Selecting the ServerSelect the server and click Next. Adding the ProjectAdd the required project, and click Finish. You can specify an optional parameter to use the Mediator API or Web Services Mediator API. Using the Advanced APISample Projects with ALDSP 3.0The samples are tested with ALDSP 3.2 and 3.01. If you are using ALDSP 3.0, you need to call the getContextClassLoader() method before accessing the DataAccessService. Specifically, when using the Java or DSP Control Mediator API, call the following method before accessing the DataAccessService: com.bea.dsp.das.HelperContextCache.setClassLoader("RetailDataspace", Thread.currentThread.getContextClassLoader(); Similarly, when using the Web Services Mediator API, call the following method before accessing the DataAccessService: com.bea.dsp.das.HelperContextCache.setClassLoader( "http://localhost:7001/RetailDataspace/RetailApplication/CustomerManagement/ProfileService.ws?WSDL", Thread.currentThread.getContextClassLoader()); Related TopicsHow Tos
Reference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation Static Mediator API Code ReferenceThis topic describes the advanced sample project that uses the Static Mediator API to call data service operations from client applications using a variety of argument and return types.
Topic MapUsing a Complex ArgumentYou can call ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using type-safe setter methods. The sample then calls the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.
Calling an Operation Using a Complex Argumentretailer.PROFILE_SERVICE profileService =(retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class ); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); if(isWebServiceClient()){ dasResult = wsDas.getServiceCase(profileService); } else { dasResult = ejbDas.getServiceCase(profileService); } Using a Complex Argument ListYou can call data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using type-safe setter methods. The sample then calls the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.
Calling an Operation Using a List of Complex Argumentsretailer.PROFILE_SERVICES profileService =(retailer.PROFILE_SERVICES)factory.create("urn:retailer", "PROFILE_SERVICES"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER6"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); if(isWebServiceClient()){ dasResult = wsDas.getServiceCases(profileService); } else { dasResult = ejbDas.getServiceCases(profileService); } Using a Complex Argument with Create-Read-Update-Delete OperationsYou can call multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using type-safe setter methods. The sample then calls the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile. If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.
Calling Multiple Operations Using Complex Argumentscom.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE"); profileServices[0]=profileService1; retailertype.PROFILE_TYPE profile1 = profileService1.createPROFILE(); profile1.setCustomerID("CUSTOMER44"); profile1.setFirstName("dummyFirstName"); profile1.setLastName("dummyLastName44"); profile1.setCustomerSince( "2001-01-01"); profile1.setEmailAddress( "dummyEmailAddress"); profile1.setTelephoneNumber("8885551212"); retailer.PROFILE_SERVICE profileService2 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE"); profileServices[1]=profileService2; retailertype.PROFILE_TYPE profile2 = profileService2.createPROFILE(); profile2.setCustomerID("CUSTOMER55"); profile2.setFirstName("dummyFirstName"); profile2.setLastName("dummyLastName55"); profile2.setCustomerSince( "2001-01-01"); profile2.setEmailAddress( "dummyEmailAddress"); profile2.setTelephoneNumber("8885551212"); if(isWebServiceClient()){ dasResult = wsDas.getCustomerByCustID("CUSTOMER44"); } else { dasResult = ejbDas.getCustomerByCustID("CUSTOMER44"); } if(!dasResult.hasNext()) { out("ADDING: "); if(isWebServiceClient()) { dasKey = wsDas.createPROFILE(profileServices); } else { dasKey = ejbDas.createPROFILE(profileServices); } while( dasKey.hasNext()){ out("DataObject : " + dataObjectToString(xh, dasKey.next())); } } else { retailer.PROFILE_SERVICE dObj= dasResult.next(); if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){ out("UPDATING: "); out("DataObject : " + dataObjectToString(xh,dObj)); com.bea.dsp.sdo.SDOUtil.enableChanges(dObj); dObj.set("PROFILE/LastName", "Smith"); if(isWebServiceClient()){ wsDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } else { ejbDas.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } } else { out("DELETING: "); out("DataObject : " + dataObjectToString(xh,dObj)); if(isWebServiceClient()){ wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } else { ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } if(isWebServiceClient()){ dasResult = wsDas.getCustomerByCustID("CUSTOMER55"); } else { dasResult = ejbDas.getCustomerByCustID("CUSTOMER55"); } if(dasResult.hasNext()){ dObj=dasResult.next(); out("DataObject : " + dataObjectToString(xh,dObj)); if(isWebServiceClient()){ wsDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } else { ejbDas.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } } } } Returning a Simple ElementYou can call ALDSP data service operations that return simple types. The example in this section determines the number of orders by calling the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.
Calling an Operation that Returns a Simple Typejava.math.BigInteger count; if(isWebServiceClient()){ count = wsDas.getOrderCount("CUSTOMER4"); } else { count = ejbDas.getOrderCount("CUSTOMER4"); } out("DataObject : " + count); if(isWebServiceClient()){ dasResult = wsDas.getOrderCounts("CUSTOMER4"); } else { dasResult = ejbDas.getOrderCounts("CUSTOMER4"); } while( dasResult.hasNext()){ java.math.BigInteger theCount = (java.math.BigInteger) dasResult.next(); out("DataObject : " + theCount); } Including AuditingYou can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT). After enabling audit, the example includes the instance of the RequestConfig object as an argument when calling methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.
Auditing Operationscom.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig(); reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT); reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes); if(isWebServiceClient()){ dasResult = wsDas.getCustomerByLoginID("Steve", reqConfig); } else { dasResult = ejbDas.getCustomerByLoginID("Steve", reqConfig); } com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit(); if (dsAudit != null) { List l = dsAudit.getAllRecords(); for (Iterator it = l.iterator(); it.hasNext();) { com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next(); Map propMap = auditRec.getAuditProperties(); for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) { String key = (String) pit.next(); out("Audit Information: " + key + " = " + propMap.get(key)); } } } while( dasResult.hasNext()){ out("DataObject : " + dataObjectToString(xh,(retailer.PROFILE_SERVICE)dasResult.next())); } Using FiltersYou can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID. After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when calling the method corresponding to data service operation.
Filtering Based on an IdentifierreqConfig = new com.bea.dsp.RequestConfig(); com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery(); filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID"); com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables(); externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5"); filter.setExternalVariables(externalVariables); /* Alteratively, filter with a hard-coded value */ // filter.addFilter("PROFILE", "PROFILE/PROFILE/CustomerID","=","CUSTOMER5"); reqConfig.setFilter(filter); try { if(isWebServiceClient()){ dasResult = wsDas.getProfile(reqConfig); } else { dasResult = ejbDas.getProfile(reqConfig); } } Related TopicsConcepts
How TosReference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation Dynamic Mediator API Code ReferenceThis topic describes the advanced sample project that uses the Dynamic Mediator API to call ALDSP data service operations from client applications using a variety of argument and return types.
Topic Map![]() Using a Complex ArgumentYou can invoke ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using the set method. The sample then invokes the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation.
Invoking an Operation Using a Complex Argumentcommonj.sdo.DataObject profileService = factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER4"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCase", new Object[] { profileService }); Using a Complex Argument ListYou can invoke ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using the set method. The sample then invokes the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation.
Invoking an Operation Using a List of Complex ArgumentsprofileServices = factory.create("urn:retailer", "PROFILE_SERVICES"); com.bea.dsp.sdo.SDOUtil.setElementName(profileServices, "urn:retailer", "PROFILES"); profile = profileServices.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER4"); profile.set("FirstName", "dummyFirstName4"); profile.set("LastName", "dummyLastName4"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); profile = profileServices.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER6"); profile.set("FirstName", "dummyFirstName6"); profile.set("LastName", "dummyLastName6"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); dasResult = (com.bea.dsp.das.DASResult) das.invoke("getServiceCases", new Object[] { profileServices }); Using a Complex Argument with Create-Read-Update-Delete OperationsYou can invoke multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using the setElementName method. The sample then invokes the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile. If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile.
Invoking Multiple Operations Using Complex ArgumentsprofileService = factory.create("urn:retailer", "PROFILE_SERVICE"); profileServices.add(profileService); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); profile1 = profileService.createDataObject("PROFILE"); profile1.set("CustomerID", "CUSTOMER44"); profile1.set("FirstName", "dummyFirstName44"); profile1.set("LastName", "dummyLastName44"); profile1.set("CustomerSince", "2001-01-01"); profile1.set("EmailAddress", "dummyEmailAddress"); profile1.set("TelephoneNumber", "8885551212"); profileService = factory.create("urn:retailer", "PROFILE_SERVICE"); profileServices.add(profileService); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); profile2 = profileService.createDataObject("PROFILE"); profile2.set("CustomerID", "CUSTOMER55"); profile2.set("FirstName", "dummyFirstName55"); profile2.set("LastName", "dummyLastName55"); profile2.set("CustomerSince", "2001-01-01"); profile2.set("EmailAddress", "dummyEmailAddress"); profile2.set("TelephoneNumber", "8885551212"); dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER44" }); if(!dasResult.hasNext()) { out("ADDING: "); dasResult = (com.bea.dsp.das.DASResult) das.invoke("createPROFILE", new Object[] { profileServices.toArray() }); while( dasResult.hasNext()) { out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next())); } } else { commonj.sdo.DataObject dObj=(commonj.sdo.DataObject)dasResult.next(); if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))) { out("UPDATING: "); out("DataObject : " + dataObjectToString(xh,dObj)); com.bea.dsp.sdo.SDOUtil.enableChanges(dObj); dObj.set("PROFILE/LastName", "Smith"); dasResult = (com.bea.dsp.das.DASResult) das.invoke("updatePROFILE", new Object[] { dObj }); } else { out("DELETING: "); out("DataObject : " + dataObjectToString(xh,dObj)); dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj }); dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByCustID", new Object[] { "CUSTOMER55" }); if(dasResult.hasNext()) { dObj=(commonj.sdo.DataObject)dasResult.next(); out("DataObject : " + dataObjectToString(xh,dObj)); dasResult = (com.bea.dsp.das.DASResult) das.invoke("deletePROFILE", new Object[] { dObj }); } } } Returning a Simple ElementYou can invoke ALDSP data service operations that return simple types. The example in this section determines the number of orders by invoking the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger.
Invoking an Operation that Returns a Simple TypedasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCount", new Object[] {"CUSTOMER4"}); while( dasResult.hasNext()) { java.math.BigInteger count = (java.math.BigInteger) dasResult.next(); out("DataObject : " + count); } dasResult = (com.bea.dsp.das.DASResult) das.invoke("getOrderCounts", new Object[] {"CUSTOMER4"}); while( dasResult.hasNext()) { java.math.BigInteger count = (java.math.BigInteger) dasResult.next(); out("DataObject : " + count); } Including AuditingYou can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT). After enabling audit, the example includes the instance of the RequestConfig object as an argument when invoking methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display.
Auditing Operationscom.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig(); reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT); reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes); dasResult = (com.bea.dsp.das.DASResult) das.invoke("getCustomerByLoginID", new Object[] { "Steve" }, reqConfig); com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit(); if (dsAudit != null) { List l = dsAudit.getAllRecords(); for (Iterator it = l.iterator(); it.hasNext();) { com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next(); Map propMap = auditRec.getAuditProperties(); for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) { String key = (String) pit.next(); out("Audit Information: " + key + " = " + propMap.get(key)); } } } while( dasResult.hasNext()) { out("DataObject : " + dataObjectToString(xh,(commonj.sdo.DataObject)dasResult.next())); } Using FiltersYou can filter the results of calls to data service operations using the ALDSP RequestConfig. The example in this section creates an instance of the RequestConfig object and then defines a filter based on the customer ID. After defining the filter, the example sets the filter on the RequestConfig object and passes the instance of RequestConfig as an argument when invoking the method corresponding to data service operation.
Filtering Based on an IdentifierreqConfig = new com.bea.dsp.RequestConfig(); com.bea.ld.filter.FilterXQuery filter=new com.bea.ld.filter.FilterXQuery() ; filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","$customerID"); com.bea.ld.ExternalVariables externalVariables=new com.bea.ld.ExternalVariables(); externalVariables.setString(new javax.xml.namespace.QName("customerID"), "CUSTOMER5"); filter.setExternalVariables(externalVariables); /* Or filter with hard-coded value */ // filter.addFilter("PROFILE","PROFILE/PROFILE/CustomerID","=","CUSTOMER5"); reqConfig.setFilter(filter); try { dasResult = das.invoke("getProfile", new Object[] {}, reqConfig); } Related TopicsConcepts
How TosReference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation ALDSP Control Static Mediator API Code ReferenceThis topic describes the advanced sample project that uses the Static Mediator API to call data service operations from ALDSP Controls using a variety of argument and return types.
Topic Map![]() Using a Complex ArgumentYou can call ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using type-safe setter methods. The sample then calls the getServiceCase method using the complex argument, which retrieves the CASE information through the identically-named ALDSP operation. Calling an Operation Using a Complex Argumentretailer.PROFILE_SERVICE profileService = (retailer.PROFILE_SERVICE)factory.create(retailer.PROFILE_SERVICE.class ); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); retailer.CASE_SERVICE[] cases=DSPControlFile.getServiceCase(profileService); Using a Complex Argument ListYou can call ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using type-safe setter methods. The sample then calls the getServiceCase method using the argument consisting of the list of complex objects, retrieving the CASE information through the identically-named ALDSP operation. Calling an Operation Using a List of Complex Argumentsretailer.PROFILE_SERVICES profileService =(retailer.PROFILE_SERVICES)factory.create("urn:retailer", "PROFILE_SERVICES"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES"); retailertype.PROFILE_TYPE profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER4"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); profile = profileService.createPROFILE(); profile.setCustomerID("CUSTOMER6"); profile.setFirstName("dummyFirstName"); profile.setLastName("dummyLastName"); profile.setCustomerSince( "2001-01-01"); profile.setEmailAddress( "dummyEmailAddress"); profile.setTelephoneNumber("8885551212"); retailer.CASE_SERVICE[] cases = DSPControlFile.getServiceCases(profileService); Using a Complex Argument with Create-Read-Update-Delete OperationsYou can call multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including calling create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using type-safe setter methods. The sample then calls the getCustomerByCustID method using a complex argument and checks whether the customer information is already stored. If not, the sample calls the createPROFILE method to create the customer profile. If a record already exists for the customer, the sample calls the updatePROFILE method to store the new information in the profileService object. If an existing record does not match, the sample calls the deletePROFILE method to remove the customer profile. Calling Multiple Operations Using Complex Argumentretailer.PROFILE_SERVICE[] profileServices = new retailer.PROFILE_SERVICE[2]; retailer.PROFILE_SERVICE profileService1 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE"); profileServices[0]=profileService1; retailertype.PROFILE_TYPE profile1 = profileService1.createPROFILE(); profile1.setCustomerID("CUSTOMER44"); profile1.setFirstName("dummyFirstName"); profile1.setLastName("dummyLastName44"); profile1.setCustomerSince( "2001-01-01"); profile1.setEmailAddress( "dummyEmailAddress"); profile1.setTelephoneNumber("8885551212"); retailer.PROFILE_SERVICE profileService2 =(retailer.PROFILE_SERVICE)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE"); profileServices[1]=profileService2; retailertype.PROFILE_TYPE profile2 = profileService2.createPROFILE(); profile2.setCustomerID("CUSTOMER55"); profile2.setFirstName("dummyFirstName"); profile2.setLastName("dummyLastName55"); profile2.setCustomerSince( "2001-01-01"); profile2.setEmailAddress( "dummyEmailAddress"); profile2.setTelephoneNumber("8885551212"); retailer.PROFILE_SERVICE[] returnedProfileServices=DSPControlFile.getCustomerByCustID("CUSTOMER44"); outputString=""; if(returnedProfileServices.length==0) { outputString=outputString +"ADDING: \n"; DSPControlFile.createPROFILE(profileServices); outputString=outputString + dataObjectsToString(profileServices); } else { retailer.PROFILE_SERVICE dObj= returnedProfileServices[0]; if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))) { outputString=outputString +"UPDATING: \n"; outputString=outputString + dataObjectsToString(profileServices); com.bea.dsp.sdo.SDOUtil.enableChanges(dObj); dObj.set("PROFILE/LastName", "Smith"); DSPControlFile.updatePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } else { outputString=outputString +"DELETING: \n"; outputString=outputString + dataObjectsToString(returnedProfileServices); DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); returnedProfileServices=DSPControlFile.getCustomerByCustID("CUSTOMER55"); if(returnedProfileServices.length>0) { dObj = returnedProfileServices[0]; outputString=outputString + dataObjectsToString(returnedProfileServices); DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{dObj}); } } } Returning a Simple ElementYou can call ALDSP data service operations that return simple types. The example in this section determines the number of orders by calling the getOrderCount and getOrderCounts methods and assigning the results to variables of type java.math.BigInteger. Calling an Operation that Returns a Simple Typejava.math.BigInteger count = DSPControlFile.getOrderCount("CUSTOMER4"); outputString=outputString + dataObjectsToString(new Object[]{count}); java.math.BigInteger[] counts = DSPControlFile.getOrderCounts("CUSTOMER4"); outputString=outputString + dataObjectsToString(counts); Including AuditingYou can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT). After enabling audit, the example includes the instance of the RequestConfig object as an argument when calling methods corresponding to data service operations. The example then retrieves the audit records and iterates through the results to output for display. Auditing Operationscom.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig(); reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT); reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes); retailer.PROFILE_SERVICE profileService[] = DSPControlFile.getCustomerByLoginID("Steve", reqConfig); outputString=dataObjectsToString(profileService); com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit(); if (dsAudit != null) { List l = dsAudit.getAllRecords(); for (Iterator it = l.iterator(); it.hasNext();) { com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next(); Map propMap = auditRec.getAuditProperties(); for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) { String key = (String) pit.next(); outputString=outputString + "Audit Information: " + key + " = " + propMap.get(key)+"\n"; } } } Related TopicsConcepts
How TosReference
edocs Home > BEA AquaLogic Data Services Platform 3.0/3.2 Documentation > ALDSP 3.2 New Features Documentation ALDSP Control Dynamic Mediator API Code ReferenceThis topic the advanced sample project that uses the Dynamic Mediator API to invoke data service operations from ALDSP Controls using a variety of argument and return types.
Topic Map![]() Using a Complex ArgumentYou can invoke ALDSP data service operations using a complex argument type. The example in this section creates a profileService object and populates the object with customer information using the set method. The sample then creates a query to call the getServiceCase operation, using the complex argument, to retrieve the CASE information. Calling an Operation Using a Complex Argumentcommonj.sdo.DataObject profileService =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILE"); commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER4"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileService), true); StringBuffer query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profile as element(retailer:PROFILE) external;\n"); query.append("tns:getServiceCase($profile)"); Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables); Using a Complex Argument ListYou can invoke ALDSP data service operations using an argument consisting of a list of complex types. The example in this section creates two profileService objects and populates the objects with customer information using the set method. The sample then creates a query to call the getServiceCase operation, using the argument consisting of the list of complex objects, to retrieve the CASE information. Invoking an Operation Using a List of Complex Argumentscommonj.sdo.DataObject profileService =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICES"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService, "urn:retailer", "PROFILES"); commonj.sdo.DataObject profile = profileService.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER4"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); profile = profileService.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER6"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profiles"), dataObject2String(xh,profileService), true); StringBuffer query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profiles as element(retailer:PROFILES) external;\n"); query.append("tns:getServiceCases($profiles)"); Object[] cases=DSPControlFile.executeQuery(query.toString(), extVariables); Using a Complex Argument with Create-Read-Update-Delete OperationsYou can invoke multiple ALDSP data service operations, each with a complex argument type, to perform a series of tasks including invoking create, read, update, and delete operations in the data service. The example in this section creates two profileService objects and populates the objects with "dummy" customer information using the set method. The sample then creates a query to call the getCustomerByCustID operation using a complex argument and checks whether the customer information is already stored. If not, the sample creates a query to call the createPROFILE operation to create the customer profile. If a record already exists for the customer, the sample creates a query to call the updatePROFILE operation to store the new information in the profileService object. If an existing record does not match, the sample creates a query to call the deletePROFILE operation to remove the customer profile. Invoking Multiple Operations Using Complex Argumentsretailer.PROFILE_SERVICE[] profileServices = new retailer.PROFILE_SERVICE[2]; commonj.sdo.DataObject profileService1 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService1, "urn:retailer", "PROFILE"); profileServices[0]=(retailer.PROFILE_SERVICE)profileService1; commonj.sdo.DataObject profile = profileService1.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER44"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName44"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); commonj.sdo.DataObject profileService2 =(commonj.sdo.DataObject)factory.create("urn:retailer", "PROFILE_SERVICE"); com.bea.dsp.sdo.SDOUtil.setElementName(profileService2, "urn:retailer", "PROFILE"); profileServices[1]=(retailer.PROFILE_SERVICE)profileService2; profile = profileService2.createDataObject("PROFILE"); profile.set("CustomerID", "CUSTOMER55"); profile.set("FirstName", "dummyFirstName"); profile.set("LastName", "dummyLastName55"); profile.set("CustomerSince", "2001-01-01"); profile.set("EmailAddress", "dummyEmailAddress"); profile.set("TelephoneNumber", "8885551212"); StringBuffer query=new StringBuffer(); query.append("declare variable $customerId as xs:string external;\n"); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("tns:getCustomerByCustID($customerId)"); com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER44", true); Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables ); outputString=""; if(returnedProfileServices.length==0) { outputString=outputString +"ADDING: \n"; /* extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,profileServices), true); query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profile as element(retailer:PROFILE)* external;\n"); query.append("tns:createPROFILE($profile)"); returnedProfileServices=DSPControlFile.executeProcedure(query.toString(), extVariables); */ returnedProfileServices=DSPControlFile.createPROFILE(profileServices); outputString=outputString + dataObjectsToString(returnedProfileServices); } else { commonj.sdo.DataObject dObj= (commonj.sdo.DataObject)returnedProfileServices[0]; if("dummyLastName44".equals(dObj.get("PROFILE/LastName"))){ outputString=outputString +"UPDATING: \n"; outputString=outputString + dataObjectsToString(profileServices); com.bea.dsp.sdo.SDOUtil.enableChanges(dObj); dObj.set("PROFILE/LastName", "Smith"); DSPControlFile.updatePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj}); /* extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,dObj), true); query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profile as changed-element(retailer:PROFILE)* external;\n"); query.append("tns:updatePROFILE($profile)"); DSPControlFile.executeProcedure(query.toString(), extVariables); */ } else { outputString=outputString +"DELETING: \n"; outputString=outputString + dataObjectsToString(returnedProfileServices); DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj}); /* extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true); query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profile as element(retailer:PROFILE)* external;\n"); query.append("tns:deletePROFILE($profile)"); DSPControlFile.executeProcedure(query.toString(), extVariables); */ query=new StringBuffer(); query.append("declare variable $customerId as xs:string external;\n"); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("tns:getCustomerByCustID($customerId)"); extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER55", true); returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables ); if(returnedProfileServices.length>0) { dObj= (commonj.sdo.DataObject)returnedProfileServices[0]; outputString=outputString + dataObjectsToString(returnedProfileServices); DSPControlFile.deletePROFILE(new retailer.PROFILE_SERVICE[]{(retailer.PROFILE_SERVICE)dObj}); /* extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("profile"), dataObject2String(xh,returnedProfileServices), true); query=new StringBuffer(); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("declare namespace retailer='urn:retailer';\n"); query.append("declare variable $profile as element(retailer:PROFILE)* external;\n"); query.append("tns:deletePROFILE($profile)"); DSPControlFile.executeProcedure(query.toString(), extVariables); */ } } } Returning a Simple ElementYou can invoke ALDSP data service operations that return simple types. The example in this section determines the number of orders by creating a query to call the getOrderCount and getOrderCounts operations and assigning the results to variables of type java.math.BigInteger. Invoking an Operation that Returns a Simple TypeoutputString=""; StringBuffer query=new StringBuffer(); query.append("declare variable $customerId as xs:string external;\n"); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("tns:getOrderCount($customerId)"); com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true); Object[] returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables); outputString=outputString + dataObjectsToString(new Object[]{returnedProfileServices}); query=new StringBuffer(); query.append("declare variable $customerId as xs:string external;\n"); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("tns:getOrderCounts($customerId)"); extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true); returnedProfileServices=DSPControlFile.executeQuery(query.toString(), extVariables ); outputString=outputString + dataObjectsToString(returnedProfileServices); Including AuditingYou can audit calls to ALDSP data service operations and later retrieve the audit information for further processing. The example in this section creates a RequestConfig object and enables the data service audit feature (RETURN_DATA_SERVICE_AUDIT). After enabling audit, the example includes the instance of the RequestConfig object as an argument when invoking operations. The example then retrieves the audit records and iterates through the results to output for display. Auditing Operationscom.bea.dsp.RequestConfig reqConfig = new com.bea.dsp.RequestConfig(); reqConfig.enableFeature(com.bea.dsp.RequestConfig.RETURN_DATA_SERVICE_AUDIT); reqConfig.setStringArrayAttribute(com.bea.dsp.RequestConfig.RETURN_AUDIT_PROPERTIES, attributes); StringBuffer query=new StringBuffer(); query.append("declare variable $customerId as xs:string external;\n"); query.append("declare namespace tns='ld:RetailApplication/CustomerManagement/ProfileService';\n"); query.append("tns:getCustomerByCustID($customerId)"); com.bea.ld.ExternalVariables extVariables=new com.bea.ld.ExternalVariables(); extVariables.setElement(new javax.xml.namespace.QName("customerId"), "CUSTOMER4", true); Object[] o=DSPControlFile.executeQuery(query.toString(), extVariables, reqConfig ); outputString=dataObjectsToString(o); /** Dump out the audit information **/ com.bea.ld.DataServiceAudit dsAudit = reqConfig.retrieveDataServiceAudit(); if (dsAudit != null) { List l = dsAudit.getAllRecords(); for (Iterator it = l.iterator(); it.hasNext();) { com.bea.ld.DSPAuditRecord auditRec = (com.bea.ld.DSPAuditRecord) it.next(); Map propMap = auditRec.getAuditProperties(); for (Iterator pit = propMap.keySet().iterator(); pit.hasNext();) { String key = (String) pit.next(); outputString=outputString + "Audit Information: " + key + " = " + propMap.get(key)+"\n"; } } } Related TopicsConcepts
How TosReference |
![]() |
Document generated by Confluence on Jul 03, 2008 12:11 |