我是Netsuite Web服务的新手。我需要做的只是通过我的Java应用程序对netsuite沙箱帐户进行身份验证并获取所有联系人。
    以下是我用于登录的wsdl文件的链接:
    https://webservices.netsuite.com/wsdl/v2012_1_0/netsuite.wsdl
    当我尝试登录上述wsdl时,出现以下错误:

  AxisFault
    faultCode: {http//schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
     faultString: You have entered an invalid email address or account number. Please try again.
     faultActor:
     faultNode:
     faultDetail:
        {urn:faults_2012_1.platform.webservices.netsuite.com}invalidCredentialsFault:<platformFaults:code>INVALID_LOGIN_CREDENTIALS</platformFaults:code><platformFaults:message>You have entered an invalid email address or account number. Please try again.</platformFaults:message>
        {http//xml.apache.org/axis/}hostname:partners-java10004.bos.netledger.com
    You have entered an invalid email address or account number. Please try again.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at java.lang.Class.newInstance(Class.java:379)
        at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
        at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
        at com.netsuite.webservices.platform.faults_2012_1.InvalidCredentialsFault.getDeserializer(InvalidCredentialsFault.java:84)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
        at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
        at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
        at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
        at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
        at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:379)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:648)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:332)
        at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
        at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
        at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
        at org.apache.axis.client.Call.invoke(Call.java:2767)
        at org.apache.axis.client.Call.invoke(Call.java:2443)
        at org.apache.axis.client.Call.invoke(Call.java:2366)
        at org.apache.axis.client.Call.invoke(Call.java:1812)
        at com.netsuite.webservices.platform_2012_1.NetSuiteBindingStub.login(NetSuiteBindingStub.java:10911)
        at com.netsuite.webservices.samples.NSClient.login(NSClient.java:381)
        at com.netsuite.webservices.samples.NSClient.main(NSClient.java:248)
    java.lang.NullPointerException
        at com.netsuite.webservices.samples.NSClient.login(NSClient.java:391)
        at com.netsuite.webservices.samples.NSClient.main(NSClient.java:248)


我也知道沙箱帐户和非沙箱帐户的wsdl可能不同,并且在wsdl下也尝试过,但这没有用。

https://webservices.sandbox.netsuite.com/wsdl/v2012_1_0/netsuite.wsdl

任何人都可以建议我是否缺少某些东西或走错路了?

以下是我正在使用的Java代码:

/**
 * Fully functional, command-line driven application that illustrates how to
 * connect to the NetSuite web services and invoke operations. This application
 * uses the Customer record as an example across all operations.
 *
 * Please see the README.html on how to compile and run. Note that the
 * nsclient.properties file must exist in the installed root directory for this
 * application to run.
 *
 */

public class NSClient   {
    /**
     * Proxy class that abstracts the communication with the NetSuite Web
     * Services. All NetSuite operations are invoked as methods of this class.
     */
    private NetSuitePortType _port;

    /**
     * Flag that indicates whether the user is currently authentciated, and
     * therefore, whether a valid session is available
     */
    private boolean _isAuthenticated;

    /**
     * Utility for writing nd logging to console
     */
    private Console _console;

    /**
     * Abstraction of the external properties file that contains configuration
     * parameters and sample data for fields
     */
    private Properties _properties = null;

    /**
     * Requested page size for search
     */
    private int _pageSize;

