/**
 * JBoss, Home of Professional Open Source.
 * Copyright 2014 Red Hat, Inc., and individual contributors
 * as indicated by the @author tags.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.pnc.termdbuilddriver.websockets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;

public class TermdTerminalConnection extends AbstractWebSocketsConnection {

    private final Logger logger = LoggerFactory.getLogger(TermdTerminalConnection.class);


    private static final String WEB_SOCKET_TERMINAL_PATH = "socket/term";
    ClientEndpoint clientEndpoint;

    public TermdTerminalConnection(URI serverBaseUri) {
        super(serverBaseUri.resolve(WEB_SOCKET_TERMINAL_PATH));
        clientEndpoint = new ClientEndpoint(new TerminalConnectionMessageHandler());
    }

    @Override
    protected ClientEndpoint getClientEndpoint() {
        return clientEndpoint;
    }

    public URI getLogsURI() {
        return URI.create(uri.toString() + "?sessionId=reconnect");
    }

    private class TerminalConnectionMessageHandler implements ClientMessageHandler {
        @Override
        public void onMessage(byte[] bytes) {
            if (logger.isDebugEnabled()) {
                logger.debug(new String(bytes));
            }
        }

        @Override
        public void onMessage(String message) {
        }
    }
}

@@ -827,16 +827,69 @@
 net.URI;
+%0Aimport java.nio.ByteBuffer;%0Aimport java.util.Arrays;
 %0A%0Apublic
@@ -1666,16 +1666,78 @@
 ndler %7B%0A
+%0A        StringBuilder responseBuffer = new StringBuilder();%0A%0A
         
@@ -1821,13 +1821,13 @@
 r.is
-Debug
+Trace
 Enab
@@ -1855,40 +1855,300 @@
     
-logger.debug(new String(bytes));
+String string = new String(bytes);%0A                if (string.equals(%22%5Cr%5Cn%22)) %7B%0A                    logger.trace(responseBuffer.toString());%0A                    responseBuffer = new StringBuilder();%0A                %7D else %7B%0A                    responseBuffer.append(string);%0A                %7D
 %0A   

Fix log writting.