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.util.List;
21:
22: import javax.xml.ws.Holder;
23:
24: import org.apache.cxf.helpers.CastUtils;
25: import org.apache.cxf.interceptor.Fault;
26: import org.apache.cxf.message.Exchange;
27: import org.apache.cxf.message.Message;
28: import org.apache.cxf.message.MessageContentsList;
29: import org.apache.cxf.phase.AbstractPhaseInterceptor;
30: import org.apache.cxf.phase.Phase;
31: import org.apache.cxf.service.model.MessagePartInfo;
32: import org.apache.cxf.service.model.OperationInfo;
33:
34: public class HolderInInterceptor extends
35: AbstractPhaseInterceptor<Message> {
36:
37: public static final String CLIENT_HOLDERS = "client.holders";
38:
39: public HolderInInterceptor() {
40: super (Phase.PRE_INVOKE);
41: }
42:
43: @SuppressWarnings("unchecked")
44: public void handleMessage(Message message) throws Fault {
45: MessageContentsList inObjects = MessageContentsList
46: .getContentsList(message);
47:
48: Exchange exchange = message.getExchange();
49:
50: OperationInfo op = exchange.get(OperationInfo.class);
51: if (op == null || !op.hasOutput() || op.getOutput().size() == 0) {
52: return;
53: }
54:
55: List<MessagePartInfo> parts = op.getOutput().getMessageParts();
56:
57: boolean client = Boolean.TRUE.equals(message
58: .get(Message.REQUESTOR_ROLE));
59: if (client) {
60: List<Holder> outHolders = CastUtils.cast((List) message
61: .getExchange().getOutMessage().get(CLIENT_HOLDERS));
62: for (MessagePartInfo part : parts) {
63: if (part.getIndex() != 0) {
64: Holder holder = (Holder) outHolders.get(part
65: .getIndex() - 1);
66: holder.value = inObjects.get(part);
67: inObjects.put(part, holder);
68: }
69: }
70: } else {
71: for (MessagePartInfo part : parts) {
72: int idx = part.getIndex() - 1;
73: if (idx >= 0) {
74: if (idx >= inObjects.size()) {
75: inObjects.set(idx, new Holder<Object>());
76: } else {
77: Object o = inObjects.get(idx);
78: inObjects.set(idx, new Holder<Object>(o));
79: }
80: }
81: }
82: }
83: }
84: }
|