I'm trying to connect DHL Webservice searchLocations DHL wsdl:https://standorte.deutschepost.de/webservice/?wsdl Here the code I'm using (just trying to test it ), I always get this exception :
de.dpag.postfinder.webservice.ServiceException_Exception: Access denied. Access key is not valid.
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;
import de.dpag.postfinder.webservice.AutomatWS;
import de.dpag.postfinder.webservice.InputAddress;
import de.dpag.postfinder.webservice.WebServiceImpl;
import de.dpag.postfinder.webservice.WebServiceImplService;
public class DHLWebService {
public static void main(String[] args) throws Exception {
InputAddress request = new InputAddress();
request.setCountryCode("DE");
request.setCity("Bonn");
request.setStreet("harles-de-Gaulle-Str");
request.setStreetNo("20");
request.setZip("53113");
List<AutomatWS> packstationsByAddress = new ArrayList<AutomatWS>();
String wsdlLocation = "https://standorte.deutschepost.de/webservice/?wsdl";
try {
URL wsdlUrl = new URL(wsdlLocation);
QName qName = new QName("http://postfinder.dpag.de/webservice", "WebServiceImplService");
WebServiceImplService dhlClientService = new WebServiceImplService(wsdlUrl, qName);
WebServiceImpl webServiceImplPort = dhlClientService.getWebServiceImplPort();
Map<String, Object> req_ctx = ((BindingProvider) webServiceImplPort).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "https://standorte.deutschepost.de/webservice/?wsdl");
Map<String, List<String>> headers = new HashMap<String, List<String>>();
//sample username and password
headers.put("Username", Collections.singletonList("test"));
headers.put("Password", Collections.singletonList("test"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
packstationsByAddress = webServiceImplPort.getPackstationsByAddress("", request);
} catch (Exception e) {
e.printStackTrace();
}
for (AutomatWS automatWS : packstationsByAddress) {
System.out.println(automatWS.getAddress());
}
}
}
I figure out the problem,the end point need to be at the end of the wsdl file as the following :
<service name="WebServiceImplService">
<port name="WebServiceImplPort" binding="tns:WebServiceImplPortBinding">
<soap:address location="https://cig.dhl.de/services/sandbox/soap" />
</port>
</service>
Then the code should be as the following :
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import de.dpag.postfinder.webservice.AutomatWS;
import de.dpag.postfinder.webservice.InputAddress;
import de.dpag.postfinder.webservice.WebServiceImpl;
import de.dpag.postfinder.webservice.WebServiceImplService;
public class DHLWebService {
//wsdl path
private static final String RELATIVE_WSDL_PATH = "";
public static void main(String[] args) throws Exception {
InputAddress request = new InputAddress();
request.setCountryCode("DE");
request.setCity("Bonn");
request.setStreet("harles-de-Gaulle-Str");
request.setStreetNo("20");
request.setZip("53113");
List<AutomatWS> packstationsByAddress = new ArrayList<>();
try {
URL wsdlLocalURL = DHLWebService.class.getResource(RELATIVE_WSDL_PATH);
QName qName = new QName("http://postfinder.dpag.de/webservice", "WebServiceImplService");
WebServiceImplService dhlClientService = new WebServiceImplService(wsdlLocalURL,qName);
WebServiceImpl webServiceImplPort = dhlClientService.getWebServiceImplPort();
Map<String, Object> req_ctx = ((BindingProvider) webServiceImplPort).getRequestContext();
// replace it with your username and password
req_ctx.put(BindingProvider.USERNAME_PROPERTY, "test");
req_ctx.put(BindingProvider.PASSWORD_PROPERTY, "test");
packstationsByAddress = webServiceImplPort.getPackstationsByAddress("", request);
} catch (Exception e) {
e.printStackTrace();
}
for (AutomatWS automatWS : packstationsByAddress) {
System.out.println(automatWS.getAddress());
}
}
}