标签: jax-ws

XMLGregorianCalendar 日期序列化为空字符串

我使用 Java 1.6wsimport从 Web 服务的 WSDL 生成源代码。请求结构中的字段之一具有xs:dateTimeWSDL 包含的 XML 模式中的类型和javax.xml.datatype.XMLGregorianCalendar生成的代码中的类型。

通过使用soapUI进行手动测试,我确定Web服务接受以下序列化值:2011-12-08, 2011-12-08Z。不接受以下内容,在这种情况下的响应是空回复(不是显式错误):2011-12-08T20:00:00, 2011-12-08T20:00:00-05:00。如果这很重要的话,服务本身是由 .NET 提供支持的。

我的想法是服务器应该接受完整的日期/时间并仅拒绝日期,但相反的是正在发生的情况。但我并不认为服务器的维护者会愿意改变。所以我试图说服客户只发送一个日期。

我无法说服我的客户端代码将XMLGregorianCalendar对象仅序列化为日期。事实上我可以,除非生成的代码可以做到这一点。当生成的客户端代码(由 生成wsimport)执行此操作时,序列化值是空字符串,并且服务器正确返回错误。我使用数据包嗅探器验证了这一点。

以下是我在请求中创建和填充日期字段的方法:

import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.TimeZone;
// also import GeneratedRequest from generated packages

private makeRequest() {
   GeneratedRequest request;
   // ...
   request.setDateField(xmlDayNow(TimeZone.getTimeZone("America/New_York"),
       6));  // broadcast day starts at 6 am EST
   // ...
}

@XmlSchemaType(name="date")
private …
Run Code Online (Sandbox Code Playgroud)

java validation jax-ws

5
推荐指数
1
解决办法
1万
查看次数

使用 WSGEN 生成工件时“缺少 SEI”

我是网络服务开发的初学者。我想使用 wsgen.exe 生成工件。

这是我的代码:

  package com.calc.ws;

  import javax.jws.WebService;

  @WebService
  public class Calculator {
      public int add(int a, int b) {
          return (a + b);
      }
      public int sub(int a, int b) {
          return (a - b);
      }
  }
Run Code Online (Sandbox Code Playgroud)

我面临的问题是当我想使用此命令(一行)从命令行生成工件时:

C:\Program Files\Java\jdk1.7.0_05\bin\wsgen 
     -cp "c:\users\mico\workspaceSOA\calcWS\src\com.calc.ws.Calculator" 
     -verbose 
     -d "C:\users\mico\classes\"
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Missing SEI.
Run Code Online (Sandbox Code Playgroud)

是什么原因造成的?

java web-services jax-ws jaxb wsgen

5
推荐指数
1
解决办法
9460
查看次数

忽略 JAX-WS 客户端中缺少的方法

我有一个模型,用于在服务器上创建 Web 服务端点。客户端使用相同的模型。但是,当向服务器添加新操作但客户端仍使用旧模型时,服务创建会失败,并出现如下异常(为了清楚起见,添加了换行符):

Exception in thread "main" javax.xml.ws.WebServiceException:
  Method someNewMethod is exposed as WebMethod, but there is no
  corresponding wsdl operation with name someNewMethod in the
  wsdl:portType{http://example.com}MyService
Run Code Online (Sandbox Code Playgroud)

我理解这个问题,但是可以忽略它吗?我希望在使用 Web 服务时能够向后兼容。只要添加方法,大多数时候就应该可以正常工作。

问题出现在getPort方法中:

Service s = Service.create(
    new URL("http://example.com/foo?wsdl"),
    new QName("http://example.com", "MyService"));
MyService m = s.getPort(MyService.class);
Run Code Online (Sandbox Code Playgroud)

java soap jax-ws

5
推荐指数
1
解决办法
1万
查看次数

我可以在 Metro 解组之前修复损坏的 XML 响应吗?

我正在使用 Metro 调用 SOAP Web 服务。我从我无法控制的服务器接收到 SOAP 响应,其正文中包含无效字符引用。我想在 Metro 解组 XML 并向我的客户端抛出异常之前修复该 XML。这可能吗?

我尝试添加 aLogicalHandler和 a ,但是当我尝试获取有效负载(分别SOAPHandler失败)时,它们都会抛出相同的解组异常。当响应没有无效的 XML 时,处理程序工作正常,让我可以访问消息。LogicalMessage.getPayload()SOAPMessageContext.getMessage()

异常如下所示:

com.sun.xml.internal.ws.encoding.soap.DeserializationException: Failed to read a response: javax.xml.bind.UnmarshalException
 - with linked exception:
[javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#]
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:421)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:357)
at com.sun.xml.internal.bind.v2.runtime.BridgeImpl.unmarshal(BridgeImpl.java:109)
at com.sun.xml.internal.bind.api.Bridge.unmarshal(Bridge.java:222)
at com.sun.xml.internal.ws.client.sei.ResponseBuilder$DocLit.readResponse(ResponseBuilder.java:539)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
... 41 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,2653]
Message: Character reference "&#
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:598)
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:81)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:182)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:355)
Run Code Online (Sandbox Code Playgroud)

有没有办法可以获取原始有效负载,修复它并替换回来并继续?

java-metro-framework jax-ws

5
推荐指数
1
解决办法
1464
查看次数

JAX-WS 和 WSDL 中的 javax.jws.WebParam.name 与 javax.jws.WebParam.partName

我在研究 WSDL 和 JAX-WS 时发现了这一点。当我在JAX-WS中编写服务接口时,如下所示:

@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld {
    @WebMethod
    @WebResult(name="helloworldstring")
    String getHelloWorldAsString(**@WebParam(name="myname")** String name);
}
Run Code Online (Sandbox Code Playgroud)

生成的 WSDL 的message请求声明如下:

<message name="getHelloWorldAsString">
    <part **name="myname"** type="xsd:string"></part>
</message>
Run Code Online (Sandbox Code Playgroud)

当我从wsimport实用程序生成客户端存根时,生成的服务类同时获取namepartName作为“myname”。

如果我在服务中根本没有指定@WebParam,则 WSDL 会获取部分名称,而arg0使用生成的服务存根wsimport会获取其声明中的name和。partNamearg0@webParam

如果我在服务类中同时指定namepartNamein ,@WebParam如下所示:

@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld {
    @WebMethod
    @WebResult(name="helloworldstring")
    String getHelloWorldAsString(**@WebParam(name="myname", partName="mypartname")**  String name);
}
Run Code Online (Sandbox Code Playgroud)

生成的 WSDL 的部件名称为mypartname …

java soap wsdl web-services jax-ws

5
推荐指数
1
解决办法
9394
查看次数

Websphere 7 错误:无法为实现类生成 WSDL 定义

请原谅我的英语

我有一个使用jax-wsspring 的应用程序,它在 tomcat 上运行良好,但我应该将其部署在Websphere 7上。

WAS7 抛出以下异常:

00000027 WSModuleDecr E WSWS7027E:由于以下错误,无法正确构建 JAX-WS 服务描述:javax.xml.ws.WebServiceException:WSWS7054E:无法为 com.foo 生成 Web 服务描述语言 (WSDL) 文件。 MyEndpoint Web 服务实现类,因为出现以下错误:java.lang.Exception:无法为实现类生成 WSDL 定义:com.foo.MyEndpoint at com.ibm.ws.websvcs.wsdl.WASWSDLGenerator.generateWsdl(WASWSDLGenerator .java:230)

我的端点类是:

@WebService(endpointInterface = "com.foo.MyService", targetNamespace = "http://www.foo.com/xsd")
public class MyEndpoint  implements MyService
{
...
}
Run Code Online (Sandbox Code Playgroud)

接口是:

@WebService(portName = "MyPort", serviceName = "MyService", 
  targetNamespace = "http://www.foo.com/xsd")
public interface MyService
{
...
}
Run Code Online (Sandbox Code Playgroud)

知道什么会导致这个问题吗?如何检查,这里到底出了什么问题?错误信息太模糊了...

java wsdl web-services jax-ws websphere-7

5
推荐指数
1
解决办法
8583
查看次数

在 Tomcat 中部署 JAX-WS war 时出错:无法解析名称“cxf-beans:beanAttributes”

我正在尝试在 Tomcat 上部署 JAX-WS Web 服务。我正在 Eclipse 中生成战争。我在运行 Tomcat 时遇到的错误是 -

SEVERE: Exception sending context initialized event to listener instance of class 
org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 

Configuration problem: 
Failed to import bean definitions from relative location [ws/ws-context.xml]
Offending resource: ServletContext resource [/WEB-INF/spring/application-context.xml]; 

nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: ...  
nested exception is org.xml.sax.SAXParseException: 
src-resolve: Cannot resolve the name 'cxf-beans:beanAttributes' to a(n) 'attribute group' 
component.
Run Code Online (Sandbox Code Playgroud)

有问题的 xml 文件是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util-3.0.xsd
        http://cxf.apache.org/jaxrs 
        http://cxf.apache.org/schemas/jaxrs.xsd
        http://www.springframework.org/schema/context …
Run Code Online (Sandbox Code Playgroud)

deployment tomcat jax-ws saxparseexception

5
推荐指数
0
解决办法
928
查看次数

将 JAXB 片段文件与 wsimport 结合使用

有两个 WSDL 共享一些用于定义数据类型的模式。以下是其中一个 WSDL 的示例:

<wsdl:definitions
    name="FooService"
    targetNamespace="http://xmlns.my.org/services/FooService/v001"
    xmlns:srv="http://xmlns.my.org/services/FooService/v001"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:fault="java:org.my.exception"
    ...
