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

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


            Method setMethod = sObjectBase.getClass().getMethod("set" + propertyName, getMethod.getReturnType());
            setMethod.invoke(sObjectBase, new Object[]{null});

            return value;
        } catch (NoSuchMethodException e) {
            throw new SalesforceException(
                    String.format("SObject %s does not have a field %s",
                            sObjectBase.getClass().getSimpleName(), propertyName),
                    e);
        } catch (InvocationTargetException e) {
            throw new SalesforceException(
                    String.format("Error getting/setting value %s.%s",
                            sObjectBase.getClass().getSimpleName(), propertyName),
                    e);
        } catch (IllegalAccessException e) {
            throw new SalesforceException(
                    String.format("Error accessing value %s.%s",
                            sObjectBase.getClass().getSimpleName(), propertyName),
                    e);
        }
    }
View Full Code Here


        if (sObjectName != null) {
            // lookup class from class map
            sObjectClass = classMap.get(sObjectName);
            if (null == sObjectClass) {
                throw new SalesforceException(String.format("No class found for SObject %s", sObjectName), null);
            }

        } else {

            // use custom response class property
            final String className = getParameter(SOBJECT_CLASS, exchange, IGNORE_BODY, NOT_OPTIONAL);
            try {
                sObjectClass = endpoint.getComponent().getCamelContext()
                        .getClassResolver().resolveMandatoryClass(className);
            } catch (ClassNotFoundException e) {
                throw new SalesforceException(
                        String.format("SObject class not found %s, %s",
                                className, e.getMessage()),
                        e);
            }
        }
View Full Code Here

            request.setEventListener(new SalesforceSecurityListener(
                    httpClient.getDestination(request.getAddress(), isHttps),
                    request, session, accessToken));
        } catch (IOException e) {
            // propagate exception
            callback.onResponse(null, new SalesforceException(
                    String.format("Error registering security listener: %s", e.getMessage()),
                    e));
        }

        // use HttpEventListener for lifecycle events
        request.setEventListener(new HttpEventListenerWrapper(request.getEventListener(), true) {

            public String reason;

            @Override
            public void onConnectionFailed(Throwable ex) {
                super.onConnectionFailed(ex);
                callback.onResponse(null,
                        new SalesforceException("Connection error: " + ex.getMessage(), ex));
            }

            @Override
            public void onException(Throwable ex) {
                super.onException(ex);
                callback.onResponse(null,
                        new SalesforceException("Unexpected exception: " + ex.getMessage(), ex));
            }

            @Override
            public void onExpire() {
                super.onExpire();
                callback.onResponse(null,
                        new SalesforceException("Request expired", null));
            }

            @Override
            public void onResponseComplete() throws IOException {
                super.onResponseComplete();

                final int responseStatus = request.getResponseStatus();
                if (responseStatus < HttpStatus.OK_200 || responseStatus >= HttpStatus.MULTIPLE_CHOICES_300) {
                    final String msg = String.format("Error {%s:%s} executing {%s:%s}",
                            responseStatus, reason, request.getMethod(), request.getRequestURI());
                    final SalesforceException exception = new SalesforceException(msg, responseStatus, createRestException(request));
                    callback.onResponse(null, exception);
                } else {
                    // TODO not memory efficient for large response messages,
                    // doesn't seem to be possible in Jetty 7 to directly stream to response parsers
                    final byte[] bytes = request.getResponseContentBytes();
                    callback.onResponse(bytes != null ? new ByteArrayInputStream(bytes) : null, null);
                }

            }

            @Override
            public void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException {
                super.onResponseStatus(version, status, reason);
                // remember status reason
                this.reason = reason.toString(StringUtil.__ISO_8859_1);
            }
        });

        // execute the request
        try {
            httpClient.send(request);
        } catch (IOException e) {
            String msg = "Unexpected Error: " + e.getMessage();
            // send error through callback
            callback.onResponse(null, new SalesforceException(msg, e));
        }

    }
View Full Code Here

        propValue = (propValue == null && convertInBody) ? exchange.getIn().getBody(String.class) : propValue;

        // error if property was not set
        if (propValue == null && !optional) {
            String msg = "Missing property " + propName;
            throw new SalesforceException(msg, null);
        }

        return propValue;
    }
View Full Code Here

                    // 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

            if (PayloadFormat.JSON.equals(format)) {
                List<RestError> restErrors = objectMapper.readValue(
                    httpExchange.getResponseContent(), new TypeReference<List<RestError>>() {
                    }
                );
                return new SalesforceException(restErrors, httpExchange.getResponseStatus());
            } else {
                RestErrors errors = new RestErrors();
                xStream.fromXML(httpExchange.getResponseContent(), errors);
                return new SalesforceException(errors.getErrors(), httpExchange.getResponseStatus());
            }
        } catch (IOException e) {
            // log and ignore
            String msg = "Unexpected Error parsing " + format + " error response: " + e.getMessage();
            log.warn(msg, e);
        } catch (RuntimeException e) {
            // log and ignore
            String msg = "Unexpected Error parsing " + format + " error response: " + e.getMessage();
            log.warn(msg, e);
        }

        // just report HTTP status info
        return new SalesforceException("Unexpected error", httpExchange.getResponseStatus());
    }
View Full Code Here

            doHttpRequest(get, new DelegatingClientCallback(callback));

        } catch (UnsupportedEncodingException e) {
            String msg = "Unexpected error: " + e.getMessage();
            callback.onResponse(null, new SalesforceException(msg, e));
        }
    }
View Full Code Here

            doHttpRequest(get, new DelegatingClientCallback(callback));

        } catch (UnsupportedEncodingException e) {
            String msg = "Unexpected error: " + e.getMessage();
            callback.onResponse(null, new SalesforceException(msg, e));
        }
    }
View Full Code Here

                break;
            case GET_QUERY_RESULT:
                processGetQueryResult(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);
            done = true;
        } catch (InvalidPayloadException e) {
            exchange.setException(new SalesforceException(
                    String.format("Unexpected Error processing %s: \"%s\"",
                            operationName, e.getMessage()), e));
            callback.done(true);
            done = true;
        } catch (RuntimeException e) {
            exchange.setException(new SalesforceException(
                    String.format("Unexpected Error processing %s: \"%s\"",
                            operationName, e.getMessage()), e));
            callback.done(true);
            done = true;
        }
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.