01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding.soap.interceptor;
19:
20: import java.util.HashMap;
21: import java.util.List;
22:
23: import org.apache.cxf.binding.soap.Soap11;
24: import org.apache.cxf.binding.soap.SoapMessage;
25: import org.apache.cxf.binding.soap.SoapVersion;
26: import org.apache.cxf.interceptor.AttachmentOutInterceptor;
27: import org.apache.cxf.interceptor.Fault;
28: import org.apache.cxf.phase.Phase;
29:
30: import static org.apache.cxf.message.Message.MIME_HEADERS;
31:
32: /**
33: * This interceptor is responsible for setting up the SOAP version
34: * and header, so that this is available to any pre-protocol interceptors
35: * that require these to be available.
36: */
37: public class SoapPreProtocolOutInterceptor extends
38: AbstractSoapInterceptor {
39:
40: public SoapPreProtocolOutInterceptor() {
41: super (Phase.PRE_STREAM);
42: getBefore().add(AttachmentOutInterceptor.class.getName());
43: }
44:
45: /**
46: * Mediate a message dispatch.
47: *
48: * @param message the current message
49: * @throws Fault
50: */
51: public void handleMessage(SoapMessage message) throws Fault {
52: ensureVersion(message);
53: ensureMimeHeaders(message);
54: }
55:
56: /**
57: * Ensure the SOAP version is set for this message.
58: *
59: * @param message the current message
60: */
61: private void ensureVersion(SoapMessage message) {
62: SoapVersion soapVersion = message.getVersion();
63: if (soapVersion == null
64: && message.getExchange().getInMessage() instanceof SoapMessage) {
65: soapVersion = ((SoapMessage) message.getExchange()
66: .getInMessage()).getVersion();
67: message.setVersion(soapVersion);
68: }
69:
70: if (soapVersion == null) {
71: soapVersion = Soap11.getInstance();
72: message.setVersion(soapVersion);
73: }
74: }
75:
76: /**
77: * Ensure the SOAP header is set for this message.
78: *
79: * @param message the current message
80: */
81: private void ensureMimeHeaders(SoapMessage message) {
82: if (message.get(MIME_HEADERS) == null) {
83: message.put(MIME_HEADERS,
84: new HashMap<String, List<String>>());
85: }
86: }
87: }
|