I'm very new to webservice request and response. I did search how to connect webservices to proxys like this post: Webservice with HTTPS and also several other post in this forum. I failed to connect to the webservice through the proxy.
Here is my code:
final String WS_URL_HTTP = "https://bcrmpiqci.tnb.com.my/dir/wsdl?p=ic/653b15a2bf3e3bfda703456d4ceac77e";
final String endPoint = "https://bcrmpiqci.hq.tnb.com.my:50101/XISOAPAdapter/MessageServlet?senderParty=&senderService=INFINITIUM&receiverParty=&receiverService=&interface=AutoPayRegistrationRequestAsync_Out&interfaceNamespace=urn:tnb.com.my:BCRM:po:PROC:FICA:AutoPay:1.0";
final String username = "username";
final String password = "password";
HttpsURLConnection con = null;
try {
URL url = new URL(WS_URL_HTTP);
//binding the authenticator
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
});
//con = (HttpURLConnection) url.openConnection();
con = (HttpsURLConnection) url.openConnection();
int resp = con.getResponseCode();
if(resp == 200){
AutoPayRegistrationRequestAsyncOutService service = new AutoPayRegistrationRequestAsyncOutService();
System.out.println(service.getHTTPSPort());
BindingProvider bindingProvider = (BindingProvider) service;
bindingProvider.getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
System.out.println(resp + " connection return ok! ");
System.out.println(con.getHeaderFields());
//put the payload soap envelop here
Header header = new Header();
header.setFileName("ujabbbbbbb");
header.setItemCount("3");
header.setSystemName("TNBEBPP");
header.setMessageID("98");
header.setPaymentID("300");
header.setSystemPassword("p@ssw0rd");
Item item = new Item();
item.setContractAccountNumber("880909090");
item.setItemMessageID("00");
item.setNewCreditCardNumber("4111111111111111");
item.setNewTokenID("adasdoqwiejijadsol");
item.setOldCreditCardNumber("4111111111111114");
item.setRegistrationIndicator("55");
item.setSenderSystemIndicator("00");
AutoPayRegistrationAsyncRequest.AutoPayRegistration value = new AutoPayRegistrationAsyncRequest.AutoPayRegistration();
value.setHeader(header);
value.getItem().add(item);
AutoPayRegistrationAsyncRequest req = new AutoPayRegistrationAsyncRequest();
req.setAutoPayRegistration(value);
AutoPayRegistrationRequestAsyncOut out = service.getHTTPSPort();
out.autoPayRegistrationRequestAsyncOut(req);
System.out.println(out.toString());
} else {
System.out.println(resp);
System.out.println("error authenticate or malform url");
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
con.disconnect();
}
I hope you guys can enlighten my knowledge here.
My wsdl:
<wsdl:port name="HTTPS_Port" binding="p1:AutoPayRegistrationRequestAsync_OutBinding">
<soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="https://bcrmpiqci.hq.tnb.com.my:50101/XISOAPAdapter/MessageServlet?senderParty=&senderService=INFINITIUM&receiverParty=&receiverService=&interface=AutoPayRegistrationRequestAsync_Out&interfaceNamespace=urn%3Atnb.com.my%3ABCRM%3Apo%3APROC%3AFICA%3AAutoPay%3A1.0"/>
</wsdl:port>