Example usage for org.xml.sax SAXException getMessage

List of usage examples for org.xml.sax SAXException getMessage

Introduction

In this page you can find the example usage for org.xml.sax SAXException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Return a detail message for this exception.

Usage

From source file:org.exist.xquery.modules.exi.EncodeExiFunction.java

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    if (args[0].isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    }/*from w  w  w . ja  va2s.  c om*/
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EXISerializer exiSerializer = null;
        if (args.length > 1) {
            if (!args[1].isEmpty()) {
                Item xsdItem = args[1].itemAt(0);
                InputStream xsdInputStream = EXIUtils.getInputStream(xsdItem, context);
                exiSerializer = new EXISerializer(baos, xsdInputStream);
            } else {
                exiSerializer = new EXISerializer(baos);
            }
        } else {
            exiSerializer = new EXISerializer(baos);
        }
        Item inputNode = args[0].itemAt(0);
        exiSerializer.startDocument();
        inputNode.toSAX(context.getBroker(), exiSerializer, new Properties());
        exiSerializer.endDocument();
        return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(),
                new ByteArrayInputStream(baos.toByteArray()));
    } catch (IOException ioex) {
        // TODO - test!
        throw new XPathException(this, ErrorCodes.FODC0002, ioex.getMessage());
    } catch (EXIException exie) {
        throw new XPathException(this, new JavaErrorCode(exie.getCause()), exie.getMessage());
    } catch (SAXException saxe) {
        throw new XPathException(this, new JavaErrorCode(saxe.getCause()), saxe.getMessage());
    }
}

From source file:org.exist.xquery.modules.httpclient.BaseHTTPClientFunction.java

/**
 * Takes the HTTP Response Body from the HTTP Method and attempts to insert it into the response tree we are building.
 *
 * <p>Conversion Preference - 1) Try and parse as XML, if successful returns a Node 2) Try and parse as HTML returning as XML compatible HTML, if
 * successful returns a Node 3) Return as base64Binary encoded data</p>
 *
 * @param   context  The context of the calling XQuery
 * @param   method   The HTTP Request Method
 * @param   builder  The MemTreeBuilder that is being used
 *
 * @throws  IOException     /*from   w  w w. j a va  2s. c  o m*/
 * @throws  XPathException  
 */
