Hi,

here is a proposal that works for me :
    public void createRequest(final MessageExchange exchange,
            final NormalizedMessage inMsg, final SmxHttpExchange
httpExchange)
            throws Exception {

        // New HTTP endpoint do not support basic auth credential
        // so here we are doing it manually
        String credentials = new
String(org.apache.commons.codec.binary.Base64
                .encodeBase64((this.username + ":" +
this.password).getBytes()));

        // Get the content of the message and transform it to a string
        ByteArrayOutputStream messageContentAsBaos = new
ByteArrayOutputStream();
        if (inMsg.getContent() != null) {
            transformer.toResult(inMsg.getContent(), new
StreamResult(messageContentAsBaos));
        }

        StringBuffer sb = new StringBuffer();
        sb.append(messageContentAsBaos.toString(), "UTF-8");

        httpExchange.setURL(getLocationUri(exchange, inMsg));
        httpExchange.addRequestHeader(HttpHeaders.HOST_BUFFER,
                new ByteArrayBuffer(new URI(getLocationUri(exchange, inMsg))
                        .getHost()));
        httpExchange.setMethod(getMethod(exchange, inMsg));

        httpExchange.setRequestHeader(HttpHeaders.CONTENT_TYPE, "text/xml");

        httpExchange.setRequestHeader(HttpHeaders.AUTHORIZATION, "Basic " +
credentials);
        httpExchange.setRequestHeader(HttpHeaders.CONTENT_LENGTH,
sb.length() + "");

        httpExchange.setRequestContent(new ByteArrayBuffer(sb.toString()));
    }

What is strange, is that it doesn't differ that much of what you do...

On Tue, Jan 19, 2010 at 10:00 AM, Jean-Baptiste Onofré <[email protected]>wrote:

> Hi,
>
> sorry, I forgot you :/
>
> I have a JMS bug to manage this morning but just after I will make a test
> case and give you the code sample.
>
> Regards
> JB
>
>
> ranarula wrote:
>
>> Any help on this would be helpful. Still struggling to get this to work.
>>
>>
>> ranarula wrote:
>>
>>> Thanks Jean for your reply.
>>>
>>> I have been trying to set the Authorization info in the createRequest in
>>> my custom marshaler as below
>>>
>>>   public void createRequest(MessageExchange exchange, NormalizedMessage
>>> inMsg, SmxHttpExchange httpExchange) throws Exception {
>>>        String authString ="";
>>>        httpExchange.setURL(getLocationUri(exchange, inMsg));
>>>
>>>        httpExchange.addRequestHeader(HttpHeaders.HOST_BUFFER, new
>>> ByteArrayBuffer(new URI(getLocationUri(exchange, inMsg)).getHost()));
>>>
>>>        httpExchange.setMethod(getMethod(exchange, inMsg));
>>>        httpExchange.setRequestHeader(HttpHeaders.CONTENT_TYPE,
>>> getContentType(exchange, inMsg));
>>>
>>> if(exchange.getEndpoint().getEndpointName().equalsIgnoreCase("reg")){
>>>                authString = "Basic somebase64string";
>>>        }
>>>        else{
>>>                authString = "Basic someotherbase64String";
>>>                }
>>>        httpExchange.addRequestHeader(HttpHeaders.AUTHORIZATION,
>>> authString);
>>>        if (getHeaders() != null) {
>>>            for (Map.Entry<String, String> e : getHeaders().entrySet()) {
>>>                httpExchange.setRequestHeader(e.getKey(), e.getValue());
>>>                            }
>>>        }
>>>
>>>        if (contentExpression != null) {
>>>            String contentToSend = applyContentExpression(exchange,
>>> inMsg);
>>>            if (contentToSend != null) {
>>>                httpExchange.setRequestContent(new
>>> ByteArrayBuffer(contentToSend.getBytes()));
>>>            }
>>>        } else if (inMsg.getContent() != null) {
>>>            ByteArrayOutputStream baos = new ByteArrayOutputStream();
>>>            transformer.toResult(inMsg.getContent(), new
>>> StreamResult(baos));
>>>            httpExchange.setRequestContent(new
>>> ByteArrayBuffer(baos.toByteArray()));
>>>        }
>>>    }
>>>
>>> But I am not able to still able to get it to work. Please confirm if this
>>> is the right way of doing so.
>>>
>>>
>>

Reply via email to