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.Iterator;
021: import java.util.List;
022: import java.util.logging.Logger;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.stream.XMLStreamReader;
026:
027: import org.apache.cxf.databinding.DataReader;
028: import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
029: import org.apache.cxf.interceptor.BareInInterceptor;
030: import org.apache.cxf.interceptor.Fault;
031: import org.apache.cxf.interceptor.URIMappingInterceptor;
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.BindingOperationInfo;
036: import org.apache.cxf.service.model.MessageInfo;
037: import org.apache.cxf.service.model.MessagePartInfo;
038: import org.apache.cxf.service.model.OperationInfo;
039: import org.apache.cxf.service.model.ServiceModelUtil;
040: import org.apache.cxf.staxutils.DepthXMLStreamReader;
041: import org.apache.cxf.staxutils.StaxUtils;
042:
043: public class RPCInInterceptor extends AbstractInDatabindingInterceptor {
044:
045: private static final Logger LOG = Logger
046: .getLogger(RPCInInterceptor.class.getName());
047:
048: public RPCInInterceptor() {
049: super (Phase.UNMARSHAL);
050: addAfter(URIMappingInterceptor.class.getName());
051: }
052:
053: private BindingOperationInfo getOperation(Message message,
054: QName opName) {
055: return ServiceModelUtil.getOperation(message.getExchange(),
056: opName);
057: }
058:
059: public void handleMessage(Message message) {
060: if (isGET(message)) {
061: LOG.info("RPCInInterceptor skipped in HTTP GET method");
062: return;
063: }
064: DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
065:
066: BindingOperationInfo operation = null;
067: if (!StaxUtils.toNextElement(xmlReader)) {
068: message.setContent(Exception.class, new RuntimeException(
069: "There must be a method name element."));
070: }
071: String opName = xmlReader.getLocalName();
072: if (isRequestor(message) && opName.endsWith("Response")) {
073: opName = opName.substring(0, opName.length() - 8);
074: }
075:
076: if (message.getExchange().get(BindingOperationInfo.class) == null) {
077: operation = getOperation(message, new QName(xmlReader
078: .getNamespaceURI(), opName));
079: if (operation == null) {
080: // it's doc-lit-bare
081: new BareInInterceptor().handleMessage(message);
082: return;
083: } else {
084: message.getExchange().put(BindingOperationInfo.class,
085: operation);
086: message.getExchange().put(OperationInfo.class,
087: operation.getOperationInfo());
088: }
089: } else {
090: operation = message.getExchange().get(
091: BindingOperationInfo.class);
092: }
093: MessageInfo msg;
094: DataReader<XMLStreamReader> dr = getDataReader(message,
095: XMLStreamReader.class);
096:
097: if (!isRequestor(message)) {
098: msg = operation.getOperationInfo().getInput();
099: } else {
100: msg = operation.getOperationInfo().getOutput();
101: }
102:
103: MessageContentsList parameters = new MessageContentsList();
104:
105: StaxUtils.nextEvent(xmlReader);
106:
107: boolean hasNext = true;
108: Iterator<MessagePartInfo> itr = msg.getMessageParts()
109: .iterator();
110: while (itr.hasNext()) {
111: MessagePartInfo part = itr.next();
112: if (hasNext) {
113: hasNext = StaxUtils.toNextElement(xmlReader);
114: }
115: if (hasNext) {
116: QName qn = xmlReader.getName();
117: while (!qn.equals(part.getConcreteName())
118: && itr.hasNext()) {
119: part = itr.next();
120: }
121: if (!qn.equals(part.getConcreteName())) {
122: throw new Fault(
123: new org.apache.cxf.common.i18n.Message(
124: "UNKNOWN_RPC_LIT_PART", LOG, qn));
125: }
126: parameters.put(part, dr.read(part, xmlReader));
127: }
128: }
129:
130: message.setContent(List.class, parameters);
131: }
132:
133: }
|