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.jaxws.interceptors;
19:
20: import java.io.IOException;
21: import java.io.OutputStream;
22: import java.util.List;
23:
24: import javax.activation.DataSource;
25: import javax.xml.soap.SOAPMessage;
26: import javax.xml.stream.XMLStreamWriter;
27:
28: import org.apache.cxf.databinding.DataWriter;
29: import org.apache.cxf.helpers.IOUtils;
30: import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
31: import org.apache.cxf.interceptor.Fault;
32: import org.apache.cxf.message.Message;
33: import org.apache.cxf.phase.Phase;
34: import org.apache.cxf.service.Service;
35:
36: public class ProviderOutDatabindingInterceptor extends
37: AbstractInDatabindingInterceptor {
38:
39: public ProviderOutDatabindingInterceptor() {
40: super (Phase.MARSHAL);
41: }
42:
43: public ProviderOutDatabindingInterceptor(String phase) {
44: super (phase);
45: }
46:
47: public void handleMessage(Message message) throws Fault {
48: Service s = message.getExchange().get(Service.class);
49:
50: XMLStreamWriter xsw = message.getContent(XMLStreamWriter.class);
51:
52: DataWriter<XMLStreamWriter> writer = s.getDataBinding()
53: .createWriter(XMLStreamWriter.class);
54: List<?> objs = (List<?>) message.getContent(List.class);
55:
56: for (Object o : objs) {
57: if (o != null) {
58: if (o instanceof SOAPMessage) {
59: message.setContent(SOAPMessage.class, o);
60: } else if (o instanceof DataSource) {
61: try {
62: message.removeContent(XMLStreamWriter.class);
63: OutputStream out = message
64: .getContent(OutputStream.class);
65: IOUtils.copy(((DataSource) o).getInputStream(),
66: out);
67: } catch (IOException ex) {
68: throw new Fault(ex);
69: }
70: } else {
71: writer.write(o, xsw);
72: }
73: }
74: }
75: }
76:
77: }
|