12.07.2015 Views

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

Database.com Metadata API Developer's Guide - Salesforce.com

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

File-Based Callsretrieve()}} catch (IOException ioe) {throw new Exception(ioe);} catch (SAXException se) {throw new Exception(se);}/*** The login call is used to obtain a token from <strong>Salesforce</strong>.* This token must be passed to all other calls to provide* authentication.*/private boolean login() throws ServiceException {String userName = getUserInput("Enter username: ");String password = getUserInput("Enter password: ");/** Next, the sample client application initializes the binding stub.** This is our main interface to the <strong>API</strong> for the Enterprise WSDL.* The getSoap method takes an optional parameter,* (a java.net.URL) which is the endpoint.* For the login call, the parameter always starts with* http(s)://login.salesforce.<strong>com</strong>. After logging in, the sample* client application changes the endpoint to the one specified* in the returned loginResult object.*/binding = (SoapBindingStub) new SforceServiceLocator().getSoap();// Time out after a minutebinding.setTimeout(60000);// Log in using the Enterprise WSDL bindingLoginResult loginResult;try {System.out.println("LOGGING IN NOW....");loginResult = binding.login(userName, password);}catch (LoginFault ex) {// The LoginFault derives from AxisFaultExceptionCode exCode = ex.getExceptionCode();if (exCode == ExceptionCode.FUNCTIONALITY_NOT_ENABLED ||exCode == ExceptionCode.INVALID_CLIENT ||exCode == ExceptionCode.INVALID_LOGIN ||exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_DOMAIN ||exCode == ExceptionCode.LOGIN_DURING_RESTRICTED_TIME ||exCode == ExceptionCode.ORG_LOCKED ||exCode == ExceptionCode.PASSWORD_LOCKOUT ||exCode == ExceptionCode.SERVER_UNAVAILABLE ||exCode == ExceptionCode.TRIAL_EXPIRED ||exCode == ExceptionCode.UNSUPPORTED_CLIENT) {System.out.println("Please be sure that you have a valid username " +"and password.");} else {// Write the fault code to the consoleSystem.out.println(ex.getExceptionCode());// Write the fault message to the consoleSystem.out.println("An unexpected error has occurred." + ex.getMessage());}return false;} catch (Exception ex) {System.out.println("An unexpected error has occurred: " + ex.getMessage());ex.printStackTrace();return false;}// Check if the password has expiredif (loginResult.isPasswordExpired()) {System.out.println("An error has occurred. Your password has expired.");return false;}/** Once the client application has logged in successfully, we use38

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!