Package org.apache.camel.component.salesforce.api

Examples of org.apache.camel.component.salesforce.api.SalesforceException


                    // if all else fails, get body as String
                    final String body = in.getBody(String.class);
                    if (null == body) {
                        String msg = "Unsupported request message body "
                            + (in.getBody() == null ? null : in.getBody().getClass());
                        throw new SalesforceException(msg, null);
                    } else {
                        request = new ByteArrayInputStream(body.getBytes(StringUtil.__UTF8_CHARSET));
                    }
                }
            }
            return request;
        } catch (XStreamException e) {
            String msg = "Error marshaling request: " + e.getMessage();
            throw new SalesforceException(msg, e);
        }
    }
View Full Code Here


            // copy headers and attachments
            exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
            exchange.getOut().getAttachments().putAll(exchange.getIn().getAttachments());
        } catch (XStreamException e) {
            String msg = "Error parsing XML response: " + e.getMessage();
            exchange.setException(new SalesforceException(msg, e));
        } catch (Exception e) {
            String msg = "Error creating XML response: " + e.getMessage();
            exchange.setException(new SalesforceException(msg, e));
        } finally {
            // cleanup temporary exchange headers
            exchange.removeProperty(RESPONSE_CLASS);
            exchange.removeProperty(RESPONSE_ALIAS);
View Full Code Here

                getLog().info("Getting Salesforce Objects...");
                restClient.getGlobalObjects(callback);
                if (!callback.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
                    throw new MojoExecutionException("Timeout waiting for getGlobalObjects!");
                }
                final SalesforceException ex = callback.getException();
                if (ex != null) {
                    throw ex;
                }
                final GlobalObjects globalObjects = mapper.readValue(callback.getResponse(),
                        GlobalObjects.class);

                // create a list of object names
                for (SObject sObject : globalObjects.getSobjects()) {
                    objectNames.add(sObject.getName());
                }
            } catch (Exception e) {
                String msg = "Error getting global Objects " + e.getMessage();
                throw new MojoExecutionException(msg, e);
            }

            // check if we are generating POJOs for all objects or not
            if ((includes != null && includes.length > 0)
                    || (excludes != null && excludes.length > 0)
                    || (includePattern != null && !includePattern.trim().isEmpty())
                    || (excludePattern != null && !excludePattern.trim().isEmpty())) {

                getLog().info("Looking for matching Object names...");
                // create a list of accepted names
                final Set<String> includedNames = new HashSet<String>();
                if (includes != null && includes.length > 0) {
                    for (String name : includes) {
                        name = name.trim();
                        if (name.isEmpty()) {
                            throw new MojoExecutionException("Invalid empty name in includes");
                        }
                        includedNames.add(name);
                    }
                }

                final Set<String> excludedNames = new HashSet<String>();
                if (excludes != null && excludes.length > 0) {
                    for (String name : excludes) {
                        name = name.trim();
                        if (name.isEmpty()) {
                            throw new MojoExecutionException("Invalid empty name in excludes");
                        }
                        excludedNames.add(name);
                    }
                }

                // check whether a pattern is in effect
                Pattern incPattern;
                if (includePattern != null && !includePattern.trim().isEmpty()) {
                    incPattern = Pattern.compile(includePattern.trim());
                } else if (includedNames.isEmpty()) {
                    // include everything by default if no include names are set
                    incPattern = Pattern.compile(".*");
                } else {
                    // include nothing by default if include names are set
                    incPattern = Pattern.compile("^$");
                }

                // check whether a pattern is in effect
                Pattern excPattern;
                if (excludePattern != null && !excludePattern.trim().isEmpty()) {
                    excPattern = Pattern.compile(excludePattern.trim());
                } else {
                    // exclude nothing by default
                    excPattern = Pattern.compile("^$");
                }

                final Set<String> acceptedNames = new HashSet<String>();
                for (String name : objectNames) {
                    // name is included, or matches include pattern
                    // and is not excluded and does not match exclude pattern
                    if ((includedNames.contains(name) || incPattern.matcher(name).matches())
                            && !excludedNames.contains(name) && !excPattern.matcher(name).matches()) {
                        acceptedNames.add(name);
                    }
                }
                objectNames.clear();
                objectNames.addAll(acceptedNames);

                getLog().info(String.format("Found %s matching Objects", objectNames.size()));
            } else {
                getLog().warn(String.format("Generating Java classes for all %s Objects, this may take a while...", objectNames.size()));
            }

            // for every accepted name, get SObject description
            final Set<SObjectDescription> descriptions = new HashSet<SObjectDescription>();

            try {
                getLog().info("Retrieving Object descriptions...");
                for (String name : objectNames) {
                    callback.reset();
                    restClient.getDescription(name, callback);
                    if (!callback.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
                        throw new MojoExecutionException("Timeout waiting for getDescription for sObject " + name);
                    }
                    final SalesforceException ex = callback.getException();
                    if (ex != null) {
                        throw ex;
                    }
                    descriptions.add(mapper.readValue(callback.getResponse(), SObjectDescription.class));
                }
View Full Code Here

                        final LoginError error = objectMapper.readValue(responseContent, LoginError.class);
                        final String msg = String.format("Login error code:[%s] description:[%s]",
                                error.getError(), error.getErrorDescription());
                        final List<RestError> errors = new ArrayList<RestError>();
                        errors.add(new RestError(msg, error.getErrorDescription()));
                        throw new SalesforceException(errors, HttpStatus.BAD_REQUEST_400);

                    default:
                        throw new SalesforceException(String.format("Login error status:[%s] reason:[%s]",
                            responseStatus, loginPost.getReason()), responseStatus);
                    }
                    break;

                case HttpExchange.STATUS_EXCEPTED:
                    final Throwable ex = loginPost.getException();
                    throw new SalesforceException(
                            String.format("Unexpected login exception: %s", ex.getMessage()), ex);

                case HttpExchange.STATUS_CANCELLED:
                    throw new SalesforceException("Login request CANCELLED!", null);

                case HttpExchange.STATUS_EXPIRED:
                    throw new SalesforceException("Login request TIMEOUT!", null);

                default:
                    throw new SalesforceException("Unknow status: " + exchangeState, null);
                }
            } catch (IOException e) {
                String msg = "Login error: unexpected exception " + e.getMessage();
                throw new SalesforceException(msg, e);
            } catch (InterruptedException e) {
                String msg = "Login error: unexpected exception " + e.getMessage();
                throw new SalesforceException(msg, e);
            }
        }

        return accessToken;
    }
