001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.binding.soap.interceptor;
019:
020: import java.util.List;
021:
022: import org.w3c.dom.Node;
023:
024: import org.apache.cxf.binding.soap.SoapMessage;
025: import org.apache.cxf.binding.soap.model.SoapHeaderInfo;
026: import org.apache.cxf.headers.Header;
027: import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
028: import org.apache.cxf.interceptor.BareInInterceptor;
029: import org.apache.cxf.interceptor.DocLiteralInInterceptor;
030: import org.apache.cxf.interceptor.Fault;
031: import org.apache.cxf.message.Exchange;
032: import org.apache.cxf.message.Message;
033: import org.apache.cxf.message.MessageContentsList;
034: import org.apache.cxf.phase.Phase;
035: import org.apache.cxf.service.model.BindingMessageInfo;
036: import org.apache.cxf.service.model.BindingOperationInfo;
037: import org.apache.cxf.service.model.MessagePartInfo;
038:
039: /**
040: * Perform databinding of the SOAP headers.
041: */
042: public class SoapHeaderInterceptor extends
043: AbstractInDatabindingInterceptor {
044:
045: public SoapHeaderInterceptor() {
046: super (Phase.UNMARSHAL);
047: addAfter(BareInInterceptor.class.getName());
048: addAfter(RPCInInterceptor.class.getName());
049: addAfter(DocLiteralInInterceptor.class.getName());
050: }
051:
052: public void handleMessage(Message m) throws Fault {
053: SoapMessage message = (SoapMessage) m;
054: Exchange exchange = message.getExchange();
055:
056: MessageContentsList parameters = MessageContentsList
057: .getContentsList(message);
058:
059: if (null == parameters) {
060: parameters = new MessageContentsList();
061: }
062:
063: BindingOperationInfo bop = exchange
064: .get(BindingOperationInfo.class);
065: if (null == bop) {
066: return;
067: }
068:
069: if (bop.isUnwrapped()) {
070: bop = bop.getWrappedOperation();
071: }
072:
073: boolean client = isRequestor(message);
074: BindingMessageInfo bmi = client ? bop.getOutput() : bop
075: .getInput();
076: if (bmi == null) {
077: // one way operation.
078: return;
079: }
080:
081: List<SoapHeaderInfo> headers = bmi
082: .getExtensors(SoapHeaderInfo.class);
083: if (headers == null || headers.size() == 0) {
084: return;
085: }
086:
087: for (SoapHeaderInfo header : headers) {
088: MessagePartInfo mpi = header.getPart();
089: Header param = findHeader(message, mpi);
090:
091: Object object = null;
092: if (param != null) {
093: message.getHeaders().remove(param);
094:
095: if (param.getDataBinding() == null) {
096: Node source = (Node) param.getObject();
097: object = getNodeDataReader(message).read(mpi,
098: source);
099: } else {
100: object = param.getObject();
101: }
102:
103: }
104:
105: parameters.put(mpi, object);
106: }
107: if (parameters.size() > 0) {
108: message.setContent(List.class, parameters);
109: }
110: }
111:
112: private Header findHeader(SoapMessage message, MessagePartInfo mpi) {
113: return message.getHeader(mpi.getConcreteName());
114: }
115: }
|