Search in sources :

Example 26 with PostConstruct

use of jakarta.annotation.PostConstruct in project starshop by beautautumn.

the class WxConfiguration method init.

@PostConstruct
public void init() {
    List<WxMiniAppProperties.Config> configs = this.properties.getConfigs();
    if (configs == null) {
        throw new RuntimeException("大哥,拜托先看下项目首页的说明(readme文件),添加下相关配置,注意别配错了!");
    }
    maServices = configs.stream().map(a -> {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(a.getAppid());
        config.setSecret(a.getSecret());
        config.setToken(a.getToken());
        config.setAesKey(a.getAesKey());
        config.setMsgDataFormat(a.getMsgDataFormat());
        WxMaService service = new WxMaServiceImpl();
        service.setWxMaConfig(config);
        routers.put(a.getAppid(), this.newRouter(service));
        return service;
    }).collect(Collectors.toMap(s -> s.getWxMaConfig().getAppid(), a -> a));
}
Also used : WxMaServiceImpl(cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl) WxMaService(cn.binarywang.wx.miniapp.api.WxMaService) WxMaDefaultConfigImpl(cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl) PostConstruct(jakarta.annotation.PostConstruct)

Example 27 with PostConstruct

use of jakarta.annotation.PostConstruct in project core by weld.

the class PopulateDatabase method startup.

@PostConstruct
public void startup() {
    try {
        String fileContent = readFileData(DATA_FILE_NAME);
        StringTokenizer st = new StringTokenizer(fileContent, "'");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        while (st.countTokens() > 1) {
            CodeFragment c = new CodeFragment();
            st.nextToken();
            c.setDatetime(formatter.parse(st.nextToken()));
            st.nextToken();
            c.setLanguage(Language.valueOf(st.nextToken()));
            st.nextToken();
            st.nextToken();
            st.nextToken();
            c.setUser(st.nextToken());
            st.nextToken();
            c.setText(st.nextToken());
            // Manual TX control, commit each record independently
            entityManager.persist(c);
        }
    } catch (Exception e) {
        log.log(Level.WARNING, "Unable to read all records from " + DATA_FILE_NAME + " file", e);
    }
    log.info("Successfully imported data!");
}
Also used : StringTokenizer(java.util.StringTokenizer) CodeFragment(org.jboss.weld.examples.pastecode.model.CodeFragment) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) PostConstruct(jakarta.annotation.PostConstruct)

Example 28 with PostConstruct

use of jakarta.annotation.PostConstruct in project myfaces by apache.

the class ClientWindowScopeContextualStorageHolder method init.

@PostConstruct
@Override
public void init() {
    super.init();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Integer numberOfClientWindowsInSession = MyfacesConfig.getCurrentInstance(facesContext).getNumberOfClientWindows();
    clientWindowExpirationStack = new LRULinkedHashMap<>(numberOfClientWindowsInSession, (eldest) -> {
        destroyAll(FacesContext.getCurrentInstance(), eldest.getKey());
    });
    pushClientWindow(facesContext, facesContext.getExternalContext().getClientWindow());
}
Also used : SessionScoped(jakarta.enterprise.context.SessionScoped) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) ClientWindow(jakarta.faces.lifecycle.ClientWindow) PostConstruct(jakarta.annotation.PostConstruct) FacesContext(jakarta.faces.context.FacesContext) Contextual(jakarta.enterprise.context.spi.Contextual) ContextualInstanceInfo(org.apache.myfaces.cdi.util.ContextualInstanceInfo) Typed(jakarta.enterprise.inject.Typed) Serializable(java.io.Serializable) ContextualStorage(org.apache.myfaces.cdi.util.ContextualStorage) AbstractContextualStorageHolder(org.apache.myfaces.cdi.util.AbstractContextualStorageHolder) LRULinkedHashMap(org.apache.myfaces.util.lang.LRULinkedHashMap) Map(java.util.Map) FacesContext(jakarta.faces.context.FacesContext) PostConstruct(jakarta.annotation.PostConstruct)

Example 29 with PostConstruct

use of jakarta.annotation.PostConstruct in project myfaces by apache.

the class AbstractContextualStorageHolder method init.

@PostConstruct
public void init() {
    storageMap = new ConcurrentHashMap<>();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object context = facesContext.getExternalContext().getContext();
    if (context instanceof ServletContext) {
        FacesApplicationArtifactHolder appBean = CDIUtils.get(beanManager, FacesApplicationArtifactHolder.class);
        if (appBean.getServletContext() != null) {
            appBean.setServletContext((ServletContext) context);
        }
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) ServletContext(jakarta.servlet.ServletContext) FacesApplicationArtifactHolder(org.apache.myfaces.cdi.FacesApplicationArtifactHolder) PostConstruct(jakarta.annotation.PostConstruct)

Example 30 with PostConstruct

use of jakarta.annotation.PostConstruct in project myfaces by apache.

the class FlowScopeContextualStorageHolder method init.

@PostConstruct
@Override
public void init() {
    super.init();
    activeFlowMapKeys = new ConcurrentHashMap<>();
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Integer numberOfClientWindowsInSession = MyfacesConfig.getCurrentInstance(facesContext).getNumberOfClientWindows();
    clientWindowExpirationStack = new LRULinkedHashMap<>(numberOfClientWindowsInSession, (eldest) -> {
        clearFlowMap(FacesContext.getCurrentInstance(), eldest.getKey());
    });
    refreshClientWindow(facesContext);
}
Also used : Flow(jakarta.faces.flow.Flow) SessionScoped(jakarta.enterprise.context.SessionScoped) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientWindow(jakarta.faces.lifecycle.ClientWindow) PostConstruct(jakarta.annotation.PostConstruct) HashMap(java.util.HashMap) FacesContext(jakarta.faces.context.FacesContext) ContextualInstanceInfo(org.apache.myfaces.cdi.util.ContextualInstanceInfo) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) Typed(jakarta.enterprise.inject.Typed) ContextualStorage(org.apache.myfaces.cdi.util.ContextualStorage) FlowUtils(org.apache.myfaces.flow.FlowUtils) List(java.util.List) AbstractContextualStorageHolder(org.apache.myfaces.cdi.util.AbstractContextualStorageHolder) LRULinkedHashMap(org.apache.myfaces.util.lang.LRULinkedHashMap) Map(java.util.Map) FlowHandler(jakarta.faces.flow.FlowHandler) Collections(java.util.Collections) BeanManager(jakarta.enterprise.inject.spi.BeanManager) FacesContext(jakarta.faces.context.FacesContext) 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