View Full Code Here

                final String reason = logoutGet.getReason();

                if (statusCode == HttpStatus.OK_200) {
                    LOG.info("Logout successful");
                } else {
                    throw new SalesforceException(
                            String.format("Logout error, code: [%s] reason: [%s]",
                                    statusCode, reason),
                            statusCode);
                }
                break;

            case HttpExchange.STATUS_EXCEPTED:
                final Throwable ex = logoutGet.getException();
                throw new SalesforceException("Unexpected logout exception: " + ex.getMessage(), ex);

            case HttpExchange.STATUS_CANCELLED:
                throw new SalesforceException("Logout request CANCELLED!", null);

            case HttpExchange.STATUS_EXPIRED:
                throw new SalesforceException("Logout request TIMEOUT!", null);

            default:
                throw new SalesforceException("Unknow status: " + done, null);
            }
        } catch (SalesforceException e) {
            throw e;
        } catch (Exception e) {
            String msg = "Logout error: " + e.getMessage();
            throw new SalesforceException(msg, e);
        } finally {
            // reset session
            accessToken = null;
            instanceUrl = null;
            // notify all session listeners of the new access token and instance url
View Full Code Here

            final RestError restError = new RestError();
            restError.setErrorCode(error.getExceptionCode());
            restError.setMessage(error.getExceptionMessage());

            return new SalesforceException(Arrays.asList(restError), request.getResponseStatus());
        } catch (SalesforceException e) {
            String msg = "Error un-marshaling Salesforce Error: " + e.getMessage();
            return new SalesforceException(msg, e);
        }
    }
