I implement a RESTful Web Service in Java using jersey and run it on
Tomcat7.
I have this query to get list of tasks :
@GET
@Path("/user_id/get/{username}/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response taskList(@PathParam("username") String username) {
Session session =
HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<Task> tasks = null;
try {
tasks = (List<Task>)session.createQuery("from Task as t
where t.user.username = :name order by t.project.key ASC,
t.deliverable.key ASC, t.activity.key ASC, t.start
ASC").setString("name", username).list();
} catch (HibernateException e) {
e.printStackTrace();
session.getTransaction().rollback();
}
session.getTransaction().commit();
return Response.ok().entity(tasks).build();
}
I test it with jersey client like :
response =
service.path("task/user_id/get/are/").type("application/json").get(Clie
ntResponse.class);
s = response.getEntity(String.class);
System.out.println(s);
An example for the result:
[{"id":5369,"start":1331428800000,"end":1331428800000,"description":"",
"started":false,"user":{"id":28,"username":"are","hash":"$2a$10$G0e7cjX
tn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"project":{"id":115,"k
ey":"are","name":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":102,"ke
y":"d","name":"Development","description":"Usually
this.","cost":690.0,"orderIndex":2,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1282,"description":"andra
saker","key":"andra","name":"Other","project":{"id":115,"key":"are","na
me":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1266,"des
cription":"","key":"other","name":"Other","project":{"id":115,"key":"ar
e","name":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":nul
l,"orderIndex":0,"done":false,"minEstimate":null,"maxEstimate":null,"ta
sk_id":0},"user":{"id":28,"username":"are","hash":"$2a$10$G0e7cjXtn60Xm
AhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderIndex":3,"done":false,
"minEstimate":10.0,"maxEstimate":30.0,"task_id":0},"link":""},{"id":532
4,"start":1331254080000,"end":1331254800000,"description":"","started":
false,"user":{"id":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx
8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"project":{"id":115,"key":"are",
"name":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":102,"ke
y":"d","name":"Development","description":"Usually
this.","cost":690.0,"orderIndex":2,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1274,"description":"","key":"login","name":"Login",
"project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1273,"des
cription":"","key":"client","name":"Android
client","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":{"i
d":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDv
c2mBaNsTGqQe1tgIZAxy"},"orderIndex":2,"done":false,"minEstimate":null,"
maxEstimate":null,"task_id":0},"user":{"id":28,"username":"are","hash":
"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderI
ndex":1,"done":false,"minEstimate":15.0,"maxEstimate":30.0,"task_id":0}
,"link":""},{"id":7901,"start":1338678900000,"end":1338678900000,"descr
iption":"","started":false,"user":{"id":28,"username":"are","hash":"$2a
$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"project":{
"id":115,"key":"are","name":"Master Thesis","description":"Android
client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":101,"ke
y":"c","name":"Consulting","description":"Just in special cases,
authorized by RĂ¼diger after discussion with
customer.","cost":990.0,"orderIndex":3,"parent":{"id":100,"key":"scrum"
,"name":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":nul
l}},"deliverable":{"id":1278,"description":"Stagtistic
check","key":"statistic","name":"Statistics","project":{"id":115,"key":
"are","name":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1273,"des
cription":"","key":"client","name":"Android
client","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":{"i
d":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDv
c2mBaNsTGqQe1tgIZAxy"},"orderIndex":2,"done":false,"minEstimate":null,"
maxEstimate":null,"task_id":0},"user":{"id":28,"username":"are","hash":
"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderI
ndex":5,"done":false,"minEstimate":20.0,"maxEstimate":40.0,"task_id":0}
,"link":""},{"id":10441,"start":1347134220000,"end":1347135120000,"desc
ription":"hello","started":false,"user":{"id":28,"username":"are","hash
":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"proj
ect":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":100,"ke
y":"scrum","name":"Scrum","description":"","cost":0.0,"orderIndex":1,"p
arent":null},"deliverable":{"id":1278,"description":"Stagtistic
check","key":"statistic","name":"Statistics","project":{"id":115,"key":
"are","name":"Master Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1273,"des
cription":"","key":"client","name":"Android
client","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":{"i
d":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDv
c2mBaNsTGqQe1tgIZAxy"},"orderIndex":2,"done":false,"minEstimate":null,"
maxEstimate":null,"task_id":0},"user":{"id":28,"username":"are","hash":
"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderI
ndex":5,"done":false,"minEstimate":20.0,"maxEstimate":40.0,"task_id":0}
,"link":""},{"id":6259,"start":1334170080000,"end":1334170140000,"descr
iption":"hi","started":false,"user":{"id":28,"username":"are","hash":"$
2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"project"
:{"id":115,"key":"are","name":"Master Thesis","description":"Android
client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":102,"ke
y":"d","name":"Development","description":"Usually
this.","cost":690.0,"orderIndex":2,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1276,"description":"","key":"task","name":"Uppgifte
r","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1273,"des
cription":"","key":"client","name":"Android
client","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":{"i
d":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDv
c2mBaNsTGqQe1tgIZAxy"},"orderIndex":2,"done":false,"minEstimate":null,"
maxEstimate":null,"task_id":0},"user":{"id":28,"username":"are","hash":
"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderI
ndex":3,"done":false,"minEstimate":15.0,"maxEstimate":30.0,"task_id":0}
,"link":""},{"id":7900,"start":1338678600000,"end":1338678780000,"descr
iption":"","started":false,"user":{"id":28,"username":"are","hash":"$2a
$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"project":{
"id":115,"key":"are","name":"Master Thesis","description":"Android
client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":102,"ke
y":"d","name":"Development","description":"Usually
this.","cost":690.0,"orderIndex":2,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1276,"description":"","key":"task","name":"Uppgifte
r","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1273,"des
cription":"","key":"client","name":"Android
client","project":{"id":115,"key":"are","name":"Master
Thesis","description":"Android client for
Timelog","date":1328396400000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":{"i
d":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDv
c2mBaNsTGqQe1tgIZAxy"},"orderIndex":2,"done":false,"minEstimate":null,"
maxEstimate":null,"task_id":0},"user":{"id":28,"username":"are","hash":
"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"orderI
ndex":3,"done":false,"minEstimate":15.0,"maxEstimate":30.0,"task_id":0}
,"link":""},{"id":6258,"start":1334170020000,"end":1334170080000,"descr
iption":"Develop","started":false,"user":{"id":28,"username":"are","has
h":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc2mBaNsTGqQe1tgIZAxy"},"pro
ject":{"id":109,"key":"mre","name":"Master Thesis Ali
Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":102,"ke
y":"d","name":"Development","description":"Usually
this.","cost":690.0,"orderIndex":2,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1495,"description":"Develop
statistic","key":"3.2","name":"statistic","project":{"id":109,"key":"mr
e","name":"Master Thesis Ali Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1240,"des
cription":"Developing","key":"3","name":"Android
Client","project":{"id":109,"key":"mre","name":"Master Thesis Ali
Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":nul
l,"orderIndex":2,"done":false,"minEstimate":0.0,"maxEstimate":0.0,"task
_id":0},"user":null,"orderIndex":2,"done":false,"minEstimate":null,"max
Estimate":null,"task_id":0},"link":""},{"id":10442,"start":134713464000
0,"end":1347135540000,"description":"hello","started":false,"user":{"id
":28,"username":"are","hash":"$2a$10$G0e7cjXtn60XmAhUx8JpNOYk.EwpIEwDvc
2mBaNsTGqQe1tgIZAxy"},"project":{"id":109,"key":"mre","name":"Master
Thesis Ali Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"activity":{"id":108,"ke
y":"v","name":"Vacation/Holidays","description":"Planned vacation
(counting agains the 25
days)","cost":300.0,"orderIndex":5,"parent":{"id":100,"key":"scrum","na
me":"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null}},
"deliverable":{"id":1237,"description":"","key":"o","name":"Other","pro
ject":{"id":109,"key":"mre","name":"Master Thesis Ali
Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":{"id":1236,"des
cription":"","key":"other","name":"Other","project":{"id":109,"key":"mr
e","name":"Master Thesis Ali Rezaei","description":"Timelog
Android","date":1328223600000,"category":{"id":100,"key":"scrum","name"
:"Scrum","description":"","cost":0.0,"orderIndex":1,"parent":null},"val
ueType":0,"fixValue":0.0,"done":0,"task_id":0},"parent":null,"user":nul
l,"orderIndex":0,"done":false,"minEstimate":null,"maxEstimate":null,"ta
sk_id":0},"user":null,"orderIndex":2,"done":true,"minEstimate":null,"ma
xEstimate":null,"task_id":0},"link":""}]
It works perfectly for this user (are) and all other users except one
on them.
That user has enormous number of tasks in the database, so I got this
error :
Caused by: java.io.IOException: Premature EOF
at sun.net.www.http.ChunkedInputStream.readAheadBlocking(Unknown
Source)
at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source)
at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at
sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknow
n Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.Reader.read(Unknown Source)
at
com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.jav
a:171)
at
com.sun.jersey.core.util.ReaderWriter.readFromAsString(ReaderWriter.jav
a:157)
at
com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.readFr
omAsString(AbstractMessageReaderWriterProvider.java:114)
at
com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(String
Provider.java:73)
at
com.sun.jersey.core.impl.provider.entity.StringProvider.readFrom(String
Provider.java:58)
at
com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:
554)
... 2 more
I appreciate for any help.