Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 851271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:24:11+00:00 2026-05-15T07:24:11+00:00

http://ooweb.sourceforge.net/tutorial.html Also any way to change the logging file for the underlying Pygmy server?

  • 0

http://ooweb.sourceforge.net/tutorial.html

Also any way to change the logging file for the underlying Pygmy server?

Not really a question, but I can’t seem to stop writing stuff like this. Maybe someone will find it useful.

I know rewriting an HTTP server is not the way to turn off the quips 😉

/* Copyright 2010 Misha Koshelev. All Rights Reserved. */
package com.mksoft.common;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.LinkedHashMap;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * Simple HTTP Server.
 *
 * @author Misha Koshelev
 */
public class HttpServer extends Thread {
    /*
     * Constants
     */

    /**
     * 404 Not Found Result
     */
    protected final static String result404NotFound="<html><head><title>404 Not Found</title></head><body bgcolor='#ffffff'><h1>404 Not Found</h1></body></html>";

    /*
     * Variables
     */

    /** 
     * Port on which HTTP server handles requests.
     */
    protected int port;
    public int getPort() { return port; }
    public void setPort(int _port) { port=_port; }

    /*
     * Constructors
     */
    public HttpServer(int _port) {
 setPort(_port);
    }

    /*
     * Helpers
     */

    /**
     * Errors
     */
    protected void error(String message) {
 System.err.println(message);
 System.err.flush();
    }

    /**
     * Debugging
     */
    protected boolean debugOutput=true;
    protected void debug(String message) {
 if (debugOutput) {
     error(message);
 }
    }

    /**
     * Lock object 
     */
    private Object lock=new Object();

    /**
     * Should we quit?
     */
    protected boolean doQuit=false;    

    /**
     * Are we done?
     */
    protected boolean areWeDone=false;

    /**
     * Process POST request headers
     */
    protected String processPostRequest(String url,LinkedHashMap<String,String> headers,String inputLine) {
 debug("HttpServer.processPostRequest: url=\""+url);
 if (debugOutput) {
     for (String key: headers.keySet()) {
  debug("HttpServer.processPostRequest: headers."+key+"=\""+headers.get(key)+"\"");
     }
 }
 debug("HttpServer.processPostRequest: inputLine=\""+inputLine+"\"");
 try {
     inputLine=new URLDecoder().decode(inputLine,"UTF-8");
 } catch (UnsupportedEncodingException uee) {
     uee.printStackTrace();
 }

 String[] keyValues=inputLine.split("&");
 LinkedHashMap<String,String> post=new LinkedHashMap<String,String>();
 for (int i=0;i<keyValues.length;i++) {
     String keyValue=keyValues[i];
     int equals=keyValue.indexOf('=');
     String key=keyValue.substring(0,equals);
     String value=keyValue.substring(equals+1);
     post.put(key,value);
 }
 return post(url,headers,post);
    }

    /**
     * Server loop (here for exception handling purposes)
     */
    protected void serverLoop() throws IOException {
 /* Start server socket */
 ServerSocket serverSocket=null;
 try {
     serverSocket=new ServerSocket(getPort());
 } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(1);
 }

 Socket clientSocket=null;
 while (true) {
     /* Quit if necessary */
     if (doQuit) {
  break;
     }

     /* Accept incoming connections */
     try {
  clientSocket=serverSocket.accept();
     } catch (IOException ioe) {
  ioe.printStackTrace();
  System.exit(1);
     }

     /* Read request */
     BufferedReader in=null;
     String inputLine=null;
     String firstLine=null;
     String blankLine=null;
     LinkedHashMap<String,String> headers=new LinkedHashMap<String,String>();
     try {
  in=new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  while (true) {
      if (blankLine==null) {
   inputLine=in.readLine();
      } else {
   /* POST request, read Content-length bytes */
   int contentLength=new Integer(headers.get("Content-Length")).intValue();
   StringBuilder sb=new StringBuilder(contentLength);
   for (int i=0;i<contentLength;i++) {
       sb.append((char)in.read());
   }
   inputLine=sb.toString();
   break;
      }
      if (firstLine==null) {
   firstLine=inputLine;
      } else if (blankLine==null) {
   if (inputLine.equals("")) {
       if (firstLine.startsWith("GET ")) {
    break;
       }
       blankLine=inputLine;
   } else {
       int colon=inputLine.indexOf(": ");
       String key=inputLine.substring(0,colon);
       String value=inputLine.substring(colon+2);
       headers.put(key,value);
   }
      }
  }
     } catch (IOException ioe) {
  ioe.printStackTrace();
     }

     /* Process request */
     String result=null;
     firstLine=firstLine.replaceAll(" HTTP/.*","");
     if (firstLine.startsWith("GET ")) {
  result=get(firstLine.replaceFirst("GET ",""),headers);  
     } else if (firstLine.startsWith("POST ")) {
  result=processPostRequest(firstLine.replaceFirst("POST ",""),headers,inputLine);
     } else {
  error("HttpServer.ServerLoop: Unhandled request \""+firstLine+"\"");
     }
     debug("HttpServer.ServerLoop: result=\""+result+"\"");

     /* Send response */
     PrintWriter out=null;
     try {
  out=new PrintWriter(clientSocket.getOutputStream(),true);
     } catch (IOException ioe) {
  ioe.printStackTrace();
     }
     if (result!=null) {
  out.println("HTTP/1.1 200 OK");
     } else {
  out.println("HTTP/1.0 404 Not Found");
  result=result404NotFound;
     }
     Date now=new Date();
     out.println("Date: "+new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z").format(now));
     out.println("Content-Type: text/html; charset=UTF-8");
     out.println("Content-Length: "+result.length());
     out.println("");
     out.print(result);

     /* Clean up */
     out.close();
     if (in!=null) {
  in.close();
     }
     clientSocket.close();
 }

 serverSocket.close();
 areWeDone=true;
 synchronized(lock) {
     lock.notifyAll();
 }
    } 

