首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >扩展dotCMS REST

扩展dotCMS REST
EN

Stack Overflow用户
提问于 2015-04-22 10:23:28
回答 1查看 704关注 0票数 1

我是dotCMS的新手(实际上我是为一个项目评估它的)。

我创建了一个自定义类型,为了简单起见,我们可以假装它只是一个带有WYSIWYG内容字段的消息。

现在,我想使用rest在web客户端应用程序中显示这条消息。

所以我收到我的留言:

代码语言:javascript
复制
/api/content/query/+structureName:Message

我得到了这个(非常完美):

代码语言:javascript
复制
"contentlets":[{
    "owner":"dotcms.org.2831",
    "content":  "<p>Hi !<\/p>\n<p>I am a <strong>Message<\/strong>.<\/p>\n<p>See you.<\/p>",
    ...
    },{
    "owner":"dotcms.org.2831",
    ...
    }
]

现在,我丢失了所有者的公共名称,并且无法用标准的rest获得它。我该怎么做?

更接近的是使用基于spring示例的osgi插件。并读取com.dotcms.rest包的源代码。我试图在app/spring/myController/test或app/spring/myController/getUserNameById/id/dotcms.org.2831上获得它,但没有成功(编辑:我得到了一个404未找到,日志中没有错误)。已知的问题出现在javadoc中:

代码语言:javascript
复制
@EnableWebMvc
@Configuration
@RequestMapping ("/myController")
@Controller
/**
 * I also try with @Path("/myController") but I got a 404 not found.
 **/
public class myController extends WebResource {

    /**
     * This default method works fine.
     **/
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView helloWorld() {
        Logger.info( this.getClass(), "Received request to hello" );
        String myMessage = "Hello World, Spring 3.1 and dotCMS!";
        // This will resolve to /application/spring/helloworld.dot
        return new ModelAndView("helloworld", "message", myMessage);
    }

    /**
     * This one dosen't accept my MappingJacksonJsonView. But no error in the logfile.
     **/
    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public ModelAndView test() {
        Logger.info( this.getClass(), "Test request" );
        Map<String,String> model = new HashMap<>();
        model.put("key", "value");
        Logger.info( this.getClass(), "Map ready" );
        MappingJacksonJsonView view = new MappingJacksonJsonView();
        Logger.info( this.getClass(), "View ready" );
        ModelAndView modelAndView = new ModelAndView(view, model);
        Logger.info( this.getClass(), "Response ready" );
        return modelAndView;
    }

    /**
     * I can't reach this method. And if so, will the Response return type even work ?
     **/
    @GET
    @Path("/getUserNameById/{params:.*}")
    @Produces("application/json")
    public Response getUserById(@Context HttpServletRequest request, @PathParam("params") String params) throws JSONException {

        InitDataObject initData = init( params, true, request, true );

        Map<String, String> paramsMap = initData.getParamsMap();
        String userId = paramsMap.get("id");
        Logger.info( this.getClass(), "Received request with userId " + userId );

        //Creating an utility response object
        ResourceResponse responseResource = new ResourceResponse( initData.getParamsMap() );

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userId", userId);
        //Get and put user public name into the jsonObject here.
        Logger.info( this.getClass(), jsonObject.toString());
        return responseResource.response(jsonObject.toString());
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-23 11:54:31

使用提供的泽西岛osgi示例。它允许您扩展和添加新的端点到dotCMS rest。请参见:

https://github.com/dotCMS/core/tree/master-3.2/docs/examples/osgi/com.dotcms.rest

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29794568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档