gpt4 book ai didi

java - 与 https 网络服务通信时收到 HTTP 302 错误代码

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:19 27 4
gpt4 key购买 nike

我有一个托管在 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 中具有以下 header 信息:(状态行)HTTP/1.1 302 Found;连接关闭 位置 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)

我非常感谢在这个问题上的任何帮助。谢谢你。

最佳答案

您是否在信任库中导入了 ssl 证书? eclipse JVM 可能有证书,而您的部署没有。

openssl s_client -connect -showcerts cert.pem此命令将下载证书。您可以使用指向您的服务器网址的任何浏览器来执行此操作。

并列出:keytool -list -keystore -storepass

如果您的证书不存在,您可以添加它:keytool -import -alias -file derp.pem -keystore -storepass

关于java - 与 https 网络服务通信时收到 HTTP 302 错误代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23835441/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com