public void run() { HTTPXMessageRefactorer refactorer = new HTTPXMessageRefactorer(); HTTPXActionMessage request = null; try { request = refactorer.createActionMessageFromStream( this.toStream(packet.getData(), packet.getLength())); } catch (HTTPXProtocolViolationException e) { LOGGER.error(e); e.printStackTrace(); } catch (IOException e) { LOGGER.error(e); e.printStackTrace(); } request.setPort(packet.getPort()); request.setHost(packet.getAddress().getHostName()); LOGGER.debug(HTTPXConstants.HTTPU + " Request:\r\n" + request.toString()); boolean bFound = false; Path tmpPath = new Path(request.getPath().getString()); try { do { for (Tuple element : registration) { if ((element.handler instanceof HTTPXPlainActionMessageHandler) && element.filter.doesPass( request.getProtocol(), request.getHost(), request.getPort(), tmpPath, request.getQueryAsString())) { LOGGER.debug("void Handler was found : " + element.handler); ((HTTPXPlainActionMessageHandler) element.handler).handlePlain(request); bFound = true; break; } } // for if (!bFound) { String strTmp = tmpPath.getString(); tmpPath.removeLastToken(); // check wheter path is root if (strTmp.equalsIgnoreCase(tmpPath.getString())) { break; } } } while (!bFound); } catch (IOException e) { LOGGER.error(e); e.printStackTrace(); } }
/* (non-Javadoc) * @see de.fhg.fokus.restac.httpx.core.communication.handler.HTTPXPlainActionMessageHandler#handlePlain(de.fhg.fokus.restac.httpx.communication.common.HTTPXActionMessage) */ public void handlePlain(HTTPXActionMessage request) throws IOException { HTTPXMessageRefactorer refactorer = new HTTPXMessageRefactorer(); InetAddress ia; DatagramPacket datagramPacket = null; byte[] data = new byte[0]; // InputStream in = refactorer.toStream(request); try { // int curChar; // StringBuilder sb = new StringBuilder(); // try { // while ((curChar = in.read()) != -1) { // sb.append((char)curChar); // } // } catch (IOException e) { // LOGGER.error(e); // e.printStackTrace(); // } // // data = sb.toString().getBytes(HTTPXConstants.DEFAULT_CHARSET); data = refactorer.toByte(request); ia = InetAddress.getByName(request.getHost()); datagramPacket = new DatagramPacket(data, data.length, ia, request.getPort()); // Send the package datagramSocket.send(datagramPacket); LOGGER.debug(HTTPXConstants.HTTPU + " package is send out"); } catch (UnsupportedEncodingException e) { LOGGER.error(e); e.printStackTrace(); } // close the socket // if (datagramSocket != null) { // datagramSocket.close(); // } }