Search in sources :

Example 6 with PostConstruct

use of jakarta.annotation.PostConstruct in project devspaces-images by redhat-developer.

the class AdminPermissionInitializer method init.

@PostConstruct
public void init() throws ServerException {
    try {
        User adminUser = userManager.getByName(name);
        grantSystemPermissions(adminUser.getId());
    } catch (NotFoundException ex) {
        LOG.warn("Admin {} not found yet.", name);
    } finally {
        eventService.subscribe(this);
    }
}
Also used : User(org.eclipse.che.api.core.model.user.User) NotFoundException(org.eclipse.che.api.core.NotFoundException) PostConstruct(jakarta.annotation.PostConstruct)

Example 7 with PostConstruct

use of jakarta.annotation.PostConstruct in project today-infrastructure by TAKETODAY.

the class DefaultUserRepository method initData.

@PostConstruct
public void initData() {
    log.info("init data: [{}]", this);
    users.put("666", new User(1, "Harry Yang", 20, "666", "666", "男", new Date()));
    users.put("6666", new User(2, "Harry Yang1", 20, "6666", "6666", "男", new Date()));
    users.put("66666", new User(3, "Harry Yang2", 20, "66666", "66666", "男", new Date()));
    users.put("666666", new User(4, "Harry Yang3", 20, "666666", "666666", "男", new Date()));
}
Also used : User(test.demo.config.User) Date(java.util.Date) PostConstruct(jakarta.annotation.PostConstruct)

Example 8 with PostConstruct

use of jakarta.annotation.PostConstruct in project eclipselink by eclipse-ee4j.

the class InitSingleton method init.

@PostConstruct
public void init() {
    LOGGER.info("\n********** init() called **********\n");
    try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        URL url = cl.getResource("org/eclipse/persistence/testing/sdo/server/Dept.xsd");
        String path = url.toExternalForm();
        SDOHelperContext.getHelperContext().getXSDHelper().define(url.openStream(), path.substring(0, path.lastIndexOf('/') + 1));
        LOGGER.info("\n********** initialized **********\n");
    } catch (Exception e) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("init() failed with error: " + e.getMessage());
        }
        e.printStackTrace();
        throw new DeptServiceInitException(e);
    }
}
Also used : URL(java.net.URL) PostConstruct(jakarta.annotation.PostConstruct)

Example 9 with PostConstruct

use of jakarta.annotation.PostConstruct in project metro-jax-ws by eclipse-ee4j.

the class HandlerChainsModel method parseHandlerFile.

/**
 * <p>This method is called internally by HandlerAnnotationProcessor,
 * and by
 * {@link com.sun.xml.ws.transport.http.DeploymentDescriptorParser}
 * directly when it reaches the handler chains element in the
 * descriptor file it is parsing.
 * @param reader should be on &lt;handler-chains&gt; element
 * @return A HandlerAnnotationInfo object that stores the
 * handlers and roles.
 */
public static HandlerAnnotationInfo parseHandlerFile(XMLStreamReader reader, ClassLoader classLoader, QName serviceName, QName portName, WSBinding wsbinding) {
    ensureProperName(reader, QNAME_HANDLER_CHAINS);
    String bindingId = wsbinding.getBindingId().toString();
    HandlerAnnotationInfo info = new HandlerAnnotationInfo();
    XMLStreamReaderUtil.nextElementContent(reader);
    List<Handler> handlerChain = new ArrayList<>();
    Set<String> roles = new HashSet<>();
    while (reader.getName().equals(QNAME_HANDLER_CHAIN)) {
        XMLStreamReaderUtil.nextElementContent(reader);
        if (reader.getName().equals(QNAME_CHAIN_PORT_PATTERN)) {
            if (portName == null) {
                logger.warning("handler chain sepcified for port " + "but port QName passed to parser is null");
            }
            boolean parseChain = JAXWSUtils.matchQNames(portName, XMLStreamReaderUtil.getElementQName(reader));
            if (!parseChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        } else if (reader.getName().equals(QNAME_CHAIN_PROTOCOL_BINDING)) {
            if (bindingId == null) {
                logger.warning("handler chain sepcified for bindingId " + "but bindingId passed to parser is null");
            }
            String bindingConstraint = XMLStreamReaderUtil.getElementText(reader);
            boolean skipThisChain = true;
            StringTokenizer stk = new StringTokenizer(bindingConstraint);
            List<String> bindingList = new ArrayList<>();
            while (stk.hasMoreTokens()) {
                String tokenOrURI = stk.nextToken();
                /*
                    Convert short-form tokens to API's binding ids
                    Unknown token, Put it as it is
                    */
                tokenOrURI = DeploymentDescriptorParser.getBindingIdForToken(tokenOrURI);
                String binding = BindingID.parse(tokenOrURI).toString();
                bindingList.add(binding);
            }
            if (bindingList.contains(bindingId)) {
                skipThisChain = false;
            }
            if (skipThisChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        } else if (reader.getName().equals(QNAME_CHAIN_SERVICE_PATTERN)) {
            if (serviceName == null) {
                logger.warning("handler chain sepcified for service " + "but service QName passed to parser is null");
            }
            boolean parseChain = JAXWSUtils.matchQNames(serviceName, XMLStreamReaderUtil.getElementQName(reader));
            if (!parseChain) {
                skipChain(reader);
                continue;
            }
            XMLStreamReaderUtil.nextElementContent(reader);
        }
        // process all <handler> elements
        while (reader.getName().equals(QNAME_HANDLER)) {
            Handler handler;
            XMLStreamReaderUtil.nextContent(reader);
            if (reader.getName().equals(QNAME_HANDLER_NAME)) {
                skipTextElement(reader);
            }
            // handler class
            ensureProperName(reader, QNAME_HANDLER_CLASS);
            try {
                handler = (Handler) loadClass(classLoader, XMLStreamReaderUtil.getElementText(reader).trim()).newInstance();
            } catch (InstantiationException | IllegalAccessException ie) {
                throw new RuntimeException(ie);
            }
            XMLStreamReaderUtil.nextContent(reader);
            // init params (ignored)
            while (reader.getName().equals(QNAME_HANDLER_PARAM)) {
                skipInitParamElement(reader);
            }
            // headers (ignored)
            while (reader.getName().equals(QNAME_HANDLER_HEADER)) {
                skipTextElement(reader);
            }
            // roles (not stored per handler)
            while (reader.getName().equals(QNAME_HANDLER_ROLE)) {
                roles.add(XMLStreamReaderUtil.getElementText(reader));
                XMLStreamReaderUtil.nextContent(reader);
            }
            // call @PostConstruct method on handler if present
            for (Method method : handler.getClass().getMethods()) {
                if (method.getAnnotation(PostConstruct.class) == null) {
                    continue;
                }
                try {
                    method.invoke(handler);
                    break;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            handlerChain.add(handler);
            // move past </handler>
            ensureProperName(reader, QNAME_HANDLER);
            XMLStreamReaderUtil.nextContent(reader);
        }
        // move past </handler-chain>
        ensureProperName(reader, QNAME_HANDLER_CHAIN);
        XMLStreamReaderUtil.nextContent(reader);
    }
    info.setHandlers(handlerChain);
    info.setRoles(roles);
    return info;
}
Also used : ArrayList(java.util.ArrayList) Handler(jakarta.xml.ws.handler.Handler) Method(java.lang.reflect.Method) UtilException(com.sun.xml.ws.util.UtilException) HandlerAnnotationInfo(com.sun.xml.ws.util.HandlerAnnotationInfo) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) List(java.util.List) PostConstruct(jakarta.annotation.PostConstruct) HashSet(java.util.HashSet)

Example 10 with PostConstruct

use of jakarta.annotation.PostConstruct in project spring-batch by spring-projects.

the class DefaultBatchConfigurer method initialize.

@PostConstruct
public void initialize() {
    try {
        this.jobRepository = createJobRepository();
        this.jobExplorer = createJobExplorer();
        this.jobLauncher = createJobLauncher();
    } catch (Exception e) {
        throw new BatchConfigurationException(e);
    }
}
Also used : BatchConfigurationException(org.springframework.batch.core.configuration.BatchConfigurationException) BatchConfigurationException(org.springframework.batch.core.configuration.BatchConfigurationException) PostConstruct(jakarta.annotation.PostConstruct)

Aggregations

PostConstruct (jakarta.annotation.PostConstruct)76 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 IOException (java.io.IOException)6 Date (java.util.Date)6 PostBean (it.vige.rubia.dto.PostBean)4 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)4 ArrayList (java.util.ArrayList)4 ForumBean (it.vige.rubia.dto.ForumBean)3 FacesContext (jakarta.faces.context.FacesContext)3 Method (java.lang.reflect.Method)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)2 HTTPServer (io.prometheus.client.exporter.HTTPServer)2 ModuleException (it.vige.rubia.ModuleException)2 CategoryBean (it.vige.rubia.dto.CategoryBean)2 TopicBean (it.vige.rubia.dto.TopicBean)2 SessionScoped (jakarta.enterprise.context.SessionScoped)2 Typed (jakarta.enterprise.inject.Typed)2 ClientWindow (jakarta.faces.lifecycle.ClientWindow)2 Serializable (java.io.Serializable)2