Error parsing from InputStream

659 views
Skip to first unread message

Hershiv Haria

unread,
Nov 27, 2009, 8:06:32 AM11/27/09
to Protocol Buffers
I am trying out protocol buffers for the first time, and have written
a simple client and servlet to send and receive the PB. It will run on
App Engine. However every time I try it hits a NoClassDefFoundError
for GeneratedMessages.

The error is:

ov 27, 2009 12:54:38 PM com.google.apphosting.utils.jetty.JettyLogger
warn
WARNING: Error for /testfileupload
java.lang.NoClassDefFoundError: com/google/protobuf/GeneratedMessage
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:700)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:
124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass
(IsolatedAppClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)
at my.testfiletransfer.TestFileUploadServlet.doGet
(TestFileUploadServlet.java:28)
at my.testfiletransfer.TestFileUploadServlet.doPost
(TestFileUploadServlet.java:20)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1093)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1084)
at com.google.appengine.tools.development.StaticFileFilter.doFilter
(StaticFileFilter.java:121)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle
(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle
(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle
(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle
(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle
(DevAppEngineWebAppContext.java:54)
at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:139)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:342)
at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
506)
at org.mortbay.jetty.HttpConnection$RequestHandler.content
(HttpConnection.java:844)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run
(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run
(BoundedThreadPool.java:442)
Caused by: java.lang.ClassNotFoundException:
com.google.protobuf.GeneratedMessage
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass
(IsolatedAppClassLoader.java:151)
at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)
... 39 more




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

The client is:

package my.testfiletransfer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import my.tft.protos.RandomMessageProtos.Note;
import my.tft.protos.RandomMessageProtos.RandomMessage;

public class TestFileUploadClient {

public static void main(String[] args) {

BufferedReader in = null;
try {
System.out.println("starting client");
File source = new File("/Users/darkmaster108/Documents/blarg.txt");
URL url = new URL("http://localhost:8080/testfileupload");
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true);
urlc.connect();

RandomMessage.Builder randomMessage = RandomMessage.newBuilder();
Note.Builder note = Note.newBuilder();
note.setName(source.getName());
StringBuffer sb = new StringBuffer();

in = new BufferedReader(new FileReader(source));

String line;
while ((line = in.readLine()) != null)
sb.append(line);

note.setMessage(sb.toString());

randomMessage.addNote(note);
randomMessage.build().writeTo(urlc.getOutputStream());
urlc.getOutputStream().close();

BufferedReader rd = new BufferedReader(new InputStreamReader(urlc
.getInputStream()));

System.out.println("Respose is:");
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
rd.close();

} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} // finally
}
}


------------------------------------------------------------------------------------------------------
The server is:

package my.testfiletransfer;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import my.tft.protos.RandomMessageProtos.RandomMessage;

@SuppressWarnings("serial")
public class TestFileUploadServlet extends HttpServlet {

public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
doGet(req, resp);
}

public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {

try {
InputStream is = req.getInputStream();
RandomMessage randomMessage = RandomMessage.parseFrom(is);
is.close();

System.err.println("Name: " + randomMessage.getNote(1).getName());
System.err.println("Message: " + randomMessage.getNote(1).getMessage
());

PrintWriter out = resp.getWriter();
out.println("ok");
out.close();
} catch(Exception e) {
System.err.println(e.getMessage());
}
}
}

Any help would be much appreciated, I'm sure I'm making a silly little
mistake.

Kenton Varda

unread,
Nov 28, 2009, 12:48:01 AM11/28/09
to Hershiv Haria, Protocol Buffers
Looks like libprotobuf.jar is missing.  The code generated by protoc depends on this library.


--

You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.



Hershiv Haria

unread,
Nov 28, 2009, 6:35:02 AM11/28/09
to Protocol Buffers
By libprotobuf.jar I assume you mean the classes compiled during
installation?

I have them in the build path, and they work on the java tutorial
project from the protobuf site.
Is there any other reason it wouldn't find the class?

On Nov 28, 5:48 am, Kenton Varda <ken...@google.com> wrote:
> Looks like libprotobuf.jar is missing.  The code generated by protoc depends
> on this library.
>
> > protobuf+u...@googlegroups.com<protobuf%2Bunsu...@googlegroups.com>
> > .

Jon Skeet

unread,
Nov 28, 2009, 4:13:00 PM11/28/09
to Protocol Buffers
On Nov 28, 11:35 am, Hershiv Haria <darkmaste...@gmail.com> wrote:
> By libprotobuf.jar I assume you mean the classes compiled during
> installation?

Not sure exactly what you mean by "installation" here - but you should
have a jar file created from Google source code, *not* generated by
protoc in response to your .proto files.

> I have them in the build path, and they work on the java tutorial
> project from the protobuf site.

If the tutorial project works, then you've definitely got the right
jar files around.

> Is there any other reason it wouldn't find the class?

Well, it looks like you're using Jetty. I suggest you consult the
Jetty documentation to find out where it expects to find libraries.

Jon

Kenton Varda

unread,
Nov 29, 2009, 12:21:03 AM11/29/09
to Hershiv Haria, Protocol Buffers
The error said:
  java.lang.NoClassDefFoundError: com/google/protobuf/GeneratedMessage

This seems to be saying tha com.google.protobuf.GeneratedMessage -- which is part of libprotobuf.jar -- is not present.  Note that it *was* clearly present when you complied your code -- otherwise you'd get a compiler error.  But you're only getting an error when *running*, which suggests that your runtime environment differs from your build environment.

To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.

Hershiv Haria

unread,
Nov 29, 2009, 5:35:00 AM11/29/09
to Protocol Buffers
You were right, my runtime environment wasn't set up correctly. As I
was using GAE I had to copy the jar to war/WEB-INF/lib, that fixed the
reading issue.

Thanks for your help!

On Nov 29, 5:21 am, Kenton Varda <ken...@google.com> wrote:
> The error said:
>   java.lang.NoClassDefFoundError: com/google/protobuf/GeneratedMessage
>
> This seems to be saying tha com.google.protobuf.GeneratedMessage -- which is
> part of libprotobuf.jar -- is not present.  Note that it *was* clearly
> present when you complied your code -- otherwise you'd get a compiler error.
>  But you're only getting an error when *running*, which suggests that your
> runtime environment differs from your build environment.
>
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages