Using POJOs in Python Scripts
This procedure uses an example of the Person class as the Java object that is used as a TeaParam to TeaOperation and return type of the TeaOperation. POJOs can be used just as you use regular Python objects.
Procedure
-
Install the
jsonpickle module. This module should be installed separately using
pip. Refer the Python documentation for more details. You need the
jsonpickle module to serialize and deserialize java objects. Based on the version of Python you are using, you can install the module using the following command:
Python Version Command 2 pip install jsonpickle 3 pip3 install jsonpickle -
Define a POJO. The following example defines a Person class:
package com.tibco.tea.agent; import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonPropertyOrder({ "name", "i" }) public class Person { private String name; private int i; public void setName(String name) { this.name = name; } public void setI(int i) { this.i = i; } public String getName() { return this.name; } public int getI() { return this.i; } }
-
Define a TeaOperation that takes a POJO as TeaParam and returns a POJO.
@TeaOperation(name = "hw", description = "Send greetings") public Person helloworld( @TeaParam(name = "greetings", description = "Greetings parameter") final Person greetings) throws IOException { return greetings; }
-
Invoke the TeaOperation as follows:
# Import the tibco.tea module and make the connection to the TEA Server >>> import tibco.tea >>> tea = tibco.tea.EnterpriseAdministrator() # First get hold of the product or member of the TeaOperation you want to invoke >>> prod = tea._unsupported_products['HelloWorldTopLevelType'] # Module of POJOs is available on that product or member in variable "module_" >>> mod = prod.module_ # Now instantiate the POJO class in python as follows >>> person = mod.Person("John Doe", 1) # Invoke the TeaOperation with the python object in the earlier line as TeaParam and consume the POJO response as a Python Object >>> response = prod.hw(person) # Use the response as you use the normal python object >>> response.name 'John Doe' >>> response.i 1
Related concepts
Copyright © Cloud Software Group, Inc. All Rights Reserved.