Invoking a JSON service over HTTP from OSB is quite straightforward. Using the Java code that we built in the previous recipe will make working with the JSON messages much simpler.
We'll assume that you have an OSB configuration project in OEPE, and that you have the Jackson and XmlBeans JAR files referred to in the previous recipe, as well as the JAR files produced by that recipe.
InvokeJSONCreditCardService
) and click on Finish.We need to import the web service definition used in the Java project in the previous recipe, as we will implement the DebitCreditCard
operation of the CreditCardService
.
i. Browse to the file directory containing the code samples for this chapter, and within the directory getting ready
, select the folder resources
.
jars
for the folder in the New Folder dialog and click on Finish.jars
folder:dist/CreditCardServiceMessages_1.0.jar
dist/CreditCardServiceMessagesXmlBeans_1.0.jar
lib/jackson-core-asl-1.9.7.jar
lib/jackson-mapper-asl-1.9.7.jar
We now need to inform OSB of the dependencies between the JAR files.
Do the same for the CreditCardServiceMessages_1.0.jar file, but click on the Add All >> button to indicate that it depends on all of the other JAR files in the projecThere will be warnings about classes from the org.joda.time
package not being available. This is an optional dependency in the Jackson Mapper, and will not be a problem.
CreditCardJSON_1.0
) and click on Finish.We'll accept the default values on the HTTP Transport and Message Handling tabs.
CreditCardService_1.0
) and click on Finish.i. On the General tab of the proxy service definition, click the Browse button to select the binding for the service's interface. Select the CreditCardBinding in the CreditCardService.wsdl, and click OK.
ii. On the Transport tab, set the Endpoint URI for the service to /ckbk/svc/CreditCard, as specified in the WSDL.
Give the Operational Branch a name (for example, CreditCardServiceOperation
) and ensure that the debitCreditCard operation is selected.
debitCreditCardRequestStage
). Drag a Java Callout activity (under Message Processing) into the stage, and click on the Browse button in the Properties pane to select the Java method to be invoked.In the Select an Archive Resource dialog, select the CreditCardServicesMessages_1.0.jar file, and click on OK.
$body
. Set the Result Value to requestJSON
; this is the variable to which the results of the Java method will be assigned.i. In the Properties pane for the Service Callout activity, click the Browse button, this will open the Select a Service Resource dialog, select CreditCardJSON_1.0.biz
and click OK.
ii. Enter requestJSON
in the Request Variable field of the Properties pane, and responseJSON
in the ResponseVariable field, as shown in the following screenshot:
i. In the Transport Headers pane of the Transport Header activity, click on the Add Header button to add a new header to the Outbound Request.
ii. Set the HTTP header Content-Type to have the value "application/json"
; this is the standard MIME type for JSON data.
debitCreditCardResponseStage
.i. Drag a Java Callout activity into the stage. Click on the Browse button in the Properties pane to select the Java method to be invoked. In the Select an Archive Resource dialog, select the CreditCardServicesMessages_1.0.jar file and click on OK.
ii. In the Select a Java Method dialog, select the debitCreditCardResponseJsonToXml method in the DebitCreditCardConverter class and click on OK.
iii. In the Properties for the Java Callout activity, set the Expression for the input parameter to $responseJSON
(the result of the previous Service Callout), and the Result Value to responseXML
.
iv. Add a Replace activity following the Java Callout, and set its properties, as shown in the following screenshot.
The Java Callout actions are used to convert between the XML and JSON message representations, using the code created in the previous recipe. The Service Callout makes the call through the Business Service to the JSON service, and uses a Transport Header activity to set the HTTP Content-Type
header to application/json
. The final Replace activity puts the XML response into the body
variable, so that OSB will return it to the caller.