    /*
     * Methods
     */

    /**
     * Run server on port specified in constructor.
     */
    public void run() {
 try {
     serverLoop();
 } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(1);
 }
    } 

    /**
     * Process GET request (should be overwritten).
     */
    public String get(String url,LinkedHashMap<String,String> headers) {
 debug("HttpServer.get: url=\""+url+"\"");
 if (debugOutput) {
     for (String key: headers.keySet()) {
  debug("HttpServer.get: headers."+key+"=\""+headers.get(key)+"\"");
     }
 }
 if (url.equals("/")) {
     return "<html><head><title>HttpServer GET Test Page</title></head>\r\n"+
  "<body bgcolor='#ffffff'>\r\n"+
  "<center><h1>HttpServer GET Test Page</h1></center>\r\n"+
  "<hr />\r\n"+
  "<center><table>\r\n"+
  "<form method='post' action='/'>\r\n"+
  "<tr><td align=right>Test 1:</td>\r\n"+
  "    <td><input type='text' name='text 1' value='test me !!! !@#$'></td></tr>\r\n"+
  "<tr><td align=right>Test 2:</td>\r\n"+
  "    <td><input type='text' name='text 2' value='type smthng'></td></tr>\r\n"+
  "<tr><td>&nbsp;</td>\r\n"+
  "    <td align=right><input type='submit' value='Submit'></td></tr>\r\n"+
  "</form>\r\n"+
  "</table></center>\r\n"+
  "<hr />\r\n"+
  "<center><a href='/quit'>Shutdown Server</a></center>\r\n"+
  "</html>";
 } else if (url.equals("/quit")) {
     quit();
     return "";
 } else {
     return null;
 }
    }

    /**
     * Process POST request (should be overwritten).
     */
    public String post(String url,LinkedHashMap<String,String> headers,LinkedHashMap<String,String> post) {
 debug("HttpServer.post: url=\""+url+"\"");
 if (debugOutput) {
     for (String key: headers.keySet()) {
  debug("HttpServer.post: headers."+key+"=\""+headers.get(key)+"\"");
     }
 }
 if (url.equals("/")) {
     String result="<html><head><title>HttpServer Post Test Page</title></head>\r\n"+
  "<body bgcolor='#ffffff'>\r\n"+
  "<center><h1>HttpServer Post Test Page</h1></center>\r\n"+
  "<hr />\r\n"+
  "<center><table>\r\n"+
  "<tr><th>Key</th><th>Value</th></tr>\r\n";     
     for (String key: post.keySet()) {
  result+="<tr><td align=right>"+key+"</td><td align=left>"+post.get(key)+"</td></tr>\r\n";
     }
     result+="</table></center>\r\n"+
  "</html>";
     return result;
 } else {
     return null;
 }
    }

    /**
     * Wait for server to quit.
     */
    public void waitForCompletion() {
 while (areWeDone==false) {
     synchronized(lock) {
  try {
      lock.wait();
  } catch (InterruptedException ie) {
  }
     }
 }
    }

    /**
     * Shutdown server.
     */
    public void quit() {
 doQuit=true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:24:11+00:00Added an answer on May 15, 2026 at 7:24 am

    Just comment out the System.out.println(getQuip()) line in the OowebServer class and recompile to remove quips.

    I’m not sure what logger pygmy uses, but I’d guess its java.util.logger so configure that the normal way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://logging.apache.org/log4net/release/config-examples.html Given the log table here: CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1,
http://jsfiddle.net/9BCrs/5/ I have this set up to load a file into a DIV using
http://developer.android.com/training/basics/firstapp/building-ui.html I have been following this tutorial, but I have two errors, both R
http://docs.python.org/library/imaplib.html states that: exception IMAP4.error Exception raised on any errors. The reason for the
http://www.dorsetdesigns.co.uk/contact.html try the form it wont send a email to me. i am using
http://jqueryui.com/demos/accordion/ You can do $('#itename').accordion('activate', 0) to make an accordion closed but that'll change
http://jsfiddle.net/CsrrD/ Given an object var viewModel = { Opts: ko.observableArray([ { d: 'a', v:
http://jsfiddle.net/h2vMN/1/ I have a text box text inside it already, in the actual application
http://jsfiddle.net/skowron_line/zPCBc/1/ var d1 = '31.05.2012'; var d2 = '01.06.2012'; var s1 = d1.split('.'); var
http://developer.android.com/guide/topics/manifest/service-element.html#proc What are the differences? If the name assigned to this attribute begins with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.