在openfire插件

时间:2018-01-22 13:20:40

标签: java json xml xmpp openfire

我已经完成了以下步骤,在openfire服务器中编写自己的自定义rest api。

public class JerseyWrapper extends ServletContainer {

    private static final long serialVersionUID = 4807992231163442643L;

    /** The Constant RESOURCE_CONFIG_CLASS_KEY. */
    private static final String RESOURCE_CONFIG_CLASS_KEY = "com.sun.jersey.config.property.resourceConfigClass";

    /** The Constant RESOURCE_CONFIG_CLASS. */
    private static final String RESOURCE_CONFIG_CLASS = "com.sun.jersey.api.core.PackagesResourceConfig";

    /** The config. */
    private static Map<String, Object> config;

    /** The prc. */
    private static PackagesResourceConfig prc;

    static {
        config = new HashMap<String, Object>();
        config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS);
        config.put("com.sun.jersey.api.json.POJOMappingFeature", true);
        prc = new PackagesResourceConfig(JerseyWrapper.class.getPackage().getName());
        prc.setPropertiesAndFeatures(config);
        prc.getClasses().add(ContactManagementController.class);
    }

    /**
     * Instantiates a new jersey wrapper.
     */
    public JerseyWrapper() {
        super(prc);
    }

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);
    }

    @Override
    public void destroy() {
        super.destroy();
    }
}


@Path("restapi/v1/de/temp")
public class ContactManagementController {

    private final Logger LOGGER = LoggerFactory.getLogger(ContactManagementController.class);

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    public void getUsers() {
        LOGGER.info("Plugin called");
    }

}

web-custom.xml包含以下内容

    <?xml version='1.0' encoding='ISO-8859-1'?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <!-- Servlets -->
    <servlet>
        <servlet-name>JerseyWrapper</servlet-name>
        <servlet-class>plugin.JerseyWrapper</servlet-class>
    </servlet>

    <!-- Servlet mappings -->
    <servlet-mapping>
        <servlet-name>JerseyWrapper</servlet-name>
        <url-pattern>/de/*</url-pattern>
    </servlet-mapping>

</web-app>

现在我打电话给http://localhost/plugins/restapi/v1/de/temp

我收到404错误。

我为我的插件编写了JerseyWrapper,还有Controller和web-custom.xml。

我已经将jar上传到了openfire插件中,但是当我点击openfire服务器时,我得到了404响应

1 个答案:

答案 0 :(得分:0)

很难说出现了什么问题。 Openfire确实提供了实现REST API的插件。也许阻力最小的路径是复制这样的插件,删除你不需要的东西,并添加你做的事情?