我正在为一个Web服务编写一个java客户端.我使用wsimport生成代理.将它们复制到我的工作区项目(在eclipse中).用几个ws调用写了一个简单的程序.现在,当我想进入soap调用时,eclipse说找不到该文件的源代码(com.sun.xml.internal.ws.client.sei.SEIStub.class).它使用来自rt.jar的这个类,它指向安装附带的src.zip.我注意到src.zip不包含丢失的java文件,所以我单独下载它们并尝试将它们添加到zip文件中.我也尝试将它们复制到我的项目中,看看我是否可以欺骗eclipse接受它们作为源文件.
我不定期编写/调试Java,所以请在这里帮助我.我真的想调试并查看jax-ws与轴的不同之处,因为调用在后面的实现中起作用.
假设我有一个带有一些注释的接口,例如:
@SpecialClass
public interface IFoo { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
假设我创建了一个实现接口的类:
public class Foo implements IFoo { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
类是否可能Foo以某种方式"继承"或自动复制来自IFoo其成员的所有或部分注释(例如,自动注释Foo为@SpecialClass等)?
这将便于实现Web服务类(如那些由JAX-WS"的wsimport"工具生成)由刚刚执行其标注的接口,而无需显式不必界面注释复制到实现类(如javax.jws.WebService,javax.xml.ws.RequestWrapper等).
这是请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://soap.ws.server.wst.fit.cvut.cz/">
<soapenv:Header>
<userId>someId</userId>
</soapenv:Header>
<soapenv:Body>
...
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
我想得到那个userId.
我试过这个
private List<Header> getHeaders() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
return CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
}
private String getHeader(String name) {
List<Header> headers = getHeaders();
if (headers != null) {
for (Header header : headers) {
logger.debug(header.getObject());
// return header by the given name
}
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
并记录[userId : …
我正在尝试使用提供商公开的Web服务.提供者在他的结尾有一个严格的检查,请求xml不应该包含没有值的标签.
我正在使用Jax-WS.如果我没有在特定对象中设置值,则它将作为空标记发送,并且标记存在.PFB这个例子说明了我的问题.
客户端XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:host="http://host.testing.webservice.com/">
<soapenv:Header/>
<soapenv:Body>
<host:testingMathod>
<arg0>
<PInfo>
<IAge>45</IAge>
<strName>Danny</strName>
</PInfo>
<strCorrId>NAGSEK</strCorrId>
<strIpAddress></strIpAddress>
</arg0>
</host:testingMathod>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
在这里,没有给出IpAddress的值,因此发送了空标签.
因此,请告诉我们在删除请求xml中的空标记时需要做些什么.Handlerchain是同一个唯一的解决方案吗?
谢谢,Naveen.
我是JAX-WS的新手.我正在尝试访问公司内远程计算机上的Web服务.
我使用wsimport工具从我们的Intranet上的WSDL资源生成JAVA类.已成功创建Java文件.
我尝试通过SOAPUI发送请求,我收到了有效的响应.但是当我尝试运行我的代码时,它会抛出Connection拒绝.
这是我的代码.
URL url = new URL("https://xmattersqa.com/api/services/xmatters-4.1.7?wsdl");
QName qname = new QName("http://www.xmatters.com/webservices/schema#4.1.7", "xmatters- 4.1.7");
FindWhoIsOnDuty f = new FindWhoIsOnDuty();
Xmatters417 cdoubleprime = new Xmatters417(url,qname);
Xmatters417PortType port = cdoubleprime.getXmatters417SOAP11PortHttp();
FindWhoIsOnDutyReturn fresponse = port.findWhoIsOnDuty("fmsopsqa","fmsopsqa", "", "", "", "Default Company", "Test Grp 1","23/02/2013 0:00:00 AM", "24/02/2013 0:00:00 AM", false);
Run Code Online (Sandbox Code Playgroud)
后来我尝试添加这段代码,它仍然无法正常工作.
Authenticator.setDefault(new ProxyAuthenticator("fmsopsqa","fmsopsqa"));
System.setProperty("http.proxHost","sprdxmaws401.corp.net");
System.setProperty("http.proxyPort", "8081");
Run Code Online (Sandbox Code Playgroud)
这就是我得到的
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection refused
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) …Run Code Online (Sandbox Code Playgroud) 我正在寻找各地试图找出如何将无状态会话bean转换为JAX-WS Web服务(我使用的是WAS 7,Websphere Integration Developer,EJB 3).不是Jax-RPC.我正式厌倦了与WID附带的向导搞乱.出于某种原因,它根本不会让我这样做...我尝试从Java bean创建一个JAX-WS Web服务,换句话说,我创建了一个Java类并在那个东西上运行向导,它创建了一个全新的项目......
那里有一个教程,只需要给我一些我需要知道的东西来创建这个Webservice而不必使用向导吗?
我用Java创建了一个Web服务JAX-WS.这是一个简单的只返回a的大写版本String:
@WebService(endpointInterface = "mod2.Mod2")
public class Mod2Impl implements Mod2 {
@Override
public String mod2(String x) {
return x.toUpperCase();
}
}
Run Code Online (Sandbox Code Playgroud)
及其界面:
@WebService
public interface Mod2 {
@WebMethod
String mod2(String x);
}
Run Code Online (Sandbox Code Playgroud)
JAX使用相关类为我生成mod2.jaxws包.响应是这样的:
@XmlRootElement(name = "mod2Response", namespace = "http://mod2/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "mod2Response", namespace = "http://mod2/")
public class Mod2Response {
@XmlElement(name = "return", namespace = "")
private String _return;
/**
*
* @return
* returns String
*/
public String getReturn() {
return this._return;
}
/**
*
* …Run Code Online (Sandbox Code Playgroud) 我已经实现了Web服务MyWebServiceImpl,如:
@WebServiceClient(//my parameters//)
@HandlerChain(file = "handlers.xml")
public class MyWebServiceImpl {...}
Run Code Online (Sandbox Code Playgroud)
我也有像MyWebService这样的接口
@WebService(//my parameters//)
@XmlSeeAlso({
com.my.ObjectFactory.class,
com.my.second.ObjectFactory.class,
com.my.third.ObjectFactory.class
})
public interface MyWebService {...}
Run Code Online (Sandbox Code Playgroud)
我想使用Soap处理程序获得响应,因此我创建了handlers.xml,LoggingHandler.然后我尝试执行我的测试类我得到错误:
javax.xml.ws.WebServiceException: {http://service.ws.my.com/}MyWebServiceImpl is not a valid service. Valid services are: {http://service.ws.my.com/}myWebService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.my.ws.service.MyWebServiceImpl.<init>(MyWebServiceImpl.java:46)
at test.MainTest.<init>(MainTest.java:354)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at …Run Code Online (Sandbox Code Playgroud) 是否可以使用jax-ws soap-webservicecan输出json格式而不是xml?
@Component
@WebService
public class HRSService {
@WebMethod
public String test(String value) {
return value; //returned as XML. JSON possible?
}
}
Run Code Online (Sandbox Code Playgroud) 我想创建一个Maven项目,它将构建我的webservice war文件,准备在GlassFish上部署.看起来像小蛋糕,但我找不到任何可以解释如何做到这一点的教程.他们中的大多数已经过时(大约在2008年).
我使用的是最新的Java(1.8),Glassfish(4.1)和Maven(3.3.3).
目标是在Glassfish上运行"hello world"Web服务.
码:
import javax.jws.WebService;
@WebService
public class Hello {
public String sayHello(String name) {
return "Hello " + name + "!";
}
}
Run Code Online (Sandbox Code Playgroud)
我应该使用什么maven插件?
jax-ws ×10
java ×7
web-services ×3
cxf ×2
annotations ×1
eclipse ×1
ejb-3.0 ×1
handler ×1
jaxb ×1
json ×1
maven ×1
moxy ×1
response ×1
soap ×1
soap-client ×1
spring ×1
websphere-7 ×1
wsimport ×1
xml ×1
xsd ×1