Saya tidak dapat melihat output dari kode Java di bawah ini di log WSO2.

    package com.esb.integration.mediators;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMText;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class DbLookup extends AbstractMediator {

    private String url;
    private String userName;
    private String password;
    private String database;
    private String status;
    private String action;
    private String DSP;
    private String USER;
    private String PID;
    private String PMJ;
    private String PMT;
    private String NZPO;
    private String PD;
    private String SD;
    public  boolean mediate(MessageContext context) {

        String url = (String) context.getProperty("url");
        String userName = (String) context.getProperty("userName");
        String password = (String) context.getProperty("password");
        String database = (String) context.getProperty("database");
        String status = (String) context.getProperty("status");
        String action = (String) context.getProperty("action");

        try {
            System.out.println("Inside DB Extractor");
            System.out.println("Action: "+action);
            Class.forName("com.access.JDBCDriver");

            Connection conn = DriverManager.getConnection(url,userName,password);
            Statement stmt = conn.createStatement();
            System.out.println("After getting connection");

             if (action.equals("updateData")){
                System.out.println("Inside  if: "+action);
                int result =0;
                DSP = (String) context.getProperty("DSP");
                USER = (String) context.getProperty("USER");
                PID = (String) context.getProperty("PID");
                PMJ = (String) context.getProperty("PMJ");
                PMT = (String) context.getProperty("PMT");
                NZPO = (String) context.getProperty("NZPO");
                PD = (String) context.getProperty("PD");
                SD = (String) context.getProperty("SD");

                String updateQuery = "Update Table Set DSP = '"+DSP+"',USER = '"+USER+"',PID = '"+PID+"',PMJ="+PMJ+",PMT="+PMT+" Where DSP<>'Y' AND NZPO='"+NZPO+"' AND PD='"+PD+"' AND SD="+SD;
                System.out.println("Query String: "+updateQuery);
                result = stmt.executeUpdate(updateQuery);
                if(result>0){
                    String response = "successfully updated "+result+" rows";
                    System.out.println("successfully added "+result);
                    context.setProperty("status",response);
                    return true;
                }

                else{
                    System.out.println("failed");
                    context.setProperty("status","0 rows were updated");
                    return true;
                }

            }
            else {
                context.setProperty("status","Failed");
                return false;
            }
        }catch (Exception e) {
            System.out.println("Got an exception! ");
            System.out.println(e.getMessage());
            context.setProperty("status","Failed");
            return false;
        }
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }
    public String getstatus() {
        return status;
    }

    public void setstatus(String status) {
        this.status = status;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }


    public String getDSP() {
        return DSP;
    }
    public void setDSP(String DSP) {
        DSP = DSP;
    }
    public String getUSER() {
        return USER;
    }
    public void setUSER(String USER) {
        USER = USER;
    }
    public String getPID() {
        return PID;
    }
    public void setPID(String PID) {
        PID = PID;
    }
    public String getPMJ() {
        return PMJ;
    }
    public void setPMJ(String PMJ) {
        PMJ = PMJ;
    }
    public String getPMT() {
        return PMT;
    }
    public void setPMT(String PMT) {
        PMT = PMT;
    }
    public String getNZPO() {
        return NZPO;
    }
    public void setNZPO(String NZPO) {
        NZPO = NZPO;
    }
    public String getPD() {
        return PD;
    }
    public void setPD(String PD) {
        PD = PD;
    }
    public String getSD() {
        return SD;
    }
    public void setSD(String SD) {
        SD = SD;
    }
}

Berikut adalah layanan proxy: -

<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="jms" statistics="disable" trace="disable" startOnLoad="true">
       <inSequence>
       <property name="userName" value="****"></property>
         <property name="password" value="****"></property>
         <property name="url" value="********"></property>         
         <property name="action" value="updateData"></property>
         <iterate id="Item" expression="//itemList/item" sequential="true">
            <target>
                 <sequence>
                                 <property name="DSP" expression="//DSP/text()"></property>
                                 <property name="USER" expression="//USER/text()"></property>
                                 <property name="PID" expression="//PID/text()"></property>
                                 <property name="PMJ" expression="//PMJ/text()"></property>
                                 <property name="PMT" expression="//PMT/text()"></property>
                                 <property name="NZPO" expression="//NZPO/text()"></property>
                                 <property name="PD" expression="//PD/text()"></property>
                                 <property name="SD" expression="//SD/text()"></property>
                                 <class name="com.esb.integration.mediators.DbLookup"></class>
                                 <log separator=",**after updatedb call**" description=""></log>

                 </sequence>
                 </target>
                 </iterator>         
         </inSequence>
         <loopback/>
          <outSequence/>
        <parameter name="transport.jms.ContentType">application/json</parameter>
    <parameter name="transport.jms.Destination">TestProxy.Q</parameter>
</proxy>

Namun, saya hanya dapat melihat pesan "setelah panggilan diperbarui" di log ketika kueri berhasil dijalankan.

Apa yang harus saya tambahkan/ubah di atas untuk mendapatkan pesan (yang ditulis sebagai System.out.println(" ")) di log WSO2?

0
Vivek Shah 12 Maret 2017, 10:57

2 jawaban

Jawaban Terbaik

Di [ESB_HOME]\repository\conf\log4j.properties masukkan ini:

log4j.logger.package=INFO, CARBON_LOGFILE, CARBON_MEMORY

Di mana package = paket kelas Anda, dalam kasus saya:

log4j.logger.org.softdevelop.test=INFO, CARBON_LOGFILE, CARBON_MEMORY

Mulai ulang server dan coba dengan:

if (log.isInfoEnabled()) {
            log.info("First Element log : " + firstElement.getLocalName());
        }       

System.out.println("First Element Text syso : " + firstElement.getText());

Dalam kasus saya, log cetak:

[2017-03-13 12:16:30,010]  INFO - testIterateProperty First Element log : jsonObject

First Element Text syso :
3
Jorge Infante Osorio 13 Maret 2017, 16:31
log.info("whatever you want");
0
Bee 12 Maret 2017, 08:23