简体   繁体   中英

How to Map a Excel file in a Database using Datamapper in Mule 3.4 ESB

Good morning to everyone,

I have a big issue with the Datamapper component in Mule ESB. I'm trying to map an Excel file (xlsx) in a table of an oracle database. To do that, I created a JDBC Connector with a Oracle DataSource and all of its stuff but when When I go to the DataMapper Wizard to create the mapping, I am not able to choose the Connector created because there are no item in the connectors list (in the Output datamapper wizard label).[Here below a screenshot of my problem]

DataMapper向导的屏幕截图

I really don't understand why, could you help me?

Moreover, I have a question to you: I need to insert in the database other fields in addition to that provided by the xls file, like MuleMessageID, xls file name and Oracle SYSDATE. Is it possibile?

To provide to you much information as possible, i'll post my mule project

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:ftp="http://www.mulesoft.org/schema/mule/ee/ftp" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <spring:beans>
        <spring:bean id="SettingProperty" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" scope="singleton">
            <spring:property name="locations">
                <spring:list>
                    <spring:value>classpath:pilot.properties</spring:value>
                </spring:list>
            </spring:property>
        </spring:bean>
    </spring:beans>

    <http:connector name="HTTPConnector" 
                    cookieSpec="netscape" 
                    doc:name="HTTP\HTTPS">
        <service-overrides messageFactory="it.aizoon.http.customHttpMultipart.MyHttpMultipartMuleMessageFactory"/>          
    </http:connector>

    <file:endpoint path="${file.output}" name="XSLXFile" responseTimeout="10000" doc:name="File"/>

    <jdbc-ee:oracle-data-source name="Oracle_Data_Source" user="${db.user}" password="${db.password}" url="${db.url}" doc:name="Oracle Data Source" transactionIsolation="UNSPECIFIED"/>
    <jdbc-ee:connector name="JdbcConnector" dataSource-ref="Oracle_Data_Source" validateConnections="true" queryTimeout="-1" doc:name="Database" pollingFrequency="0">
        <jdbc-ee:query key="storedProc" value="CALL ${db.storedProc}" />
    </jdbc-ee:connector>
    <data-mapper:config name="xls_to_db_grf" transformationGraphPath="xls_to_db.grf" doc:name="xls_to_db_grf"/>

    <!-- Starting Flow Declaration -->
    <flow name="zonal_imbalance_1.0Flow1" doc:name="zonal_imbalance_1.0Flow1">
        <http:inbound-endpoint 
            address="http://${conn.host}:${conn.port}/${conn.path}"
            connector-ref="HTTPConnector" doc:name="HTTP" exchange-pattern="request-response"/>
        <wildcard-filter pattern="*/${conn.path}*" caseSensitive="true" doc:name="Wildcard"/>
        <file:outbound-endpoint responseTimeout="10000" doc:name="Store XSLX File" path="C:\Users\paride.letizia\MuleStudio\workspace_ee\zonal_imbalance_1.0\src\test\resources\outputFolder"/>
        <data-mapper:transform doc:name="DataMapper"/>
        <jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryTimeout="-1"  doc:name="ORACLE Database" queryKey="example" connector-ref="JdbcConnector">
            <jdbc-ee:query key="example" value="SELECT * FROM prova;"/>
        </jdbc-ee:outbound-endpoint>
</flow>
</mule>

Thank you very very much to all of you, in advance. I look forward to hearing from you.

I don't know exactly why they decided to add JDBC "connectors", but they do not really behave as connectors. Connectors are meant to establish a connection with non-standard services with special API, so in order to establish a connection with an Oracle DB, just follow the standard way.

See the Anypoint documentation for more details, specifically the paragraph named "Endpoints and connectors":

Connectors function like endpoints by sending and receiving data over a transport. However, while endpoints are generic for a widely-used protocol (such as JDBC, FTP, HTTP, POP3, etc) each connector is built to optimize the connection with a specific third-party API, such as Salesforce or Twitter.

Endpoints serve your needs in most cases in which you are connecting to an external resource that has a standard format or protocol. For example, if you are connecting to an Oracle database or a MS SQL database, you can use the Database endpoint, because those databases output their data in a standard format; there is no need for an Oracle or MS SQL connector. Similarly, you don't need a connector for a particular kind of file, like a .csv file. The File endpoint can be configured to input and output data to any kind of text file format, including .csv, so there is no need for a csv connector.

Related: Difference between Mule Connectors and Transports

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM