当前位置: 首页 > news >正文

微信建设网站襄阳做网站公司

微信建设网站,襄阳做网站公司,广州app网站建设,iis默认网站路径jax-rs jax-ws让我们假设一家企业正在一个集中式系统中维护用户身份验证详细信息。 我们需要创建一个AuthenticationService#xff0c;它将获取凭据#xff0c;对其进行验证并返回状态。 其余的应用程序将使用AuthenticationService对用户进行身份验证。 创建Authentication… jax-rs jax-ws 让我们假设一家企业正在一个集中式系统中维护用户身份验证详细信息。 我们需要创建一个AuthenticationService它将获取凭据对其进行验证并返回状态。 其余的应用程序将使用AuthenticationService对用户进行身份验证。 创建AuthenticationService接口如下所示 package com.sivalabs.caas.services; import javax.jws.WebService;import com.sivalabs.caas.domain.AuthenticationStatus; import com.sivalabs.caas.domain.Credentials; import com.sivalabs.caas.exceptions.AuthenticationServiceException;WebService public interface AuthenticationService { public AuthenticationStatus authenticate(Credentials credentials) throws AuthenticationServiceException; }package com.sivalabs.caas.domain; /*** author siva**/ public class Credentials {private String userName;private String password;public Credentials() {}public Credentials(String userName, String password) {super();this.userName userName;this.password password;}//setters and getters}package com.sivalabs.caas.domain;/*** author siva**/ public class AuthenticationStatus {private String statusMessage;private boolean success;//setters and getters}package com.sivalabs.caas.exceptions;/*** author siva**/ public class AuthenticationServiceException extends RuntimeException {private static final long serialVersionUID 1L;public AuthenticationServiceException(){}public AuthenticationServiceException(String msg){super(msg);} } 现在让我们实现AuthenticationService。 package com.sivalabs.caas.services;import java.util.HashMap; import java.util.Map;import javax.jws.WebService;import com.sivalabs.caas.domain.AuthenticationStatus; import com.sivalabs.caas.domain.Credentials; import com.sivalabs.caas.exceptions.AuthenticationServiceException;/*** author siva**/ WebService(endpointInterfacecom.sivalabs.caas.services.AuthenticationService,serviceNameAuthenticationService, targetNamespacehttp://sivalabs.blogspot.com/services/AuthenticationService) public class AuthenticationServiceImpl implements AuthenticationService {private static final Mapstring, string CREDENTIALS new HashMapstring, string();static{CREDENTIALS.put(admin, admin);CREDENTIALS.put(test, test); }Overridepublic AuthenticationStatus authenticate(Credentials credentials) throws AuthenticationServiceException{if(credentials null){throw new AuthenticationServiceException(Credentials is null);}AuthenticationStatus authenticationStatus new AuthenticationStatus();String userName credentials.getUserName();String password credentials.getPassword();if(userNamenull || userName.trim().length()0 || passwordnull || password.trim().length()0){authenticationStatus.setStatusMessage(UserName and Password should not be blank);authenticationStatus.setSuccess(false);}else{if(CREDENTIALS.containsKey(userName) password.equals(CREDENTIALS.get(userName))){authenticationStatus.setStatusMessage(Valid UserName and Password);authenticationStatus.setSuccess(true);}else{authenticationStatus.setStatusMessage(Invalid UserName and Password);authenticationStatus.setSuccess(false);}}return authenticationStatus;} } 为了简单起见我们在此根据存储在HashMap中的静态数据检查凭据。 在实际的应用程序中将根据数据库进行此检查。 现在我们将发布WebService。 package com.sivalabs.caas.publisher;import javax.xml.ws.Endpoint;import com.sivalabs.caas.services.AuthenticationServiceImpl;public class EndpointPublisher {public static void main(String[] args){Endpoint.publish(http://localhost:8080/CAAS/services/AuthenticationService, new AuthenticationServiceImpl());}} 运行此独立的类以发布AuthenticationService。 要检查服务是否已成功发布请将浏览器指向URL http// localhost8080 / CAAS / services / AuthenticationServicewsdl。 如果该服务成功发布您将看到WSDL内容。 现在让我们创建一个独立测试客户端来测试Web服务。 package com.sivalabs.caas.client;import java.net.URL;import javax.xml.namespace.QName; import javax.xml.ws.Service;import com.sivalabs.caas.domain.AuthenticationStatus; import com.sivalabs.caas.domain.Credentials; import com.sivalabs.caas.services.AuthenticationService;/*** author siva**/ public class StandaloneClient {public static void main(String[] args) throws Exception{URL wsdlUrl new URL(http://localhost:8080/CAAS/services/AuthenticationService?wsdl);QName qName new QName(http://sivalabs.blogspot.com/services/AuthenticationService, AuthenticationService);Service service Service.create(wsdlUrl,qName);AuthenticationService port service.getPort(AuthenticationService.class);Credentials credentialsnew Credentials();credentials.setUserName(admin1);credentials.setPassword(admin);AuthenticationStatus authenticationStatus port.authenticate(credentials);System.out.println(authenticationStatus.getStatusMessage());credentials.setUserName(admin);credentials.setPassword(admin);authenticationStatus port.authenticate(credentials);System.out.println(authenticationStatus.getStatusMessage());}} 不用我们自己编写StandaloneClient我们可以使用wsimport命令行工具生成Client。 wsimport工具在JDK / bin目录中。 转到项目的src目录然后执行以下命令。 wsimport -keep -p com.sivalabs.caas.client http// localhost8080 / CAAS / services / AuthenticationServicewsdl 它将在com.sivalabs.caas.client软件包中生成以下Java和类文件。 Authenticate.java AuthenticateResponse.java AuthenticationService_Service.java AuthenticationService.java AuthenticationServiceException_Exception.java AuthenticationServiceException.java AuthenticationStatus.java Credentials.java ObjectFactory.java 包信息.java 现在您可以使用生成的Java文件来测试服务。 public static void main(String[] args) throws Exception {AuthenticationService_Service service new AuthenticationService_Service();com.sivalabs.caas.client.AuthenticationService authenticationServiceImplPort service.getAuthenticationServiceImplPort();com.sivalabs.caas.client.Credentials credentials new com.sivalabs.caas.client.Credentials();credentials.setUserName(admin1);credentials.setPassword(admin);com.sivalabs.caas.client.AuthenticationStatus authenticationStatus authenticationServiceImplPort.authenticate(credentials);System.out.println(authenticationStatus.getStatusMessage());credentials.setUserName(admin);credentials.setPassword(admin);authenticationStatus authenticationServiceImplPort.authenticate(credentials);System.out.println(authenticationStatus.getStatusMessage()); } 现在我们将看到如何在Tomcat服务器上部署JAX-WS WebService。 我们将在apache-tomcat-6.0.32上部署在http://sivalabs.blogspot.com/2011/09/developing-webservices-using-jax-ws.html中开发的AuthenticationService。 要部署我们的AuthenticationService我们需要添加以下配置。 1.web.xml web-applistenerlistener-classcom.sun.xml.ws.transport.http.servlet.WSServletContextListener/listener-class/listenerservletservlet-nameauthenticationService/servlet-nameservlet-classcom.sun.xml.ws.transport.http.servlet.WSServlet/servlet-classload-on-startup1/load-on-startup/servletservlet-mappingservlet-nameauthenticationService/servlet-nameurl-pattern/services/AuthenticationService/url-pattern/servlet-mapping /web-app 2.创建一个新文件WEB-INF / sun-jax-ws.xml ?xml version1.0 encodingUTF-8? endpointsxmlnshttp://java.sun.com/xml/ns/jax-ws/ri/runtimeversion2.0endpointnameAuthenticationServiceimplementationcom.sivalabs.caas.services.AuthenticationServiceImplurl-pattern/services/AuthenticationService//endpoints 3.从http://jax-ws.java.net/下载JAX-WS参考实现。 将所有jar文件从jaxws-ri / lib文件夹复制到WEB-INF / lib。 现在将应用程序部署在Tomcat服务器上。 您不需要像使用EndpointPublisher那样由我们自己发布服务。 Tomcat启动并运行后请在http// localhost8080 / CAAS / services / AuthenticationServicewsdl中查看生成的wsdl。 现在如果您使用独立客户端测试AuthenticationService它将可以正常工作。 public static void testAuthenticationService()throws Exception {URL wsdlUrl new URL(http://localhost:8080/CAAS/services/AuthenticationService?wsdl);QName qName new QName(http://sivalabs.blogspot.com/services/AuthenticationService, AuthenticationService);Service service Service.create(wsdlUrl,qName);AuthenticationService port service.getPort(AuthenticationService.class);Credentials credentialsnew Credentials();credentials.setUserName(admin);credentials.setPassword(admin);AuthenticationStatus authenticationStatus port.authenticate(credentials);System.out.println(authenticationStatus.getStatusMessage()); } 但是如果尝试使用wsimport工具生成的客户端代码进行测试请确保在客户端类路径中没有jax-ws-ri jar。 否则您将得到以下错误 Exception in thread main java.lang.NoSuchMethodError: javax.xml.ws.WebFault.messageName()Ljava/lang/String;at com.sun.xml.ws.model.RuntimeModeler.processExceptions(RuntimeModeler.java:1162)at com.sun.xml.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:898) 参考 “ 我的实验”博客上的 JCG合作伙伴 Siva Reddy提供了使用JAX-WS开发WebServices和在Tomcat-6上部署JAX-WS WebService的信息 。 翻译自: https://www.javacodegeeks.com/2012/03/web-services-with-jax-ws-on-tomcat.htmljax-rs jax-ws
http://wiki.neutronadmin.com/news/368541/

