Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@HttpTest(method = Method.POST, ...) without content leads to NullPointerException #42

Open
YA2O opened this issue Jun 4, 2013 · 4 comments

Comments

@YA2O
Copy link

YA2O commented Jun 4, 2013

In com.eclipsesource.restfuse.annotation.HttpTest, the default value for content is an empty string. This content value does not work for a POST request (@httptest(method = Method.POST, ..., content = "") ).

It is an expected use case to use a HTTP POST without content; this is often the case when creating resources in a ReSTful web service, with the data for the resource provided by the server, like e.g. a timestamp (e.g. /users/john/checkin/).

Stack Trace:

java.lang.NullPointerException
at com.github.kevinsawicki.http.HttpRequest$CloseOperation.done(HttpRequest.java:647)
at com.github.kevinsawicki.http.HttpRequest$Operation.call(HttpRequest.java:608)
at com.github.kevinsawicki.http.HttpRequest.copy(HttpRequest.java:2380)
at com.github.kevinsawicki.http.HttpRequest.send(HttpRequest.java:2727)
at com.eclipsesource.restfuse.internal.InternalRequest.post(InternalRequest.java:76)
at com.eclipsesource.restfuse.internal.HttpTestStatement.callService(HttpTestStatement.java:119)
at com.eclipsesource.restfuse.internal.HttpTestStatement.sendRequest(HttpTestStatement.java:105)
at com.eclipsesource.restfuse.internal.BasicStatement.evaluate(BasicStatement.java:30)
at com.eclipsesource.restfuse.internal.HttpTestStatement.doEvaluate(HttpTestStatement.java:84)
at com.eclipsesource.restfuse.internal.HttpTestStatement.evaluate(HttpTestStatement.java:64)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

@gicappa
Copy link

gicappa commented Jul 30, 2013

+1

@eugen-r
Copy link

eugen-r commented Sep 13, 2013

Fix suggestion:
In class com.eclipsesource.restfuse.internal.RequestConfiguration replace method "private void addBody( HttpTest test, InternalRequest request )" as follows:


private void addBody( HttpTest test, InternalRequest request ) {
if( !test.file().equals( "" ) ) {
request.setContent( getFileStream( test.file() ) );
} else if( !test.content().equals( "" ) ) {
request.setContent( getContentStream( test.content() ) );
} else {
//omit NULL content as this leads to NullPointerException later.
request.setContent( new ByteArrayInputStream( new byte[0] ) );
}
}


For me this works well :-)

@Tmarty
Copy link

Tmarty commented May 20, 2014

+1

@NehaBhatia
Copy link

We are running into the same issue. Are there any plans to merge this suggestion in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants