Reputation: 45
I am trying to read a url through properties file and passing into the apache http post constructor.when I did this I am getting 404 error and when hard code it,it is working fine.I don't know what is the difference between two approaches. After reading from properties file i am printing the variable on console,it is showing the exact url,but I am getting '404 not found' when i passed the same string variable in http apache client.Can anyone guide me on this.Thanks
Reading URL :
requestURL = MWTConfiguration.getInstance().getValue("NPCI_AUTH_URL");
System.out.println("Request URL :"+requestURL);
objAuthRequest.setPid(objFITransXTRequest.getPid());
objAuthRequest.setRbd("");
authResponse =objMWTHttpClient.execute(strRequestJson, requestURL);
Client Code :
public String execute(String requestData, String strURL) throws ParseException, Exception {
String strResponse = "";
StringBuffer objSBuffer = new StringBuffer();
try {
HttpClient httpClient = HttpClientBuilder.create().build();
System.out.println("URLLLL : :"+strURL);
HttpPost reqFundTransf = new HttpPost(strURL);
StringEntity params = new StringEntity(requestData);
reqFundTransf.addHeader("content-type", "application/json");
reqFundTransf.setEntity(params);
HttpResponse objResponse = httpClient.execute(reqFundTransf);
HttpEntity objRespEntity = objResponse.getEntity();
BufferedReader objBReader = new BufferedReader(new InputStreamReader(objRespEntity.getContent()));
while ((strResponse = objBReader.readLine()) != null) {
objSBuffer.append(strResponse);
}
} catch (Exception e) {
throw new Exception(e);
}
return objSBuffer.toString();
Console View :
URLLLL : :http://223.30.66.28:8080/AEPSNPCI/rest/aepsauth/authentication
2017-03-14 16:08:27 DEBUG RequestAddCookies:122 - CookieSpec selected: best-match
2017-03-14 16:08:27 DEBUG RequestAuthCache:75 - Auth cache not set in the context
2017-03-14 16:08:27 DEBUG PoolingHttpClientConnectionManager:219 - Connection request: [route: {}->http://223.30.66.28:8080][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
2017-03-14 16:08:27 DEBUG PoolingHttpClientConnectionManager:250 - Connection leased: [id: 0][route: {}->http://223.30.66.28:8080][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
2017-03-14 16:08:27 DEBUG MainClientExec:217 - Opening connection {}->http://223.30.66.28:8080
2017-03-14 16:08:27 DEBUG HttpClientConnectionOperator:120 - Connecting to /223.30.66.28:8080
2017-03-14 16:08:27 DEBUG HttpClientConnectionOperator:127 - Connection established 10.9.31.135:44782<->223.30.66.28:8080
2017-03-14 16:08:27 DEBUG MainClientExec:238 - Executing request POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1
2017-03-14 16:08:27 DEBUG MainClientExec:243 - Target auth state: UNCHALLENGED
2017-03-14 16:08:27 DEBUG MainClientExec:249 - Proxy auth state: UNCHALLENGED
2017-03-14 16:08:27 DEBUG headers:124 - http-outgoing-0 >> POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> content-type: application/json
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Content-Length: 729
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Host: 223.30.66.28:8080
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Connection: Keep-Alive
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.3.4 (java 1.5)
2017-03-14 16:08:27 DEBUG headers:127 - http-outgoing-0 >> Accept-Encoding: gzip,deflate
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "POST /AEPSNPCI/rest/aepsauth/authentication HTTP/1.1[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "content-type: application/json[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Content-Length: 729[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Host: 223.30.66.28:8080[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.4 (java 1.5)[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 >> "[\r][\n]"
2017-03-14 16:08:27 DEBUG wire:86 - http-outgoing-0 >> "{"modality":{"fp":true,"otp":false},"uidNumber":"496640436689","rrn":"707316193975","pid":"YUVIL7CKWbBjFV+UCZBKGMnLJeHSNJjrZ6r+0kyfMZl0VEKNeIHyeaXFPLsYXyxJ9qISBTPmN/4qrS82AT781Q\u003d\u003d","rbd":"","hmac":"XuVPiZ9kLxHSAzxzyFqu+eY18F1bQVqOzjbGF7Pc21L2ohIFM+Y3/iqtLzYBPvzV","ci":"20170227","sKey":"lrq66RF9C0H00tFVA3MjRRui0NFyM/1BlYxfJkzHFZhrWaLt1xpUd7M1z1skeXqJwNmB7Ygcyht22Tqr701eHSiZTKWl6N4gJLDr4EZjDB+OYqDTg28qSiHC3/TDvASr9m+F0ymKZhAdw7aASf+ZCxpkdjBOI/FzaIlTo67r9azYeVKPd/53bnpOvboxUdpt0coI8ElheTArcE5xQVDVC3Y5iJYkARjVgRonrjWSLlb0D9WzZ2Aolq2vnwo7nnglb0uqiqanUUrStqK//MNcVq5R5acu5hZv83XZNH0m/4v1+Ku3zQp0Kuc6nRNkE0M6f+LKZJ8JlkeSnIwoubFA1Q\u003d\u003d","metaData":{"udc":"AX20123","pip":"10.230.23.24","lot":"P","lov":"244221"}}"
2017-03-14 16:08:27 DEBUG wire:72 - http-outgoing-0 << "HTTP/1.1 404 Not Found[\r][\n]"
Upvotes: 0
Views: 1105
Reputation: 375
try changing it to backslash.
You might have be missing escape character for forward slash in your url mentioned in properties file.
try using '\/' before forward slash.
Upvotes: 0
Reputation: 127
Use the Trim Function there might be a white space either in end or in start of string.
HttpPost reqFundTransf = new HttpPost(strURL.trim());
Upvotes: 1