2017年3月23日木曜日

[iDempiere 2.1] WebService Schema Update


 iDempiere 2.1 provide Web Service (WS) interfaces over SOAP and REST. The user can use the WS in order to create, update and view the Records in DB Table.

WebService Request XML is managed by XML Schema strictly. I needed to modify this XML Schema, and I researched how to generate Data-binding Java classes to parse Request XML depending on XML Schema.

○ Environment:

[iDempiere]
    Version: 2.1
 [Eclipse]
     Pleiades 4.5 Mars
  [OS]
     Windows 7 SP1

 iDempiere 2.1 uses xmlbeans-2.5.0 to parse Request XML. The Data-binding Java classes are stored in idempiere-xmlbeans-1.0.jar at @WORKSPACE@\org.idempiere.webservices\WEB-INF\lib. I had to re-create idempiere-xmlbeans-1.0.jar after updating XML schema in order to reflect schema change to iDempiere WebService actually. I could use xmlbeans Ant Task to create Data-binding Java classed from XML Schema.

○ Create a Project for idempiere-xmlbeans

    First of all, I created a new eclipse project for idempiere-xmlbeans like the below.


      1. build.xml - Ant build file to create Xmlbeans Data-binding Java classes. It is mentioned later.
      2. idempiere-schema.xsd - Request XML Schema. I found its original file at @WORKSPACE@\org.idempiere.webservices\WEB-INF\xsd and modified and copied it here.
      3. xmlbeans-2.5.0.jar - xmlbeans jar iDempiere 2.1 is using. I found it at @WORKSPACE@\org.idempiere.webservices\WEB-INF\lib and copied it here.

○ Execution of Ant Task to generate Xmlbeans Data-binding Java classes

   I wrote  in build.xml like the below.

<?xml version="1.0" encoding="UTF-8"?>
<project default="xmlbeans_build" name="build">
<taskdef name="xmlbean" classname="org.apache.xmlbeans.impl.tool.XMLBean" classpath="lib/xmlbeans-2.5.0.jar" />
 <target name="xmlbeans_build">
                <xmlbean schema="idempiere-schema.xsd" destfile="idempiere-xmlbeans-1.0.jar"/>
 </target>
</project>
    Then  I execute Ant build by eclipse Ant Runner. I add xmlbean-2.5.0.jar into classpath for Ant like the below.



   Ant showed console messages like the below. I was successful to create the new  idempiere-xmlbeans-1.0.jar file.

  Buildfile: @WORKSPACE@\idempiere-xmlbeans\build.xml
xmlbeans_build:
  [xmlbean] Time to build schema type system: 2.53 seconds
  [xmlbean] Time to generate code: 0.853 seconds
  [xmlbean] Compiling 90 source files to @
HOMEPATH@\AppData\Local\Temp\xbean1594992734447386704.d\classes
  [xmlbean] warning: [options] bootstrap class path not set in conjunction with -source 1.4
  [xmlbean] 1 warning
  [xmlbean] Time to compile code: 5.379 seconds
  [xmlbean] Building jar:
@WORKSPACE@\idempiere-xmlbeans\idempiere-xmlbeans-1.0.jar
BUILD SUCCESSFUL
Total time: 14 seconds

○ Reference:

1. https://xmlbeans.apache.org/





2017年3月10日金曜日

[iDedempiere 2.1] Web Service


 iDempiere 2.1 provide Web Service (WS) interfaces over SOAP and REST. The user can use the WS in order to create, update and view the Records in DB Table.

ModelADService - It can be used for view Records and  Simple Record edition.
CompositeInterface - It can be used for Multiple Record edition.

○ Environment:

[iDempiere]
    Version: 2.1
 [Eclipse]
     Pleiades 4.5 Mars
  [OS]
     Windows 7 SP1

○ Setting Web Service on iDempiere

 The WS is working on iDempiere if iDempiere is installed already. But, "Web Service Security" Record is need to be created to allow the user to access WS on iDempiere. Web Service Security is managed depending on Client as well as other Record in iDempiere. So, Client Admistrator must create Web Service Security Record with the Client in order to allow members in the Client to access WS.
 If you test WS by Garden Client, you don't have to prepare Web Service Security Record by yourself because these exist already. The examples following use
