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.interceptor;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.HashSet;
023: import java.util.List;
024: import java.util.ResourceBundle;
025: import java.util.Set;
026: import java.util.logging.Logger;
027:
028: import javax.xml.namespace.QName;
029: import javax.xml.stream.XMLStreamReader;
030:
031: import org.apache.cxf.common.i18n.BundleUtils;
032: import org.apache.cxf.databinding.DataReader;
033: import org.apache.cxf.endpoint.Endpoint;
034: import org.apache.cxf.message.Exchange;
035: import org.apache.cxf.message.Message;
036: import org.apache.cxf.message.MessageContentsList;
037: import org.apache.cxf.phase.Phase;
038: import org.apache.cxf.service.model.BindingMessageInfo;
039: import org.apache.cxf.service.model.BindingOperationInfo;
040: import org.apache.cxf.service.model.MessageInfo;
041: import org.apache.cxf.service.model.MessagePartInfo;
042: import org.apache.cxf.service.model.OperationInfo;
043: import org.apache.cxf.service.model.ServiceInfo;
044: import org.apache.cxf.staxutils.DepthXMLStreamReader;
045: import org.apache.cxf.staxutils.StaxUtils;
046:
047: public class BareInInterceptor extends AbstractInDatabindingInterceptor {
048: private static final Logger LOG = Logger
049: .getLogger(BareInInterceptor.class.getName());
050: private static final ResourceBundle BUNDLE = BundleUtils
051: .getBundle(BareInInterceptor.class);
052:
053: private static Set<String> filter = new HashSet<String>();
054:
055: static {
056: filter.add("void");
057: filter.add("javax.activation.DataHandler");
058: }
059:
060: public BareInInterceptor() {
061: super (Phase.UNMARSHAL);
062: addAfter(URIMappingInterceptor.class.getName());
063: }
064:
065: public void handleMessage(Message message) {
066: if (isGET(message) && message.getContent(List.class) != null) {
067: LOG.info("BareInInterceptor skipped in HTTP GET method");
068: return;
069: }
070:
071: DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
072: Exchange exchange = message.getExchange();
073:
074: DataReader<XMLStreamReader> dr = getDataReader(message);
075: MessageContentsList parameters = new MessageContentsList();
076:
077: Endpoint ep = exchange.get(Endpoint.class);
078: BindingOperationInfo bop = exchange
079: .get(BindingOperationInfo.class);
080: ServiceInfo si = ep.getEndpointInfo().getService();
081: // XXX - Should the BindingMessageInfo.class be put on
082: // the message?
083: //MessageInfo msgInfo = message.get(MessageInfo.class);
084: BindingMessageInfo msgInfo = null;
085:
086: boolean client = isRequestor(message);
087:
088: Collection<OperationInfo> ops = null;
089: if (bop == null) {
090: ops = new ArrayList<OperationInfo>();
091: ops.addAll(si.getInterface().getOperations());
092: if (xmlReader.getEventType() == XMLStreamReader.END_ELEMENT
093: && !client) {
094: //empty input
095: //TO DO : check duplicate operation with no input
096: for (OperationInfo op : ops) {
097: MessageInfo bmsg = op.getInput();
098: if (bmsg.getMessageParts().size() == 0) {
099: BindingOperationInfo boi = ep.getEndpointInfo()
100: .getBinding().getOperation(op);
101: exchange.put(BindingOperationInfo.class, boi);
102: exchange.put(OperationInfo.class, op);
103: exchange.setOneWay(op.isOneWay());
104: }
105: }
106:
107: }
108: } else if (msgInfo == null) {
109: // XXX - Is the call to
110: // AbstractInDatabindingInterceptor.getMessageInfo()
111: // necessary? Should we put the BindingMessageInfo on
112: // the message instead of the MessageInfo?
113: // msgInfo = getMessageInfo(message, bop, exchange);
114: getMessageInfo(message, bop);
115: if (client) {
116: msgInfo = bop.getOutput();
117: } else {
118: msgInfo = bop.getInput();
119: }
120: }
121:
122: int paramNum = 0;
123:
124: while (StaxUtils.toNextElement(xmlReader)) {
125: QName elName = xmlReader.getName();
126: Object o = null;
127:
128: MessagePartInfo p;
129: if (msgInfo != null && msgInfo.getMessageParts() != null) {
130: assert msgInfo.getMessageParts().size() > paramNum;
131: p = msgInfo.getMessageParts().get(paramNum);
132: } else {
133: p = findMessagePart(exchange, ops, elName, client,
134: paramNum);
135: }
136:
137: if (p == null) {
138: throw new Fault(new org.apache.cxf.common.i18n.Message(
139: "NO_PART_FOUND", BUNDLE, elName),
140: Fault.FAULT_CODE_CLIENT);
141: }
142:
143: o = dr.read(p, xmlReader);
144:
145: if (o != null) {
146: parameters.put(p, o);
147: }
148: paramNum++;
149: }
150: if (parameters.size() > 0) {
151: message.setContent(List.class, parameters);
152: }
153: }
154: }
|