Question

I develop a google glass app using mirror api. during development I used "Introspected tunnels to localhost" to receive the notification.

Now I uploaded my app on production server. So now I configure my callback URL as my domain name like https://www.mydomain.com:8443/notify. But I get empty notification.

in notify servlet:

BufferedReader notificationReader = new BufferedReader(
        new InputStreamReader(request.getInputStream()));
String notificationString = ""; 
int lines = 0;

while (notificationReader.ready()) {
    notificationString += notificationReader.readLine();
    lines++;

    if (lines > 1000) {
        throw new IOException(
                "Attempted to parse notification payload that was unexpectedly long.");
    }
}

LOG.info("\ngot raw notification : " + notificationString);

in catalina.out

Feb 13, 2014 12:51:48 PM com.google.glassware.NotifyServlet doPost
INFO: got raw notification : 

How can I solve it?

Was it helpful?

Solution

StringBuffer stringBuffer = new StringBuffer();
                String line = "";
                BufferedReader bufferReader = new BufferedReader(
                                       new InputStreamReader(request.getInputStream()));
                while ((line = bufferReader.readLine()) != null) {         
                    stringBuffer.append(line);
                }
                notificationString = stringBuffer.toString();

Hope it will works.

OTHER TIPS

I think you should use readLine() method.One of the answer from stack overflow suggest not using ready() for such requirements.

The ready method tells us if the Stream is ready to be read. Imagine your stream is reading data from a network socket. In this case, the stream may not have ended, because the socket has not been closed, yet it may not be ready for the next chunk of data, because the other end of the socket has not pushed any more data.

In the above scenario, we cannot read any more data until the remote end pushes it, so we have to wait for the data to become available, or for the socket to be closed. The ready() method tells us when the data is available.

I had this same problem and I changed the code to look like this:

 StringBuffer jb = new StringBuffer();
 String notificationString = "";
 String line = "";
 BufferedReader reader = request.getReader();
 while ((line = reader.readLine()) != null) {         
     jb.append(line);
 }
 notificationString = jb.toString();

Try This One:

while(notificationReader.ready()) {
    notificationString = notificationString.concat(notificationReader.readLine());
    lines++;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top