Authors: Sarah Honacki and Clayton Clark
This tutorial demonstrates how to add identifiers to a completed analytical service using the StockManager service from the Develop an Advanced caGrid Analytical Service tutorial. This guide is intended for developers or those who are interested in learning how identifiers work and how they can be used in a service.
- Non-Secure Tomcat Container
- Completed StockManager Service
- Deployed Transfer Service
The StockManager service will need to be deployed to a non-secure container since the service itself is not secure. [Install a non-secure Tomcat container using the caGrid Installer]. Security can be added later by [securing the service and its resources]
This tutorial expands upon a completed StockManager service from the Develop an Advanced caGrid Analytical Service tutorial. If you have not completed the tutorial, a identifiers:completed StockManager service is also available for download.
|The completed StockManager Service is built through Phase 3 of the tutorial. To use the service, simply unzip it to an empty directory.|
The StockManager service takes in a symbol and returns a chart. Since the chart is binary data (i.e., an image), the service uses Transfer to return the chart. Transfer must be deployed to the same container to which the invoking grid service is deployed. Since the StockManager service will be deployed to the non-secure Tomcat container, Transfer will also be deployed to the same container.
Several steps are involved in adding identifiers to the StockManager Service. The basic outline involves adding the createIdentifer operation in Introduce, implementing the operation, and deploying the service to a container. However, several data types and JARs from the identifier's framework will need to be added in order for the service to use them.
To begin, data types that will be used by the StockManager service first need to be imported.
- Copy c:%CAGRID_LOCATION%\projects\identifiers-namingauthority-gridsvc\schema\IdentifiersNAService (containing the IdentifiersNAServiceTypes.xmd and org.cagrid.identifiers.namingauthority.xmd files) to C:\StockManager\schema.
- Next, import the data types into the StockManager service through Introduce:
- Start Introduce:
- Open the StockManager service by selecting "Modify Service" and then browsing to the StockManager directory.
- Select the Types tab.
- In the panel on the right, select the Add/Remove tab.
- Within this tab, select the File System tab.
- Browse to the C:%CAGRID_LOCATION%\projects\identifiers-namingauthority-gridsvc\schema\IdentifiersNAService directory and select the file "org.cagrid.identifiers.namingauthority.xsd".
- Click Add.
- The identifier data types have now been added on the left.
3. Save the service.
Now that the data types have been added, we can use Introduce to add a new method using these data types to the service.
- Select the Services tab.
- Select "StockPortfolioManager (Service Context)", and then click Add Method on the right.
- Enter "getIdentifier" for the Method Name.
- Enter "Returns an identifier for the portfolio" in the Method Description field.
- Click the Output tab.
- Double-click "String" from the list on the left under "Data Types".
7. Click Done.
8. Save the service.
You should now see the "getIdentifer" method added on the left under "StockPortfolioManager (Service Context)."
Since the createIdentifier operation has been created and the service has been saved, Introduce has generated all of the required code for the operation to work as the grid service operation. Next, the operation needs to be implemented by adding the actual code for the operation. Before this can be done, however, the necessary JARs need to be added to the project library for the StockManager service. The JARs are dependencies of the naming authority.
- Open %CAGRID_LOCATION%/projects/identifiers-client/ext/dependencies/impl/jars.
- Copy the following jars to the location "%>StockManager/lib":
- Open Eclipse.
- Import the StockManager project:
- Select File and then Import...
- Select Existing Projects into Workspace and click Next.
- Browse to the location of the StockManager service and click Finish.
- Add the jars to the project library:
- Right-click on the StockManager project from the Package Explorer window on the left and select Properties.
- Select Java Build Path from the left panel in the properties window.
- Select the Libraries tab and then click Add JARs...
- Browse to StockManager/lib and add all of the listed JARs.
- Click OK to close the properties window.
With the JARs added to the StockManager service library, the operation can now be implemented.
- In a text editor or Eclipse, open the following file:
- Add the following imports:
3. Locate the getIdentifier method.
- With this:
With the operation implemented, the next step is to test the service. To do this, the Introduce-generated client will be modified to invoke the service operation. By adding a call with getIdentifier operation in the client main method, an identifier will be created for the portfolio and then displayed.
- Open: %STOCKMANAGER%/src/org/cagrid/introduce/tutorial/stockmanager/client/StockManagerClient.java
- Add the following:
- Then, after:
4. Delete the following:
5. Save the file.
1. In a terminal, change directory to the service and run ant all:
If ant does not return a BUILD SUCCESSFUL make sure you do not have a typo in the client implementation file.
2. Deploy the project in a command prompt:
To recap, the createIdentifier operation has been created and implemented, a test for the operation has been added to the client, and the service has been deployed to a container. To verify that the service is running, start the Tomcat container:
Once the container is started, verify that the service is running by accessing the grid service URL in a browser: http://localhost:8080/wsrf/services/cagrid/StockManager.
You should see the following:
Next, run the client to verify that the StockManager is able to create identifers:
You should see an output similar to the following:
Here you can see that the identifier is displayed for your use. A identifiers:completed StockManager service that uses identifiers has been provided if you would like to work with identifiers without going through this tutorial. To use the service, complete the prerequisites and deploy the service to a container.