如何在Symfony上处理soap empty web方法返回?

时间:2018-01-29 21:04:11

标签: java php symfony jax-ws

技术:JAX-WS和Symfony 4

问题

我编写了一个方法,根据数据库中的类别返回帖子,问题是结果为空"当传递的类别没有帖子时#34; 它在我的网站上抛出一个错误,说返回是未定义的,否则如果它不是空的或单个值它完美的工作,任何提示,以避免在我使用没有帖子的新数据库部署它时遇到此问题。

Java代码

/**
 * @param category
 * @param amountOfPosts
 * @return 
 */
@WebMethod(operationName = "getPostsByCategory")
public ArrayList<Post> getPostsByCategory(
        @WebParam(name = "category") String category,
        @WebParam(name = "amountOfPosts") int amountOfPosts
) 
{
    ArrayList<Post> posts = new ArrayList<>();
    try {
        this.connection = this.context.openConnection();

        String query = "SELECT * FROM POST WHERE POST_CATEGORY_ID = " + 
        category + " LIMIT " + amountOfPosts;
        new QueryRunner()
                .query(this.connection, query, new ArrayListHandler())
                .stream()
                .map(resultSet -> 
                {
                    Post post = new Post();
                    post.setPostId((int) resultSet[0]);
                    post.setPostTitle((String) resultSet[1]);
                    post.setPostDescription((String) resultSet[2]);
                    post.setPostCategoryId((int) resultSet[3]);
                    post.setPostContent((String) resultSet[4]);
                    post.setPostAuthor((String) resultSet[5]);
                    post.setPostDate((String) resultSet[6]);
                    post.setPostSlug((String) resultSet[7]);
                    post.setPostThumbnail((String) resultSet[8]);
                    post.setPostCountry((String) resultSet[9]);
                    post.setPostStateId((int) resultSet[10]);
                    return post;
                })
                .collect(Collectors.toCollection(() -> posts));

        this.context.closeConnection(this.connection);
    } catch (SQLException ex) {
        Logger.getLogger(AecaWebService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return posts;
}

Symfony Code(PHP代码)

    $categoryOnePosts = $wsdl->getPostsByCategory(array(
        'category' => 1
        'amountOfPosts' => 5,
    ));

    return $this->render('view.twig', array(
        'categoryOnePosts' => $categoryOnePosts->return, #this causes the problem when empty
    ));

php中的错误:注意:未定义的属性:stdClass :: $ return

0 个答案:

没有答案