Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询页面(crmod中的web服务)从excel读取java代码!!未找到跳过值_Java_Excel_Web Services_Search_Crm - Fatal编程技术网

查询页面(crmod中的web服务)从excel读取java代码!!未找到跳过值

查询页面(crmod中的web服务)从excel读取java代码!!未找到跳过值,java,excel,web-services,search,crm,Java,Excel,Web Services,Search,Crm,我已经用java编写了crm随需应变web服务的代码。代码从excel中读取第一列(id),并在crm中查询它,并相应地插入值。如果找到“id”,它将插入其他值,但当在crm中找不到“id”时,代码将以错误消息终止。我希望代码查询一条记录,如果找到,则插入其他值,但如果未找到该记录,则应跳过该记录并查询下一个id,而不会在两者之间终止 请帮忙 以及如何跳过没有值(null)的单元格?导入crmondemand.ws.account.AccountWS\u AccountInsertChild\u

我已经用java编写了crm随需应变web服务的代码。代码从excel中读取第一列(id),并在crm中查询它,并相应地插入值。如果找到“id”,它将插入其他值,但当在crm中找不到“id”时,代码将以错误消息终止。我希望代码查询一条记录,如果找到,则插入其他值,但如果未找到该记录,则应跳过该记录并查询下一个id,而不会在两者之间终止

请帮忙

以及如何跳过没有值(null)的单元格?