    /**
     * Constructor
     * @throws ServiceException
     * @throws FileNotFoundException
     * @throws IOException
     */
    public NSClient() throws ServiceException, FileNotFoundException, IOException   {
        _isAuthenticated = false;
        // Setting pageSize to 20 records per page
        _pageSize = 500;
        // Instantiate console logger
        _console = new Console("info");
        // In order to use SSL forwarding for SOAP messages. Refer to FAQ for details
        System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
        //System.setProperty("https.protocols", "SSLv3");
        // Locate the NetSuite web service.
        NetSuiteServiceLocator service = new NetSuiteServiceLocator();

        /*NetSuiteService service = new NetSuiteService();
        service.AllowAutoRedirects = true;*/


        // Enable client cookie management. This is required.
        //service.setMaintainSession(true);

        service.setNetSuitePortEndpointAddress("https://webservices.sandbox.netsuite.com/services/NetSuitePort_2012_1");
        // Get the service port
        _port = service.getNetSuitePort();//service.getNetSuitePort(new URL("https://localhost:8443/services/NetSuitePort_2009_1"));
        // Setting client timeout to 2 hours for long running operations

        ((NetSuiteBindingStub) _port).setTimeout(1000 * 60 * 60 * 2);

        // Reference to properties file that contains configuration data as
        // well as sample data. This file is named nsclient.properties and
        // is located in the root directory of this installation.
        _properties = new Properties();
        _properties.load(new FileInputStream("nsclient.properties"));
    }

    /**
     * Main function that presents the user with the available options and
     * invokes the methods that encasulate the methods calls to the web services
     * operations.
     *
     * @param args -
     *            array of command line arguments
     * @throws SOAPException
     */
    public static void main(String args[]) throws SOAPException  {
        NSClient ns = null;

        // Instantiate the NetSuite web services
        try {
            ns = new NSClient();
        } catch (ServiceException ex) {
            System.out
                    .println("\n\n[Error]: Error in locating the NetSuite web services. "
                            + ex.getMessage());
        } catch (FileNotFoundException ex) {
            System.out
                    .println("\n\n[Error]: Cannot find nsclient.properties file. Please ensure that "
                            + "this file is in the root directory of this application. ");
        } catch (IOException ex) {
            System.out.println("\n\n[Error]: An IO error has occured. "
                    + ex.getMessage());
        }
        // Process command line arguments
        // if ( !ns.processCmdArgs( args ) )
        // return;

        // Iterate through command options
        while (true) {
            try {
                int myChoice = 0;
                String strMyChoice = null;
                ns._console.writeLn("\nPlease make a selection:");
                ns._console.writeLn("  1) Login");
                ns._console.writeLn("  2) Add a customer");
                ns._console
                        .writeLn("  3) Add a customer with custom fields (CFs must exist)");
                ns._console.writeLn("  4) Update a customer (internalId required)");
                ns._console
                        .writeLn("  5) Upsert for customer (ExternalId required)");
                ns._console
                        .writeLn("  6) Update a list of customers (internalIds required)");
                ns._console
                        .writeLn("  7) Delete a list of customers (internalIds required)");
                ns._console.writeLn("  8) Get a customer (internalId required)");
                ns._console
                        .writeLn("  9) Get a list of customers (internalIds required)");
                ns._console.writeLn("  10) Search for customers");
                ns._console
                        .writeLn(" 11) Add a Custom Record (Custom Record must exist, internalId required)");
                ns._console
                        .writeLn(" 12) Delete a Custom Record (internalId required)");
                ns._console
                        .writeLn(" 13) Search for a Custom Record (internalId required)");
                ns._console.writeLn(" 14) Get other list values");
                ns._console.writeLn(" 15) Upload a file");
                ns._console.writeLn(" 16) Logout");
                ns._console.writeLn("  Q) Quit");
                ns._console.write("\nSelection: ");

                // Get user input
                strMyChoice = ns._console.readLn();

                // Process the user response
                ns._console.writeLn("");
                if ("Q".equals(strMyChoice.toUpperCase())) {
                    ns._console.write("\nPress any key to quit ... ");
                    String response = ns._console.readLn();
                    break;
                } else {
                    myChoice = Integer.parseInt(strMyChoice);
                    //Setting preferences for the web services client
                    ns.setPreferences();
                    switch (myChoice) {
                    case 1:
                        if (ns._isAuthenticated) {
                            ns._console
                                    .info("This user is already logged in and has a valid session.");
                        }
                        ns.login(false);
                        break;
                    case 2:
                        ns.addCustomer();
                        break;
                    case 3:
                        ns.addCustomerWithCustomFields();
                        break;
                    case 4:
                        ns.updateCustomer();
                        break;
                    case 5:
                        ns.upsertCustomer();
                        break;
                    case 6:
                        ns.updateCustomerList();
                        break;
                    case 7:
                        ns.deleteCustomerList();
                        break;
                    case 8:
                        ns.getCustomer();
                        break;
                    case 9:
                        ns.getCustomerList();
                        break;
                    case 10:
                        ns.searchCustomer();
                        break;
                    case 11:
                        ns.addCustomRecord();
                        break;
                    case 12:
                        ns.deleteCustomRecord();
                        break;
                    case 13:
                        ns.searchCustomRecord();
                        break;
                    case 14:
                        ns.getAll();
                        break;
                    case 15:
                        ns.uploadFile();
                        break;
                    case 16:
                        ns.logout();
                        break;
                    }
                }
            } catch (NumberFormatException ex) {
                ns._console
                        .info("\nInvalid choice. Please select once of the following options.");
            } catch (ExceededRecordCountFault ex) {
                ns._console
                        .fault("\nExceeded the maximum allowed number of records. "
                                + ex.getMessage());
                ns._console.info("   [Fault Code]: " + ex.getFaultCode());
            } catch (ExceededUsageLimitFault ex) {
                ns._console.fault("\nExceeded rat limit. " + ex.getMessage());
                ns._console.info("   [Fault Code]: " + ex.getFaultCode());
            } catch (InsufficientPermissionFault ex) {
                ns._console
                        .fault("\nYou do not have sufficent permission for this request. "
                                + ex.getMessage());
                ns._console.info("   [Fault Code]: " + ex.getFaultCode());
            } catch (InvalidSessionFault ex) {
                ns._console.fault("\nInvalid Session. " + ex.getMessage());
                ns._console.info("   [Fault Code]: " + ex.getFaultCode());
            } catch (SOAPFaultException ex) {
                ns._console
                        .fault("There was an error processing this request. "
                                + ex.getMessage());
                ns._console.info("   [Fault Code]: " + ex.getFaultCode());
                ns._console.info("   [Fault String]: " + ex.getFaultString());
                ns._console.info("   [Fault Actor]: " + ex.getFaultActor());
                ns._console.info("   [Fault Detail]: " + ex.getDetail());
            } catch (RemoteException ex) {
                ns._console.fault("\nRemoteException: " + ex.getMessage());
            } finally {
            }
        }
    }