"CreateBPartner".

○SoapUI

 Adempire and iDempiere have test scripts to test WS in org.adempiere.webservice package. Soap UI is the application to test WS over SOAP and REST, which is introduced in Adempiere book in order to execute these test scripts in Adempiere.
 The latest version of Soap UI can be downloaded here. Test scripts in iDempiere are created by former version, but these can be executed by the latest version as well.

○Test WS over SOAP

 Test WS over SOAP can be done by test scripts. 

1. Import SOAP project from the script in iDempiere (%iDempiere_Home%\org.idempiere.webservices\testScripts\iDempiereWebServices-soapui-project.xml)

      


2. Edit SOAP XML.
 Open XML for createData

And edit the following fields under "_0:ADLoginRequest" to fit your environment if it is needed.
  1. _0:user
  2. _0:pass
  3. _0:ClientID
  4. _0:OrgID
  5. _0:WarehouseID
  6. _0:stage

2. Edit SOAP XML.
3.  Click Submit button to execute the test script.


○Test WS over REST

 iDempiere provides REST interfaces also. the REST provided by iDempiere recieves XML as request, not JSON. The request XML is as same as XML request in SOAP request.
 REST request also can be sent by Soap UI. But, there is no test scripts for REST in iDempiere now. The user need to create project and request record in Soap UI by themselves to execute WS over REST test.

1. Create REST project on Soap UI.
   URL: http://localhost:8080/ADInterface/services/rest/model_adservice/create_data




2.  Create new POST method under new REST project.

3.  Create new Request under POST method.


Set Media Type: application/xml
Set XML following as POST data. edit tags under "_0:ADLoginRequest" tag to fit your environment if it is needed as SOAP test.

<_0:ModelCRUDRequest xmlns:_0="http://idempiere.org/ADInterface/1_0">
 <_0:ModelCRUD>
  <_0:serviceType>CreateBPartner</_0:serviceType>
  <_0:TableName>C_BPartner</_0:TableName>
  <!--<_0:RecordID>0</_0:RecordID>-->
  <!--<_0:Action>Create</_0:Action>-->
  <_0:DataRow>
   <_0:field column="Value">
    <_0:val>GlobalQSS</_0:val>
   </_0:field>
   <_0:field column="Name">
    <_0:val>Quality Systems &amp; Solutions</_0:val>
   </_0:field>
   <_0:field column="TaxID">
    <_0:val>830.085.359-4</_0:val>
   </_0:field>
   <_0:field column="IsVendor">
    <_0:val>Y</_0:val>
   </_0:field>
   <_0:field column="IsCustomer">
    <_0:val>N</_0:val>
   </_0:field>
   <_0:field column="IsTaxExempt">
    <_0:val>N</_0:val>
   </_0:field>
   <_0:field column="Name2">
    <_0:val>QSS Ltda. - http://www.globalqss.com</_0:val>
   </_0:field>
   <_0:field column="C_BP_Group_ID">
    <_0:val>104</_0:val>
   </_0:field>
  </_0:DataRow>
 </_0:ModelCRUD>
 <_0:ADLoginRequest>
  <_0:user>WebService</_0:user>
  <_0:pass>WebService</_0:pass>
  <_0:lang>en_US</_0:lang>
  <_0:ClientID>11</_0:ClientID>
  <_0:RoleID>50004</_0:RoleID>
  <_0:OrgID>11</_0:OrgID>
  <_0:WarehouseID>103</_0:WarehouseID>
  <_0:stage>9</_0:stage>
 </_0:ADLoginRequest>
</_0:ModelCRUDRequest>

4.  Click Submit button to execute the test script.



     Response XML is displayed in the right pane.
   

○ Reference:

1. http://ultra00.hatenablog.com/entry/2013/11/18/114542
2. https://groups.google.com/forum/#!topic/idempiere/82cXxgq_Qh4