protected void receive(String content, String address, Session session) { try { IncomingMessage<?> message = _factory.create(content); message.setAddress(address); message.setSession(session); message.execute(); } catch (UserException e) { send(User.parseAddress(address), new NotLogon()); } catch (Exception e) { Logger.getInstance().error(e); } }
public void send(String address, OutgoingMessage message) { try { message.populateJSON(); URLConnection connection = new URL(address).openConnection(); connection.setConnectTimeout(30000); connection.setReadTimeout(30000); setSession(connection); connection.setDoOutput(true); OutputStream out = connection.getOutputStream(); out.write(message.toString().getBytes()); out.close(); connection.getInputStream().close(); rememberSession(connection); } catch (Exception e) { Logger.getInstance().error(e); } }