EJB作为企业应用程序项目中的WebService

时间:2016-03-22 23:35:31

标签: java web-services soap glassfish ejb

我在Netbeans中创建了一个Maven企业应用程序项目。我创建了一个示例EJB,一个Remote和一个本地接口。现在我想通过使用这些EJB发布SOAP Web服务,但是有些事我做错了,因为在glassfish中我无法查看端点(使用wsdl等)。但它被列为一个组成部分:

组件名称: RecommendationSOAPService,SHITSTORMRECOMMENDER

模块名称: ShitstormRecommender-ejb-1.0.jar,ShitstormRecommender-ejb-1.0.jar

类型: StatelessSessionBean,StatelessSessionBean

我的EJB:

import com.sun.javafx.scene.control.skin.VirtualFlow;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import org.andy.dto.Recommendation;
import org.andy.dto.RecommendationRequest;

    @Stateless(name = "SHITSTORMRECOMMENDER")
    public class ShitstormRecommenderEJB implements ShitstormReommenderEJBRemote,
            ShitstormRecommenderEJBLocal {

        @Override
        public List<Recommendation> getRecommendation(RecommendationRequest request) {
            Recommendation r1 = new Recommendation("Task 2", 10, "blubb");
            Recommendation r2 = new Recommendation("Task 1", 5, "bla");
            List<Recommendation> recommendations = new ArrayList<>();
            recommendations.add(r1);
            recommendations.add(r2);
            return recommendations;
        }

    }

我的远程接口(本地界面与@local的外观相同):

@Remote
public interface ShitstormReommenderEJBRemote {
    public List<Recommendation> getRecommendation(RecommendationRequest request);
}

我的WebService-Class(位于带有接口和EJB的ejb-Container中):

package org.andy.service;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import org.andy.dto.Recommendation;
import org.andy.dto.RecommendationRequest;
import org.andy.ejb.ShitstormReommenderEJBRemote;

@WebService(
        name= "ShitstormRecommender",
        portName = "ShitstormRecommenderPort",
        serviceName = "ShitstormRecommenderService",
        targetNamespace = "http://shitstormRecommendation.org"
        )
@Stateless
public class RecommendationSOAPService{

    @EJB
    private ShitstormReommenderEJBRemote recommender;

    @WebMethod
    public String sayCiao(){
        return "ciao";
    }
    @WebMethod
    @WebResult(name="recommendations")
    public List<Recommendation> getRecommendation(
            @WebParam(name="recommendationRequest") RecommendationRequest request) {
        return recommender.getRecommendation(request);
    }
}

也许你可以说,我必须做些什么才能让它发挥作用?我已经从tutorial中尝试过了。它似乎有效,但我想我已经忘了。

非常感谢你的帮助!

0 个答案:

没有答案