private void tryConnect(URL serverURL) throws IOException { URLConnection connection = null; try { connection = getConnectionHandler().getConnection(serverURL); connection.connect(); } finally { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).disconnect(); } } } }
private URLConnection getConnection(URL url) throws IOException { return getConnectionHandler().getConnection(url); }
URL sendURL = new URL(serverURL, m_name + "/" + COMMAND_SEND); sendConnection = connectionHandler.getConnection(sendURL); sendConnection.setDoOutput(true); if (sendConnection instanceof HttpURLConnection) { for (Long storeID : storeIDs) { URL queryURL = new URL(serverURL, m_name + "/" + COMMAND_QUERY + "?" + PARAMETER_TARGETID + "=" + identification + "&" + PARAMETER_LOGID + "=" + storeID); URLConnection queryConnection = connectionHandler.getConnection(queryURL); try { synchronizeStore(storeID, queryConnection.getInputStream(), writer);
/** * Prepares the connection for the next chunk, if needed. * * @return <code>true</code> if the prepare was successful (there was a next chunk to be read), <code>false</code> * otherwise. * @throws IOException * in case of I/O exception. */ private boolean prepareNextChunk() throws IOException { if ((m_conn == null) && contentRemaining()) { m_conn = m_handler.getConnection(m_url); applyRangeHeader(m_conn); long[] contentInfo = getContentRangeInfo(m_conn); // No, not yet, update our local administration... if (m_contentInfo != null) { // verify the total size (paranoia sanity check)... if (m_contentInfo[1] >= 0 && contentInfo[1] >= 0 && m_contentInfo[1] != contentInfo[1]) { throw new IOException("Stream size mismatch between different chunks!"); } } m_contentInfo = contentInfo; } // Make sure there's still content remaining to be read... return (m_conn != null) && contentRemaining(); } }
@Test public void testBasicAuthOK() throws Exception { Map<String, String> props = new HashMap<>(); props.put(AgentConstants.CONFIG_CONNECTION_AUTHTYPE, Types.BASIC.name()); props.put(AgentConstants.CONFIG_CONNECTION_USERNAME, USERNAME); props.put(AgentConstants.CONFIG_CONNECTION_PASSWORD, PASSWORD); ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configurationHandler.putAll(props); ConnectionHandler connectionHandler = m_agentContext.getHandler(ConnectionHandler.class); HttpURLConnection connection = (HttpURLConnection) connectionHandler.getConnection(m_basicAuthURL); assertEquals(connection.getResponseCode(), HttpServletResponse.SC_OK); } }
@Test public void testBasicAuthFORBIDDEN() throws Exception { Map<String, String> props = new HashMap<>(); props.put(AgentConstants.CONFIG_CONNECTION_AUTHTYPE, Types.NONE.name()); ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configurationHandler.putAll(props); ConnectionHandler connectionHandler = m_agentContext.getHandler(ConnectionHandler.class); HttpURLConnection connection = (HttpURLConnection) connectionHandler.getConnection(m_basicAuthURL); assertEquals(connection.getResponseCode(), HttpServletResponse.SC_FORBIDDEN); }