Первый раз работаю над сервисами SOAP.Мне нужно позвонить в этот веб-сервис.http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL
Вот 2 из 11 заглушек, сгенерированных мной с использованием wsimport
Я пытался целый день, но получаю эту ошибкусообщение.Зачем?Я подозреваю, потому что я не передал в заголовке аутентификации правильно.Но в то же время мне интересно, почему полученная заглушка не поставляется с заголовком Authentication как параметром метода?это нормально?Нужна помощь.Я так запутался.
Исключение в потоке "main" com.sun.xml.internal.ws.fault.ServerSOAPFaultException: клиент получил ошибку SOAP от сервера: серверу не удалось обработать запрос.---> Ссылка на объект не установлена на экземпляр объекта.Пожалуйста, посмотрите журнал сервера, чтобы найти более подробную информацию о точной причине сбоя.
WebLITETSServicesSoap.java
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
@WebService(name = "WebLITE_TSServicesSoap", targetNamespace = "TransactionalSubmissionsSvcs")
@XmlSeeAlso({
ObjectFactory.class
})
public interface WebLITETSServicesSoap {
@WebMethod(operationName = "GetTemplateList", action = "TransactionalSubmissionsSvcs/GetTemplateList")
@WebResult(name = "GetTemplateListResult", targetNamespace = "TransactionalSubmissionsSvcs")
@RequestWrapper(localName = "GetTemplateList", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateList")
@ResponseWrapper(localName = "GetTemplateListResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.GetTemplateListResponse")
public String getTemplateList();
@WebMethod(operationName = "SendWithXML", action = "TransactionalSubmissionsSvcs/SendWithXML")
@WebResult(name = "SendWithXMLResult", targetNamespace = "TransactionalSubmissionsSvcs")
@RequestWrapper(localName = "SendWithXML", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXML")
@ResponseWrapper(localName = "SendWithXMLResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithXMLResponse")
public String sendWithXML(
@WebParam(name = "xmldoc", targetNamespace = "TransactionalSubmissionsSvcs")
SendWithXML.Xmldoc xmldoc);
@WebMethod(operationName = "SendWithJSON", action = "TransactionalSubmissionsSvcs/SendWithJSON")
@WebResult(name = "SendWithJSONResult", targetNamespace = "TransactionalSubmissionsSvcs")
@RequestWrapper(localName = "SendWithJSON", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSON")
@ResponseWrapper(localName = "SendWithJSONResponse", targetNamespace = "TransactionalSubmissionsSvcs", className = "transactionalsubmissionssvcs.SendWithJSONResponse")
public String sendWithJSON(
@WebParam(name = "emaillist", targetNamespace = "TransactionalSubmissionsSvcs")
String emaillist,
@WebParam(name = "params", targetNamespace = "TransactionalSubmissionsSvcs")
String params);
}
WebLITETSServices.java
import javax.xml.namespace.QName;
import javax.xml.ws.*;
import java.net.MalformedURLException;
import java.net.URL;
@WebServiceClient(name = "WebLITE_TSServices", targetNamespace = "TransactionalSubmissionsSvcs", wsdlLocation = "http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL")
public class WebLITETSServices
extends Service
{
private final static URL WEBLITETSSERVICES_WSDL_LOCATION;
private final static WebServiceException WEBLITETSSERVICES_EXCEPTION;
private final static QName WEBLITETSSERVICES_QNAME = new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServices");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://demomt.weblite.com.my/TS_Services/SubmissionsService.asmx?WSDL");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
WEBLITETSSERVICES_WSDL_LOCATION = url;
WEBLITETSSERVICES_EXCEPTION = e;
}
public WebLITETSServices() {
super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME);
}
public WebLITETSServices(WebServiceFeature... features) {
super(__getWsdlLocation(), WEBLITETSSERVICES_QNAME, features);
}
public WebLITETSServices(URL wsdlLocation) {
super(wsdlLocation, WEBLITETSSERVICES_QNAME);
}
public WebLITETSServices(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, WEBLITETSSERVICES_QNAME, features);
}
public WebLITETSServices(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public WebLITETSServices(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
@WebEndpoint(name = "WebLITE_TSServicesSoap")
public WebLITETSServicesSoap getWebLITETSServicesSoap() {
return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class);
}
@WebEndpoint(name = "WebLITE_TSServicesSoap")
public WebLITETSServicesSoap getWebLITETSServicesSoap(WebServiceFeature... features) {
return super.getPort(new QName("TransactionalSubmissionsSvcs", "WebLITE_TSServicesSoap"), WebLITETSServicesSoap.class, features);
}
private static URL __getWsdlLocation() {
if (WEBLITETSSERVICES_EXCEPTION!= null) {
throw WEBLITETSSERVICES_EXCEPTION;
}
return WEBLITETSSERVICES_WSDL_LOCATION;
}
}
Я попытался запустить с TestApplication
public class TestApplication {
public static void main(String[] args) throws MalformedURLException {
MailAdapterApplication adapterApplication = new MailAdapterApplication();
adapterApplication.run();
}
public void run() throws MalformedURLException {
WebLITETSServices services = new WebLITETSServices();
WebLITETSServicesSoap servicesSoap = services.getPort(WebLITETSServicesSoap.class);
Map<String, Object> req_ctx =((BindingProvider)servicesSoap).getRequestContext();
Map<String, List<String>> headers = new HashMap<>();
headers.put("Username",Collections.singletonList("sansun@weblite.com.my"));
headers.put("Password", Collections.singletonList("P@ssW0rd32!"));
headers.put("APIKey", Collections.singletonList("QdrLKxog"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
System.out.println(servicesSoap.getTemplateList());
}
}