It's all about the answers!

Ask a question

Seialization of an HttpResponse/getting the OutputStream


Thomas Bollinger (4651) | asked Jul 30 '09, 5:31 a.m.
Hi there,

Im developing a REST Service based on JRS.

For my Server Im using the org.apache.http Lib, as proposed in the SDK Wiki-examples.

One of my resources is a Tree-Structure, which implements java.io.Serializable, and the only way to get RESTful access to it, is responding to GET-request with the serialized version of the tree. Am I right or did i miss something?

I domt want to serialize the data file-based, but stream-based. Therefore I need an (Object-)OutputStream attatched to the response. I tried it with org.apache.http.entity.SerializableEntity, but still dont find any OutputStream connected with the response. How do I get the OutputStream?

	private static TreeNode<TransferInformation> TREE = null;


@Override
public void doGet(HttpRequest request, HttpResponse response) throws IOException{

//Set content/Entity
if(TREE == null){
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
return;
}else{
try{

response.setEntity(new SerializableEntity(((Serializable)TREE), true));
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}

}
}


Greetings,
Thomas

Be the first one to answer this question!


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.