Search in sources :

Example 1 with BatchProcessingException

use of net.idea.modbcum.i.exceptions.BatchProcessingException in project ambit-mirror by ideaconsult.

the class QueryResource method getRepresentation.

protected Representation getRepresentation(Variant variant) throws ResourceException {
    try {
        if (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
            if ((queryObject != null) && (queryObject instanceof Serializable))
                return new ObjectRepresentation((Serializable) returnQueryObject(), MediaType.APPLICATION_JAVA_OBJECT);
            else
                throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
        }
        if (MediaType.APPLICATION_JAVASCRIPT.equals(variant.getMediaType())) {
            if (!isJSONPEnabled())
                throw new ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
        }
        if (queryObject != null) {
            IProcessor<Q, Representation> convertor = null;
            Connection connection = null;
            int retry = 0;
            while (retry < maxRetry) {
                try {
                    DBConnection dbc = new DBConnection(getContext());
                    configureRDFWriterOption(((AmbitApplication) getApplication()).getProperties().getRDFwriter());
                    configureSDFLineSeparators(((AmbitApplication) getApplication()).getProperties().getConfigChangeLineSeparator());
                    configureDatasetMembersPrefixOption(((AmbitApplication) getApplication()).getProperties().isDatasetMembersPrefix());
                    convertor = createConvertor(variant);
                    if (convertor instanceof RepresentationConvertor)
                        ((RepresentationConvertor) convertor).setLicenseURI(getLicenseURI());
                    connection = dbc.getConnection();
                    Reporter reporter = ((RepresentationConvertor) convertor).getReporter();
                    if (reporter instanceof IDBProcessor)
                        ((IDBProcessor) reporter).setConnection(connection);
                    Representation r = convertor.process(queryObject);
                    r.setCharacterSet(CharacterSet.UTF_8);
                    return r;
                } catch (ResourceException x) {
                    throw x;
                } catch (NotFoundException x) {
                    Representation r = processNotFound(x, retry);
                    retry++;
                    if (r != null)
                        return r;
                } catch (BatchProcessingException x) {
                    if (x.getCause() instanceof NotFoundException) {
                        Representation r = processNotFound((NotFoundException) x.getCause(), retry);
                        retry++;
                        if (r != null)
                            return r;
                    } else {
                        Context.getCurrentLogger().severe(x.getMessage());
                        throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
                    }
                } catch (SQLException x) {
                    Representation r = processSQLError(x, retry, variant);
                    retry++;
                    if (r == null)
                        continue;
                    else
                        return r;
                } catch (Exception x) {
                    Context.getCurrentLogger().severe(x.getMessage());
                    throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
                } finally {
                // try { if (connection !=null) connection.close(); }
                // catch (Exception x) {};
                // try { if ((convertor !=null) &&
                // (convertor.getReporter() !=null))
                // convertor.getReporter().close(); } catch (Exception
                // x) {}
                }
            }
            return null;
        } else {
            if (variant.getMediaType().equals(MediaType.TEXT_HTML))
                try {
                    IProcessor<Q, Representation> convertor = createConvertor(variant);
                    Representation r = convertor.process(null);
                    return r;
                } catch (Exception x) {
                    throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x, variant);
                }
            else {
                throw new RResourceException(Status.CLIENT_ERROR_BAD_REQUEST, error, variant);
            }
        }
    } catch (RResourceException x) {
        throw x;
    } catch (ResourceException x) {
        throw new RResourceException(x.getStatus(), x, variant);
    } catch (Exception x) {
        throw new RResourceException(Status.SERVER_ERROR_INTERNAL, x, variant);
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) Serializable(java.io.Serializable) IDBProcessor(net.idea.modbcum.i.IDBProcessor) SQLException(java.sql.SQLException) Reporter(net.idea.modbcum.i.reporter.Reporter) QueryURIReporter(net.idea.restnet.db.QueryURIReporter) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) AmbitApplication(ambit2.rest.AmbitApplication) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) ObjectRepresentation(org.restlet.representation.ObjectRepresentation) Representation(org.restlet.representation.Representation) IProcessor(net.idea.modbcum.i.processors.IProcessor) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) RepresentationConvertor(net.idea.restnet.c.RepresentationConvertor) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) RResourceException(ambit2.rest.exception.RResourceException) ObjectRepresentation(org.restlet.representation.ObjectRepresentation)

