我的任务是在JBOSS7应用程序服务器上使用JSF2,EJB3开发Web应用程序。
该应用程序非常简单,但是我必须使用其他人开发的Web服务(soap / wsdl)。
在SOAPUI的帮助下,上述Web服务可以完美运行。
问题:集成到Java代码中时,显示错误消息:“ 服务器发送了HTTP状态代码404:null ”
能给我建议吗?
谢谢
WSDL
enter image description here
使用SoapUi进行测试:
enter image description here
注意:在使用soapUi进行测试的过程中,您必须手动集成端点URL和soapaction值。
类:ResponseHeader.java
package com.myproject.site;
public class ResponseHeader {
private int code;
public ResponseHeader() {
super();
// TODO Auto-generated constructor stub
}
public ResponseHeader(int code) {
super();
this.code = code;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
接口SiteService.java:
package com.myproject.site;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace = "http://www.monsite.com/webservices/app-homeSecurityValidation-ws", name = "app-homeSecurityValidation-ws")
public interface SiteService {
@WebMethod
public ResponseHeader HomeSecurityValidationRequest(
@WebParam(name = "verif", targetNamespace = "")
java.lang.String verif,
@WebParam(name = "login", targetNamespace = "")
java.lang.String account,
@WebParam(name = "password", targetNamespace = "")
java.lang.String password
) ;
}
类主Test.java:
package com.myproject.site;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;
public class Test {
public static void main(String[] args) throws SOAPException, IOException {
try {
String soapEndpointUrl = "http://10.168.12.12:8080/homeSecurityValidation/app-homeSecurityValidation-ws";
String soapAction = "homeSecurityValidation";
URL url = new URL("http://10.168.12.12:8080/homeSecurityValidation/app-homeSecurityValidation-ws.wsdl");
QName qName = new QName("http://www.monsite.com/webservices/app-homeSecurityValidation-ws",
"app-homeSecurityValidation-ws");
/*********/
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", soapAction);
soapMessage.saveChanges();
Service service = Service.create(url, qName);
SiteService hello = (SiteService) service.getPort(SiteService.class);
BindingProvider bp = (BindingProvider) hello;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapEndpointUrl);
ResponseHeader r = hello.HomeSecurityValidationRequest("OK",
"mylogin",
"mypassword");
System.out.println("response: " + r.getCode());
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
控制台Eclipse
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 404: null
atcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:296)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:245)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:203)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:123)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:163)
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:135)
at com.sun.proxy.$Proxy10.homeSecurityValidationRequest(Unknown Source)
at com.myproject.site.Test.main(Test.java:49)
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."