    /**
     * Logs the user into NetSuite using the login() operation.
     *
     * @param isAuto -
     *            flag to indicate whether this is being called from another
     *            operation
     *
     * @throws RemoteException
     *
     */
    public void login(boolean isAuto) throws RemoteException {
        if (!_isAuthenticated) {
            // Check whether this is a forced login as part of another operation
            if (isAuto)
                _console.writeLn("\nYou need to first login before invoking this operation ...");

            // Populate Passport object with all login information
            Passport passport = new Passport();
            RecordRef role = new RecordRef();

            // Determine whether to get login information from config
            // file or prompt for it
            if ("true".equals(_properties.getProperty("promptForLogin"))) {
                _console.writeLn("\nPlease enter your login information: ");
                System.out.print("  E-mail: ");
                passport.setEmail(_console.readLn());
                System.out.print("  Password: ");
                passport.setPassword(_console.readLn());
                System.out.print("  Role internalId (press enter for default administrator role): ");
                role.setInternalId(_console.readLn());
                //passport.setRole(role);
                System.out.print("  Account: ");
                passport.setAccount(_console.readLn());
            } else {

                System.out.println("**************   In else ::::");
                passport.setEmail(_properties.getProperty("login.email"));
                passport.setPassword(_properties.getProperty("login.password"));
                //role.setInternalId(_properties.getProperty("login.roleinternalId"));
                //passport.setRole(role);
                passport.setAccount(_properties.getProperty("login.acct"));
            }

            // Login to NetSuite
            _console.info("\nLogging into NetSuite");
            _console.info("  Username: " + passport.getEmail());
            _console.info("  Account: " + passport.getAccount());

            Status status = null;
            try {
                status = (_port.login(passport)).getStatus();
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // Process the response

            try{

            if (status.isIsSuccess() == true) {
                _isAuthenticated = true;
                _console.info("\nThe login was successful and a new session has been created.");
            } else {
                // Should never get here since any problems with the
                // login should have resulted in a SOAP fault
                _console.info("Login failed");
                _console.error(getStatusDetails(status));
            }
            }

            catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    /**
     * Logs a user out using the logout() operation.
     *
     * @throws RemoteException
     */
    public void logout() throws RemoteException {
        if (_isAuthenticated) {
            _console.info("\nLogging out of NetSuite\n");

            // Logout from NetSuite
            Status status = (_port.logout()).getStatus();

            if (status.isIsSuccess() == true) {
                _isAuthenticated = false;
                _console.info("Logout successful");
            } else {
                // Should never get here since any problems with the
                // logout should have resulted in a SOAP fault
                _console.error(getStatusDetails(status));
            }
        } else {
            _console
                    .info("\nThe logout() operation cannot be invoked because there is no active session. "
                            + "You must be first logged on before attempting to logout.\n");
        }
    }

    private void setPreferences() throws SOAPException
    {
        // Cast your login NetSuitePortType variable to a NetSuiteBindingStub
        NetSuiteBindingStub stub = (NetSuiteBindingStub) _port;

        // Clear the headers to make sure you know exactly what you are sending.
        // Headers do not overwrite when you are using Axis/Java
        stub.clearHeaders();

        // Create a new SOAPHeaderElement, this is what the NetSuiteBindingStub
        // will accept
        // This is the same command for all preference elements, ie you might
        // substitute "useDefaults" for "searchPreferences"
        SOAPHeaderElement prefHeader = new SOAPHeaderElement(
            "urn:messages.platform.webservices.netsuite.com",
            "preferences");
        Preferences prefs = new Preferences();
        prefs.setIgnoreReadOnlyFields(new Boolean(true));
        prefHeader.setObjectValue(prefs);

        SOAPHeaderElement searchPrefHeader = new SOAPHeaderElement(
                "urn:messages.platform.webservices.netsuite.com",
                "searchPreferences");

        // Create your Actual SearchPreference Object, this contains the
        // elements you are allowed to set.
        // In this case it is PageSize (for pagination of searches) and
        // BodyFieldsOnly (reserved)
        SearchPreferences searchPrefs = new SearchPreferences();
        searchPrefs.setPageSize(new Integer(_pageSize));
        searchPrefs.setBodyFieldsOnly(new Boolean(true));

        // setObjectValue applies search preference object to the HeaderElement
        searchPrefHeader.setObjectValue(searchPrefs);


        // setHeader applies the Header Element to the stub
        // Again, note that if you reuse your NetSuitePort object (vs logging in
        // before every request)
        // that headers are sticky, so if in doubt, call clearHeaders() first.
        stub.setHeader(prefHeader);
        stub.setHeader(searchPrefHeader);
    }

    private String getStatusDetails(Status status) {
        if (status == null) return "empty status object";

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < status.getStatusDetail().length; i++) {
            sb.append("[Code=" + status.getStatusDetail()[i].getCode() + "] "
                    + status.getStatusDetail()[i].getMessage() + "\n");
        }
        return sb.toString();
    }
}

最佳答案

通常,要进入沙箱,您需要设置服务,例如:

    NetSuiteServiceLocator service = new NetSuiteServiceLocator();
    service.setNetSuitePortEndpointAddress("https://webservices.sandbox.netsuite.com/services/NetSuitePort_2012_2");

关于java - NetSuite上的电子邮件地址或帐号无效,但凭证正确,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36624270/

10-12 04:23