Integration
Publishing a Web Service
By default the MECEAP does not generate the Web Service of DataObject
or DocumentType
, but if you need to generate, this option can be change in your specific entity.
Data Object (Table)
This change can be made in the XMLs or on the Web.
Web
This feature can be enabled in the Data Object edit page
XML
This feature can be enabled using changelog
Creating a new entity
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<changeLog xmlns="http://meceap.me.com.br/schema/changeLog-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://meceap.me.com.br/schema/changeLog-mapping http://docs.misy.me/xsd/changeLog-mapping.xsd">
<changeSet author="nelson" description="create DO" id="01-01-0001">
<addDataObject baseName="doNotUse" description="For testing purposes only" name="doNotUse" pluralBaseName="doNotUse" webService="true">
...
</addDataObject>
</changeSet>
</changeLog>
Changing an existent entity
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<changeLog xmlns="http://meceap.me.com.br/schema/changeLog-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://meceap.me.com.br/schema/changeLog-mapping http://docs.misy.me/xsd/changeLog-mapping.xsd">
<changeSet author="nelson" description="create DO" id="01-01-0001">
<changeDataObject baseName="doNotUse" webService="true" />
</changeSet>
</changeLog>
Document Type (Document)
This change can be made in the XMLs or on the Web.
Web
This feature can be enabled in the Document Type edit page
XML
This feature can be enabled using changelog
Creating a new document
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<changeLog xmlns="http://meceap.me.com.br/schema/changeLog-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://meceap.me.com.br/schema/changeLog-mapping http://docs.misy.me/xsd/changeLog-mapping.xsd">
<changeSet author="nelson" description="create doc" id="01-01-0001">
<addDocumentType description="DocTestDoNotUse" displayName="DocTestDoNotUse" name="DocTestDoNotUse"
pluralName="DocTestDoNotUse" sequenceStrategy="">
<properties>
<item key="WEBSERVICE" value="true"/>
</properties>
</addDocumentType>
</changeSet>
</changeLog>
Changing an existent document
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<changeLog xmlns="http://meceap.me.com.br/schema/changeLog-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://meceap.me.com.br/schema/changeLog-mapping http://docs.misy.me/xsd/changeLog-mapping.xsd">
<changeSet author="nelson" description="change doc" id="01-01-0002">
<changeDocumentType description="DocTestDoNotUse" displayName="DocTestDoNotUse" name="DocTestDoNotUse"
pluralName="DocTestDoNotUse" sequenceStrategy="">
<properties>
<item key="WEBSERVICE" value="true"/>
</properties>
</changeDocumentType>
</changeSet>
</changeLog>
Publishing a Integration Service
The platform implements two differents types of integration, SOAP and REST.
Basically you need to expose an interface to each of then.
In our example we will expose a service of contacts.
SOAP
Your SOAP interface needs to extend the CustomWebService
interface.
@Integration(name = "ContactSOAPService", namespace = "http://service.message.misy101.me.com.br/")
@WebService(targetNamespace = "http://service.message.misy101.me.com.br/")
public interface ContactSOAPService extends CustomWebService {
// -------------------------- OTHER METHODS --------------------------
List<Contact> getAll();
}
REST
Your REST interface needs to extend the CustomRESTService
interface.
@Integration(name = "ContactRESTService", namespace = "http://service.message.misy101.me.com.br/")
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface ContactRESTService extends CustomRESTService {
// -------------------------- OTHER METHODS --------------------------
@GET
@Path("/all")
List<Contact> getAll();
}
POJO
You had better to use small pojos containing just the fields that will be used.
@XmlRootElement(name = "Contact", namespace = "http://message.misy101.me.com.br/")
@XmlType(name = "Contact", namespace = "http://message.misy101.me.com.br/")
public class Contact {
// ------------------------------ FIELDS ------------------------------
private String name;
// -------------------------- STATIC METHODS --------------------------
public static List<Contact> mapFrom(List<br.com.me.appbuilder.Contact> models) {
List<Contact> contacts = new ArrayList<>();
for (br.com.me.misy101.Contact model : models) {
Contact contact = new Contact();
contact.setName(model.getName());
contacts.add(contact);
}
return contacts;
}
// --------------------- GETTER / SETTER METHODS ---------------------
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Implementation
After that we must to create an implementation.
@Service
public class ContactServiceIntegration implements ContactRESTService, ContactSOAPService {
// ------------------------------ FIELDS ------------------------------
@Inject
private ContactManager contactManager;
// ------------------------ INTERFACE METHODS ------------------------
// --------------------- Interface ContactSOAPService ---------------------
@Override
public List<Contact> getAll() {
return Contact.mapFrom(contactManager.getAll());
}
}
Test
Finally you can test your services .
You can access the admin menu to list all services availables including yours.
Remember to use basic authentication.
REST | |
---|---|
Endpoint address | http://localhost:8080/api/misy101/custom/ContactRESTService |
WADL | http://localhost:8080/api/misy101/custom/ContactRESTService?_wadl |
SOAP | |
---|---|
Endpoint address | http://localhost:8080/api/ws/misy101/custom/ContactSOAPService |
WSDL | http{http://service.message.misy101.me.com.br/}ContactSOAPServiceService |
Target namespace | http://service.message.misy101.me.com.br |
Consuming a SOAP Service
WSDL File
First you need put your WSDL in the mapping files.
Path src/main/mapping/integration
Example:
src/main/mapping/integration/ContactSOAPService.wsdl.xml
<?xml version='1.0' encoding='UTF-8'?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://service.message.misy101.me.com.br/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
name="ContactSOAPServiceService" targetNamespace="http://service.message.misy101.me.com.br/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.message.misy101.me.com.br/"
xmlns:ns1="http://message.misy101.me.com.br/" elementFormDefault="unqualified"
targetNamespace="http://service.message.misy101.me.com.br/" version="1.0">
<xs:import namespace="http://message.misy101.me.com.br/"/>
<xs:element name="getAll" type="tns:getAll"/>
<xs:element name="getAllResponse" type="tns:getAllResponse"/>
<xs:complexType name="getAll">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="getAllResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" type="ns1:Contact"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://message.misy101.me.com.br/"
targetNamespace="http://message.misy101.me.com.br/" version="1.0">
<xs:element name="Contact" type="tns:Contact"/>
<xs:complexType name="Contact">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getAllResponse">
<wsdl:part element="tns:getAllResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getAll">
<wsdl:part element="tns:getAll" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ContactSOAPService">
<wsdl:operation name="getAll">
<wsdl:input message="tns:getAll" name="getAll">
</wsdl:input>
<wsdl:output message="tns:getAllResponse" name="getAllResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ContactSOAPServiceServiceSoapBinding" type="tns:ContactSOAPService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getAll">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getAll">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getAllResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ContactSOAPServiceService">
<wsdl:port binding="tns:ContactSOAPServiceServiceSoapBinding" name="ContactSOAPServicePort">
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Now you need to run the maven goals ceap:upload-mapping
and ceap:download-jar
.
After this you will have a data contract.
As you can see in the admin page, here you can configure the integration parameters, like url, credentials and etc.
Invoking the soap API
To consume the api you just need to inject the generated service.
Example:
import br.com.me.misy101.message.Contact;
import br.com.me.misy101.message.service.ContactSOAPService;
public class ContactIntegrationService {
// ------------------------------ FIELDS ------------------------------
@Inject
private ContactSOAPService contactSOAPService;
// -------------------------- OTHER METHODS --------------------------
public List<Contact> getAll() {
return contactSOAPService.getAll();
}
}
Consuming a REST Service
As well as the WSDL, basically you will follow the same steps.
WADL File
Put your WADL file in the mapping files.
Path src/main/mapping/integration
Example:
src/main/mapping/integration/ContactRESTService.wadl.xml
<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"><grammars><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://message.misy101.me.com.br/" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://message.misy101.me.com.br/">
<xs:element name="Contact" type="tns:Contact"/>
<xs:complexType name="Contact">
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Contacts">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:Contact"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</grammars><resources base="http://localhost:8080/api/misy101/custom/ContactRESTService"><resource path="/" id="{http://service.message.misy101.me.com.br/}ContactRESTService"><method name="GET" id="getAll"><response><representation mediaType="application/json" element="prefix1:Contacts"/></response></method></resource></resources></application>
Invoking the rest API
To consume the api you just need to inject the generated service.
Example:
import br.com.me.misy101.message.Contact;
import br.com.me.misy101.message.service.ContactRESTService;
public class ContactIntegrationService {
// ------------------------------ FIELDS ------------------------------
@Inject
private ContactRESTService contactRESTService;
// -------------------------- OTHER METHODS --------------------------
public List<Contact> getAll() {
return contactRESTService.getAll();
}
}