You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Nick Betteridge <n....@syntactics.com> on 2000/10/10 13:08:53 UTC

[CATALINA] Servlet problem

I hope that this is a problem and not incompetence:

A simple servlet and client - the client sends an object, the servlet
reads the object and sends it back.

What happens is that the client sends the object, catalina maps the
servlet class correctly and then waits for the the object (which has
already been sent). Tracing catalina shows that the server thread stops
at line : 'Object obj = ois.readObject();'

The Server
----------

package com.syntactics.library.server;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import javax.naming.InitialContext;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.String;
public class SynLibraryRequestProcessor extends HttpServlet {

    URL                     u_servlet;
    URLConnection           uc_servlet;

    OutputStream            os_servlet;
    InputStream             is_servlet;
    ObjectOutputStream      oos_send;
    ObjectInputStream       ois_read;

  public void doPost(HttpServletRequest req, HttpServletResponse res)
                                throws ServletException, IOException {
    try {
        HttpSession session = req.getSession(true);
        ServletInputStream in = req.getInputStream();
        ObjectInputStream ois = new ObjectInputStream(in);
        Object obj = ois.readObject();
        ois.close();
        in.close();
        //
        ServletOutputStream out = res.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(obj);
        oos.close();
        out.close();

    } catch ( Exception e ) {
        e.printStackTrace();
  }
}


The Client
-----------
package com.syntactics.library.server.client;
import java.awt.*;
import java.awt.Cursor.*;
import java.awt.Component.*;
import java.awt.event.*;
import java.awt.event.ComponentEvent;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date.*;

public class SynLibraryClient {

    URL                     u_servlet;
    URLConnection           uc_servlet;

    OutputStream            os_servlet;
    InputStream             is_servlet;

    ObjectOutputStream      oos_send;
    ObjectInputStream       ois_read;
    
    public SynLibraryClient() {
    }

 public static void main(String[] args) {
    SynLibraryClient slc = new SynLibraryClient();
    
    slc.example();
}

private void example() {
    try {

        u_servlet = new URL("http","library.syntactics.com",8080,"/");
        uc_servlet = u_servlet.openConnection();
        uc_servlet.setDoOutput( true );
        uc_servlet.setDoInput( true );
        uc_servlet.setUseCaches( false );
        uc_servlet.setRequestProperty("Content-Type",
                           "application/x-www-form-urlencoded");
        os_servlet = uc_servlet.getOutputStream();
        oos_send = new ObjectOutputStream( os_servlet );
        String str = new String("something!");
        oos_send.writeObject( str );
        oos_send.flush();
        oos_send.close();
        
        is_servlet = uc_servlet.getInputStream();
        ois_read = new ObjectInputStream( is_servlet );
        if (((String)ois_read.readObject()).equals("something!")) {
            System.out.println("Jolly Good");
        }

        ois_read.close();

    } catch ( Exception e ) {
        System.out.println( "Client exception caught" + e );
        e.printStackTrace();
    }
  }

}

Catalina Output
---------------
StandardEngine[null]: Mapping server name 'library.syntactics.com'
StandardEngine[null]:  Trying a direct match
SynHost[library.syntactics.com]: Mapping request URI '/'
SynHost[library.syntactics.com]:   Trying the longest context path
prefix
SynHost[library.syntactics.com]:  Mapped to context ''
StandardContext[]: Mapping contextPath='' with requestURI='/' and
relativeURI='/'
StandardContext[]:   Trying exact match
StandardContext[]:  Mapped to servlet
'com.syntactics.library.server.SynLibraryRequestProcessor' with servlet
path '/' and path info 'null' and update=true
com.syntactics.library.server.SynLibraryRequestProcessor: init
Manager[]: Seeding random number generator class
java.security.SecureRandom
Manager[]: Seeding of random number generator has been completed

War Directory
-------------
WEB-INF
  web.xml
  classes/com/syntactics/library/server/SynLibraryRequestProcessor

web.xml
-------
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
    <servlet>
        <servlet-name>
            com.syntactics.library.server.SynLibraryRequestProcessor
        </servlet-name>
        <servlet-class>
            com.syntactics.library.server.SynLibraryRequestProcessor
        </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>
            com.syntactics.library.server.SynLibraryRequestProcessor
        </servlet-name>
        <url-pattern>
            /
        </url-pattern>
    </servlet-mapping>
</web-app>

Re: [CATALINA] Servlet problem

Posted by Nick Betteridge <n....@syntactics.com>.
Hi Remy

Sorry for the delay in getting back to you. I've just spent the morning
looking around my setup for problems. I initially started off by
downloading one of the latest night-builds. I forgot to mention that I'm
using the embedded version.

When I started up the new build (using
org.apache.catalina.connector.test.HttpConnector and debug=0) I got the
following Exception. The un-jared war still remains the same as the
details I posted in the original message. I have enclosed after the
Exception the bulk of my 'main' in the embedded startup.

I can see from the trace that 'new URL(path)', where path is a straight
forward path, does not like it without any protocol prepended - this is
occuring during the set up of repositories (StandardLoader)

If you can shed any light on the problem I would be more than grateful

Regards and thanks

Nick

--------------------

Exception in thread "main" java.lang.IllegalArgumentException:
java.net.MalformedURLException: no protocol:
/export/home/nick/java/build/catalina/libwebapps/libweb/WEB-INF/classes
        at
org.apache.catalina.loader.StandardClassLoader.addRepository(StandardClassLoader.java:357)
        at
org.apache.catalina.loader.StandardLoader.addRepository(StandardLoader.java:442)
        at
com.syntactics.servers.war.ContextConfig.loaderConfig(ContextConfig.java:676)
        at
com.syntactics.servers.war.ContextConfig.start(ContextConfig.java:782)
        at
com.syntactics.servers.war.ContextConfig.lifecycleEvent(ContextConfig.java:130)
        at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:155)
        at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1172)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:2395)
        at
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:816)
        at