private void insertResponseBody(final XQueryContext context, final HttpMethod method,
        final MemTreeBuilder builder, final Map<String, Boolean> parserFeatures,
        final Map<String, String> parserProperties) throws IOException, XPathException {
    NodeImpl responseNode = null;

    final InputStream bodyAsStream = method.getResponseBodyAsStream();

    // check if there is a response body
    if (bodyAsStream != null) {

        CachingFilterInputStream cfis = null;
        FilterInputStreamCache cache = null;
        try {

            //we have to cache the input stream, so we can reread it, as we may use it twice (once for xml attempt and once for string attempt)
            cache = FilterInputStreamCacheFactory
                    .getCacheInstance(new FilterInputStreamCacheFactory.FilterInputStreamCacheConfiguration() {
                        @Override
                        public String getCacheClass() {
                            return (String) context.getBroker().getConfiguration()
                                    .getProperty(Configuration.BINARY_CACHE_CLASS_PROPERTY);
                        }
                    });

            cfis = new CachingFilterInputStream(cache, bodyAsStream);

            //mark the start of the stream
            cfis.mark(Integer.MAX_VALUE);

            // determine the type of the response document
            final Header responseContentType = method.getResponseHeader("Content-Type");

            final MimeType responseMimeType = getResponseMimeType(responseContentType);
            if (responseContentType != null) {
                builder.addAttribute(new QName("mimetype", null, null), responseContentType.getValue());
            }

            //try and parse the response as XML
            try {
                //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);
                responseNode = (NodeImpl) ModuleUtils.streamToXML(context, shieldedInputStream);
                builder.addAttribute(new QName("type", null, null), "xml");
                responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
            } catch (final SAXException se) {
                // could not parse to xml
                // not an error in itself, it will be treated either as HTML,
                // text or binary here below
                final String msg = "Request for URI '" + method.getURI().toString()
                        + "' Could not parse http response content as XML (will try html, text or fallback to binary): "
                        + se.getMessage();
                if (logger.isDebugEnabled()) {
                    logger.debug(msg, se);
                } else {
                    logger.info(msg);
                }
            } catch (final IOException ioe) {
                final String msg = "Request for URI '" + method.getURI().toString()
                        + "' Could not read http response content: " + ioe.getMessage();
                logger.error(msg, ioe);
                throw new XPathException(msg, ioe);
            }

            if (responseNode == null) {
                //response is NOT parseable as XML

                //is it a html document?
                if (responseMimeType.getName().equals(MimeType.HTML_TYPE.getName())) {

                    //html document
                    try {

                        //reset the stream to the start, as we need to reuse since attempting to parse to XML
                        cfis.reset();

                        //parse html to xml(html)

                        //we have to use CloseShieldInputStream otherwise the parser closes the stream and we cant later reread
                        final InputStream shieldedInputStream = new CloseShieldInputStream(cfis);

                        responseNode = (NodeImpl) ModuleUtils
                                .htmlToXHtml(context, method.getURI().toString(),
                                        new InputSource(shieldedInputStream), parserFeatures, parserProperties)
                                .getDocumentElement();
                        builder.addAttribute(new QName("type", null, null), "xhtml");
                        responseNode.copyTo(null, new DocumentBuilderReceiver(builder));
                    } catch (final URIException ue) {
                        throw new XPathException(this, ue.getMessage(), ue);
                    } catch (final SAXException se) {
                        //could not parse to xml(html)
                        logger.debug(
                                "Could not parse http response content from HTML to XML: " + se.getMessage(),
                                se);
                    }
                }
            }

            if (responseNode == null) {

                //reset the stream to the start, as we need to reuse since attempting to parse to HTML->XML
                cfis.reset();

                if (responseMimeType.getName().startsWith("text/")) {

                    // Assume it's a text body and URL encode it
                    builder.addAttribute(new QName("type", null, null), "text");
                    builder.addAttribute(new QName("encoding", null, null), "URLEncoded");

                    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    final byte buf[] = new byte[4096];
                    int read = -1;
                    while ((read = cfis.read(buf)) > -1) {
                        baos.write(buf);
                    }

                    builder.characters(URLEncoder.encode(EncodingUtil.getString(baos.toByteArray(),
                            ((HttpMethodBase) method).getResponseCharSet()), "UTF-8"));
                    baos.close();
                } else {

                    // Assume it's a binary body and Base64 encode it
                    builder.addAttribute(new QName("type", null, null), "binary");
                    builder.addAttribute(new QName("encoding", null, null), "Base64Encoded");

                    BinaryValue binary = null;
                    try {
                        binary = BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(),
                                cfis);
                        builder.characters(binary.getStringValue());
                    } finally {
                        // free resources
                        if (binary != null) {
                            binary.destroy(context, null);
                        }
                    }
                }
            }
        } finally {
            if (cache != null) {
                try {
                    cache.invalidate();
                } catch (final IOException ioe) {
                    LOG.error(ioe.getMessage(), ioe);
                }
            }

            if (cfis != null) {
                try {
                    cfis.close();
                } catch (final IOException ioe) {
                    LOG.error(ioe.getMessage(), ioe);
                }
            }
        }
    }
}

