01: /*
02: * $Id: MuleProtocolHeadersOutInterceptor.java 11366 2008-03-14 11:48:22Z dirk.olmes $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.transport.cxf.support;
12:
13: import static org.mule.api.config.MuleProperties.MULE_EVENT_PROPERTY;
14:
15: import org.mule.api.MuleEvent;
16: import org.mule.transport.http.HttpConstants;
17:
18: import java.util.Arrays;
19: import java.util.List;
20: import java.util.Map;
21:
22: import org.apache.cxf.helpers.CastUtils;
23: import org.apache.cxf.helpers.HttpHeaderHelper;
24: import org.apache.cxf.interceptor.Fault;
25: import org.apache.cxf.interceptor.MessageSenderInterceptor.MessageSenderEndingInterceptor;
26: import org.apache.cxf.message.Message;
27: import org.apache.cxf.phase.AbstractPhaseInterceptor;
28: import org.apache.cxf.phase.Phase;
29:
30: public class MuleProtocolHeadersOutInterceptor extends
31: AbstractPhaseInterceptor<Message> {
32:
33: public MuleProtocolHeadersOutInterceptor() {
34: super (Phase.PREPARE_SEND_ENDING);
35: getBefore().add(MessageSenderEndingInterceptor.class.getName());
36: }
37:
38: public void handleMessage(Message message) throws Fault {
39: MuleEvent event = (MuleEvent) message.getExchange().get(
40: MULE_EVENT_PROPERTY);
41:
42: if (event == null) {
43: return;
44: }
45:
46: Map<String, List<String>> reqHeaders = CastUtils
47: .cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
48: if (reqHeaders != null) {
49: for (Map.Entry<String, List<String>> e : reqHeaders
50: .entrySet()) {
51: event.getMessage().setProperty(e.getKey(),
52: format(e.getValue()));
53: }
54: }
55: }
56:
57: private String format(List<String> value) {
58: StringBuilder sb = new StringBuilder();
59: boolean first = true;
60:
61: for (String s : value) {
62: if (!first) {
63: sb.append(", ");
64: first = false;
65: } else {
66: first = false;
67: }
68:
69: sb.append(s);
70: }
71: return sb.toString();
72: }
73: }
|