上の要求を書いて、これまでのところ、私が知って持っているときにIOExceptionがすべてについても、など要求はサーバーに届いていますか?出力ストリーム
は、今私が成功したURLの接続をオープンしていると言うことができ、時間を読み出し、時間を接続しますデータを書き込むためにoutputStreamを得ました。
これで、サーバーにデータを書き込もうとしましたが、out.write(requestByte); したがって、もし私がIO例外を受け取るのであれば、out.write(requestByte)それはどういう意味ですか?
リクエストはサーバーに届いているかどうかを確認します。ここで
try {
out.write(requestByte);
logger.info("API Request sent at : " + sdf.format(new Date()));
out.close();
} catch (IOException e) {
logger.info("Exception while writing request to output stream");
e.printStackTrace();
}
は完全なコードです....
try {
bridgeUrl = new URL(url);
if (connectionTime == null) {
connectionTime = StartupCache.getInstance().getConfigByKey(getUniqueKey(ConfigurationConstant.CONNECTION_TIME_OUT));
//connectionTime = TransactionPersistence.getInstance().getConfigByConfigKey(ConfigurationConstant.CONNECTION_TIME_OUT);
if (connectionTime != null && connectionTime.getConfigValue().trim().length() > 0) {
connectionTimeOutInMilliSec = Integer.valueOf(connectionTime.getConfigValue());
}
}
if (bridgeUrl.getProtocol().equalsIgnoreCase("https")) {
ignoreSslCertificateAuthentication();
httpConn = (HttpsURLConnection) bridgeUrl.openConnection();
} else {
httpConn = (HttpURLConnection) bridgeUrl.openConnection();
}
logger.info("\ Request : "+request+"\n");
request="JsonData="+request;
byte[] requestByte = request.getBytes();
httpConn.setRequestProperty("Content-Length", String.valueOf(requestByte.length));
httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpConn.setRequestMethod("POST");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setConnectTimeout(connectionTimeOutInMilliSec);
httpConn.setReadTimeout(connectionTimeOutInMilliSec);
out = httpConn.getOutputStream();
try {
out.write(requestByte);
logger.info("API Request sent at : " + sdf.format(new Date()));
out.close();
} catch (IOException e) {
logger.info("Exception while writing request to output stream");
e.printStackTrace();
}
}catch(MalformedURLException exMurl){
logger.info(exMurl.getMessage());
throw new ApiRequestPostingException("Exception occured while posting request to server");
}
catch(SocketTimeoutException stout){
logger.error(stout.getMessage());
stout.printStackTrace();
if (httpConn != null) {
logger.info("Closing httpConn in exception blcok of output stream connection....");
httpConn.disconnect();
}
throw new ApiRequestPostingException("Exception occured while posting request to server");
}catch(IOException ioex){
logger.error(ioex.getMessage());
ioex.printStackTrace();
if (httpConn != null) {
logger.info("Closing httpConn in exception blcok of output stream connection....");
httpConn.disconnect();
}
throw new ApiRequestPostingException("Exception occured while posting request to server");
}
IOExceptionを取得していないということは、データがサーバーに到達したことを意味しないことに言及する価値があります。 –
@ EJPご清聴ありがとうございます。 – ROHIT