Java类的消息正文编写器。。。未找到MIME媒体类型text/html
我正在使用jms/atmosphere框架在两个应用程序之间进行通信。 其中一个应用程序是主题的消息生成器,发送以下类型的自定义对象:Java类的消息正文编写器。。。未找到MIME媒体类型text/html,java,json,glassfish,jersey,atmosphere,Java,Json,Glassfish,Jersey,Atmosphere,我正在使用jms/atmosphere框架在两个应用程序之间进行通信。 其中一个应用程序是主题的消息生成器,发送以下类型的自定义对象: @XmlRootElement public class A implements Serializable{ public A(){} /* some private properties */ } 另一方面,不止一个消费者正在收听该主题,并根据id进行不同的订阅 @GET @Produces({Me
@XmlRootElement
public class A implements Serializable{
public A(){}
/* some private properties */
}
另一方面,不止一个消费者正在收听该主题,并根据id进行不同的订阅
@GET
@Produces({MediaType.APPLICATION_JSON})
public SuspendResponse<A> subscribe() {
return new SuspendResponse.SuspendResponseBuilder<A>()
.broadcaster(topic)
.outputComments(true)
.addListener(new EventsLogger()).build();
}
@Override
public void incomingBroadcast() {
try {
String id = getID();
if (id.startsWith("/*")) {
id = "atmosphere";
}
logger.info("Looking up Connection Factory {}", FACTORY_NAME);
Context ctx = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(FACTORY_NAME);
logger.info("Looking up topic: {}", TOPIC_NAME);
Topic topic = (Topic) ctx.lookup(TOPIC_NAME);
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
logger.info("Create consumer for : {}", id);
String selector = String.format("BroadcasterId = '%s'", id);
consumer = session.createConsumer(topic, selector);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message msg) {
try {
ObjectMessage om = (ObjectMessage) msg;
A a = (A) om.getObject();
if (a!= null && bc != null) {
broadcastReceivedMessage(a);
}
logger.info("Broadcasted message: {} ", a);
} catch (JMSException ex) {
logger.warn("Failed to broadcast message", ex);
}
}
});
publisher = session.createProducer(topic);
connection.start();
logger.info("JMS created for topic {}, with filter {}", TOPIC_NAME, selector);
} catch (Throwable ex) {
throw new IllegalStateException("Unable to initialize MyBroadcaster", ex);
}
}
我使用的是Netbeans 7.0.1、glassfish 3.1.1、atmosphere 0.8.1、jersey 1.11。我在网上搜索并尝试了任何可能的解决方案,但都无济于事 对于通过Jersey传输的类,似乎需要实现所需的MessageBodyWriter 您可以将@Provider附加到类A,并使其实现MessageBodyWriter,例如: @提供者 公共类A实现MessageBodyWriter
这将迫使您在jersey传输方法中的对象时重写所需的方法(writeTo、getSize、isWriteable)。我也有同样的问题,原因是我的类路径中没有jersey的json模块。您可以简单地通过在maven上添加以下依赖项来修复它
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.14</version>
</dependency>
泽西岛
泽西json
1.14
这不起作用。我在订阅之前直接实现了MessageBodyWriter,并覆盖了这些方法,但它们从未被调用。您是否已将MessageBodyWriter注册到应用程序(javax.ws.rs.core.Application)中?jersey启动时,Application.getClasses()方法返回一组类,并且应在此集中返回提供程序(如MessageBodyWriter)。我添加了jersey json依赖项,但问题仍然是一样的。当您想要生成json时,需要此依赖项,但OP需要htmlbroken链接,请修复?
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.14</version>
</dependency>