- 浏览: 95964 次
文章分类
最新评论
-
jXee:
lgs0626 写道求源码,兄弟给共享下吧 "jee ...
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection -
lgs0626:
求源码,兄弟给共享下吧
jee6 学习笔记 4 - CRUD 2: View Details, Primefaces row selection
Exposing an EJB as web service is just a matter of a few annotations.
This example exposes an ejb as standard SOAP web services. It uses default JAX-WS 2.1.6, which is part of the JDK1.6 distribution now.
It has two approaches:
1. Define a service interface and apply the @WebService on the interface. All the public methods would be exposed as web services.
2. Apply the @WebService to the implementation class directly, without an service interface. If you don't want to expose a public method in the class, apply @WebMethod(exclude=true) to the method.
here's the ejb3.1 implementation class StudentDAOImp after the "find" method exposed as a web service:
Since web services are normally deployed as web applications, The wsdl url of the deployed web service has this pattern: http://server:port/context/service?wsdl
JBoss and Glassfish provide admin screens to display the wsdl url. In JBoss 6.1, the deployed web services can be found in this screen:
http://localhost:8180/jbossws/services
you can click the endpoint address links of the services to view its wsdl. The StudentDAOImp service has this url for its wsdl:
http://localhost:8180/ProJee6/StudentDAOImp?wsdl
Here's the screen shot of JBoss web services screen:
This example exposes an ejb as standard SOAP web services. It uses default JAX-WS 2.1.6, which is part of the JDK1.6 distribution now.
It has two approaches:
1. Define a service interface and apply the @WebService on the interface. All the public methods would be exposed as web services.
2. Apply the @WebService to the implementation class directly, without an service interface. If you don't want to expose a public method in the class, apply @WebMethod(exclude=true) to the method.
here's the ejb3.1 implementation class StudentDAOImp after the "find" method exposed as a web service:
package com.jxee.ejb.student; import java.util.List; import javax.ejb.Stateless; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; import org.apache.log4j.Logger; import com.jxee.ejb.usr.UserDAOImp; import com.jxee.model.student.Student; /** * Rules of usage of @javax.jws.WebService * * If the @WebService annotation of an service implementation class references * a SEI(Service Endpoint Interface), the implementation class must not have * any @WebMethod annotations. * * All public methods for an SEI are considered exposed methods regardless of * whether the @WebMethod annotation is specified or not. * * It is incorrect to have an @WebMethod annotation on an SEI that contains the * exclude attribute. * * For an implementation class that does not reference an SEI, if the @WebMethod * annotation is specified with a value of exclude=true, that method is not exposed. * * If the @WebMethod annotation is not specified, all public methods are exposed * including the inherited methods, except for that inherited from java.lang.Object. */ @Stateless @WebService public class StudentDAOImp implements StudentDAO { private static final Logger log = Logger.getLogger(UserDAOImp.class); @PersistenceContext(unitName="punit.projee6") private EntityManager em; @WebMethod public List<Student> find(@WebParam(name="name") String nameFilter, @WebParam(name="max") int max) { String pattern = nameFilter != null ? "%" + nameFilter + "%" : "%"; String sql = "select s from Student s where s.name like :pattern"; Query q = em.createQuery(sql); q.setParameter("pattern", pattern); q.setFirstResult(0); q.setMaxResults(max); return q.getResultList(); } @WebMethod(exclude=true) public void add(Student stu) { log.debug("adding new student: " + stu); if(stu.getId() != null) { // set null to avoid exception "org.hibernate.PersistentObjectException: detached entity passed to persist" stu.setId(null); } em.persist(stu); } @WebMethod(exclude=true) public void update(Student stu) { log.debug("updating student: " + stu); em.merge(stu); } @WebMethod(exclude=true) public void delete(Student stu) { Student todel = em.find(Student.class, stu.getId()); log.debug("student loaded to delete: " + todel); em.remove(todel); } }
Since web services are normally deployed as web applications, The wsdl url of the deployed web service has this pattern: http://server:port/context/service?wsdl
JBoss and Glassfish provide admin screens to display the wsdl url. In JBoss 6.1, the deployed web services can be found in this screen:
http://localhost:8180/jbossws/services
you can click the endpoint address links of the services to view its wsdl. The StudentDAOImp service has this url for its wsdl:
http://localhost:8180/ProJee6/StudentDAOImp?wsdl
Here's the screen shot of JBoss web services screen:
发表评论
-
ActiveMQ and Spring JMS Framework Message Loss
2019-06-28 07:15 29Java Message Service (JMS) prov ... -
how to proxy to k8s web console
2018-06-28 07:16 525### how to access k8s web conso ... -
Call Stored Procedure with JPA 2.1
2018-06-27 10:57 612JPA 2.1 introduces APIs to call ... -
Send response and then process - async processing
2017-10-12 09:35 506If your request processing take ... -
java 8 time api test
2017-08-29 05:40 432public class ParseUtcDateTime ... -
Setup ApiKey in header with Swagger generated client code
2017-08-23 06:41 434@Value("${api.base.path} ... -
Simple tool to monitor jvm memory usage and garbage collection
2016-10-13 06:06 311JDK has built-in tool to moni ... -
Externalize Application Config properties with JBoss 7.1
2017-06-02 12:09 300If you have configuration pro ... -
JPA native query does not support setting list parameters
2014-03-27 06:45 965you might want to do the ... -
Owning Side and Inverse Side of JPA entity relationships
2013-09-10 07:08 754Entity relationships may be b ... -
avoid setParameter for "order by" in JPQL
2013-03-07 05:55 749you might want to create a JP ... -
JPA Path Expression, operator IN and Collection properties
2013-01-23 16:25 1336If we want to select the Orde ... -
与JEE6/EJB3.1相比, Spring framework 丧失了几乎所有的优势
2013-01-19 13:13 993The Spring framework was a ma ... -
Simple EasyMock tutorial
2012-12-20 11:57 618http://veerasundar.com/blog/20 ... -
Servlet 3.0 @WebFilter and @WebServlet
2012-12-04 07:09 2629Servlet 3.0 provides new annota ... -
Why JSF2 @ViewScoped not working?
2012-12-03 06:55 1338javax.faces.bean.ViewScoped sai ... -
When to configure an XA datasource?
2012-11-16 12:58 1221If you ever came across this wa ... -
java ee transaction and datasource concepts
2012-11-10 13:48 9831. What is a transaction? A tra ... -
pass params to primefaces confirmation dialog box
2012-09-28 19:30 1296<p:dataTable id="idStuD ... -
Handle Big Dataset with Real Pagination with Primefaces 3.3 LazyDataModel
2012-09-21 13:41 5580If you have millions of record ...
相关推荐
NULL 博文链接:https://jxee.iteye.com/blog/1608820
开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32开发工具 eclipse-jee-mars-2-win32...
eclipse-jee-2020-06-R-win32-x86_64
eclipse-jee-2022-09-R-win32-x86_64.zip 适用于Windows x86_64
eclipse-jee-2022-03-R-win32-x86_64.zip
eclipse-jee-mars-R-win32-x86_64.zip 截至2015.06.30 eclipse-j2ee 最新版
Eclipse IDE for Enterprise Java and Web Developers (eclipse-jee-2021-12-R-win32-x86_64.zip)适用于Windwos x86_64
eclipse-jee-2021-06-R-win32-x86_64.zip
eclipse-jee-2021-12-R-win32-x86_64 eclipse-jee-2021-12-R-win32-x86_64 eclipse-jee-2021-12-R-win32-x86_64
NULL 博文链接:https://jxee.iteye.com/blog/1575432
eclipse-jee-2021-03-R-win32-x86_64
eclipse-jee-mars-2-win32 javaee开发工具 eclipse-jee-mars-2-win32 javaee开发工具
eclipse-jee-oxygen-R-win32.7z.003
eclipse-jee-2018-09-win32-x86_64.zip
eclipse-jee-2020-09-R-win32-x86_64.zip
eclipse-jee-ganymede-SR2-win32.zip
eclipse-jee-2023-09-R-win32-x86_64.zip 适用于Windows系统
eclipse-jee-2020-12-R-win32-x86_64,最新版本eclipse4.18,需要其他版本eclipse可以查询我资源列表
eclipse-jee-2022-06-R-win32-x86_64.zip 适用于Windows x86_64