HttpServer.LOG.warn(io);
LOG.warn(io);
	public void run() {		String req;		String first;		String line;		String contentType = "text/xml";		String name = null;		String username = null;		String password = null;		int method = HTTP_BAD_REQUEST;		int len = 0;		StringBuffer input = new StringBuffer();		File tempFile = null;		BrokerPool brokerPool = null;		try {			brokerPool = BrokerPool.getInstance();		} catch (EXistException e) {			throw new RuntimeException(e.getMessage());		}		// the main loop of this thread		while (true) {			while ((sock == null) && !terminate)				synchronized (this) {					try {						wait(500);					} catch (InterruptedException ie) {					}				}			if (terminate)				break;			try {				DataInputStream is = 					new DataInputStream(new BufferedInputStream(sock.getInputStream()));								len = -1;				contentType = "text/xml";				// parse http-header				while (true) {					req = is.readLine();					if (req == null)						break;					StringTokenizer tok = new StringTokenizer(req, " ");					if (!tok.hasMoreTokens())						break;					first = tok.nextToken();					if (first.equals("GET")) {						method = GET;						name = tok.nextToken();					} else if (first.equals("POST")) {						method = POST;						name = tok.nextToken();					} else if (first.equals("HEAD")) {						method = HEAD;						name = tok.nextToken();					} else if (first.equals("PUT")) {						method = PUT;						name = tok.nextToken();					} else if (req.toUpperCase().startsWith("CONTENT-LENGTH:")) {						try {							len = Integer.parseInt(tok.nextToken());						} catch (NumberFormatException nf) {							HttpServer.LOG.warn(nf);							method = HTTP_BAD_REQUEST;							break;						}					} else if (req.toUpperCase().startsWith("CONTENT-TYPE:"))						contentType = tok.nextToken();					else if (req.toUpperCase().startsWith("AUTHORIZATION:")) {						String auth = req.substring("AUTHORIZATION:".length())								.trim();						byte[] c = Base64.decode(auth.substring(6).getBytes());						String s = new String(c);						int p = s.indexOf(':');						username = s.substring(0, p);						password = s.substring(p + 1);						user = checkUser(brokerPool, username, password);						if (user == null)							method = HTTP_FORBIDDEN;					}				}				// get request body				if (len > 0) {					byte[] buffer = new byte[2048];					int count;					int l = 0;					if (method == PUT) {						// put may send a lot of data, so save it						// to a temporary file first.						tempFile = File.createTempFile("exist", ".xml");						OutputStream os = new FileOutputStream(tempFile);						do {							count = is.read(buffer);							if (count > 0)								os.write(buffer, 0, count);							l += count;						} while (l < len);						os.close();					} else {						do {							count = is.read(buffer);							if (count > 0)								input.append(new String(buffer, 0, count, "UTF-8"));							l += count;						} while (l < len);					}				}				if (user == null)					// no user specified: assume guest identity					user = new User("guest", "guest", "guest");				try {					broker = brokerPool.get();					broker.setUser(user);				} catch (EXistException e) {					throw new RuntimeException(e.getMessage());				}				try {					// select method					switch (method) {						case HTTP_FORBIDDEN :							errorReply(HTTP_FORBIDDEN);							break;						case HTTP_BAD_REQUEST :							errorReply(HTTP_BAD_REQUEST);							break;						case GET :							get(name, len);							break;						case POST :							post(input.toString(), name, len, contentType);							break;						case PUT :							put(tempFile, name, len);							break;						default :							errorReply(HTTP_BAD_REQUEST);							break;					}				} finally {					brokerPool.release(broker);					broker = null;					user = null;				}				is.close();				input = new StringBuffer();			} catch (IOException io) {				HttpServer.LOG.warn(io);			}			sock = null;			xslStyle = null;			pool.release(this);		}		pool.release(this);	}