Package org.apache.ace.agent

Examples of org.apache.ace.agent.ConnectionHandler


     */
    @Test
    public void testReadPartialContentWithOffsetOk() throws Exception {
        String content = m_content;

        ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false));
        ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL, 48);

        assertEquals(slurpAsStringWithBuffer(is), content.substring(48));
    }
View Full Code Here


    /**
     * Tests that we cannot read partial content if given a non-byte range value in the Content-Range header.
     */
    @Test(expectedExceptions = IOException.class)
    public void testReadPartialContentWithoutByteRangeValueFail() throws Exception {
        ConnectionHandler handler = new TestConnectionHandler(new FailingContentConnection(m_content, Failure.PARTIAL_NON_BYTE_RANGE));
        ContentRangeInputStream is = null;

        try {
            is = new ContentRangeInputStream(handler, m_testURL);
            is.read(); // should fail!
View Full Code Here

    /**
     * Tests that we cannot read partial content without a Content-Range header.
     */
    @Test(expectedExceptions = IOException.class)
    public void testReadPartialContentWithoutContentRangeHeaderFail() throws Exception {
        ConnectionHandler handler = new TestConnectionHandler(new FailingContentConnection(m_content, Failure.PARTIAL_NO_CONTENT_RANGE));
        ContentRangeInputStream is = null;

        try {
            is = new ContentRangeInputStream(handler, m_testURL);
            is.read(); // should fail!
View Full Code Here

     */
    @Test
    public void testReadPartialEmptyContentByteForByteOk() throws Exception {
        String content = "";

        ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false));
        ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL);

        assertEquals(slurpAsStringByteForByte(is), content);
    }
View Full Code Here

     */
    @Test
    public void testReadPartialEmptyContentOk() throws Exception {
        String content = "";

        ConnectionHandler handler = new TestConnectionHandler(new PartialContentConnection(content, false));
        ContentRangeInputStream is = new ContentRangeInputStream(handler, m_testURL);

        assertEquals(slurpAsStringWithBuffer(is), content);
    }
View Full Code Here

    }

    private ServiceRegistration registerConnectionHandler() {
        return m_bundleContext
            .registerService(ConnectionHandler.class.getName(), new ConnectionHandler() {

                @Override
                public URLConnection getConnection(URL url) throws IOException {
                    return url.openConnection();
                }
View Full Code Here

        m_agentContext.setHandler(IdentificationHandler.class, identificationHandler);

        DiscoveryHandler discoveryHandler = (m_discoveryHandler != null) ? m_discoveryHandler : new DiscoveryHandlerImpl();
        m_agentContext.setHandler(DiscoveryHandler.class, discoveryHandler);

        ConnectionHandler connectionHandler = (m_connectionHandler != null) ? m_connectionHandler : new ConnectionHandlerImpl();
        m_agentContext.setHandler(ConnectionHandler.class, connectionHandler);

        m_agentContext.addComponent(new EventLoggerImpl(context));

        // Lastly, inject the (custom) controller for this agent...
View Full Code Here

        if (identification == null || serverURL == null) {
            logWarning("No identification or server URL present, cannot send feedback!");
            return;
        }

        ConnectionHandler connectionHandler = getConnectionHandler();
        URLConnection sendConnection = null;
        Writer writer = null;

        try {
            URL sendURL = new URL(serverURL, m_name + "/" + COMMAND_SEND);

            sendConnection = connectionHandler.getConnection(sendURL);
            sendConnection.setDoOutput(true);
            if (sendConnection instanceof HttpURLConnection) {
                ((HttpURLConnection) sendConnection).setChunkedStreamingMode(8192);
            }
            writer = new BufferedWriter(new OutputStreamWriter(sendConnection.getOutputStream()));

            SortedSet<Long> storeIDs = m_storeManager.getAllFeedbackStoreIDs();
            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);
                }
                catch (IOException e) {
                    handleIOException(queryConnection);
View Full Code Here

TOP

Related Classes of org.apache.ace.agent.ConnectionHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.