我想问一个关于jax-ws 中的@UsesJAXBContext注释的问题。我试图让它在客户端工作,但我可能遗漏了一些东西。这是我的情况:
我有网络服务与操作:
@WebMethod(operationName = "putToQueue")
public boolean put(@WebParam(name = "queueName") String queueName, @WebParam(name = "element") Object element) {
return queues.get(queueName).offer(element);
}
在客户端,我生成了 QueueService 和 Queue(端口)......以及其他东西...... [响应请求。在这种情况下无关紧要。] 我想让用户定义他/她可以放入队列的对象。但是,要调用put(...)操作,我需要将对象(我尝试发送)绑定到 JAXBContext 中。我可以通过 在生成的队列存根顶部的@XmlSeeAlso来做到这一点[我试过这个并且它有效]。尽管如此,我需要更通用的解决方案来帮助我在运行时绑定对象。我认为我可以创建@QueueMessage注释和ClientJAXBContextFactory并在创建时将标记的类添加到上下文中。
public class ClientJAXBContextFactory implements JAXBContextFactory {
@Override
public JAXBRIContext createJAXBContext(SEIModel seim, List<Class> classes, List<TypeReference> references) throws JAXBException {
Reflections reflections = new Reflections("");
Set<Class<?>> annotated = reflections.getTypesAnnotatedWith(QueueMessage.class);
classes.addAll(annotated);
return JAXBContextFactory.DEFAULT.createJAXBContext(seim, classes, references);
}
}
接下来我尝试在生成的队列之上使用@UsesJAXBContext 。
@WebService(name = "Queue")
@UsesJAXBContext(ClientJAXBContextFactory.class)
public interface Queue {
...
}
但是createJAXBContext(...)没有被调用,而 jax-ws 只是简单地创建了他的 JAXBContextImpl。
我读过了:
http://weblogs.java.net/blog/jitu/archive/2008/08/control_of_jaxb.html
http://www.techques.com/question/1-5627173/Specify-JAXB-Packages-in-SLSB-and-JAX-WS
还有一些关于stackOverFlow 的问题。我将不胜感激。是否可以实施我的问题中提出的想法?
我也可能会在服务器端添加它...... @UsesJAXBContext有效。但对我来说,让它在客户端工作很重要。