From source file:org.exist.xquery.modules.xslfo.RenderFunction.java

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    // gather input XSL-FO document
    // if no input document (empty), return empty result as we need data to
    // process/*from   ww w  .j av a2 s.c  o m*/
    if (args[0].isEmpty()) {
        return Sequence.EMPTY_SEQUENCE;
    }

    Item inputNode = args[0].itemAt(0);

    // get mime-type
    String mimeType = args[1].getStringValue();

    // get parameters
    Properties parameters = new Properties();
    if (!args[2].isEmpty()) {
        parameters = ModuleUtils.parseParameters(((NodeValue) args[2].itemAt(0)).getNode());
    }

    ProcessorAdapter adapter = null;
    try {
        adapter = ((XSLFOModule) getParentModule()).getProcessorAdapter();

        NodeValue configFile = args.length == 4 ? (NodeValue) args[3].itemAt(0) : null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        ContentHandler contentHandler = adapter.getContentHandler(context.getBroker(), configFile, parameters,
                mimeType, baos);

        // process the XSL-FO
        contentHandler.startDocument();
        inputNode.toSAX(context.getBroker(), contentHandler, new Properties());
        contentHandler.endDocument();

        // return the result
        return BinaryValueFromInputStream.getInstance(context, new Base64BinaryValueType(),
                new ByteArrayInputStream(baos.toByteArray()));
    } catch (SAXException se) {
        throw new XPathException(this, se.getMessage(), se);
    } finally {
        if (adapter != null) {
            adapter.cleanup();
        }
    }
}

From source file:org.extensiblecatalog.ncip.v2.aleph.AlephLookupItemService.java

/**
 * Handles a NCIP LookupItem service by returning data from Aleph.
 *
 * @param initData//  www  .  j a  va 2 s  . c  o  m
 *            the LookupItemInitiationData
 * @param serviceManager
 *            provides access to remote services
 * @return LookupItemResponseData
 */
