protected void addRequestHeaders(Hashtable headers) { if (connection == null || headers == null) return; Enumeration keys = headers.keys(); while (keys.hasMoreElements()) { String keyValue = (String) keys.nextElement(); String headerValue = (String) headers.get(keyValue); addRequestHeaders(keyValue, headerValue); } }
private byte[] sendHttpMessage(byte[] body) throws IOException { HttpMessageContext context = HttpMessageContext.getInstance(); context.Debug("GNHttpConnection [sendHttpMessage] starts"); if (context.getLogheader()) { context.Info(logMessageSetting()); } connection.setDoInput(true); if (body != null) { connection.setDoOutput(true); OutputStream os = TimedURLConnection.getOutputStream(connection, timeout * 1000); context.Debug("GNHttpConnection [sendHttpMessage] sending message ..."); os.write(body); context.Debug("GNHttpConnection [sendHttpMessage] message sent"); } context.Debug( "GNHttpConnection [sendHttpMessage] TimedURLConnection.getInputStream timeout[" + timeout + " S]"); InputStream is = TimedURLConnection.getInputStream(connection, timeout * 1000); responseCode = connection.getResponseCode(); context.Debug("GNHttpConnection [sendHttpMessage] responseCode[" + responseCode + "]"); responseMessage = HttpMessageContext.getMessage(is); responseheaders = new Hashtable<String, String>(); int no = 0; while (true) { String headerName = connection.getHeaderFieldKey(no); String headerValue = connection.getHeaderField(no); if (headerName != null && headerName.length() > 0) { responseheaders.put(headerName, headerValue); } else { if (headerValue == null || headerValue.length() <= 0) break; } no++; } if (context.getLogheader()) { GTConfigFile head = new GTConfigFile(responseheaders); context.Debug("GNHttpConnection [sendHttpMessage] responseHeader\r\n" + head); context.Debug( "GNHttpConnection [sendHttpMessage] responseMessage\r\n" + new String(getResponseMessage())); context.Info("GNHttpConnection [sendHttpMessage] success for " + url); } else context.Info("GNHttpConnection [sendHttpMessage] success for " + url); return responseMessage; }