我正在使用Netbeans根据WSDL文件自动创建Web服务客户端.这很好用,除了我正在使用的web服务要求我将HTTP头中的自定义cookie传递给每个web服务以证明我的身份.
我使用一个名为的web服务Utility来获得我的授权.这将设置一个cookie,需要在对任何Web服务的所有后续调用中提供.
这可以通过设置来完成javax.xml.ws.session.maintain对true上的端口web服务的BindingProvider.这适用于后续调用Utilitywebservice中的方法.问题是这只维护该单个Web服务的会话/ cookie.我也需要其他人.
我需要将cookie传递给一个名为 "我如何实现此目标" 的单独 Web服务History?拥有一个超级服务类是否可行,实用程序和历史记录都可以扩展并与之共享相同的会话状态?
我知道这不是提出问题的正确方法,但我遇到了问题:
我有一个本地存储的wsdl,我需要创建一个Web服务客户端来调用该Web服务.问题是服务是在防火墙后面,我必须通过代理连接到它,然后我必须验证连接到WS.
我所做的是使用Apache CXF 2.4.6生成WS客户端,然后设置系统范围的代理
System.getProperties().put("proxySet", "true");
System.getProperties().put("https.proxyHost", "10.10.10.10");
System.getProperties().put("https.proxyPort", "8080");
Run Code Online (Sandbox Code Playgroud)
我知道这不是最好的做法,所以请提出一个更好的解决方案,如果有人能给我一个关于如何设置验证的提示我真的很感激它
java web-services jax-ws webservices-client jax-ws-customization
默认情况下,当RuntimeException在我的服务器上发生扩展的未捕获异常时,JAX-WS会构建以下SOAP错误消息:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>[runtime exception message here]</faultstring>
<detail>
<ns2:exception class="java.lang.RuntimeException" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false" xmlns:ns2="http://jax-ws.dev.java.net/">
<message>[runtime exception message here too]</message>
<ns2:stackTrace>
[stack trace details]
</ns2:stackTrace>
</ns2:exception>
</detail>
</S:Fault>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
哪种有意义,除了我想改变那种行为以便发送它:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>S:Server</faultcode>
<faultstring>Something wrong happened and it's totally our fault</faultstring>
</S:Fault>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
请注意,消息不应该是RuntimeException的消息内容,而是针对可能在服务器端进行扩展的任何异常的自定义静态消息.RuntimeException
我无法更改WSDL,我不想设置自定义异常.
我正在使用spring插件: com.sun.xml.ws.transport.http.servlet.WSSpringServlet
我怎样才能做到这一点?
我收到此错误消息:
[警告] 忽略:绑定文件“file:/home/jeusdi/projects/salut/hes/hes-visor-api-service/src/jaxws/bindings.xml”。它不是 jaxws 或 jaxb 绑定文件
它告诉我我的binding.xml文件无效,它将被忽略。
我的binding.xml文件内容是:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.0">
<jaxb:bindings >
<jaxb:globalBindings typesafeEnumMaxMembers="2000"/>
</jaxb:bindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
有一个由年轻的杨优秀的文章,介绍了如何使用的wsimport创建具有异步Web服务调用Web服务客户端工件.异步要求WSDL具有标记
<enableAsyncMapping>true</enableAsyncMapping>
在其绑定部分.如果您使用自下而上的方法和JAX-WS带注释的Java类,则无法直接在WSDL中执行此操作,因为WSDL是Web服务器上生成的工件.相反,当在WSDL上执行wsimport时,您使用Ant或Maven等构建工具来包含此绑定.
生成的客户端工件具有返回a的异步方法调用
Future<?>
Run Code Online (Sandbox Code Playgroud)
或者a
Response
Run Code Online (Sandbox Code Playgroud)
这是一个未来.
阅读杨的文章后我的问题是为什么不只是使用Executors和Futures滚动我自己的异步Web服务调用.wsimport创建的工件是否提供了一些我无法通过自己的方法看到的优势?
如果有人对这两种方法都有经验或见解,我将非常感谢您的反馈.
JAX-WS要求传输的所有类都具有默认的构造函数(no-arg构造函数).我不明白这个要求,因为客户端基于WSDL创建自己的类.IMO此要求仅适用于那些用作Webservice输入参数的类.
有谁知道如何规避这一要求?
我有几个几百个wsdl文件.每当我为它们创建客户端jaxb客户端类时,Jaxb会自动将所有日期/时间字段映射到XMLGregorianCalender.经过大量的谷歌搜索,我发现提供单独的绑定文件是唯一的解决方案.
我不想提供wsdl位置,因为我有很多,否则我必须为每个wsdl创建一个单独的绑定文件.
下面是我使用的绑定文件.
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" >
<globalBindings>
<javaType name="java.util.Date" xmlType="xsd:dateTime" />
</globalBindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
它使用Date类型创建了jaxb类,但它也自动创建了一个名为Adapter1.java的适配器,这是我不想要的.我有自己的包结构,不能偏离它.
org.w3._2001.xmlschema
此适配器将日期从String转换为java.util.Date,我的应用程序失败,因为转换器应该从XMLGregorianCalender转换为java.util.Date
所以,我自己写了一个适配器
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Calendar;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class DateAdapter extends XmlAdapter<XMLGregorianCalendar, Date> {
@Override
public XMLGregorianCalendar marshal(Date date) throws Exception {
GregorianCalendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTime(date);
XMLGregorianCalendar xmlGregorianCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
return xmlGregorianCalendar;
}
@Override
public Date unmarshal(XMLGregorianCalendar xmlGregorianCalendar) throws Exception {
return xmlGregorianCalendar.toGregorianCalendar().getTime();
}
}
Run Code Online (Sandbox Code Playgroud)
并更改了我的自定义文件,如下所示:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" >
<globalBindings>
<javaType name="java.util.Date" …Run Code Online (Sandbox Code Playgroud) 我正在使用maven-jaxws-plugin从我的wsdl,schema中生成java类.它不会在生成的类中生成@XmlElementWrapper注释.从这篇文章我明白我需要使用jaxb-xew-plugin但是我无法使用maven-jaxws-plugin.任何帮助,将不胜感激.这是我试过的配置
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<xjcArgs>
<xjcArg>-no-header</xjcArg>
<xjcArg>-Xxew</xjcArg>
<xjcArg>-Xxew:instantiate lazy</xjcArg>
<xjcArg>-Xxew:delete</xjcArg>
</xjcArgs>
<extension>true</extension>
<wsdlDirectory>${basedir}/src/main/resources</wsdlDirectory>
<wsdlFiles>
<wsdlFile>attribute-service.wsdl</wsdlFile>
</wsdlFiles>
<sourceDestDir>${project.build.directory}/generated</sourceDestDir>
<verbose>true</verbose>
<keep>true</keep>
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.0</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如果它只能与maven-jaxb2-plugin集成,你可以帮我搞网络服务吗?基本上如何指定wsdl以及如何生成Service类?(使用@WebService注释)
谢谢,
Bhagya
wsimport maven-jaxb2-plugin jax-ws-customization jaxb-xew-plugin
我之前使用过JAX-WS,但之前没有将自定义对象作为参数传递过.我正在使用GlassFish 3.1,NetBeans 7.3并通过NetBeans JAX-WS向导创建服务.我的问题是当服务器上接收到传递给服务的自定义对象(Criteria)为null时.我可以成功传递像int这样的默认类型.
@WebService(serviceName = "ECLService")
@Stateless()
public class ECLService {
@EJB
PersistenceImpl persistence;
@WebMethod(operationName = "listRevisions")
public List<Revision> listRevisions(@WebParam(name="criteria")Criteria criteria) {
System.out.println("criteria is "+(criteria ==null ? "null":" not null"));
List<Revision> revisions = persistence.getRevisions(criteria);
return revisions;
}
}
Run Code Online (Sandbox Code Playgroud)
Criteria.java
@XmlRootElement
public class Criteria implements Serializable {
private static final long serialVersionUID = 1L;
public static final String LIST_TYPE = "criteria.key.listtype";
public static final String TYPE_ALL = "criteria.value.all";
public static final String TYPE_ERROR = "criteria.value.error";
public static final String TYPE_ARCHIVE …Run Code Online (Sandbox Code Playgroud) 我在Jax-WS中遇到问题,我公开的服务无法处理以下消息:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<CCGW_CUSTOM_HEADER xmlns="">
<CCGW_CUSTOM_HEADER xmlns="Key"><?xml version="1.0" encoding="utf-16"?>&#xD;<CcgwCustomHeaderData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">&#xD; <ClientSystemType>ClientSystem</ClientSystemType>&#xD;</CcgwCustomHeaderData></CCGW_CUSTOM_HEADER>
</CCGW_CUSTOM_HEADER>
</S:Header>
<S:Body>
<HeartbeatRequest xmlns="http://my-site.com/CCGWCallback">
<conferenceId>this is a heartbeat</conferenceId>
</HeartbeatRequest>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
但是,服务器能够处理此消息:
<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<CCGW_CUSTOM_HEADER xmlns="">
<CCGW_CUSTOM_HEADER xmlns="Key"><?xml version="1.0" encoding="utf-16"?>&#xD;<CcgwCustomHeaderData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">&#xD; <ClientSystemType>ClientSystem</ClientSystemType>&#xD;</CcgwCustomHeaderData></CCGW_CUSTOM_HEADER>
</CCGW_CUSTOM_HEADER>
</S:Header>
<S:Body>
<ns2:HeartbeatRequest xmlns:ns2="http://my-site.com/CCGWCallback">
<conferenceId xmlns="">this is a heartbeat</conferenceId>
</ns2:HeartbeatRequest>
</S:Body>
</S:Envelope>
Run Code Online (Sandbox Code Playgroud)
我想要做的是找到一种方法来删除":ns2"前缀.
我将感激你的帮助.
Nadav
jax-ws ×8
java ×4
jaxb ×3
web-services ×3
wsimport ×2
asynchronous ×1
cookies ×1
spring ×1
xml ×1