1 /*
2 * Copyright 2009 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.openehealth.ipf.commons.ihe.ws.cxf;
17
18 import org.apache.cxf.attachment.AttachmentSerializer;
19 import org.apache.cxf.binding.soap.SoapMessage;
20 import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
21 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
22 import org.apache.cxf.interceptor.Fault;
23 import org.apache.cxf.message.Message;
24 import org.apache.cxf.phase.Phase;
25
26 /**
27 * Workaround for a compatibility issue with Axis 2 0.9x.
28 * <p>
29 * Older versions of Axis 2 only accept our message if the content-type
30 * contains a type of "text/xml". The CXF {@link AttachmentSerializer}
31 * does not set this field. Therefore, we add it with this interceptor.
32 * @author Jens Riemschneider
33 */
34 public class FixContentTypeOutInterceptor extends AbstractSoapInterceptor {
35 /**
36 * Constructs the interceptor.
37 */
38 public FixContentTypeOutInterceptor() {
39 super(Phase.PRE_STREAM);
40 addAfter(AttachmentOutInterceptor.class.getName());
41 }
42
43 @Override
44 public void handleMessage(SoapMessage message) throws Fault {
45 // Cool stuff for Axis 0.9
46 String ct = (String) message.get(Message.CONTENT_TYPE);
47 if (!ct.contains("type=")) {
48 message.put(Message.CONTENT_TYPE, ct + "; type=\"text/xml\"");
49 }
50 }
51 }
52