简体   繁体   English

使用xml而不是jaxb注释的Java Web服务工具?

[英]Java webservice tool that uses xml instead of jaxb annotations?

I have a service layer that I would like to convert into a webservice. 我有一个要转换为Web服务的服务层。 However I hate using annotations because they severely limit code reusability in my common base classes. 但是我讨厌使用注释,因为它们严重限制了我的通用基类中的代码可重用性。 Some webservices use a subset of the objects, and I don't want things exposed for one service to be exposed for another. 一些Web服务使用对象的子集,而我不希望将某个服务公开的内容公开给另一服务。

I had the same issue with hibernate, however the hbm xml mappings allow me to share the same domain objects and have different mappings for different services, which works great. 我在hibernate中遇到了同样的问题,但是hbm xml映射允许我共享相同的域对象,并且对不同的服务具有不同的映射,这很好用。 Is there any kind of rest webservice framework for java that will allow me to describe my api and scheme objects with xml, and still gain the benefits of converting these objects to json/xml etc? 是否有任何类型的Java其余Web服务框架可让我用xml描述我的api和scheme对象,仍然获得将这些对象转换为json / xml等的好处?

You could describe your web services in WADL , which is XML based, then generate your code using CXF's wadl2java tool . 您可以使用基于XML的WADL描述您的Web服务,然后使用CXF的wadl2java工具生成代码。 Note that WADL is not widely adopted as of yet, so you have to decide how important it is to you, to do contract-first REST services. 请注意,WADL到目前为止尚未得到广泛采用,因此您必须确定它对您的重要性,以进行合同优先的REST服务。

Spring Web Services is another annotation-free framework based on XML for Web Services publishing. Spring Web Services是另一个基于XML的免注释框架,用于Web Services发布。 You should give it a try 你应该试试看

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group. 注意:我是EclipseLink JAXB(MOXy)的负责人,并且是JAXB 2(JSR-222)专家组的成员。

EclipseLink JAXB (MOXy) has an extension that allows you to represent the metadata as an XML file. EclipseLink JAXB(MOXy)具有扩展名,使您可以将元数据表示为XML文件。 You can leverage this metadata in a JAX-RS environment using a ContextResolver: 您可以使用ContextResolver在JAX-RS环境中利用此元数据:

package blog.bindingfile.jaxrs;

import java.io.*;
import java.util.*;

import javax.ws.rs.Produces;
import javax.ws.rs.ext.*;
import javax.xml.bind.*;

import org.eclipse.persistence.jaxb.JAXBContextFactory;

import blog.bindingfile.Customer;

@Provider
@Produces({"application/xml", "application/json"})
public class CustomerContextResolver implements ContextResolver<JAXBContext> {

    private JAXBContext jc;

    public CustomerContextResolver() {
        Map<String, Object> props = new HashMap<String, Object>(1);
        props.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "blog/bindingfile/binding.xml");
        jc = JAXBContext.newInstance(new Class[] {Customer.class} , props);
    }

    public JAXBContext getContext(Class<?> clazz) {
        if(Customer.class == clazz) {
            return jc;
        }
        return null;
    }

}

For More Information 欲获得更多信息

Related Stack Overflow Questions 相关堆栈溢出问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM