我对Web服务很陌生.我无法找到JAX-WS和CXF之间的区别.
根据我的理解,JAX-WS是java和CXF提供的规范的实现.
如果我错了,请纠正我.
我正在创建一个JAX-WS类型的Web服务,其操作返回一个对象WebServiceReply.WebServiceReply类本身包含Object类型的字段.根据操作,各个操作将使用几种不同的数据类型填充该字段.
发布WSDL(我正在使用Netbeans 6.7),并获得一个ASP.NET应用程序来检索和解析WSDL很好,但是当我尝试调用一个操作时,我会收到以下异常:
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class [LDataObject.Patient; nor any of its super class is known to this context.]
Run Code Online (Sandbox Code Playgroud)
如何在DataObject.Patient类中标记注释,以及WebServiceReply类以使其工作?我无法根据目标类中的注释来编组关于编组的权威资源,所以如果有人能够指出我也会很好.
@XmlRootElement(name="WebServiceReply")
public class WebServiceReply {
private Object returnedObject;
private String returnedType;
private String message;
private String errorMessage;
.......... // Getters and setters follow
}
Run Code Online (Sandbox Code Playgroud)
@XmlRootElement(name="Patient")
public class Patient {
private int uid;
private Date versionDateTime;
private String name;
private String identityNumber;
private List<Address> addressList;
private List<ContactNumber> contactNumberList;
private List<Appointment> appointmentList;
private List<Case> caseList;
} …Run Code Online (Sandbox Code Playgroud) 我有一个需要访问Web服务的Java应用程序(不是applet).已经使用JAX-WS生成了Web服务的代理,并且似乎工作正常.在一种情况下,它需要通过Web代理服务器(实际上是Squid 3.0)进行通信,该服务器设置为需要NTLM身份验证.
在Sun的JRE 1.6.0_14上运行,一切都可以正常访问HTTP URL,而无需任何更改:内置的NTLM身份验证器启动,它们都无法正常工作.但是,如果Web服务URL是HTTPS URL,则Web服务调用将在Sun的代码内部失败:
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.lang.NullPointerException
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:142)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
... our web service call ...
Caused by: java.lang.NullPointerException
at sun.net.www.protocol.http.NTLMAuthentication.setHeaders(NTLMAuthentication.java:175)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1487)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:164)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:896)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:109)
... 16 more
Run Code Online (Sandbox Code Playgroud)
查看Sun的bug数据库会在这些类中出现一些例外情况,但所有这些异常似乎都已得到修复.有没有人遇到这样的事情?有人有这个工作吗?
我正在使用JAX-WS Web服务(客户端和公开服务),是否有任何API来测试这些Web服务?
我在设置jax-ws超时方面遇到了麻烦.我的代码是:
@WebServiceClient(name = "VoipDBJDBCService", targetNamespace = "http://db.server.voipmeter.jextreme.eu/", wsdlLocation = "http://trace0.nyc.blinkmind.com:8080/voipdb?wsdl")
public class VoipDBJDBCService extends Service {
public VoipDBJDBCService(URL wsdlLocation) {
super(wsdlLocation, new QName("http://db.server.voipmeter.jextreme.eu/", "VoipDBJDBCService"));
}
@WebEndpoint(name = "VoipDBJDBCPort")
public VoipDB getVoipDBJDBCPort() {
return super.getPort(new QName("http://db.server.voipmeter.jextreme.eu/", "VoipDBJDBCPort"), VoipDB.class);
}
}
Run Code Online (Sandbox Code Playgroud)
用法:
VoipDB db = new VoipDBJDBCService(new URL(url)).getVoipDBJDBCPort();
Run Code Online (Sandbox Code Playgroud)
我如何挂断超时?我在这里找到了"解决方案":https://jax-ws.dev.java.net/guide/HTTP_Timeouts.html但我不知道我将把它挂钩.如何获取代理?当我调用getPort客户端尝试连接,然后如果服务器没有响应则永远挂起.
更新:如果这有任何区别,则从applet init()方法中调用此代码.
使用Service和Dispatch类与SOAPConnection类从Java代码调用Web服务之间有什么区别(哲学或其他)?
例如,像这样:
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = scf.createConnection();
SOAPMessage reply = soapConnection.call(soapMessage, url);
Run Code Online (Sandbox Code Playgroud)
vs大致沿着这些方向的东西?
svc = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = svc.createDispatch(portName, SOAPMessage.class, service.Mode.MESSAGE);
SOAPMessage reply = (SOAPMessage)dispatch.invoke(soapMessage);
Run Code Online (Sandbox Code Playgroud)
这些之间有什么区别,为什么选择一种方法而不是另一种?
我们使用了类JAXWSProperties从com.sun.*包中的代码,以这样设置超时属性:
import com.sun.xml.internal.ws.developer.JAXWSProperties;
...
Map<String, Object> ctxt = ((BindingProvider) port).getRequestContext();
ctxt.put(JAXWSProperties.CONNECT_TIMEOUT, 10000);
Run Code Online (Sandbox Code Playgroud)
它在本地Eclipse中编译良好,但不在连续集成系统上编译(两者都使用JDK 1.6).通过研究这个问题,我了解到com.sun.*应该避免使用这个包.
所以我的问题是:
JAXWSProperties?我正在寻找一个与Eclipse一起使用的JAX-WS教程.我特别想要的是一些使用自上而下的方法,你有一个wsdl文件的url并运行wsgen来生成你的存根.
谢谢!
我用cxf创建了一个带有xew插件的web服务客户端,用于列表展开
问题是null列表中的内容消失了.例如:
我有一个List<String>带有字符串和null-entry的请求
当请求现在到达服务器时,它只包含字符串而不是null条目.因此示例列表中只有2个条目.
这里是wsdl的一个例子:
[..]
<!-- the request -->
<xsd:element name="createGroup">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="1" name="in1" nillable="true" type="ns2:ArrayOfRole"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
[..]
<!-- the list which will be unwrapped -->
<xsd:complexType name="ArrayOfRole">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Role" nillable="true" type="xsd:String"/>
</xsd:sequence>
</xsd:complexType>
Run Code Online (Sandbox Code Playgroud)
我正在使用maven来生成ws客户端
<properties>
<cxf.version>3.0.5</cxf.version>
<jaxbBasic.version>0.6.5</jaxbBasic.version>
</properties>
[..]
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>src/main/java</sourceRoot>
<defaultOptions>
<bindingFiles>
<bindingFile>${basedir}/jaxbBindings.xml</bindingFile>
<bindingFile>${basedir}/jaxwsBindings.xml</bindingFile>
</bindingFiles> …Run Code Online (Sandbox Code Playgroud) 尽管如此我已经定义了相关的依赖项,如下所示,java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl当我的应用程序调用Web服务时获取异常.
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.2.10</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
<type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
ps servlet容器是Apache Tomcat 9.0.4.
ps Java版:9.0.1.