`
IT民工%
  • 浏览: 45735 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

web service 问题收集

阅读更多

转载自:http://www.educity.cn/wenda/147229.html

jax-ws WebService相关问题(一)

  1.使用JDK6自带的JAX-WS + Jboss4.2.3 开发WebService发布WebService报错? java.lang.ClassNotFoundException: com.sun.xml.ws.transport.

   解释:JDK本身不带基于Servlet的代码,自带的jax-ws 不带WSServlet和WSServletContextListener两个类,在j2ee的jar包里才有

  解决方案:

  a.使用代码中Endpoint.publish()发布(轻量级HTTP Server);

  Endpoint.publish("http://localhost:8080/HelloService", new HelloSEI());

  缺点是每次代码发布很麻烦,修改也麻烦,而且每个IP和端口只能发布一个

  b.使用Spring自带的SimpleJaxWsServiceExporter发布(轻量级HTTP Server);

  <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter"> <property name="baseAddress" value="http://localhost:8080/"/> </bean> <bean id="accountServiceEndpoint" class="example.AccountServiceEndpoint"> ... </bean>

  缺点是每个IP和端口只能发布一个

   c.使用jaxws-spring.jar提供的WSSpringServlet方式发布(Servlet发布):

  这需要使用到2个额外的jar包:

  jaxws-spring-1.8.jar

  xbean-spring-v2-2.8.jar

  配置方式:

  web.xml

  <web-app> <!-- this is for Spring --> <listener> <listener-class>org.springframeworntext.ContextLoaderListener</listener-class> </listener> <!-- these are for JAX-WS --> <servlet> <servlet-name>jaxws-servlet</servlet-name> <servlet-class>com.sun.xml.ws.transport.;/servlet-class> </servlet> <servlet-mapping> <servlet-name>jaxws-servlet</servlet-name> <url-pattern>/add</url-pattern> </servlet-mapping> ... if you deploy more services, you might need more <servlet-mapping>s ... </web-app>

  applicationContext.xml

  <beans xmlns="" xmlns:xsi="" xmlns:ws="" xmlns:wss="" xsi:schemaLocation=" g/core "> <wss:binding url="/add" service="#addService" /> <wss:binding url="/sub"> <wss:service><!-- nested bean is of course fine --> <ws:service bean="#myService" /> </wss:service> </wss:binding> <!-- this bean implements web service methods --> <bean id="myService" class="foo.MyService" /> <!-- simplest definition only needs the class name --> <ws:service id="addService" impl="foo.MyAddService" handlers="#myHandler"/> <bean id="myHandler" class="foo.MyHandler" /> </beans>

  2.Client端同样部署在jboss web容器上的时候,客户端调用报: java.lang.ClassCastException: com.sun.xml.ws.client.WSServiceDelegate cannot be cast to javax.xml.ws.spi.ServiceDelegate21

  解释: 这是由于JBOSS有自带的jax-ws api的实现,称为jbossws。导致api类实现冲突。

  解决方案:

  思路是将JDK总的JAX-WS实现相关的类替换为加载JBOSS的JAX-WS API实现类。

  做法是将jboss/lib/endorsed/ 目录下的:

  jboss-jaxrpc.jar

  jboss-jaxws.jar

  jboss-jaxws-ext.jar

  jboss-saaj.jar

  xercesImpl.jar

  拷贝到%JAVA_HOME%/jre/endorsed/目录下。(这使用了JDK的endorsed机制,请查阅相关资料)

  JDK的endorsed目录可以根据System.getProperty("java.endorsed.dirs")获得。 需要注意的是:在web容器使用哪个JDK就在那个JDK下面去修改。

  3.发布的wsdl里面如果import 了wsdl和xsd文件时,客户端访问每次都会Addressing,如何将本地war包里面的xsd和wsdl和发布的服务绑定上?

  解释:这个是由于WS的机制造成的,JAX-WS官方提供了解决方案。

  解决方案:采用添加jax-ws-catalog的方式,绑定本地的xsd和wsdl

  <catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer=" system"> < system systemId=" " uri="HelloService.wsdl"/> </catalog>

  Jax-ws-catalog.xml的放置位置:

  wsimport 命令行或者ant任务

  使用-catalog 可选参数,指定catalog file. 例如:

  -catalog jax-ws-catalog.xml

  WebService客户端运行时环境

  Classpath下的该目录:META-INF/jax-ws-catalog.xml

  (.jar包中的META-INF/jax-ws-catalog.xml也算)

  轻量级的基于HTTP server (j2se)的endpoint发布

  就是说是通过调用接口EndPoint.publish(),并指定了HttpServer的。

  包括通过Spring的轻量级发布辅助类发布的:

  org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter

  org.springframework.remoting.jaxws.SimpleHttpServerJaxWsServiceExporter

  Classpath下的该目录:META-INF/jax-ws-catalog.xml

  基于Servlet的endpoint

  WEB-INF/jax-ws-catalog.xml

  基于JSR 109标准的 EJB 模块发布

  META-INF/jax-ws-catalog.xml

  笔者在使用CXF作为webservice实现的时候通过指定jax-ws-catalog.xml是能够很好的被加载解析。但是使用JDK自带的jax-ws或者Metro jax-ws RI时,使用JBOSS作为发布容器,始终不能正确执行jax-ws-catalog.xml中描述的 import wsdl/xsdschema引用替换,进一步调试发现是通过jndi的方式访问了jax-ws-catalog.xml,但是没达到使用本地wsdl/xsd的效果

  4.如何采用endpoint的方式发布一个servcename下有多个portname的WebService

  how to publish multi port webservice with same serviceName

  解释:一般看JAX-WS RI上的例子或者Spring的两个http Stand alone publish 发布辅助类(上文提到的:Spring的轻量级发布辅助类),都看不到这方面的资料。是因为多 port 使用的比较少。

  解决方案:扩展Spring提供的http endpoint pubish类 :AbstractJaxWsServiceExporter。

  该类胡自动解析带有@WebService注解的初始化为Spring bean了的endpoint发布类,并基于配置的basepath进行发布,发布地址:http://hostname:port/basepath/serviceName/portName

  代码:

  import java.net.InetSocketAddress; import java.util.List; import javax.jws.WebService; import javax.xml.ws.Endpoint; import javax.xml.ws.WebServiceProvider; import ormons.logging.Log; import ormons.logging.LogFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.remoting.jaxws.AbstractJaxWsServiceExporter; import co.; import co.; import co.; import co.; public class PortableHttpServerJaxWsServiceExporter extends AbstractJaxWsServiceExporter { private static final Logger LOG = LoggerFactory.getLogger(PortableHttpServerJaxWsServiceExporter.class); public PortableHttpServerJaxWsServiceExporter() { port = 8080; backlog = -1; shutdownDelay = 0; basePath = "/"; localServer = false; } public void setServer(HttpServer server) { this.server = server; } public void setPort(int port) { this.port = port; } public void setHostname(String hostname) { this.hostname = hostname; } public void setBacklog(int backlog) { this.backlog = backlog; } public void setShutdownDelay(int shutdownDelay) { this.shutdownDelay = shutdownDelay; } public void setBasePath(String basePath) { this.basePath = basePath; } public void setFilters(List<Filter> filters) { this.filters = filters; } public void setAuthenticator(Authenticator authenticator) { this.authenticator = authenticator; } @Override public void afterPropertiesSet() throws Exception { if (server == null) { InetSocketAddress address = (hostname == null new InetSocketAddress( port) : new InetSocketAddress(hostname, port)); server = HttpServer.create(address, backlog); if (logger.isInfoEnabled()) logger.info((new StringBuilder( "Starting HttpServer at address ")).append(address) .toString()); server.start(); localServer = true; LOG.info("Start hostname: {}, port: {}", hostname, port); } super.afterPropertiesSet(); } @Override protected void publishEndpoint(Endpoint endpoint, WebService annotation) { endpoint.publish(buildHttpContext(endpoint, annotation.serviceName(), annotation.portName())); } @Override protected void publishEndpoint(Endpoint endpoint, WebServiceProvider annotation) { endpoint.publish(buildHttpContext(endpoint, annotation.serviceName(), annotation.portName())); } protected HttpContext buildHttpContext(Endpoint endpoint, String serviceName, String portName) { String fullPath = calculateEndpointPath(endpoint, serviceName, portName); HttpContext (fullPath); if (filters != null) ().addAll(filters); if (authenticator != null) (authenticator); LOG.info("Listen http context at full path : {}.", ()); return httpContext; } protected String calculateEndpointPath(Endpoint endpoint, String serviceName, String portName) { if (null == portName) { return (new StringBuilder(String.valueOf(basePath))).append( serviceName).toString(); } return (new StringBuilder(String.valueOf(basePath))) .append(serviceName).append("/").append(portName).toString(); } @Override public void destroy( { super.destroy(); if (localServer) { logger.info("Stopping HttpServer"); server.stop(shutdownDelay); } } protected final Log logger = LogFactory.getLog(getClass()); private HttpServer server; private int port; private String hostname; private int backlog; private int shutdownDelay; private String basePath; private List<Filter> filters; private Authenticator authenticator; private boolean localServer; }

  发布方式:

  <bean class="com.huawei.ossj.ws.publisher.PortableHttpServerJaxWsServiceExporter"> <property name="basePath" value="/" /> <property name="port" value="19900" /> </bean>

分享到:
评论

相关推荐

    web service第一次启动慢

    【web service的释放】winform 程序第一次访问Webservice 慢的问题.pdf 文档为网上收集,版权归原作者所有,O(∩_∩)O谢谢。

    web service

    提供了几本web service方面的应用书,可以给不少初学者在资料搜集方面提供便利

    小程序源码 从中调用web service的源码.zip

    免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累... 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。

    小程序源码 从中调用web service的源码.rar

    免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累... 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。

    WebOA网络办公自动化系统

    服务器运行环境安装好后,将 WebOA.rar 解压缩到IIS站点主目录下,设置 App_Data 和 App_Data_Backup 文件夹网站运行帐号(建议用NETWORK SERVICE)有修改权限;然后打开浏览器在地址栏中输入服务器 IP 地址进入登录...

    service-streamer:增强深度学习应用程序的Web服务

    什么是Service Streamer? 微型批次收集数据样本,通常用于深度学习模型。 通过这种方式,模型可以利用GPU的并行计算能力。 但是,用户对Web服务的请求通常是离散的。 如果使用传统的循环服务器或线程服务器,GPU将...

    windows server 2008 企业版WEB服务器环境的配置、windows server 2008基本配置技巧、windows server 2008 WEB服务器安全初级设置篇

    这些资源我费了很大力才收集起来的, 我个人觉得非常有用,今天就分享给大家, 希望对大家有帮助。 windows server 2008 企业版WEB服务器环境的配置、windows server 2008基本配置技巧、windows server 2008 WEB...

    WebOA网络办公自动化系统 v19.4.zip

    服务器运行环境安装好后,将 WebOA.rar 解压缩到IIS站点主目录下,设置 App_Data 和 App_Data_Backup 文件夹网站运行帐号(建议用NETWORK SERVICE)有修改权限;然后打开浏览器在地址栏中输入服务器 IP 地址进入登录...

    Web Operations

     ·理解为何从应用程序和基础设施收集统计数据都很重要  ·为数据库架构和规模日益增长带来的隐患考虑通用的处理方法  ·学习如何处理宕机和降级相关的人为因素  ·找到在蜂拥而至的巨大流量后避免灾难的方法  ...

    alexa-web-information-service-api-samples:通过代码示例向AWS Marketplace上的Alexa.com APis发出已签名的请求

    Alexa Web信息服务Api示例此存储库包含各种语言的代码示例,以向AWS Marketplace上的Alexa Web Information Service API发出签名请求。 这些样本旨在演示如何使用订阅服务后提供的API用户凭据和API计划密钥向Alexa ...

    最新的web开发常用WebService

    web服务接口 收集了开发中常用的一些webservice地址,是当前最全的webservice地址

    WebOA网络办公自动化系统 v19.11

    安装说明:服务器运行环境安装好后,将 WebOA.rar 解压缩到IIS站点主目录下,设置 App_Data 和 App_Data_Backup 文件夹网站运行帐号(建议用NETWORK SERVICE)有修改权限;然后打开浏览器在地址栏中输入服务器 IP 地址...

    智能化WEB信息搜索引擎的研究与实现

    which can use Web robots or Web site entry to collect documents, then analyzes and deals with this information, creates and maintains index database, gives a service of search to the user. When user ...

    Web Operations:Keep data on time(网站运维)

     ·理解为何从应用程序和基础设施收集统计数据都很重要  ·为数据库架构和规模日益增长带来的隐患考虑通用的处理方法  ·学习如何处理宕机和降级相关的人为因素  ·找到在蜂拥而至的巨大流量后避免灾难的方法  ...

    WebOA 网络办公自动化软件 20.1

    安装说明:服务器运行环境安装好后,将 WebOA.rar 解压缩到IIS站点主目录下,设置 App_Data 和 App_Data_Backup 文件夹网站运行帐号(建议用NETWORK SERVICE)有修改权限;然后打开浏览器在地址栏中输入服务器 IP ...

    discovery-web-crawler:搜寻网站并填充Watson Discovery Collection

    发现网络爬虫 搜寻网站并填充Watson Discovery Collection。... serviceUrl : 'YOUR_SERVICE_URL' , apikey : 'YOUR_APIKEY' , environmentId : 'YOUR_ENVIRONMENT_ID' , collectionId : 'YOUR_COLLECTION_ID' ,

    Web开发敏捷之道-应用Rails进行敏捷Web开发-第三版.rar

    相比第2版中的内容,Rails 2增加了REST、资源、轻量级web service等新特性。本书涵盖了这些全新的内容,因此能更好地体现出Rails框架的发展现状。 整体而言,全书既有直观的实例,又有深入的分析,同时还涵盖了web...

    WEB渗透测试数据库

    webshell收集,详见相关目录readme.md文件 3.7 script 常用脚本 3.8 exploit 一些有用的exploit,详见相关目录readme.md文件 4 备注 项目中的字典等文件统一使用“/**”作为注释符,注释符在一行开头,且只能注释...

    simple-logging-service:轻量级的Web跟踪应用程序,用于在单页Webapp上记录用户操作。 使用Piwik:registered:Web分析库收集信息,并使用Node.js在Redis,RabbitMQ或Kafka中存储数据

    该项目基于 ,这是一种收集Web分析并将数据存储在Cloudant数据库中的简单方法。 该项目使用微服务体系结构分解了这个概念,因此,该项目不仅将数据写入Cloudant数据库,还根据运行时环境变量将数据添加到各种输出中...

    QWS dataset

    收集了2507个web服务的信息. QWS度量是使用作者开发的Web Service Broker(WSB)框架进行的. 与第一版相比主要有以下区别: (1)数量大大增加(365-&gt;2507) (2) 不包含WsRF ranking和classification参数

Global site tag (gtag.js) - Google Analytics