>
    <wsdl:types>
        <xsd:schema>
            <xsd:import namespace="java:org.my.exception" schemaLocation="../xsd/common/BusinessException.xsd"/>
            <xsd:import namespace="http://xmlns.my.org/services/FooServiceMessages/v001" schemaLocation="../xsd/fooservice/FooServiceMessages_v001.xsd"/>
        </xsd:schema>
    </wsdl:types>
    ...
    <wsdl:message name="BusinessException">
        <wsdl:part element="fault:BusinessException" name="BusinessException"/>
    </wsdl:message>
    ...
    <wsdl:portType name="IFooService">
        <wsdl:operation name="getItems">
            ...
            <wsdl:fault message="srv:BusinessException" name="BusinessException"/>
        </wsdl:operation>
        ...
    </wsdl:portType>
    ...
</wsdl:definitions>
Run Code Online (Sandbox Code Playgroud)

BusinessException.xsd是常见的方案之一。

我正在尝试通过这些 WSDL 生成 Java 代码wsimport。将公共模式与 WSDLd 分开编译,然后在编译 WSDL 时重用从这些模式派生的类是合理的。为此,我生成了一个 JAXB Episode 文件以及常见的 Java 代码:

<bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
  <bindings scd="x-schema::tns" xmlns:tns="java:org.my.exception">
    <schemaBindings map="false">
      <package name="org.my.integration.dto.common"/>
    </schemaBindings>
    <bindings scd="~tns:BusinessException">
      <class ref="org.my.integration.dto.common.BusinessException"/>
    </bindings> …
Run Code Online (Sandbox Code Playgroud)

xsd wsdl jax-ws jaxb wsimport

5
推荐指数
1
解决办法
2712
查看次数

jax-ws maven 插件将 wsdlLocation 设置为绝对路径

我使用生成网络服务客户端

<plugin> 
 <groupId>org.jvnet.jax-ws-commons</groupId> 
 <artifactId>jaxws-maven-plugin</artifactId> 
 <version>2.3</version> 
 <configuration>
  <target>2.1</target> 
  <xnocompile>false</xnocompile> 
 </configuration>
 <executions>
  <execution> 
   <goals> 
    <goal>wsimport</goal> 
   </goals>
  </execution> 
 </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我的 EndpointService.wsdl 位于 src/main/wsdl 中。插件生成带注释的 EndointServiceService.java

@WebServiceClient(name = "EndpointServiceService", targetNamespace = "http://soap.endpoint.fsg.ftc/", wsdlLocation = "file:/D:/Source/java/branches/9.3.0/camel-smev/wscapi/src/wsdl/EndpointService.wsdl")
Run Code Online (Sandbox Code Playgroud)

所以如果 wsdl

D:/Source/java/branches/9.3.0/camel-smev/wscapi/src/wsdl/EndpointService.wsdl 
Run Code Online (Sandbox Code Playgroud)

不存在(在另一台机器上),它在运行时抛出异常。如果我将 wsdl 复制到此目录,它会成功运行。我如何将 wsdl 包含到我的目标 jar 中并让客户端使用它?或者如何在运行时完全排除 wsdl 依赖性?也许尝试旧版本或其他插件?

wsdl web-services jax-ws maven jaxws-maven-plugin

5
推荐指数
1
解决办法
3215
查看次数

JaxWS:外部化 Http 管道名称属性

我有 SOAP Web 服务的 WSDL 文件,我需要通过 http 调用它。使用 cxf wsdl2java 插件我创建了存根方法。

我已经使用 jaxws 创建了 Web 服务客户端。Web 服务启用了基本身份验证。我正在尝试配置 http 管道

 my application.properties
 --------------------------
 webservices.http.auth.username=username
 webservices.http.auth.password=password
 fold.webservices.http.auth.authtype=Basic
 webservices.http.conduit.property.name=https://fixed_deposits-test.co.in/fold-webservices/services.*
 fold.updateservice.soap.address=https://fixed_deposits-test.co.in/fold-webservices/services/UpdateService
 ----------------------------     
Run Code Online (Sandbox Code Playgroud)

我的春天背景...

 <?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
        xmlns:sec="http://cxf.apache.org/configuration/security"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd
                    http://cxf.apache.org/configuration/security http://cxf.apache.org/schemas/configuration/security.xsd
                    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

   <bean id="properties" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
      <property name="locations">
        <util:list>
            <value>file:${config.dir}/application.properties</value>
        </util:list>
      </property>
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
   </bean>

   <jaxws:client id="updateServiceClient" serviceClass="com.fold.facade.v1.UpdateService" address="${fold.updateservice.soap.address}" >
      <jaxws:inInterceptors>
        <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" >
            <property name="prettyLogging" value="true" />
        </bean>
      </jaxws:inInterceptors>
      <jaxws:outInterceptors>
        <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" …
Run Code Online (Sandbox Code Playgroud)

soap web-services jax-ws apache-camel webservices-client

5
推荐指数
1
解决办法
6459
查看次数