Example 2 with BatchProcessingException

use of net.idea.modbcum.i.exceptions.BatchProcessingException in project ambit-mirror by ideaconsult.

the class AbstractResource method getRepresentation.

protected Representation getRepresentation(Variant variant) throws ResourceException {
    try {
        setTokenCookies(variant, useSecureCookie(getRequest()));
        setStatus(Status.SUCCESS_OK);
        if (MediaType.APPLICATION_JAVA_OBJECT.equals(variant.getMediaType())) {
            if ((queryObject != null) && (queryObject instanceof Serializable))
                return new ObjectRepresentation((Serializable) queryObject, MediaType.APPLICATION_JAVA_OBJECT);
            else
                throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE);
        }
        if (queryObject != null) {
            IProcessor<Q, Representation> convertor = null;
            try {
                getResponse().setStatus(response_status);
                convertor = createConvertor(variant);
                Representation r = convertor.process(queryObject);
                return r;
            } catch (NotFoundException x) {
                Representation r = processNotFound(x, variant);
                return r;
            } catch (BatchProcessingException x) {
                if (x.getCause() instanceof NotFoundException) {
                    Representation r = processNotFound((NotFoundException) x.getCause(), variant);
                    return r;
                } else {
                    getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, x);
                    return null;
                }
            } catch (RResourceException x) {
                getResponse().setStatus(x.getStatus());
                return x.getRepresentation();
            } catch (ResourceException x) {
                getResponse().setStatus(x.getStatus());
                return null;
            } catch (Exception x) {
                getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, x);
                return null;
            } finally {
            }
        } else {
            getResponse().setStatus(response_status == null ? Status.CLIENT_ERROR_BAD_REQUEST : response_status, error);
            return null;
        }
    } catch (Exception x) {
        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, x);
        return null;
    }
}
Also used : Serializable(java.io.Serializable) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) RResourceException(ambit2.rest.exception.RResourceException) ResourceException(org.restlet.resource.ResourceException) Representation(org.restlet.representation.Representation) ObjectRepresentation(org.restlet.representation.ObjectRepresentation) RResourceException(ambit2.rest.exception.RResourceException) ObjectRepresentation(org.restlet.representation.ObjectRepresentation) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) RResourceException(ambit2.rest.exception.RResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) ResourceException(org.restlet.resource.ResourceException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException)

Example 3 with BatchProcessingException

use of net.idea.modbcum.i.exceptions.BatchProcessingException in project ambit-mirror by ideaconsult.

the class ModelResource method readVariables.

protected void readVariables(ModelQueryResults model) throws ResourceException {
    ModelTemplates query = new ModelTemplates();
    query.setFieldname(model);
    QueryTemplateReporter<ModelTemplates> reporter = null;
    Connection connection = null;
    try {
        DBConnection dbc = new DBConnection(getContext());
        connection = dbc.getConnection();
        query.setValue("dependent");
        reporter = new QueryTemplateReporter<ModelTemplates>(model.getDependent());
        reporter.setCloseConnection(false);
        reporter.setConnection(connection);
        // dependent
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // this is ok
            } else
                throw x;
        }
        query.setValue("independent");
        reporter.setConnection(connection);
        reporter.setOutput(model.getPredictors());
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // this is ok
            } else
                throw x;
        }
        query.setValue("predicted");
        reporter.setConnection(connection);
        reporter.setOutput(model.getPredicted());
        try {
            reporter.process(query);
        } catch (BatchProcessingException x) {
            if (x.getCause() instanceof NotFoundException) {
            // ok, it may change the structure only
            } else
                throw x;
        }
    } catch (Exception x) {
        getLogger().log(Level.FINE, x.getMessage(), x);
    }
    try {
        reporter.setCloseConnection(true);
    } catch (Exception x) {
        getLogger().log(Level.WARNING, x.getMessage(), x);
    } finally {
        try {
            reporter.close();
        } catch (Exception x) {
        }
    }
    try {
        connection.close();
    } catch (Exception x) {
    }
}
Also used : DBConnection(ambit2.rest.DBConnection) ModelTemplates(ambit2.db.search.property.ModelTemplates) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) Connection(java.sql.Connection) DBConnection(ambit2.rest.DBConnection) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) ResourceException(org.restlet.resource.ResourceException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException)

