use of org.slf4j.Logger in project Openfire by igniterealtime.
the class ServerDialback method createOutgoingSession.
/**
* Creates a new connection from the Originating Server to the Receiving Server for
* authenticating the specified domain.
*
* @param localDomain domain of the Originating Server to authenticate with the Receiving Server.
* @param remoteDomain IP address or hostname of the Receiving Server.
* @param port port of the Receiving Server.
* @return an OutgoingServerSession if the domain was authenticated or <tt>null</tt> if none.
*/
public LocalOutgoingServerSession createOutgoingSession(String localDomain, String remoteDomain, int port) {
final Logger log = LoggerFactory.getLogger(Log.getName() + "[Acting as Originating Server: Create Outgoing Session from: " + localDomain + " to RS at: " + remoteDomain + " (port: " + port + ")]");
log.debug("Creating new outgoing session...");
String hostname = null;
int realPort = port;
try {
// Establish a TCP connection to the Receiving Server
final Socket socket = SocketUtil.createSocketToXmppDomain(remoteDomain, port);
if (socket == null) {
log.info("Unable to create new outgoing session: Cannot create a plain socket connection with any applicable remote host.");
return null;
}
connection = new SocketConnection(XMPPServer.getInstance().getPacketDeliverer(), socket, false);
log.debug("Send the stream header and wait for response...");
StringBuilder stream = new StringBuilder();
stream.append("<stream:stream");
stream.append(" xmlns:stream=\"http://etherx.jabber.org/streams\"");
stream.append(" xmlns=\"jabber:server\"");
stream.append(" to=\"").append(remoteDomain).append("\"");
stream.append(" from=\"").append(localDomain).append("\"");
stream.append(" xmlns:db=\"jabber:server:dialback\"");
stream.append(">");
connection.deliverRawText(stream.toString());
// Set a read timeout (of 5 seconds) so we don't keep waiting forever
int soTimeout = socket.getSoTimeout();
socket.setSoTimeout(RemoteServerManager.getSocketTimeout());
XMPPPacketReader reader = new XMPPPacketReader();
reader.setXPPFactory(FACTORY);
reader.getXPPParser().setInput(new InputStreamReader(ServerTrafficCounter.wrapInputStream(socket.getInputStream()), CHARSET));
// Get the answer from the Receiving Server
XmlPullParser xpp = reader.getXPPParser();
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
eventType = xpp.next();
}
log.debug("Got a response. Check if the remote server supports dialback...");
if ("jabber:server:dialback".equals(xpp.getNamespace("db"))) {
log.debug("Dialback seems to be supported by the remote server.");
// Restore default timeout
socket.setSoTimeout(soTimeout);
String id = xpp.getAttributeValue("", "id");
OutgoingServerSocketReader socketReader = new OutgoingServerSocketReader(reader);
if (authenticateDomain(socketReader, localDomain, remoteDomain, id)) {
log.debug("Successfully authenticated the connection with dialback.");
// Domain was validated so create a new OutgoingServerSession
StreamID streamID = BasicStreamIDFactory.createStreamID(id);
LocalOutgoingServerSession session = new LocalOutgoingServerSession(localDomain, connection, socketReader, streamID);
connection.init(session);
// Set the hostname as the address of the session
session.setAddress(new JID(null, remoteDomain, null));
log.debug("Successfully created new outgoing session!");
return session;
} else {
log.debug("Failed to authenticate the connection with dialback.");
// Close the connection
connection.close();
}
} else {
log.debug("Error! Invalid namespace in packet: '{}'. Closing connection.", xpp.getText());
// Send an invalid-namespace stream error condition in the response
connection.deliverRawText(new StreamError(StreamError.Condition.invalid_namespace).toXML());
// Close the connection
connection.close();
}
} catch (Exception e) {
log.error("An exception occurred while creating outgoing session to remote server:", e);
// Close the connection
if (connection != null) {
connection.close();
}
}
log.warn("Unable to create a new outgoing session");
return null;
}
use of org.slf4j.Logger in project camel by apache.
the class JavaSocketTests method testSocketReadOnClosedConnection.
@Test
public void testSocketReadOnClosedConnection() throws Exception {
final Thread acceptThread = new Thread() {
Logger log = LoggerFactory.getLogger("acceptThread");
@Override
public void run() {
boolean running = true;
try {
Socket echoSocket = serverSocket.accept();
log.info("Accepted connection: {}", echoSocket.getInetAddress());
echoSocket.setSoTimeout(2000);
while (echoSocket.isConnected() && !echoSocket.isClosed()) {
StringBuilder responseBuilder = new StringBuilder(500);
InputStream reader = echoSocket.getInputStream();
OutputStream writer = echoSocket.getOutputStream();
do {
int readByte = -1;
int available = -1;
try {
available = reader.available();
log.info("InputStream.available returned {}", available);
readByte = reader.read();
log.trace("Processing byte: {}", readByte);
switch(readByte) {
case -1:
if (echoSocket.isConnected() && !echoSocket.isClosed()) {
log.info("Available returned {}", reader.available());
log.warn("Socket claims to still be open, but END_OF_STREAM received - closing echoSocket");
try {
echoSocket.close();
} catch (Exception ex) {
log.warn("Exception encountered closing echoSocket after END_OF_STREAM received", ex);
}
}
running = false;
break;
case 10:
log.info("Complete Message - Sending Response");
byte[] response = responseBuilder.toString().getBytes();
responseBuilder.setLength(0);
writer.write(response, 0, response.length);
writer.write('\n');
break;
default:
responseBuilder.append((char) readByte);
}
} catch (SocketTimeoutException timeoutEx) {
log.info("Timeout reading data - available returned {}", available);
}
} while (echoSocket.isConnected() && !echoSocket.isClosed());
}
} catch (IOException ioEx) {
log.error("IOException in run method", ioEx);
} finally {
try {
serverSocket.close();
} catch (IOException ioEx) {
log.error("Exception encountered closing server socket", ioEx);
}
}
log.info("Finished processing connection");
}
};
acceptThread.start();
clientSocket = new Socket();
clientSocket.setSoTimeout(1000);
clientSocket.connect(serverSocket.getLocalSocketAddress(), 10000);
clientSocket.setTcpNoDelay(true);
log.info("Begining message send loop ");
byte[] message = "Hello World".getBytes();
BufferedReader reader;
for (int i = 1; i <= messageCount; ++i) {
reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
OutputStream writer = clientSocket.getOutputStream();
log.info("Sending payload");
writer.write(message, 0, message.length);
writer.flush();
log.info("Sending terminator");
writer.write('\n');
writer.flush();
log.info("Received Response #{}: {}", i, reader.readLine());
Thread.sleep(1000);
}
log.info("Message send loop complete - closing connection");
// Javadoc for Socket says closing the InputStream will close the connection
clientSocket.getInputStream().close();
if (!clientSocket.isClosed()) {
log.warn("Closing input stream didn't close socket");
clientSocket.close();
}
log.info("Sleeping ...");
Thread.sleep(5000);
}
use of org.slf4j.Logger in project pinpoint by naver.
the class HbaseTraceDao method setSpanMapper.
@Autowired
@Qualifier("spanMapper")
public void setSpanMapper(RowMapper<List<SpanBo>> spanMapper) {
final Logger logger = LoggerFactory.getLogger(spanMapper.getClass());
if (logger.isDebugEnabled()) {
spanMapper = CellTraceMapper.wrap(spanMapper);
}
this.spanMapper = spanMapper;
}
use of org.slf4j.Logger in project openhab1-addons by openhab.
the class ColorIlluminanceImpl method setLogger.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public void setLogger(Logger newLogger) {
Logger oldLogger = logger;
logger = newLogger;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.COLOR_ILLUMINANCE__LOGGER, oldLogger, logger));
}
use of org.slf4j.Logger in project openhab1-addons by openhab.
the class AccelerometerLedImpl method setLogger.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
*
* @generated
*/
@Override
public void setLogger(Logger newLogger) {
Logger oldLogger = logger;
logger = newLogger;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ModelPackage.ACCELEROMETER_LED__LOGGER, oldLogger, logger));
}
Aggregations