Thanks for the suggestion, Yoav, but thus far in my experiments, sendError 
seems to

--Send "Content-Type: text/html;charset=utf-8"
--Ignore the content I've written (using ServletResponse.getOutputStream()) and 
instead send the generic Tomcat HTML 'Server Error' message. Which of course is 
even worse for a web service client, since it's not well-formed XML.... ;-)

I'm trying:

servletResponse.setContentType("text/xml");
...
soapResponse.save(servletResponse.getOutputStream());
servletResponse.sendError(500);

(where soapResponse.save writes the XML to the specified OutputStream)

Using sendError(int, String) does effectively the same thing, except with the 
string message included in the HTML response.


When I instead tried:
servletResponse.setContentType("text/xml");
...
servletResponse.setStatus(500);
soapResponse.save(servletResponse.getOutputStream());

I got the appropriate XML contents back, but with Content-Type set to 
"text/html;charset=utf-8" instead of "text/xml"


There must be a way to do this - plenty of people use Tomcat to handle SOAP web 
services...I'll check the Axis source and see how they handle it. But any 
suggestions would be welcome.

Thanks again,
Aaron Dunlop

-----Original Message-----
From: Shapira, Yoav [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 08, 2004 5:59 AM
To: Tomcat Users List
Subject: RE: HttpServletResponse.setStatus and setContentType



Hi,
You know, the JavaDoc for HttpServletResponse#setStatus is pretty clear
on this ;)  Use sendError for errors, setStatus for normal responses.

Yoav Shapira http://www.yoavshapira.com
 

>-----Original Message-----
>From: Dunlop, Aaron [mailto:[EMAIL PROTECTED]
>Sent: Tuesday, December 07, 2004 5:44 PM
>To: Tomcat Users List
>Subject: HttpServletResponse.setStatus and setContentType
>
>I have a standard HTTP servlet acting as an XML web service endpoint,
>running on an embedded Tomcat 5.0.30.
>
>I of course use HttpServletResponse.setContentType to specify that the
>response is "text/xml". When the request is successful and I set a 2xx
HTTP
>response code, the Content-Type header looks as expected. But if an
error
>is detected and I return an HTTP error code (using setStatus), the
Content-
>Type header specifies "text/html;charset=utf-8" instead of "text/xml".
>
>It doesn't seem to matter whether I call setContentType before or after
>setStatus, and all the 4xx and 5xx codes I've tried trigger this
behavior.
>
>I'd just ignore it, but unfortunately, the WSI Basic Profile specifies
that
>a SOAP fault must return a 500 along with the XML fault. And some
clients
>(ahem... .NET...) seem to choke trying to parse the fault when the
wrong
>content-type is returned.
>
>I didn't find anything in the specs or documentation that indicated to
me
>that this was required behavior, but perhaps I'm missing something.
>
>Any ideas?
>
>Thanks in advance,
>Aaron Dunlop
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




This e-mail, including any attachments, is a confidential business 
communication, and may contain information that is confidential, proprietary 
and/or privileged.  This e-mail is intended only for the individual(s) to whom 
it is addressed, and may not be saved, copied, printed, disclosed or used by 
anyone else.  If you are not the(an) intended recipient, please immediately 
delete this e-mail from your computer system and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to