ReSTful WS - 自动生成jsp等

时间:2013-10-03 07:17:03

标签: web-services rest jax-rs webservice-client restful-url

列出我的应用程序中存在的一些Web服务(方法):

'POST'示例:

@Path("/searchProfileConfigurator")
public class SearchProfileConfiguratorWP {

    /* POSSIBLY, later Inject it or instantiate in no-arg constructor */
    private SearchProfileConfigurator searchProfileConfigurator;

    @POST
    @Path("/addJob")
    @Consumes(MediaType.APPLICATION_JSON)
    public void addJob(SearchProfile searchProfile) {
        // sanityCheck
        // Apply rules.
        // if all is ok .... insert into database.
        // Generate job id.

        if (LogManager.isDebugOn()) {
            LogManager.debug("SearchProfileConfiguratorWP ::: addJob :::"
                    + searchProfile);
        }

        searchProfileConfigurator = new SearchProfileConfigurator();
        searchProfileConfigurator.addJob(searchProfile);

        if (LogManager.isDebugOn()) {
            LogManager
                    .debug("SearchProfileConfiguratorWP ::: addJob ::: Returning ");
        }
    }
}

'GET'示例:

public class SearchProfileReposMgrWP {

    private static SearchProfileReposMgr _spm = SearchProfileReposMgr
            .getInstance();

    @GET
    @Path("/getAllActiveJobs")
    @Produces(MediaType.APPLICATION_JSON)
    public ArrayList<SearchProfile> getAllActiveJobs() {
        if (LogManager.isDebugOn()) {
            LogManager
                    .debug("SearchProfileReposMgrWP ::: getAllActiveJobs ::: " +
                            "Get all active jobs");
        }
        return _spm.getAllActiveJobs();
    }
}

SearchProfile POJO:

package sapphire.social.connector.pojo;

import java.util.ArrayList;
import java.util.List;

public class SearchProfile {

    public Long getId() {
        return searchProfileId;
    }
    public void setId(Long searchProfileId) {
        this.searchProfileId = searchProfileId;
    }
    public SearchProfileOwner getOwner() {
        return searchProfileOwner;
    }
    public void setOwner(SearchProfileOwner searchProfileOwner) {
        this.searchProfileOwner = searchProfileOwner;
    }
    public SearchProfileDetails getDetails() {
        return details;
    }
    public void setDetails(SearchProfileDetails details) {
        this.details = details;
    }
    public SceduleDetails getSceduleDetails() {
        return sceduleDetails;
    }
    public void setSceduleDetails(SceduleDetails sceduleDetails) {
        this.sceduleDetails = sceduleDetails;
    }
    public List<Connector> getConnectors() {
        return connectors;
    }
    public void setConnectors(List<Connector> connectors) {
        this.connectors = connectors;
    }

    private Long searchProfileId;
    private SearchProfileOwner searchProfileOwner;
    private SearchProfileDetails details;
    private SceduleDetails sceduleDetails;
    private List<Connector> connectors = new ArrayList<Connector>();
}

现在对于'getAllActiveJobs',我不需要在GET中发送任何查询参数,但是在'addJob'的POST中,我发送一个复杂的JSON,如下所示:

{"connectors":[{"connectorType":"FACEBOOK"},{"config":{"entry":[{"key":{"type":"string","value":"USE_API"},"value":{"type":"string","value":"ALL_JOBS_COUNTRY"}}]},"connectorType":"LINKEDIN"},{"connectorType":"TWITTER"},{"connectorType":"YOUTUBE"}],"details":{"numberOfURL":0,"profileName":"Honda"},"owner":{"fbToken":"CAAFW94zKeCABAPAm0jn7s0AcOlfyZCnxJoozzFWzKmSwZCZCkgDTN55nD08berllyJSZAWktJKw2rAlLj7xw8bxKSKFSr8WDxA4PxxeQ6ivNJSV22o6KHJ8L4OoSxTcX3SPubELl1fTKZAeZAfGIALu3IjqTLMANqDSsdYJ2ZCMVVAULExuNaAa","ldnToken":"AQW8RdBSvtlkFkcjZZo5oh7c4HXFWwpPpbntqYOXjBv0sCjZt07mgmC99DH0S3EN8wvwwbVLgLGi0Kck2G4FYog52S4ZAKQxQ9Y-7QkxFVQqHJi_wgAYwE9SbVIidTf_S63ljqfBvgdQSq6Qjzgukp9EhECoGbQ6WdXLTHZW0-KfzP--lNE","twtaccessToken":"1285192843-eBRpwLmDhp60NZe0I77Pb5JXDFDj67w2z7QoWXD","twtaccessTokenSecret":"q5LZ2DkEuPOWdOARn742PTGitGQq8AU4uHWG7hK6M","twtconsumerKey":"cmZaUbCeDpb9SWCwUlCNsA","twtconsumerSecret":"4FsHhU2KuYsbowCJsuZ4RtsUq4rpLQQcQAGeXkIZqY"}}

现在假设我想要一个前端,比如每个用于'addJob'和'getAllActiveJobs'的JSP,有没有办法自动生成相同的东西?如果是'addJob', JSP必须有一个表单,可以使用所有可以构造SearchProfile POJO的INPUT。

前端旨在供某些管理员使用。可以通过在表单中​​填充参数来添加作业的人员,这些表单又将被调用到ReST。

注意: 我不希望手动创建表单和/或在我的WS方法中包含@FormParam

0 个答案:

没有答案