我在Apache Tomcat中托管了一个java Web服务。 Tomcat Server.xml文件有一个这样的条目:
Connector port="8025" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
但是,端口8443(假设是ssl端口)已被注释掉。
使用HTTPWatch,我注意到服务器正在将客户端请求重定向到http://sa-dev-sf.erp.net/testWSthree/service?wsdl。而不是https:// ..并且在httpwatch中有以下标题信息:(状态 - 行)HTTP / 1.1 302找到;连接关闭位置sa-dev-sf.erp.net/testWSthree/service?wsdl
这是我的客户端测试类。如果我在tomcat服务器中部署客户端并调用该服务,我将收到错误(请参阅下面的日志)。请注意,使用Eclipse IDE
在本地计算机上运行正常import a.Service; //from wsimport
import a.ServiceImplService; //from wsimport
public class Call {
public String callTest(){
ServiceImplService serviceImpl = new ServiceImplService();
Service s = serviceImpl.getServiceImplPort();
final BindingProvider getResultBP = (BindingProvider) s ;
getResultBP.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://sa-dev.erp.xxxx.net/testWSthree/service");
System.out.println(s.salaryUpgrade("sanjoy"));
}}
以下是 wsimport 生成的两个类:
@WebService(name = "Service", targetNamespace = "http://a/")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface Service {
/**
* @param name
* @return returns java.lang.String
*/
@WebMethod(operationName = "SalaryUpgrade")
@WebResult(partName = "return")
@Action(input = "http://a/Service/SalaryUpgradeRequest", output = "http://a/Service/SalaryUpgradeResponse")
public String salaryUpgrade(
@WebParam(name = "name", partName = "name")
String name);
}
和
@WebServiceClient(name = "ServiceImplService", targetNamespace = "http://a/", wsdlLocation =
"https://sa-dev.erp.xxxxx.net/testWSthree/service?wsdl")
public class ServiceImplService extends javax.xml.ws.Service
{
private final static URL SERVICEIMPLSERVICE_WSDL_LOCATION;
private final static WebServiceException SERVICEIMPLSERVICE_EXCEPTION;
private final static QName SERVICEIMPLSERVICE_QNAME = new QName("http://a/", "ServiceImplService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("https://sa-dev.erp.xxxxx.net/testWSthree/service?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
SERVICEIMPLSERVICE_WSDL_LOCATION = url;
SERVICEIMPLSERVICE_EXCEPTION = e;
}
public ServiceImplService() {
super(__getWsdlLocation(), SERVICEIMPLSERVICE_QNAME);
}
public ServiceImplService(WebServiceFeature... features) {
super(__getWsdlLocation(), SERVICEIMPLSERVICE_QNAME, features);
}
public ServiceImplService(URL wsdlLocation) {
super(wsdlLocation, SERVICEIMPLSERVICE_QNAME);
}
public ServiceImplService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, SERVICEIMPLSERVICE_QNAME, features);
}
public ServiceImplService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public ServiceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns Service
*/
@WebEndpoint(name = "ServiceImplPort")
public a.Service getServiceImplPort() {
return super.getPort(new QName("http://a/", "ServiceImplPort"), Service.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns Service
*/
@WebEndpoint(name = "ServiceImplPort")
public a.Service getServiceImplPort(WebServiceFeature... features) {
return super.getPort(new QName("http://a/", "ServiceImplPort"), Service.class, features);
}
private static URL __getWsdlLocation() {
if (SERVICEIMPLSERVICE_EXCEPTION!= null) {
throw SERVICEIMPLSERVICE_EXCEPTION;
}
return SERVICEIMPLSERVICE_WSDL_LOCATION;
}
}
当我从Eclipse IDE调用Web服务时,这工作正常。但是,如果我在我们的tomcat服务器中部署此客户端应用程序并调用该服务,则会收到以下错误:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.xml.ws.WebServiceException: Failed to access the WSDL at: https://sa-dev.erp.xxxxx.net/testWSthree/service?wsdl. It failed with:
Got sa-dev-sf.erp.umasscs.net while opening stream from https://sa-dev.erp.xxxxx.net /testWSthree/service?wsdl.
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:173)
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:155)
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)
com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:257)
com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:220)
com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
javax.xml.ws.Service.<init>(Service.java:77)
a.ServiceImplService.<init>(ServiceImplService.java:41)
ws.callWS.Call.callTest(Call.java:26)
org.apache.jsp.index_jsp._jspService(index_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
java.io.IOException: Got sa-dev-sf.erp.umasscs.net while opening stream from https://sa- dev.erp.xxxxx.net/testWSthree/service?wsdl
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.createReader(RuntimeWSDLParser.java:842)
com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.resolveWSDL(RuntimeWSDLParser.java:283)
我真的很感激这个问题上的任何帮助。谢谢你。
答案 0 :(得分:1)
您是否在信任存储区导入ssl证书? eclipse JVM可能有证书而你的部署没有。
openssl s_client -connect -showcerts&lt; / dev / null | openssl x509 -outform PEM&gt; cert.pem 此命令将下载证书。您可以使用任何指向您服务器网址的浏览器来执行此操作。
并列出:keytool -list -keystore -storepass
如果您的证书不在那里,请添加: keytool -import -alias -file derp.pem -keystore -storepass