@Override
public LookupItemResponseData performService(LookupItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final LookupItemResponseData responseData = new LookupItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId().getItemIdentifierValue().isEmpty();

    if (itemIdIsEmpty) {

        Problem p = new Problem(new ProblemType("Item id is undefined."), null, null);
        responseData.setProblems(Arrays.asList(p));

    } else {

        AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager;

        try {
            AlephItem alephItem = alephRemoteServiceManager.lookupItem(initData);

            // update NCIP response data with aleph item data
            if (alephItem != null) {
                updateResponseData(initData, responseData, alephItem);
            } else {
                Problem p = new Problem(Version1LookupItemProcessingError.UNKNOWN_ITEM, "",
                        "Item " + initData.getItemId().getItemIdentifierValue() + " was not found.");
                responseData.setProblems(Arrays.asList(p));
            }

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (AlephException ae) {
            Problem p = new Problem(new ProblemType(ae.getShortMessage()), null, ae.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.aleph.AlephLookupUserService.java

@Override
public LookupUserResponseData performService(LookupUserInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final LookupUserResponseData responseData = new LookupUserResponseData();

    String patronId = null;//  w  w w . j  a  v a 2  s  . c  o m
    String password = null;
    boolean authenticationIncluded = false;

    if (initData.getUserId() != null)
        patronId = initData.getUserId().getUserIdentifierValue();
    else {
        for (AuthenticationInput authInput : initData.getAuthenticationInputs()) {
            if (authInput.getAuthenticationInputType().getValue()
                    .equals(Version1AuthenticationInputType.USER_ID.getValue())) {
                patronId = authInput.getAuthenticationInputData();
            } else if (authInput.getAuthenticationInputType().getValue()
                    .equals(Version1AuthenticationInputType.PASSWORD.getValue())) {
                password = authInput.getAuthenticationInputData();
            }
        }
        authenticationIncluded = true;
    }

    boolean userIdIsEmpty = patronId.isEmpty();
    boolean authIsSetAndPwIsEmpty = initData.getAuthenticationInputs() != null
            && initData.getAuthenticationInputs().size() > 0 && (password == null || password.isEmpty());

    if (userIdIsEmpty || authIsSetAndPwIsEmpty) {
        List<Problem> problems = new ArrayList<Problem>();

        if (!authenticationIncluded) {

            Problem p = new Problem(new ProblemType("User Id is undefined."), null, null,
                    "Element UserIdentifierValue is empty.");
            problems.add(p);

        } else {
            if (userIdIsEmpty) {

                Problem p = new Problem(new ProblemType("User Id is undefined."), null, null,
                        "Set AuthenticationInputType to \"" + Version1AuthenticationInputType.USER_ID.getValue()
                                + "\" to specify user id input.");
                problems.add(p);

            }
            if (authIsSetAndPwIsEmpty) {

                Problem p = new Problem(new ProblemType("Password is undefined."), null,
                        "Can't authenticate without password specified.",
                        "Set AuthenticationInputType to \""
                                + Version1AuthenticationInputType.PASSWORD.getValue()
                                + "\" to specify password input.");
                problems.add(p);

            }
        }

        responseData.setProblems(problems);
    } else {

        if (authenticationIncluded) {
            // Just authenticate patronId with password input through X-Services ..

            AgencyId suppliedAgencyId;

            AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager;

            if (initData.getInitiationHeader() != null
                    && initData.getInitiationHeader().getToAgencyId() != null)
                suppliedAgencyId = initData.getInitiationHeader().getToAgencyId().getAgencyId();
            else
                suppliedAgencyId = new AgencyId(alephRemoteServiceManager.getDefaultAgencyId());

            try {

                String username = alephRemoteServiceManager.authenticateUser(suppliedAgencyId, patronId,
                        password);

                // Later is UserId from initData copied to responseData - we need to overwrite AuthInputs
                initData.setUserId(createUserId(suppliedAgencyId, username));

                AlephRestDlfUser alephUser = alephRemoteServiceManager.lookupUser(username, initData);

                updateResponseData(initData, responseData, alephUser, alephRemoteServiceManager);

            } catch (IOException ie) {
                Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                        "Are you connected to the Internet/Intranet?");
                responseData.setProblems(Arrays.asList(p));
            } catch (SAXException se) {
                Problem p = new Problem(new ProblemType("Processing SAXException error."), null,
                        se.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (AlephException ae) {
                Problem p = new Problem(new ProblemType("Processing AlephException error."), null,
                        ae.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (ParserConfigurationException pce) {
                Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                        pce.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (Exception e) {
                Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                        StringUtils.join(e.getStackTrace(), "\n"));
                responseData.setProblems(Arrays.asList(p));
            }
        } else {
            // Regular lookup User ..

            AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager;

            AlephRestDlfUser alephUser = null;
            try {
                alephUser = alephRemoteServiceManager.lookupUser(patronId, initData);

                updateResponseData(initData, responseData, alephUser, alephRemoteServiceManager);
            } catch (MalformedURLException mue) {
                Problem p = new Problem(new ProblemType("Processing MalformedURLException error."), null,
                        mue.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (IOException ie) {
                Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                        "Are you connected to the Internet/Intranet?");
                responseData.setProblems(Arrays.asList(p));
            } catch (SAXException se) {
                Problem p = new Problem(new ProblemType("Processing SAXException error."), null,
                        se.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (AlephException ae) {
                Problem p = new Problem(new ProblemType("Processing AlephException error."), null,
                        ae.getMessage());
                responseData.setProblems(Arrays.asList(p));
            } catch (Exception e) {
                Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                        e.getMessage());
                responseData.setProblems(Arrays.asList(p));
            }
        }
    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.aleph.AlephRenewItemService.java

@Override
public RenewItemResponseData performService(RenewItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final RenewItemResponseData responseData = new RenewItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId() == null
            || initData.getItemId().getItemIdentifierValue().isEmpty();
    boolean userIdIsEmpty = initData.getUserId() == null
            || initData.getUserId().getUserIdentifierValue().isEmpty();

    if (itemIdIsEmpty || userIdIsEmpty) {

        List<Problem> problems = new ArrayList<Problem>();

        if (itemIdIsEmpty) {

            Problem p = new Problem(new ProblemType("Item id is undefined."), null, null,
                    "Cannot renew unknown item.");
            problems.add(p);//from ww  w  .  j av a  2 s  .  c  o  m

        }
        if (userIdIsEmpty) {

            Problem p = new Problem(new ProblemType("User Id is undefined."), null, null,
                    "Cannot renew item for unknown user.");
            problems.add(p);

        }
        responseData.setProblems(problems);

    } else {

        AlephRemoteServiceManager alephRemoteServiceManager = (AlephRemoteServiceManager) serviceManager;

        try {
            AlephRenewItem renewItem = alephRemoteServiceManager.renewItem(initData);

            if (renewItem.getProblem() == null) {
                updateResponseData(responseData, initData, renewItem);
            } else
                responseData.setProblems(Arrays.asList(renewItem.getProblem()));

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (AlephException ae) {
            Problem p = new Problem(new ProblemType("Processing AlephException error."), null, ae.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.koha.KohaLookupItemService.java

/**
 * Handles a NCIP LookupItem service by returning data from Koha.
 *
 * @param initData// w  w  w  .  j a  v a2 s  . c  o m
 *            the LookupItemInitiationData
 * @param serviceManager
 *            provides access to remote services
 * @return LookupItemResponseData
 */
@Override
public LookupItemResponseData performService(LookupItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final LookupItemResponseData responseData = new LookupItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId().getItemIdentifierValue().isEmpty();

    if (itemIdIsEmpty) {

        Problem p = new Problem(new ProblemType("Item id is undefined."), null, null);
        responseData.setProblems(Arrays.asList(p));

    } else {

        KohaRemoteServiceManager kohaRemoteServiceManager = (KohaRemoteServiceManager) serviceManager;

        try {
            JSONObject kohaItem = kohaRemoteServiceManager.lookupItem(initData);
            updateResponseData(initData, responseData, kohaItem);

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (KohaException ke) {
            Problem p = new Problem(new ProblemType(ke.getShortMessage()), null, ke.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.koha.KohaLookupUserService.java

@Override
public ILSDIvOneOneLookupUserResponseData performService(ILSDIvOneOneLookupUserInitiationData initData,
        ServiceContext serviceContext, RemoteServiceManager serviceManager) throws ServiceException {

    final ILSDIvOneOneLookupUserResponseData responseData = new ILSDIvOneOneLookupUserResponseData();

    KohaRemoteServiceManager kohaRemoteServiceManager = (KohaRemoteServiceManager) serviceManager;

    try {/*from ww  w . j  a  v a 2 s.c o  m*/

        boolean authenticated = false;
        if (initData.getAuthenticationInputs() != null && initData.getAuthenticationInputs().size() > 1) {
            processAuthInput(initData, kohaRemoteServiceManager, responseData);
            authenticated = true;
        }

        if (desiredAnything(initData)) {
            if (initData.getUserId() == null
                    || initData.getUserId().getUserIdentifierValue().trim().isEmpty()) {
                responseData.setProblems(Arrays.asList(new Problem(new ProblemType("UserId is undefined."),
                        null, null, "Cannot lookup unkown user ..")));
            } else {
                JSONObject kohaUser = kohaRemoteServiceManager.lookupUser(initData);
                updateResponseData(initData, responseData, kohaUser, kohaRemoteServiceManager);
            }
        } else if (authenticated)
            responseData.setUserId(initData.getUserId());
        else
            throw KohaException.create400BadRequestException("You have not desired anything processable");

    } catch (MalformedURLException mue) {
        Problem p = new Problem(new ProblemType("Processing MalformedURLException error."), null,
                mue.getMessage());
        responseData.setProblems(Arrays.asList(p));
    } catch (IOException ie) {
        Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                "Are you connected to the Internet/Intranet?");
        responseData.setProblems(Arrays.asList(p));
    } catch (SAXException se) {
        Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
        responseData.setProblems(Arrays.asList(p));
    } catch (KohaException ke) {
        Problem p = new Problem(new ProblemType(ke.getShortMessage()), null, ke.getMessage());
        responseData.setProblems(Arrays.asList(p));
    } catch (Exception e) {
        Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                StringUtils.join(e.getStackTrace(), "\n"));
        responseData.setProblems(Arrays.asList(p));

    }
    return responseData;
}

From source file:org.extensiblecatalog.ncip.v2.koha.KohaRenewItemService.java

@Override
public RenewItemResponseData performService(RenewItemInitiationData initData, ServiceContext serviceContext,
        RemoteServiceManager serviceManager) throws ServiceException {

    final RenewItemResponseData responseData = new RenewItemResponseData();

    boolean itemIdIsEmpty = initData.getItemId() == null
            || initData.getItemId().getItemIdentifierValue().isEmpty();
    boolean userIdIsEmpty = initData.getUserId() == null
            || initData.getUserId().getUserIdentifierValue().isEmpty();

    if (itemIdIsEmpty || userIdIsEmpty) {

        List<Problem> problems = new ArrayList<Problem>();

        if (itemIdIsEmpty) {

            Problem p = new Problem(new ProblemType("Item id is undefined."), null, null,
                    "Cannot renew unknown item.");
            problems.add(p);/* w  ww  . j a v  a  2  s .c o  m*/

        }
        if (userIdIsEmpty) {

            Problem p = new Problem(new ProblemType("User Id is undefined."), null, null,
                    "Cannot renew item for unknown user.");
            problems.add(p);

        }
        responseData.setProblems(problems);

    } else {

        KohaRemoteServiceManager kohaRemoteServiceManager = (KohaRemoteServiceManager) serviceManager;

        try {
            JSONObject renewItem = kohaRemoteServiceManager.renewItem(initData);

            updateResponseData(responseData, initData, renewItem);

        } catch (IOException ie) {
            Problem p = new Problem(new ProblemType("Processing IOException error."), ie.getMessage(),
                    "Are you connected to the Internet/Intranet?");
            responseData.setProblems(Arrays.asList(p));
        } catch (SAXException se) {
            Problem p = new Problem(new ProblemType("Processing SAXException error."), null, se.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (KohaException ke) {
            Problem p = new Problem(new ProblemType(ke.getShortMessage()), null, ke.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (ParserConfigurationException pce) {
            Problem p = new Problem(new ProblemType("Processing ParserConfigurationException error."), null,
                    pce.getMessage());
            responseData.setProblems(Arrays.asList(p));
        } catch (Exception e) {
            Problem p = new Problem(new ProblemType("Unknown processing exception error."), null,
                    StringUtils.join(e.getStackTrace(), "\n"));
            responseData.setProblems(Arrays.asList(p));
        }
    }
    return responseData;
}

From source file:org.fcrepo.server.security.xacml.pdp.data.FedoraPolicyStore.java

@Override
public void init() throws PolicyStoreException, FileNotFoundException {
    if (log.isDebugEnabled()) {
        Runtime runtime = Runtime.getRuntime();
        log.debug("Total memory: " + runtime.totalMemory() / 1024);
        log.debug("Free memory: " + runtime.freeMemory() / 1024);
        log.debug("Max memory: " + runtime.maxMemory() / 1024);
    }//  w w w  . ja va 2 s .  co  m
    super.init();
    // if no pid namespace was specified, use the default specified in fedora.fcfg
    if (pidNamespace.equals("")) {
        pidNamespace = fedoraServer.getModule("org.fcrepo.server.storage.DOManager")
                .getParameter("pidNamespace");
    }

    // check control group was supplied
    if (datastreamControlGroup.equals("")) {
        throw new PolicyStoreException(
                "No control group for policy datastreams was specified in FedoraPolicyStore configuration");
    }
    if (validateSchema) {
        String schemaLocation = schemaLocations.get(XACML20_POLICY_NS);
        if (schemaLocation == null) {
            throw new PolicyStoreException("Configuration error - no policy schema specified");
        }
        try {
            String serverHome = fedoraServer.getHomeDir().getCanonicalPath() + File.separator;

            String schemaPath = ((schemaLocation).startsWith(File.separator) ? "" : serverHome)
                    + schemaLocation;
            FileInputStream in = new FileInputStream(schemaPath);
            PolicyParser policyParser = new PolicyParser(in);
            ValidationUtility.setFeslPolicyParser(policyParser);
        } catch (IOException ioe) {
            throw new PolicyStoreException(ioe.getMessage(), ioe);
        } catch (SAXException se) {
            throw new PolicyStoreException(se.getMessage(), se);
        }
    }
}