Register Web Service

Questions and answers on developing, deploying and using plugins and JavaBeans

Register Web Service

Postby cybersack » Fri Apr 08, 2005 8:34 am

My server-side plugin registers a servlet:

iServerAccess.registerWebService("ANewServlet", new MyServlet());

The URL is:
http://localhost:8080/servoy-service/AN ... ?some=data

When I first hit the servlet (say via a browser), the init(/** no param**/) method is invoked. I log it successfully.

However, this and subsequent invocations of doGet or doPost using the above URL from a browser fail to get invoked. Likewise, if the URL is invoked via java code similar to:

HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(false); // system may not ask the user
conn.setDoOutput(true); // we want to send things
conn.setRequestProperty( "Content-type", "binary/x-java-serialized" );
OutputStream rawOutStream = conn.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(rawOutStream);
oos.writeObject(request);
oos.flush();
conn.connect();

...then it also fails to regiter an invocation of doPost (or doGet etc).

What am I doing wrong here ?

mtia
User avatar
cybersack
 
Posts: 302
Joined: Sun Jan 02, 2005 1:17 am

Postby jcompagner » Fri Apr 08, 2005 5:31 pm

so really if you have that url loaded in the browser
and then you hit CTRL-F5 (force refresh or what ever)
then you will not see the doGet method invoked on the servlet?
Are you really sure?
Only thing i can think of is caching or that the servlet crashes? And is removed from the application (this looks very unlikely)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby cybersack » Sat Apr 09, 2005 5:09 am

Unfortunately, I am really sure :(

Actually, something strange must be happening at the server because here's my debugging of the connection and the returned streams:

-->conn=sun.net.www.protocol.http.HttpURLConnection:http://localhost:8080/servoy-service/ANewServlet
-->connection=sun.net.www.protocol.http.HttpURLConnection:http://localhost:8080/servoy-service/ANewServlet

InputStream inputStream = connection.getInputStream();
-->inputStream=sun.net.www.protocol.http.EmptyInputStream@4f2189

Notice that an empty input stream is returned by the server.

Maybe I should be coding against the service method ??? :
protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException

instead of doPost and doGet....but that would be almost insane !

Here's my stack trace (because I dump it) from the init() call:

java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:1064)
at au.com.practica.data.servlet.MyServlet.init(MyServlet.java:41)
at com.servoy.j2db.server.servlets.WebServicesServlet.init(Unknown Source)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:852)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:615)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:534)
User avatar
cybersack
 
Posts: 302
Joined: Sun Jan 02, 2005 1:17 am

Postby cybersack » Sat Apr 09, 2005 11:54 pm

Seeing as I am not getting any further with this problem, I am attaching a server-side plugin which loads a servlet. If you compile this (in the default package) and place it on your plugin classpath, it should load.

If you are testing locally, URL is:
http://localhost:8080/servoy-service/AServlet

If anyone can actually see the stack dump on any method other than init(), please post back. Otherwise, I can only assume this is a Servoy or servoy-tomcat issue.

thanks
julian

here is plugin source:
**********************************************************
import java.io.IOException;
import java.rmi.Remote;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.servoy.j2db.plugins.IServerAccess;
import com.servoy.j2db.plugins.IServerPlugin;
import com.servoy.j2db.plugins.PluginException;
import com.servoy.j2db.preference.PreferencePanel;
import com.servoy.j2db.util.Debug;

public class ServletPlugin
implements IServerPlugin, Remote
{
public ServletPlugin()
{
super();
}

public void initialize(final IServerAccess iServerAccess) throws PluginException
{
try
{
iServerAccess.registerWebService("AServlet", new HttpServlet()
{
/** {@inheritDoc} */
public void init() throws ServletException
{
Thread.dumpStack();
super.init();
}

/** {@inheritDoc} */
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException
{
Thread.dumpStack();
super.doGet(arg0, arg1);
}

/** {@inheritDoc} */
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException
{
Thread.dumpStack();
super.doPost(arg0, arg1);
}

/** {@inheritDoc} */
protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException
{
Thread.dumpStack();
super.service(arg0, arg1);
}

/** {@inheritDoc} */
public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException
{
Thread.dumpStack();
super.service(arg0, arg1);
}

});
System.out.println("Service Registered");
}
catch (Exception e)
{
Debug.error(e);
e.printStackTrace();
}
}

public void load() throws PluginException
{
System.out.println("ServletPlugin.load() invoked");
}

public void unload() throws PluginException
{
System.out.println("ServletPlugin.unload() invoked");
}

public PreferencePanel[] getPreferencePanels()
{
return null;
}

public Map getRequiredPropertyNames()
{
return new Hashtable();
}

public Properties getProperties()
{
return new Properties();
}
}


**********************************************************
User avatar
cybersack
 
Posts: 302
Joined: Sun Jan 02, 2005 1:17 am

Postby jcompagner » Mon Apr 11, 2005 11:15 am

until now you need another / in youre name

http://localhost:8080/servoy-service/AServlet/

to execute youre servlet.
I changed this behaviour (after 2.2RC4)
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby pbakker » Mon Apr 11, 2005 11:36 am

Johan,

While looking at this: If you go to http://localhost:8080/servoy-service while there are no WebServices registered, you get a page saying something like No webServices installed"

When you do install a WebService and go to http://localhost:8080/servoy-service, you get a TomCat internall error page.

I would expect a list of the registered Webservices here (since it says "No webServices installed" when there are none). If this is not possible, a blank page or a redirect to the http://localhost:8080/index.html would be a lot neater, I think.

Just my 5 cents,

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby jcompagner » Mon Apr 11, 2005 1:25 pm

i could show a list of webservices, but is this always information you want to show to the outside world?

I fixed the error page, it shows now just a page with the text:

Servoy web services page
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby pbakker » Mon Apr 11, 2005 1:28 pm

What I always do when having to make such a desicion: Make it configurable :D

Tnx for removing the error page.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 31 guests

cron