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.systest.versioning;
19:
20: import java.util.Set;
21:
22: import javax.xml.stream.XMLStreamException;
23: import javax.xml.stream.XMLStreamReader;
24:
25: import org.apache.cxf.endpoint.Endpoint;
26: import org.apache.cxf.interceptor.AbstractEndpointSelectionInterceptor;
27: import org.apache.cxf.interceptor.Fault;
28: import org.apache.cxf.interceptor.StaxInInterceptor;
29: import org.apache.cxf.message.Message;
30: import org.apache.cxf.phase.Phase;
31:
32: public class MediatorInInterceptor extends
33: AbstractEndpointSelectionInterceptor {
34:
35: public MediatorInInterceptor() {
36: super (Phase.POST_STREAM);
37: addBefore(StaxInInterceptor.class.getName());
38: }
39:
40: @Override
41: protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
42: XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
43: if (!xsr.isStartElement()) {
44: try {
45: xsr.nextTag();
46: } catch (XMLStreamException e) {
47: throw new Fault(e);
48: }
49: }
50:
51: if (!xsr.isStartElement()) {
52: return null;
53: }
54:
55: String schemaNamespace = xsr.getNamespaceURI();
56:
57: //if the incoming message has a namespace contained "2007/03/21", we redirect the message
58: //to the new version of service on endpoint "local://localhost:9027/SoapContext/version2/SoapPort"
59: for (Endpoint ep : eps) {
60: if (schemaNamespace.indexOf("2007/03/21") != -1) {
61: if ("2".equals(ep.get("version"))) {
62: return ep;
63: }
64: } else if ("1".equals(ep.get("version"))) {
65: return ep;
66: }
67: }
68:
69: return null;
70: }
71:
72: }
|