Hi Andrzej
could you use the "dataType" argument instead of the "beforeSend" one?
$.ajax({type: 'GET',
url: myUrl,
success: onAjaxSuccess,
error: onAjaxError,
cache: false,
dataType: "xml");
Best regards,
Thierry Boileau
> Thierry,
>
> 1) Our JQuery Ajax call:
>
> $.ajax({
> type: 'GET',
> url: myUrl,
> success: onAjaxSuccess,
> error: onAjaxError,
> cache: false,
> beforeSend :
> function(xhr){xhr.setRequestHeader('Accept','application/xml')}
> });
>
> Will generate Accept header of "*/*, application/xml". We want
> "application/xml".
>
> 2) Our Restlet 1.1.5
>
> @Override
> public Restlet createRoot() {
> // Create a router Restlet.
> Router router = new Router(getContext());
>
> // Attach our routers.
> router.attach("/test", HelloWorldResource.class);
> router.attach("/file/status", FileStatusResource.class);
>
> return router;
> }
>
>
> public FileStatusResource(Context context, Request request, Response
> response) {
> super(context, request, response);
>
> // Read URI query strings.
> Form form = request.getOriginalRef().getQueryAsForm();
> if (form != null) {
> setUser(form.getFirstValue("user", isIgnoreCase()));
> setOriginalUri(form.getFirstValue("originalUri",
> isIgnoreCase()));
> setAction(form.getFirstValue("action", isIgnoreCase()));
> }
>
> // Variants that our resource generates.
> getVariants().add(new Variant(MediaType.APPLICATION_JSON));
> getVariants().add(new Variant(MediaType.APPLICATION_XML));
>
> }
>
> @Override
> public Representation represent(Variant variant) throws ResourceException {
> Representation representation = null;
>
> // Validate request
> if (StringUtils.isBlank(getUser())) {
> log.debug("GET FileStatusResource bad user. ");
> representation = representError(variant, new
> ErrorMessage());
>
> getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
> return representation;
> }
>
> representation = representGet(this,variant);
> return representation;
> }
>
> public final Representation representGet(CoralReefResource crr, Variant
> variant)
> throws ResourceException {
> Representation representation = null;
>
> log.debug("HTTP GET for : " + variant.getMediaType().getName());
> ...
>
>
>
>
> Thierry Boileau wrote:
>
>> Hello Andrzej,
>>
>> I wonder if the source cause if your issue is out there.
>> Could you tell us how are built your resources? How do you send the
>> request using jquery?
>>
>> Best regards,
>> Thierry Boileau
>>
>>
>>> Our Restlet resource server APPLICATION_JSON and APPLICATION_XML. A
>>> JQuery
>>> client, sets the Accept Type to "*/*, application/xml". So the Restlet
>>> negotiates that APPLICATION_JSON should be returned as expected. However,
>>> we
>>> want APPLICATION_XML to be served. The problem is that we are unable to
>>> remove the "*/*" as the first Accept type in JQuery. JQuery seems to tack
>>> on
>>> the "*/*" as an Accept Type to every request we send.
>>>
>>> Is there an elegant way in Restlet to filter the "*/*" values, e.g. ALL
>>> or
>>> APPLICATION_ALL? We can certainly get the Accept Headers in Restlet and
>>> re-arrange the Accept list ourselves to "override" the Restlet
>>> negotiation.
>>> We are thinking of filtering, after Restlet negotiation, based on the
>>> User-Agent header for this particular JQuery client, so as not to "break"
>>> the Restlet behaviour for other clients (which is what we expect.)
>>>
>>>
>> ------------------------------------------------------
>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2430776
>>
>>
>>
>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2430802