/** * Creates a BatchStatus and initializes it * based on an exception. * * @param e */ public BatchStatus(ServiceException e) { code = e.getHttpErrorCodeOverride(); if (code == -1) { code = HttpURLConnection.HTTP_INTERNAL_ERROR; } reason = e.getMessage(); contentType = e.getResponseContentType(); content = e.getResponseBody(); }
/** * Handles a redirect exception by generating the new URL to use for the * redirect. */ protected URL handleRedirectException(RedirectRequiredException redirect) throws ServiceException { try { return new URL(redirect.getRedirectLocation()); } catch (MalformedURLException e) { ServiceException se = new ServiceException( CoreErrorDomain.ERR.invalidRedirectedToUrl); se.setInternalReason("Invalid redirected-to URL - " + redirect.getRedirectLocation()); throw se; } }
/** * Creates a new exception, registers it and sets {@code currentException}. * The first time this method is called, {@code currentException} is set * to {@code initialException}. * @return the new value of {@code currentException} */ private ServiceException nextException() { // nextException/currentException if (currentException == null) { currentException = initialException; return currentException; } try { // Create an exception of the same type as this one // and make it a sibling. currentException = initialException.getClass() .getConstructor(String.class).newInstance( initialException.getMessage()); initialException.addSibling(currentException); return currentException; } catch (InstantiationException ie) { throw new IllegalStateException(ie); } catch (NoSuchMethodException nsme) { throw new IllegalStateException(nsme); } catch (IllegalAccessException iae) { throw new IllegalStateException(iae); } catch (InvocationTargetException ite) { throw new IllegalStateException(ite); } }
/** * Extracts errors from a {@link ServiceException}. * * @param e the ServiceException to be parsed */ public void addErrors(ServiceException e) { addErrors(e.getMessage(), e.getResponseContentType(), e.getResponseBody()); }
/** * Creates and initializes a BatchInterrupted object. * * @param cause exception that caused batch processing to stop * @param totalCount number of entries parsed so far, note that * it is to be expected that {@code totalCount >= successCount + errorCount} * @param successCount number of entries processed successfully so far * @param errorCount number of entries rejected so far */ public BatchInterrupted(Throwable cause, int totalCount, int successCount, int errorCount) { this(getReasonFromException(cause), totalCount, successCount, errorCount); if (cause instanceof ServiceException) { ServiceException se = (ServiceException)cause; content = se.getResponseBody(); contentType = se.getResponseContentType(); } }
String domainName = se.getDomainName(); sb.append("<domain>"); sb.append(escape(domainName)); sb.append("</domain>\n"); String codeName = se.getCodeName(); sb.append("<code>"); sb.append(escape(codeName)); sb.append("</code>\n"); String location = se.getLocation(); LocationType locationType = se.getLocationTypeWithDefault(); if (location != null) { sb.append("<location type='"); sb.append(escape(locationType.toString())); sb.append("'>"); sb.append(escape(location)); sb.append("</location>\n"); String internalReason = se.getInternalReason(); if (internalReason != null) { sb.append("<internalReason>"); sb.append(escape(internalReason)); sb.append("</internalReason>\n"); String extendedHelp = se.getExtendedHelp(); if (extendedHelp != null) { sb.append("<extendedHelp>"); sb.append(escape(extendedHelp));
/** * Inserts a new Entry into the feed, if the feed is currently associated with * a Service. * * @return the inserted Entry returned by the Service. * * @throws ServiceException If there is no associated GData service or the * service is unable to perform the insertion. * * @throws UnsupportedOperationException If insert is not supported for the * target feed. * * @throws IOException If there is an error communicating with the GData * service. */ public <T extends Entry> T insert(T newEntry) throws ServiceException, IOException { if (feedState.service == null) { throw new ServiceException( CoreErrorDomain.ERR.entryNotAssociated); } Link postLink = getEntryPostLink(); if (postLink == null) { throw new UnsupportedOperationException("Media cannot be inserted"); } URL postUrl = new URL(postLink.getHref()); throw new UnsupportedOperationException("Not supported yet"); // return feedState.service.insert(postUrl, newEntry); }
if ((se.getResponseContentType() == null) || (se.getResponseBody() == null)) { return null; if (se.getHttpErrorCodeOverride() == HttpURLConnection.HTTP_BAD_GATEWAY) { return new AppsForYourDomainException( AppsForYourDomainErrorCode.ServerBusy, if ((se.getResponseContentType().equals(new ContentType("text/xml"))) && (se.getResponseBody().contains("AppsForYourDomainErrors"))) { try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource( new StringReader(se.getResponseBody()))); Element root = document.getDocumentElement(); NodeList errorList = root.getElementsByTagName("error"); AppsForYourDomainException exception = new AppsForYourDomainException(AppsForYourDomainErrorCode .getEnumFromInt(errorCode), invalidInput, se.getHttpErrorCodeOverride()); return exception;
/** * Return true if this ServiceException matches the specified * {@link ErrorContent} in domain name and code name. Sibling exceptions are * not checked. */ public boolean matches(ErrorContent code) { return getDomainName().equals(code.getDomainName()) && getCodeName().equals(code.getCodeName()); }
/** * Add a <strong>Throwable</strong> to a message context, the message from the throwable is embedded as * the Synapse contstant ERROR_MESSAGE. * * @param ctxt Synapse Message Context to which the error tags need to be added * @param throwable Throwable that needs to be parsed and added * @param errorCode integer type error code to be added to ERROR_CODE Synapse constant */ protected final void storeErrorResponseStatus(final MessageContext ctxt, final Throwable throwable, final int errorCode) { if (throwable instanceof ServiceException) { ctxt.setProperty(SynapseConstants.ERROR_DETAIL, ((ServiceException) throwable).getResponseBody()); } ctxt.setProperty(SynapseConstants.ERROR_CODE, errorCode); ctxt.setProperty(SynapseConstants.ERROR_MESSAGE, throwable.getMessage()); ctxt.setFaultResponse(true); }
/** * Converts the exception into a well-formated XML error * message suitable for external uses. * * @param includeDebugInfo if {@code true}, include debug information. * Such error message should only be returned to internal clients. */ public String toXmlErrorMessage(boolean includeDebugInfo) { StringBuilder sb = new StringBuilder(); sb.append("<errors xmlns='http://schemas.google.com/g/2005'>\n"); for (ServiceException sibling : siblings) { addXmlError(sibling, sb, includeDebugInfo); } sb.append("</errors>\n"); return sb.toString(); }
/** * {@inheritDoc} * * <p>If {@code cause} is a {@link ServiceException}, it is added to * the list of siblings so that the original exception appears when * using XML error output. */ @Override public Throwable initCause(Throwable cause) { super.initCause(cause); if (cause instanceof ServiceException) { addSibling((ServiceException) cause); } return this; }
String domainName = se.getDomainName(); sb.append("<domain>"); sb.append(escape(domainName)); sb.append("</domain>\n"); String codeName = se.getCodeName(); sb.append("<code>"); sb.append(escape(codeName)); sb.append("</code>\n"); String location = se.getLocation(); LocationType locationType = se.getLocationType(); if (locationType == null) { locationType = LocationType.OTHER; sb.append(escape(locationType.toString())); sb.append("'>"); sb.append(escape(location)); sb.append("</location>\n"); String internalReason = se.getInternalReason(); if (internalReason != null) { sb.append("<internalReason>"); sb.append(escape(internalReason)); sb.append("</internalReason>\n"); String extendedHelp = se.getExtendedHelp(); if (extendedHelp != null) { sb.append("<extendedHelp>");
throw new ServiceException( CoreErrorDomain.ERR.entryNotAssociated);
/** * Creates and initializes a BatchInterrupted object. * * @param cause exception that caused batch processing to stop * @param totalCount number of entries parsed so far, note that * it is to be expected that {@code totalCount >= successCount + errorCount} * @param successCount number of entries processed successfully so far * @param errorCount number of entries rejected so far */ public BatchInterrupted(Throwable cause, int totalCount, int successCount, int errorCount) { this(getReasonFromException(cause), totalCount, successCount, errorCount); if (cause instanceof ServiceException) { ServiceException se = (ServiceException)cause; content = se.getResponseBody(); contentType = se.getResponseContentType(); } }
/** * Extracts errors from a {@link ServiceException}. * * @param e the ServiceException to be parsed */ public void addErrors(ServiceException e) { addErrors(e.getMessage(), e.getResponseContentType(), e.getResponseBody()); }
if ((se.getResponseContentType() == null) || (se.getResponseBody() == null)) { return null; if (se.getHttpErrorCodeOverride() == HttpURLConnection.HTTP_BAD_GATEWAY) { return new AppsForYourDomainException( AppsForYourDomainErrorCode.ServerBusy, if ((se.getResponseContentType().equals(new ContentType("text/xml"))) && (se.getResponseBody().contains("AppsForYourDomainErrors"))) { try { DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource( new StringReader(se.getResponseBody()))); Element root = document.getDocumentElement(); NodeList errorList = root.getElementsByTagName("error"); AppsForYourDomainException exception = new AppsForYourDomainException(AppsForYourDomainErrorCode .getEnumFromInt(errorCode), invalidInput, se.getHttpErrorCodeOverride()); return exception;
/** * Return true if this ServiceException matches the specified * {@link ErrorContent} in domain name and code name. Sibling exceptions are * not checked. */ public boolean matches(ErrorContent code) { return getDomainName().equals(code.getDomainName()) && getCodeName().equals(code.getCodeName()); }
/** * Converts the exception into a well-formated XML error * message suitable for external uses. * * @param includeDebugInfo if {@code true}, include debug information. * Such error message should only be returned to internal clients. */ public String toXmlErrorMessage(boolean includeDebugInfo) { StringBuilder sb = new StringBuilder(); sb.append("<errors xmlns='http://schemas.google.com/g/2005'>\n"); for (ServiceException sibling : siblings) { addXmlError(sibling, sb, includeDebugInfo); } sb.append("</errors>\n"); return sb.toString(); }
/** * {@inheritDoc} * * <p>If {@code cause} is a {@link ServiceException}, it is added to * the list of siblings so that the original exception appears when * using XML error output. */ @Override public Throwable initCause(Throwable cause) { super.initCause(cause); if (cause instanceof ServiceException) { addSibling((ServiceException) cause); } return this; }