You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by aaaa0441 <gm...@yahoo.com.cn> on 2011/11/09 04:10:58 UTC
Use Wicket 1.5 to serve "text/xml" content type (Rest-style)
Hi yo'all,
I did quite a lot Googling and searched this forum, but still did not find
what I was looking for.
Basically I need to create pages that respond with xml content with
"text/xml" content-type.
In some posts, Igor suggested to overwrite "configureResponse" method. So I
tried the following
@Override
protected void configureResponse(WebResponse response) {
response.setContentType("text/xml");
super.configureResponse(response);
}
which does not work. The page response's content-type is still "text/html".
I also tried to overwrite "getMarkupType" method, as shown here
@Override
public MarkupType getMarkupType() {
return new MarkupType("xml", MarkupType.XML_MIME);
}
which also does not work and throws
"org.apache.wicket.markup.MarkupNotFoundException: Can not determine Markup.
Component is not yet connected to a parent. [Page class = SomePage, id = 3,
render count = 1]".
One user who was asking questions on this forum created the following
article, which could serve my purpose.
http://blog.brunoborges.com.br/2008/11/restful-web-services-with-wicket.html
So I migrated his code to Wicket 1.5, as shown below.
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.MarkupType;
import org.apache.wicket.markup.html.WebPage;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Created by IntelliJ IDEA.
* User: Ma Ding
* Date: 11/9/11
* Time: 9:46 AM
*/
public class RestXmlPage extends WebPage {
public RestXmlPage() {
setStatelessHint(true);
}
private CharSequence getXML() {
return "<top><id><12></id><name>round n round</name></top>";
}
@Override
protected void onRender() {
try {
PrintWriter pw = new PrintWriter(((HttpServletResponse)
getResponse().getContainerResponse()).getOutputStream());
pw.write(getXML().toString());
pw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public MarkupType getMarkupType() {
return new MarkupType("xml", MarkupType.XML_MIME);
}
@Override
public final boolean hasAssociatedMarkup() {
return false;
}
@Override
public final Component add(Behavior... behaviors) {
throw new UnsupportedOperationException(
"WebServicePage does not support IBehaviours");
}
}
But this page also throws "org.apache.wicket.markup.MarkupNotFoundException:
Can not determine Markup. Component is not yet connected to a parent."
exception.
Could anyone spare some time and help me with this?
Thanks a lot!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Use-Wicket-1-5-to-serve-text-xml-content-type-Rest-style-tp4018490p4018490.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Use Wicket 1.5 to serve "text/xml" content type (Rest-style)
Posted by aaaa0441 <gm...@yahoo.com.cn>.
Thanks, Lim. That does the trick!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Use-Wicket-1-5-to-serve-text-xml-content-type-Rest-style-tp4018490p4018601.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Use Wicket 1.5 to serve "text/xml" content type (Rest-style)
Posted by TH Lim <ss...@gmail.com>.
try reversing the statements in configureResponse(...) body
@Override
protected void configureResponse(WebResponse response) {
super.configureResponse(response);
response.setContentType("text/xml");
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Use-Wicket-1-5-to-serve-text-xml-content-type-Rest-style-tp4018490p4018575.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org