Search in sources :

Example 21 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class CasVersion method getDateTime.

/**
 * Gets last modified date/time for the module.
 *
 * @return the date/time
 */
@SneakyThrows
public static ZonedDateTime getDateTime() {
    final Class clazz = CasVersion.class;
    final URL resource = clazz.getResource(clazz.getSimpleName() + ".class");
    if ("file".equals(resource.getProtocol())) {
        return DateTimeUtils.zonedDateTimeOf(new File(resource.toURI()).lastModified());
    }
    if ("jar".equals(resource.getProtocol())) {
        final String path = resource.getPath();
        final File file = new File(path.substring(5, path.indexOf('!')));
        return DateTimeUtils.zonedDateTimeOf(file.lastModified());
    }
    if ("vfs".equals(resource.getProtocol())) {
        final File file = new VfsResource(resource.openConnection().getContent()).getFile();
        return DateTimeUtils.zonedDateTimeOf(file.lastModified());
    }
    LOGGER.warn("Unhandled url protocol: [{}] resource: [{}]", resource.getProtocol(), resource);
    return ZonedDateTime.now();
}
Also used : UtilityClass(lombok.experimental.UtilityClass) VfsResource(org.springframework.core.io.VfsResource) File(java.io.File) URL(java.net.URL) SneakyThrows(lombok.SneakyThrows)

Example 22 with SneakyThrows

use of lombok.SneakyThrows in project admin-console-beta by connexta.

the class GraphQLServlet method query.

private void query(String query, String operationName, Map<String, Object> variables, GraphQLSchema schema, HttpServletRequest req, HttpServletResponse resp, GraphQLContext context) throws IOException {
    if (Subject.getSubject(AccessController.getContext()) == null && context.getSubject().isPresent()) {
        Subject.doAs(context.getSubject().get(), new PrivilegedAction<Void>() {

            @Override
            @SneakyThrows
            public Void run() {
                query(query, operationName, variables, schema, req, resp, context);
                return null;
            }
        });
    } else {
        runListeners(operationListeners, l -> runListener(l, it -> it.beforeGraphQLOperation(context, operationName, query, variables)));
        ExecutionResult executionResult = new GraphQL(schema, getQueryExecutionStrategy(), getMutationExecutionStrategy()).execute(query, operationName, context, transformVariables(schema, query, variables));
        List<GraphQLError> errors = executionResult.getErrors();
        Object data = executionResult.getData();
        String response = mapper.writeValueAsString(createResultFromDataAndErrors(data, errors));
        resp.setContentType(APPLICATION_JSON_UTF8);
        resp.setStatus(STATUS_OK);
        resp.getWriter().write(response);
        if (errorsPresent(errors)) {
            runListeners(operationListeners, l -> l.onFailedGraphQLOperation(context, operationName, query, variables, data, errors));
        } else {
            runListeners(operationListeners, l -> l.onSuccessfulGraphQLOperation(context, operationName, query, variables, data));
        }
    }
}
Also used : InvalidSyntaxError(graphql.InvalidSyntaxError) Setter(lombok.Setter) GraphQL(graphql.GraphQL) ExecutionStrategy(graphql.execution.ExecutionStrategy) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) ServletException(javax.servlet.ServletException) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExecutionResult(graphql.ExecutionResult) HttpServletRequest(javax.servlet.http.HttpServletRequest) CharStreams(com.google.common.io.CharStreams) GraphQLError(graphql.GraphQLError) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) GraphQLSchema(graphql.schema.GraphQLSchema) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) RuntimeJsonMappingException(com.fasterxml.jackson.databind.RuntimeJsonMappingException) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) PrivilegedAction(java.security.PrivilegedAction) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Subject(javax.security.auth.Subject) Consumer(java.util.function.Consumer) ValidationError(graphql.validation.ValidationError) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Part(javax.servlet.http.Part) Optional(java.util.Optional) AccessController(java.security.AccessController) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) InputStream(java.io.InputStream) GraphQL(graphql.GraphQL) SneakyThrows(lombok.SneakyThrows) GraphQLError(graphql.GraphQLError) ExecutionResult(graphql.ExecutionResult)

Example 23 with SneakyThrows

use of lombok.SneakyThrows in project spring-data-mongodb by spring-projects.

the class ResultsWriter method jsonifyResults.

/**
 * Convert {@link RunResult}s to JMH Json representation.
 *
 * @param results
 * @return json string representation of results.
 * @see org.openjdk.jmh.results.format.JSONResultFormat
 */
@SneakyThrows
static String jsonifyResults(Collection<RunResult> results) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ResultFormatFactory.getInstance(ResultFormatType.JSON, new PrintStream(baos, true, "UTF-8")).writeOut(results);
    return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SneakyThrows(lombok.SneakyThrows)

Example 24 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class SamlIdPMetadataConfiguration method samlSelfSignedCertificateWriter.

@ConditionalOnMissingBean(name = "samlSelfSignedCertificateWriter")
@Bean
@SneakyThrows
public SamlIdPCertificateAndKeyWriter samlSelfSignedCertificateWriter() {
    final URL url = new URL(casProperties.getServer().getPrefix());
    final DefaultSamlIdPCertificateAndKeyWriter generator = new DefaultSamlIdPCertificateAndKeyWriter();
    generator.setHostname(url.getHost());
    generator.setUriSubjectAltNames(CollectionUtils.wrap(url.getHost().concat("/idp/metadata")));
    return generator;
}
Also used : DefaultSamlIdPCertificateAndKeyWriter(org.apereo.cas.support.saml.idp.metadata.writer.DefaultSamlIdPCertificateAndKeyWriter) URL(java.net.URL) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) SneakyThrows(lombok.SneakyThrows) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) OpenSamlConfigBean(org.apereo.cas.support.saml.OpenSamlConfigBean) Bean(org.springframework.context.annotation.Bean)

Example 25 with SneakyThrows

use of lombok.SneakyThrows in project cas by apereo.

the class AbstractSamlObjectBuilder method newSoapObject.

/**
 * New soap object t.
 *
 * @param <T>        the type parameter
 * @param objectType the object type
 * @return the t
 */
@SneakyThrows
public <T extends SOAPObject> T newSoapObject(final Class<T> objectType) {
    final QName qName = getSamlObjectQName(objectType);
    final SOAPObjectBuilder<T> builder = (SOAPObjectBuilder<T>) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName);
    if (builder == null) {
        throw new IllegalStateException("No SAML object builder is registered for class " + objectType.getName());
    }
    return objectType.cast(builder.buildObject(qName));
}
Also used : SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder) QName(javax.xml.namespace.QName) SneakyThrows(lombok.SneakyThrows)

Aggregations

SneakyThrows (lombok.SneakyThrows)592 lombok.val (lombok.val)292 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)59 HashMap (java.util.HashMap)51 List (java.util.List)42 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 LinkedHashMap (java.util.LinkedHashMap)29 File (java.io.File)27 Collectors (java.util.stream.Collectors)25 Path (java.nio.file.Path)24 IOException (java.io.IOException)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 URL (java.net.URL)20 Slf4j (lombok.extern.slf4j.Slf4j)20 InputStream (java.io.InputStream)19 Map (java.util.Map)19 Cleanup (lombok.Cleanup)17 FishingActivityQuery (eu.europa.ec.fisheries.ers.service.search.FishingActivityQuery)16 SearchFilter (eu.europa.ec.fisheries.uvms.activity.model.schemas.SearchFilter)16