gpt4 book ai didi

java - gnu.mail.providers.nntp.NNTPMessage 的容器类

转载 作者:行者123 更新时间:2023-12-01 15:27:34 28 4
gpt4 key购买 nike

为什么 Glassfish 显示此 Facelets 错误:

javax.el.ELException: /foo/client.xhtml @11,74 value="#{messageBean.messages}": javax.mail.MessagingException: Socket closed;
nested exception is:
java.net.SocketException: Socket closed

我将其归因于点击 leafnode在本地主机上太频繁且太快。下面的 Glassfish 日志显示从 leafnode 成功检索消息,但多次调用 SingletonNNTP.loadMessages()。

如何正确处理socket?有时 Leafnode 会提供所需的输出,有时则不会。

INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/NNTPjsf'
INFO: WEB0671: Loading application [NNTPjsf] at [/NNTPjsf]
INFO: NNTPjsf was successfully deployed in 2,574 milliseconds.
INFO: MessageBean..
INFO: MessageBean..
INFO: MessageBean.getMessages..
INFO: MessageBean.getNNTP..
INFO: MAKING SINGLETON..
INFO: NNTP.loadMessages...
INFO: NNTP.loadMessages...
nntp: <200 Leafnode NNTP Daemon, version 1.11.8 running at localhost (my fqdn: dur.bounceme.net)
nntp: >GROUP comp.lang.java.help
nntp: <211 82 3 84 comp.lang.java.help group selected
nntp: >GROUP comp.lang.java.help
nntp: <211 82 3 84 comp.lang.java.help group selected
nntp: >XHDR Message-ID 3-84
nntp: <221 Message-ID header (from overview) for postings 3-84:
nntp: <3 <afp6m75oi6nli4b6q87s317lkc13g689c2@4ax.com>
nntp: <4 <ed7f31e9-8a19-46c7-9a7c-ad8aabfb9599@x10g2000pbi.googlegroups.com>
nntp: <5 <uA4ar.13560$fj7.13111@newsfe20.iad>

支持 bean 如下:

package net.bounceme.dur.nntp;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import javax.mail.Message;

@Named
@SessionScoped
public class MessageBean implements Serializable {

private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(MessageBean.class.getName());
private static Level level = Level.INFO;
private DataModel dm = null;

public MessageBean() {
logger.log(level, "MessageBean..");
}

public List<Message> getMessages() throws Exception {
logger.log(level, "MessageBean.getMessages..");
List<Message> messages = getNNTP();
return messages;
}

public DataModel getModel() throws Exception {
logger.log(level, "MessageBean.getModel..");
List<Message> messages = getNNTP();
dm = new ListDataModel(messages);
return dm;
}

private synchronized List<Message> getNNTP() throws Exception {
logger.log(level, "MessageBean.getNNTP..");
List<Message> messages = new ArrayList<Message>();
SingletonNNTP nntp = SingletonNNTP.INSTANCE;
messages = nntp.getMessages(false);
logger.log(level, "MessageBean.getNNTP nntp.size: {0}", messages.size());
return messages;
}
}

单例:

package net.bounceme.dur.nntp;

import static java.lang.System.out;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.*;

public enum SingletonNNTP {

INSTANCE;
private final Logger logger = Logger.getLogger(SingletonNNTP.class.getName());
private final Level level = Level.INFO;
private Properties props = new Properties();
private List<Message> messages = new ArrayList<Message>();

private SingletonNNTP() {
out.println("MAKING SINGLETON..");
props = PropertiesReader.getProps();
boolean loaded = false;
try {
loaded = setMessages(false);
} catch (Exception ex) {
Logger.getLogger(SingletonNNTP.class.getName()).log(Level.SEVERE, "FAILED TO LOAD MESSAGES", ex);
}
}

public List<Message> getMessages(boolean debug) throws Exception {
logger.log(level, "NNTP.getMessages...");
logMessages();
return Collections.unmodifiableList(messages);
}

private boolean setMessages(boolean debug) throws Exception {
logger.log(level, "NNTP.loadMessages...");
Session session = Session.getDefaultInstance(props);
session.setDebug(debug);
Store store = session.getStore(new URLName(props.getProperty("nntp.host")));
store.connect();
Folder root = store.getDefaultFolder();
Folder folder = root.getFolder(props.getProperty("nntp.group"));
folder.open(Folder.READ_ONLY);
Message[] msgs = folder.getMessages();
messages = Arrays.asList(msgs);
folder.close(false);
store.close();
if (debug) {

}
return true;
}

private void logMessages() throws Exception {
logger.log(level, "NNTP.logMessages..");
for (Message m : messages) {
logger.log(level, String.valueOf(m.getMessageNumber()));
logger.log(level, m.getSubject());
logger.log(level, m.getContent().toString());
}
}

private void persistMessages() throws Exception {
//entities.Messages
}
}

最佳答案

该消息意味着您关闭了套接字,然后尝试对其进行读取或写入。您正在尝试在关闭连接后读取消息内容。当连接打开时,您需要保存的不是消息本身,而是其内容。

关于java - gnu.mail.providers.nntp.NNTPMessage 的容器类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9985444/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com