View Full Code Here

        try {
            Unmarshaller unmarshaller = context.createUnmarshaller();
            JAXBElement<T> result = unmarshaller.unmarshal(new StreamSource(response), resultClass);
            return result.getValue();
        } catch (JAXBException e) {
            throw new SalesforceException(
                    String.format("Error unmarshaling response {%s:%s} : %s",
                            request.getMethod(), request.getRequestURI(), e.getMessage()),
                    e);
        } catch (IllegalArgumentException e) {
            throw new SalesforceException(
                    String.format("Error unmarshaling response for {%s:%s} : %s",
                            request.getMethod(), request.getRequestURI(), e.getMessage()),
                    e);
        }
    }
View Full Code Here

            ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
            marshaller.marshal(input, byteStream);
            request.setRequestContent(new ByteArrayBuffer(byteStream.toByteArray()));
            request.setRequestContentType(contentType);
        } catch (JAXBException e) {
            throw new SalesforceException(
                    String.format("Error marshaling request for {%s:%s} : %s",
                            request.getMethod(), request.getRequestURI(), e.getMessage()),
                    e);
        } catch (IllegalArgumentException e) {
            throw new SalesforceException(
                    String.format("Error marshaling request for {%s:%s} : %s",
                            request.getMethod(), request.getRequestURI(), e.getMessage()),
                    e);
        }
    }
View Full Code Here

        } catch (SalesforceException e) {
            exchange.setException(e);
            callback.done(true);
            return true;
        } catch (RuntimeException e) {
            exchange.setException(new SalesforceException(e.getMessage(), e));
            callback.done(true);
            return true;
        }

        // call Salesforce asynchronously
        try {
            // call Operation using REST client
            switch (operationName) {
            case GET_VERSIONS:
                processGetVersions(exchange, callback);
                break;
            case GET_RESOURCES:
                processGetResources(exchange, callback);
                break;
            case GET_GLOBAL_OBJECTS:
                processGetGlobalObjects(exchange, callback);
                break;
            case GET_BASIC_INFO:
                processGetBasicInfo(exchange, callback);
                break;
            case GET_DESCRIPTION:
                processGetDescription(exchange, callback);
                break;
            case GET_SOBJECT:
                processGetSobject(exchange, callback);
                break;
            case CREATE_SOBJECT:
                processCreateSobject(exchange, callback);
                break;
            case UPDATE_SOBJECT:
                processUpdateSobject(exchange, callback);
                break;
            case DELETE_SOBJECT:
                processDeleteSobject(exchange, callback);
                break;
            case GET_SOBJECT_WITH_ID:
                processGetSobjectWithId(exchange, callback);
                break;
            case UPSERT_SOBJECT:
                processUpsertSobject(exchange, callback);
                break;
            case DELETE_SOBJECT_WITH_ID:
                processDeleteSobjectWithId(exchange, callback);
                break;
            case GET_BLOB_FIELD:
                processGetBlobField(exchange, callback);
                break;
            case QUERY:
                processQuery(exchange, callback);
                break;
            case QUERY_MORE:
                processQueryMore(exchange, callback);
                break;
            case SEARCH:
                processSearch(exchange, callback);
                break;
            default:
                throw new SalesforceException("Unknow operation name: " + operationName, null);
            }
        } catch (SalesforceException e) {
            exchange.setException(new SalesforceException(
                    String.format("Error processing %s: [%s] \"%s\"",
                            operationName, e.getStatusCode(), e.getMessage()),
                    e));
            callback.done(true);
            return true;
        } catch (RuntimeException e) {
            exchange.setException(new SalesforceException(
                    String.format("Unexpected Error processing %s: \"%s\"",
                            operationName, e.getMessage()),
                    e));
            callback.done(true);
            return true;
View Full Code Here

        try {
            // set the value with the set method
            Method setMethod = sObjectBase.getClass().getMethod("set" + name, value.getClass());
            setMethod.invoke(sObjectBase, value);
        } catch (NoSuchMethodException e) {
            throw new SalesforceException(
                    String.format("SObject %s does not have a field %s",
                            sObjectBase.getClass().getName(), name),
                    e);
        } catch (InvocationTargetException e) {
            throw new SalesforceException(
                    String.format("Error setting value %s.%s",
                            sObjectBase.getClass().getSimpleName(), name),
                    e);
        } catch (IllegalAccessException e) {
            throw new SalesforceException(
                    String.format("Error accessing value %s.%s",
                            sObjectBase.getClass().getSimpleName(), name),
                    e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.salesforce.api.SalesforceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.