Example 4 with BatchProcessingException

use of net.idea.modbcum.i.exceptions.BatchProcessingException in project ambit-mirror by ideaconsult.

the class ProfileReader method process.

/*
	 * (non-Javadoc)
	 * 
	 * @see ambit2.base.interfaces.IProcessor#process(java.lang.Object)
	 */
/*
	 * ambit2.base.exceptions.AmbitException: Communication Error (1001) -
	 * sun.security.validator.ValidatorException: PKIX path building failed:
	 * sun. security.provider.certpath.SunCertPathBuilderException: unable to
	 * find valid certification path to requested target at
	 * ambit2.rest.property.ProfileReader.process(ProfileReader.java:82) at
	 * ambit2.rest.query.StructureQueryResource.createTemplate(
	 * StructureQueryResource.java:147) at
	 * ambit2.rest.query.StructureQueryResource.createTemplate(
	 * StructureQueryResource.java:119) at
	 * ambit2.rest.query.StructureQueryResource.createTemplate(
	 * StructureQueryResource.java:115) at
	 * ambit2.rest.dataset.DatasetStructuresResource.createQuery(
	 * DatasetStructuresResource.java:39) at
	 * ambit2.rest.dataset.DatasetResource.createQuery(DatasetResource.java:188)
	 * at
	 * ambit2.rest.dataset.DatasetResource.createQuery(DatasetResource.java:55)
	 * at
	 */
@Override
public Template process(Reference uri) throws AmbitException {
    if (profile == null)
        setProfile(new Template());
    if (uri == null)
        return profile;
    Object q;
    try {
        q = CallableQueryProcessor.getQueryObject(uri, applicationReference, context, cookies == null ? null : cookies.toString(), agent, referer);
        if ((q != null) && (q instanceof AbstractPropertyRetrieval)) {
            try {
                reporter.setConnection(getConnection());
                reporter.process((AbstractPropertyRetrieval) q);
            } catch (NotFoundException x) {
            // this is ok
            } catch (BatchProcessingException x) {
                if (x.getCause() instanceof NotFoundException) {
                // ok
                } else
                    logger.log(Level.WARNING, x.getMessage(), x);
            } catch (Exception x) {
                logger.log(Level.WARNING, x.getMessage(), x);
            } finally {
                // the reporter closes the connection as well
                try {
                    // reporter.setCloseConnection(true); //the caller
                    // should decide!
                    reporter.close();
                } catch (Exception x) {
                }
            }
        }
        return profile;
    } catch (Exception x) {
        throw new AmbitException(x);
    } finally {
        q = null;
    }
}
Also used : AbstractPropertyRetrieval(ambit2.db.search.property.AbstractPropertyRetrieval) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) NotFoundException(net.idea.modbcum.i.exceptions.NotFoundException) BatchProcessingException(net.idea.modbcum.i.exceptions.BatchProcessingException) Template(ambit2.base.data.Template) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Aggregations

AmbitException (net.idea.modbcum.i.exceptions.AmbitException)4 BatchProcessingException (net.idea.modbcum.i.exceptions.BatchProcessingException)4 NotFoundException (net.idea.modbcum.i.exceptions.NotFoundException)4 ResourceException (org.restlet.resource.ResourceException)3 DBConnection (ambit2.rest.DBConnection)2 RResourceException (ambit2.rest.exception.RResourceException)2 Serializable (java.io.Serializable)2 Connection (java.sql.Connection)2 ObjectRepresentation (org.restlet.representation.ObjectRepresentation)2 Representation (org.restlet.representation.Representation)2 Template (ambit2.base.data.Template)1 ProcessorException (ambit2.base.processors.ProcessorException)1 AbstractPropertyRetrieval (ambit2.db.search.property.AbstractPropertyRetrieval)1 ModelTemplates (ambit2.db.search.property.ModelTemplates)1 AmbitApplication (ambit2.rest.AmbitApplication)1 SQLException (java.sql.SQLException)1 IDBProcessor (net.idea.modbcum.i.IDBProcessor)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1 IProcessor (net.idea.modbcum.i.processors.IProcessor)1 Reporter (net.idea.modbcum.i.reporter.Reporter)1