org.apache.catalina.core.StandardHost.addChild(StandardHost.java:334)
        at
com.syntactics.servers.war.SynWarServer.main(SynWarServer.java:905)

----------------------------------

    public static void main(String args[]) {

        SynWarServer embedded = new SynWarServer();
        embedded.setDebug(0);
        embedded.setLogger(new SystemOutLogger());
        String home = System.getProperty("catalina.home");
        int tmpValue = 0;
        
        // Start up this embedded server (to prove we can dynamically
        // add and remove containers and connectors later)
        try {
            embedded.start();
        } catch (LifecycleException e) {
            System.err.println("start: " + e.toString());
            e.printStackTrace();
        }

        // Assemble and install a very basic container hierarchy
        // that simulates a portion of the one configured in server.xml
        // by default
        Engine engine = embedded.createEngine();

        StandardHost host2 =
embedded.createHost("library.syntactics.com", home + "/libwebapps");
        engine.addChild(host2);
        host2.addChild(embedded.createContext("/", home +
"/libwebapps/libweb"));
        
        embedded.addEngine(engine);

        // Assemble and install a non-secure connector for port 8080
        Connector connector =
            embedded.createConnector(null, 8080, false);
        embedded.addConnector(connector);

        try {
            Thread.sleep(2 * 60 * 1000L);       // Two minutes
        } catch (InterruptedException e) {
            ;
        }

        embedded.removeEngine(engine);

        // Shut down this embedded server (should have nothing left to
do)
        try {
            embedded.stop();
        } catch (LifecycleException e) {
            System.err.println("stop: " + e.toString());
            e.printStackTrace();
        }

    }


-------------------------------------------------------------------

Remy Maucherat wrote:
> 
> > I hope that this is a problem and not incompetence:
> >
> > A simple servlet and client - the client sends an object, the servlet
> > reads the object and sends it back.
> >
> > What happens is that the client sends the object, catalina maps the
> > servlet class correctly and then waits for the the object (which has
> > already been sent). Tracing catalina shows that the server thread stops
> > at line : 'Object obj = ois.readObject();'
> 
> Could you try again with the test connector and send me the results ?
> 
> In your server.xml file, change :
>     <Connector className="org.apache.catalina.connector.http.HttpConnector"
>                port="8080" minProcessors="5" maxProcessors="75"
>                acceptCount="10" debug="0"/>
> into
>     <Connector className="org.apache.catalina.connector.test.HttpConnector"
>                port="8080" minProcessors="5" maxProcessors="75"
>                acceptCount="10" debug="0"/>
> 
> Thanks,
> Remy
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

-- 
Nick Betteridge
Syntactics Limited, 2 Calais Street, London SE5 9LP, UK.
Tel:+44 (0)20 7564 5678 Fax:+44 (0)20 7564 5679 Mobile:+44 (0)
7710088462
http://www.syntactics.com :

Re: [CATALINA] Servlet problem

Posted by Remy Maucherat <re...@apache.org>.
> I hope that this is a problem and not incompetence:
> 
> A simple servlet and client - the client sends an object, the servlet
> reads the object and sends it back.
> 
> What happens is that the client sends the object, catalina maps the
> servlet class correctly and then waits for the the object (which has
> already been sent). Tracing catalina shows that the server thread stops
> at line : 'Object obj = ois.readObject();'

Could you try again with the test connector and send me the results ?

In your server.xml file, change :
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               acceptCount="10" debug="0"/>
into
    <Connector className="org.apache.catalina.connector.test.HttpConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               acceptCount="10" debug="0"/>

Thanks,
Remy