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.Collection;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.apache.cxf.binding.soap.Soap11;
025: import org.apache.cxf.binding.soap.Soap12;
026: import org.apache.cxf.binding.soap.SoapMessage;
027: import org.apache.cxf.binding.soap.model.SoapOperationInfo;
028: import org.apache.cxf.endpoint.Endpoint;
029: import org.apache.cxf.helpers.CastUtils;
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.phase.Phase;
034: import org.apache.cxf.service.model.BindingOperationInfo;
035: import org.apache.cxf.service.model.OperationInfo;
036:
037: public class SoapActionInInterceptor extends AbstractSoapInterceptor {
038:
039: public SoapActionInInterceptor() {
040: super (Phase.READ);
041: addAfter(ReadHeadersInterceptor.class.getName());
042: addAfter(EndpointSelectionInterceptor.class.getName());
043: }
044:
045: public void handleMessage(SoapMessage message) throws Fault {
046: if (message.getVersion() instanceof Soap11) {
047: Map<String, List<String>> headers = CastUtils
048: .cast((Map) message.get(Message.PROTOCOL_HEADERS));
049: if (headers != null) {
050: List<String> sa = headers.get("SOAPAction");
051: if (sa != null && sa.size() > 0) {
052: String action = sa.get(0);
053: if (action.startsWith("\"")) {
054: action = action.substring(1,
055: action.length() - 1);
056: }
057: getAndSetOperation(message, action);
058: }
059: }
060: } else if (message.getVersion() instanceof Soap12) {
061: String ct = (String) message.get(Message.CONTENT_TYPE);
062:
063: if (ct == null) {
064: return;
065: }
066:
067: int start = ct.indexOf("action=");
068: if (start != -1) {
069: int end;
070: if (ct.charAt(start + 7) == '\"') {
071: start += 8;
072: end = ct.indexOf('\"', start);
073: } else {
074: start += 7;
075: end = ct.indexOf(';', start);
076: if (end == -1) {
077: end = ct.length();
078: }
079: }
080:
081: getAndSetOperation(message, ct.substring(start, end));
082: }
083: }
084: }
085:
086: private void getAndSetOperation(SoapMessage message, String action) {
087: if ("".equals(action)) {
088: return;
089: }
090:
091: Exchange ex = message.getExchange();
092: Endpoint ep = ex.get(Endpoint.class);
093:
094: Collection<BindingOperationInfo> bops = ep.getBinding()
095: .getBindingInfo().getOperations();
096: for (BindingOperationInfo boi : bops) {
097: SoapOperationInfo soi = (SoapOperationInfo) boi
098: .getExtensor(SoapOperationInfo.class);
099: if (soi != null && soi.getAction().equals(action)) {
100: ex.put(BindingOperationInfo.class, boi);
101: ex.put(OperationInfo.class, boi.getOperationInfo());
102: return;
103: }
104: }
105: }
106:
107: }
|