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.binding.http.interceptor;
19:
20: import java.util.ResourceBundle;
21: import java.util.logging.Logger;
22:
23: import org.apache.cxf.binding.http.URIMapper;
24: import org.apache.cxf.common.i18n.BundleUtils; //import org.apache.cxf.endpoint.Endpoint;
25: import org.apache.cxf.interceptor.Fault;
26: import org.apache.cxf.message.Message;
27: import org.apache.cxf.phase.AbstractPhaseInterceptor;
28: import org.apache.cxf.phase.Phase;
29: import org.apache.cxf.service.Service;
30: import org.apache.cxf.service.model.BindingOperationInfo;
31:
32: public class DispatchInterceptor extends
33: AbstractPhaseInterceptor<Message> {
34:
35: public static final String RELATIVE_PATH = "relative.path";
36: private static final Logger LOG = Logger
37: .getLogger(DispatchInterceptor.class.getName());
38: private static final ResourceBundle BUNDLE = BundleUtils
39: .getBundle(DispatchInterceptor.class);
40:
41: public DispatchInterceptor() {
42: super (Phase.PRE_STREAM);
43: }
44:
45: public void handleMessage(Message message) {
46: String path = (String) message.get(Message.PATH_INFO);
47: String address = (String) message.get(Message.BASE_PATH);
48: String method = (String) message
49: .get(Message.HTTP_REQUEST_METHOD);
50:
51: //String address = message.getExchange().get(Endpoint.class).getEndpointInfo().getAddress();
52:
53: if (address.startsWith("http")) {
54: int idx = address.indexOf('/', 7);
55: if (idx != -1) {
56: address = address.substring(idx);
57: }
58: }
59:
60: if (path.startsWith(address)) {
61: path = path.substring(address.length());
62: if (!path.startsWith("/")) {
63: path = "/" + path;
64: }
65: }
66:
67: if (path.endsWith("/")) {
68: path = path.substring(0, path.length() - 1);
69: }
70: message.put(RELATIVE_PATH, path);
71: LOG.info("Invoking " + method + " on " + path);
72:
73: URIMapper mapper = (URIMapper) message.getExchange().get(
74: Service.class).get(URIMapper.class.getName());
75:
76: BindingOperationInfo op = mapper.getOperation(path, method,
77: message);
78:
79: if (op == null) {
80: throw new Fault(new org.apache.cxf.common.i18n.Message(
81: "NO_OP", BUNDLE, method, path));
82: }
83:
84: message.getExchange().put(BindingOperationInfo.class, op);
85: }
86: }
|