导入crmondemand.ws.account.AccountWS\u AccountInsertChild\u输入;
导入crmondemand.ws.account.AccountWS\u AccountInsertChild\u输出;
导入crmondemand.ws.account.AccountWS\u AccountUpdate\u输入;
导入crmondemand.ws.account.AccountWS\u AccountUpdate\u输出;
导入crmondemand.ws.account.Default\u BindingStub;
导入crmondemand.xml.account.account;
导入crmondemand.xml.account.RelatedAccount;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.math.BigDecimal;
导入java.math.biginger;
导入java.net.HttpURLConnection;
导入java.net.InetSocketAddress;
导入java.net.MalformedURLException;
导入java.net.Proxy;
导入java.net.URL;
导入java.rmi.RemoteException;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Calendar;
导入java.util.Date;
导入java.util.Iterator;
导入java.util.List;
导入java.util.Properties;
导入java.util.StringTokenizer;
导入java.util.TimeZone;
导入javax.xml.rpc.ServiceException;
进口jxl.Cell;
导入jxl.CellType;
进口jxl.Sheet;
导入jxl.工作簿;
导入jxl.read.biff.BiffException;
导入org.apache.axis.AxisProperties;
导入org.apache.log4j.Logger;
导入org.apache.poi.hssf.usermodel.HSSFCell;
导入org.apache.poi.hssf.usermodel.HSSFDateUtil;
导入org.apache.poi.hssf.usermodel.HSSFRow;
导入org.apache.poi.hssf.usermodel.HSSFSheet;
导入org.apache.poi.hssf.usermodel.HSSFWorkbook;
导入org.apache.poi.poifs.filesystem.poifsfsystem;
公共类认证{
私有字符串输入文件;
公共静态整数长度;
公共void setInputFile(字符串inputFile){
this.inputFile=inputFile;
}
静态记录器=Logger.getLogger(accrel1.class);
公共静态URL重新身份验证(属性)引发畸形的URL异常{
//System.setProperty(“https.proxyHost”、“172.17.24.24”);
//System.setProperty(“https.proxyPort”、“8003”);
//System.setProperty(“https.proxyHost”、“145.247.13.164”);
//System.setProperty(“https.proxyPort”、“3128”);
//System.setProperty(“javax.net.ssl.trustStore”,“C:\\ProgramFiles\\Java\\jdk1.6.0\u 31\\jre\\lib\\cacerts”);
System.out.println(“登录”);
字符串JSSessionID_已满=
登录(“https://secure-ausomxapa.crmondemand.com/Services/Integration",
"物业","物业",;
System.out.println(“连接到CRM…”+jsessionid_full);
字符串jssessionid=getSessionId(jssessionid_full);
System.out.println(“JSSessionID:+JSSessionID”);
字符串端点=
"https://secure-ausomxapa.crmondemand.com/Services/Integration" +
“jsessionid=“+jsessionid;
URL urlAddr=新的java.net.URL(端点);
System.out.println(“建立连接…”);
返回urlAddr;
}
公共静态无效urlqueryWS1(URL urlAddr,列表cellDataList,
属性)引发RemoteException,
服务例外,
畸形感觉{
AxisProperties.setProperty(“https.proxyHost”,
getProperty(“proxyhost”);
AxisProperties.setProperty(“https.proxyPort”,
getProperty(“proxyport”);
//setProperty(“http.nonProxyHosts”、“secure ausomxapa.crmondemand.com”);
crmondemand.ws.account.AccountWS\u AccountQueryPage\u输入帐户列表=
新建crmondemand.ws.account.AccountWS_AccountQueryPage_Input();
crmondemand.ws.account.AccountWS\u AccountQueryPage\u输出大纲视图=
新建crmondemand.ws.account.AccountWS_AccountQueryPage_Output();
crmondemand.xml.account.account[]accounts=
新的crmondemand.xml.account.account[1];
crmondemand.xml.account.account=
新的crmondemand.xml.account.account();
字符串stringCellValue[]=新字符串[6000];
int k=0;
int flag=0,notflag=0,noparentflag=0;
System.out.println(“CellDatasize:+cellDataList.size());
对于(int i=1;iimport crmondemand.ws.account.AccountWS_AccountInsertChild_Input;
import crmondemand.ws.account.AccountWS_AccountInsertChild_Output;
import crmondemand.ws.account.AccountWS_AccountUpdate_Input;
import crmondemand.ws.account.AccountWS_AccountUpdate_Output;
import crmondemand.ws.account.Default_BindingStub;
import crmondemand.xml.account.Account;
import crmondemand.xml.account.RelatedAccount;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import java.math.BigDecimal;
import java.math.BigInteger;

import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;

import java.rmi.RemoteException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

import java.util.TimeZone;

import javax.xml.rpc.ServiceException;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;

import jxl.read.biff.BiffException;

import org.apache.axis.AxisProperties;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class accrel1 {

private String inputFile;
public static int length;

public void setInputFile(String inputFile) {
    this.inputFile = inputFile;
}
static Logger logger = Logger.getLogger(accrel1.class);


public static URL reauthentication(Properties properties) throws MalformedURLException     {

    // System.setProperty("https.proxyHost", "172.17.24.24");
    // System.setProperty("https.proxyPort", "8003");
    //System.setProperty("https.proxyHost", "145.247.13.164");
    // System.setProperty("https.proxyPort", "3128");

    // System.setProperty("javax.net.ssl.trustStore","C:\\ProgramFiles\\Java\\jdk1.6.0_31\\jre\\lib\\cacerts");
    System.out.println("Loggin In");
    String jsessionid_full =
        logon("https://secure-ausomxapa.crmondemand.com/Services/Integration",
              "################", "##########", properties);
    System.out.println("Connecting to CRM..." + jsessionid_full);
    String jsessionid = getSessionId(jsessionid_full);
    System.out.println("JSessionid: " + jsessionid);
    String endpoint =
        "https://secure-ausomxapa.crmondemand.com/Services/Integration" +
        ";jsessionid=" + jsessionid;
    URL urlAddr = new java.net.URL(endpoint);
    System.out.println("Establishing Connection...");
    return urlAddr;


}

public static void urlqueryWS1(URL urlAddr, List cellDataList,
                               Properties properties) throws RemoteException,
                                                             ServiceException,
                                                             MalformedURLException {



    AxisProperties.setProperty("https.proxyHost",
                               properties.getProperty("proxyhost"));
    AxisProperties.setProperty("https.proxyPort",
                               properties.getProperty("proxyport"));
    // AxisProperties.setProperty("http.nonProxyHosts", "secure-ausomxapa.crmondemand.com");

    crmondemand.ws.account.AccountWS_AccountQueryPage_Input accountlist =
        new crmondemand.ws.account.AccountWS_AccountQueryPage_Input();
    crmondemand.ws.account.AccountWS_AccountQueryPage_Output outlist =
        new crmondemand.ws.account.AccountWS_AccountQueryPage_Output();
    crmondemand.xml.account.Account[] accounts =
        new crmondemand.xml.account.Account[1];
    crmondemand.xml.account.Account account =
        new crmondemand.xml.account.Account();

    String stringCellValue[] = new String[6000];
    int k = 0;
    int flag = 0, notflag = 0, noparentflag = 0;
    System.out.println("CellDatasize:" + cellDataList.size());
    for (int i = 1; i < cellDataList.size(); i++) {

        crmondemand.ws.account.Account service =
            new crmondemand.ws.account.AccountLocator();
        Default_BindingStub stub =
            (Default_BindingStub)service.getDefault(urlAddr);

        List cellTempList = (List)cellDataList.get(i);
        for (int j = 0; j < cellTempList.size(); j++) {
            HSSFCell hssfCell = (HSSFCell)cellTempList.get(j);
            //System.out.println("Cell Type:" + i + "," + j + "  " +  hssfCell.getCellType());
            if (hssfCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                stringCellValue[j] = hssfCell.getStringCellValue();
                // logger.info(i + "," + j + "\t" + stringCellValue[j] + "\t");
            } else if (hssfCell.getCellType() ==
                       HSSFCell.CELL_TYPE_NUMERIC) {
                if (HSSFDateUtil.isCellDateFormatted(hssfCell)) {
                    System.out.println(hssfCell.getDateCellValue());
                    Date date = new Date();
                    date = hssfCell.getDateCellValue();
                    SimpleDateFormat df =
                        new SimpleDateFormat("MM/dd/yyyy");
                    stringCellValue[j] = df.format(date);

                } else {

                    stringCellValue[j] = new BigDecimal(hssfCell.getNumericCellValue()).toPlainString(); 
                    //logger.info("Number"+i+","+j+ "\t"+stringCellValue[j] + "\t");
                }


            }
        }


        AccountWS_AccountInsertChild_Input child =
            new AccountWS_AccountInsertChild_Input();
        AccountWS_AccountInsertChild_Output childs =
            new AccountWS_AccountInsertChild_Output();


        crmondemand.xml.account.Account[] accrels =
            new crmondemand.xml.account.Account[1];
        crmondemand.xml.account.Account accrel =
            new crmondemand.xml.account.Account();


        RelatedAccount[] relaccounts = new RelatedAccount[1];
        RelatedAccount relaccount = new RelatedAccount();
        logger.info("Inserting " + i + "Record: "+stringCellValue[0]);

        relaccount.setRelationshipRole(stringCellValue[1]);
        relaccount.setRelatedAccountId(stringCellValue[2]);
        relaccount.setStartDate(stringCellValue[6]);
        relaccount.setEndDate(stringCellValue[7]);
        relaccount.setReverseRelationshipRole(stringCellValue[3]);
        relaccount.setComments(stringCellValue[4]);
        relaccount.setRelationshipStatus(stringCellValue[5]);


        relaccounts[0] = relaccount;

        accrel.setAccountId(stringCellValue[0]); //JDE Account ID
        accrel.setListOfRelatedAccount(relaccounts);

        accrels[0] = accrel;

        child.setListOfAccount(accrels);


        try {
            childs = stub.accountInsertChild(child);
            logger.info(i + "th Record Inserted");
            ++flag;
        } catch (Exception e) {
            logger.info("Network Error: Re-Authenticating" + e);


            urlAddr = reauthentication(properties);

            stub = (Default_BindingStub)service.getDefault(urlAddr);
            childs = stub.accountInsertChild(child);
            logger.info(i + "th Record Inserted in 2nd Attempt");
            ++flag;
        }
//logger.info("Total No. Of Records Processed"+flag);


    }
    logger.info("Total No. Of Records Processed"+flag);
}

private void readExcelFile(URL urlAddr, String fileName,
                           Properties properties) throws ServiceException,
                                                         RemoteException,
                                                         MalformedURLException {
    System.out.println("Reading Excel File");
    /**
* Create a new instance for cellDataList
*/
    List cellDataList = new ArrayList();
    try {
        /**
* Create a new instance for FileInputStream class
*/
        FileInputStream fileInputStream = new FileInputStream(fileName);

        /**
* Create a new instance for POIFSFileSystem class
*/
        POIFSFileSystem fsFileSystem =
            new POIFSFileSystem(fileInputStream);

        /*
* Create a new instance for HSSFWorkBook Class
*/
        HSSFWorkbook workBook = new HSSFWorkbook(fsFileSystem);
        HSSFSheet hssfSheet = workBook.getSheetAt(0);

        /**
* Iterate the rows and cells of the spreadsheet
* to get all the datas.
*/
        Iterator rowIterator = hssfSheet.rowIterator();

        while (rowIterator.hasNext()) {
            HSSFRow hssfRow = (HSSFRow)rowIterator.next();
            Iterator iterator = hssfRow.cellIterator();
            List cellTempList = new ArrayList();

            while (iterator.hasNext()) {
                HSSFCell hssfCell = (HSSFCell)iterator.next();
                cellTempList.add(hssfCell);

            }
            cellDataList.add(cellTempList);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    /**
* Call the printToConsole method to print the cell data in the
* console.
*/
    urlqueryWS1(urlAddr, cellDataList, properties);

}



private static String logon(String wsLocation, String userName,
                            String password, Properties properties) {
    String sessionString = "FAIL";
    int port =
        Integer.parseInt(properties.getProperty("proxyport")); //Converting String Port Number to Integer.
    try {
        Proxy proxy =
            new Proxy(Proxy.Type.HTTP, new InetSocketAddress(properties.getProperty("proxyhost"),
                                                             port));
        // create an HTTPS connection to the On Demand webservices
        URL wsURL = new URL(wsLocation + "?command=login");
        HttpURLConnection wsConnection =
            (HttpURLConnection)wsURL.openConnection(proxy);
        // we don't want any caching to occur
        wsConnection.setUseCaches(false);
        // we want to send data to the server
        // wsConnection.setDoOutput(true);
        // set some http headers to indicate the username and passwod we are using to logon
        wsConnection.setRequestProperty("UserName", userName);
        wsConnection.setRequestProperty("Password", password);
        wsConnection.setRequestMethod("GET");
        // see if we got a successful response
        if (wsConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
            // get the session id from the cookie setting
            sessionString = getCookieFromHeaders(wsConnection);
        }
    } catch (Exception e) {
        System.out.println("Logon Exception generated :: " + e);
    }
    return sessionString;
}

private static String getCookieFromHeaders(HttpURLConnection wsConnection) {
    // debug code - display all the returned headers
    String headerName;
    String headerValue = "FAIL";
    for (int i = 0; ; i++) {
        headerName = wsConnection.getHeaderFieldKey(i);
        if (headerName != null && headerName.equals("Set-Cookie")) {
            // found the Set-Cookie header (code assumes only one cookie is being set)
            headerValue = wsConnection.getHeaderField(i);
            break;
        }
    }
    // return the header value (FAIL string for not found)
    return headerValue;
}

private static String getSessionId(String cookie) {
    StringTokenizer st = new StringTokenizer(cookie, ";");
    String jsessionid = st.nextToken();
    st = new StringTokenizer(jsessionid, "=");
    st.nextToken();

    return st.nextToken();
}


public static void main(String[] args) throws IOException,
                                              ServiceException {

    String jsessionid, jsessionid_full;
    String endpoint;


    AxisProperties.setProperty("https.proxyHost", "172.25.9.240");
    AxisProperties.setProperty("https.proxyPort", "2006");

    System.setProperty("https.proxyHost", "172.25.9.240");
    System.setProperty("https.proxyPort", "2006");

    // System.setProperty("https.proxyHost", "145.247.13.164");
    // System.setProperty("https.proxyPort", "3128");
    Properties properties = new Properties();
    properties.load(new FileInputStream("C:\\Users\\10608011\\Documents\\Account_Config.properties")); //Windows Path

        System.setProperty("javax.net.ssl.trustStore","C:\\Oracle\\Middleware3\\jdk160_24\\jre\\lib\\security\\cacerts");
    System.out.println("Logging In");
    jsessionid_full =
            logon("https://secure-ausomxapa.crmondemand.com/Services/Integration",
                  "############", "###########", properties);
    System.out.println("Establishing " + jsessionid_full);
    jsessionid = getSessionId(jsessionid_full);
    System.out.println("Jsessionid: " + jsessionid);
    endpoint =
            "https://secure-ausomxapa.crmondemand.com/Services/Integration" +
            ";jsessionid=" + jsessionid;
    URL urlAddr = new java.net.URL(endpoint);


    String fileName =
        "D:" + File.separator + "Test2.xls"; // Windows Path
    // String fileName =File.separator + "u01"+File.separator +"CRM_DEV"+File.separator +
    //                "sofwaredepot"+File.separator +"PALS_200_11Feb2013.xls";               //Linux Path /u01/CRM_DEV/softwaredepot

    // String fileName="PALS_200_11Feb2013.xls";
    final long start = System.currentTimeMillis();
    logger.info("Start Time:" + start);
    new accrel1().readExcelFile(urlAddr, fileName, properties);
    final long durationInMilliseconds = System.currentTimeMillis() - start;
    System.out.println("Time(Min) for Data Upload: " +
                       durationInMilliseconds / 60000 + "mins.");
    logger.info("Duration for Data Upload: " +
                durationInMilliseconds / 60000 + "mins.");


}
}