相关文章:

  • 淘宝联盟交钱建设网站微信h5在哪个网站做
  • 深圳网站设计哪家比较好柳州市建设工程质量安全监督管理处网站
  • 企业网站建设费用属于什么科目免费做自己的网站有钱赚吗
  • 做数据图网站西安市做网站公司
  • 建设网站需要分析什么wordpress媒体库相册
  • 怎么在网站上做模式题库做货代哪个网站上好找客户
  • 建设网站商城后台系统旅游网站制作文献
  • 专业网站开发开发河北建设厅网站没有注册
  • 深圳网站设计制作建设英文定机票网站建设
  • 建筑工程招聘网站哪个好上海4a广告公司
  • 中文网站开发工具百度下载安装2022最新版
  • 黄冈做网站做响应式网站是不是都用rem
  • 建设工程网站新专家入库北京 网站建设600
  • 包头网站设计如何建学校网站
  • 视频播放网站模板国外建设网站情况
  • 企业网站的开发保险购买平台有哪些
  • 上海建设工程招投标在什么网站南宁建设网站哪里好
  • 高级网站开发技术无锡优化网站费用
  • 原材料价格查询网站企业域名如何申请
  • 域名访问过程会不会影响网站访问开发app费用
  • 网站建站麻烦吗百度最怕哪个部门去投诉
  • 太谷网站建设做调研的网站一般有哪些
  • 摄影网站导航wordpress导航菜单制作
  • .net 手机网站源码下载软件项目实施流程八个阶段
  • 企业公司网站制作网站建设详细
  • 网站制作哪些分类销售管理5大要素
  • 网站推广10大方法网站改版影响排名吗
  • 怎样营销网站爱站关键词挖掘
  • 昆山网站建设推广计算机应用技术好就业吗
  • 优设网网站设计评价自己怎么做网站卖东西