user3044240 February 2016

How to read and change body of a HTTP request?

I want to perform a REST operation on a request that gets generated for a user. I am trying to read the contents of the request body using this:

BufferedReader reader = null;
String info =null;
try
        {
            reader = httpRequest.getReader();
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            e1.getMessage();
        }

I keep getting this exception:

     <b>exception</b>
            <pre>java.lang.reflect.UndeclaredThrowableException
com.sun.proxy.$Proxy88.getReader(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)

It is on the getReader line. After this I want to do something like:

try
        {
            while((data =reader.readLine()) != null){
                LOGGER.debug("Line read from data is: "+ info);
                buffer.append(data);
            }
        }
        catch (IOException e1)
        {

            e1.printStackTrace();
        }

I cant get around that Exception. Any help is appreciated. Thanks.

Answers


Richard Barker February 2016

So it looks like your service reference (the RESTful service you're connecting to) is throwing an exception that your program isn't ready for nor understands. Or at least that's how I understand the docs on UndeclaredThrowableException.

https://docs.oracle.com/javase/7/docs/api/java/lang/reflect/UndeclaredThrowableException.html

Post Status

Asked in February 2016
Viewed 2,534 times
Voted 5
Answered 1 times

Search




Leave an answer