| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| CxfBinding |
|
| 0.0;0 |
| 1 | /** |
|
| 2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
| 3 | * contributor license agreements. See the NOTICE file distributed with |
|
| 4 | * this work for additional information regarding copyright ownership. |
|
| 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
| 6 | * (the "License"); you may not use this file except in compliance with |
|
| 7 | * the License. You may obtain a copy of the License at |
|
| 8 | * |
|
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 10 | * |
|
| 11 | * Unless required by applicable law or agreed to in writing, software |
|
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 14 | * See the License for the specific language governing permissions and |
|
| 15 | * limitations under the License. |
|
| 16 | */ |
|
| 17 | package org.apache.camel.component.cxf; |
|
| 18 | ||
| 19 | import org.apache.cxf.message.Message; |
|
| 20 | import org.apache.cxf.message.MessageImpl; |
|
| 21 | ||
| 22 | import java.io.InputStream; |
|
| 23 | import java.util.Set; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * The binding of how Camel messages get mapped to Apache CXF and back again |
|
| 27 | * |
|
| 28 | * @version $Revision: 563822 $ |
|
| 29 | */ |
|
| 30 | 1 | public class CxfBinding { |
| 31 | public Object extractBodyFromCxf(CxfExchange exchange, Message message) { |
|
| 32 | // TODO how do we choose a format? |
|
| 33 | 0 | return getBody(message); |
| 34 | } |
|
| 35 | ||
| 36 | protected Object getBody(Message message) { |
|
| 37 | 0 | Set<Class<?>> contentFormats = message.getContentFormats(); |
| 38 | 0 | for (Class<?> contentFormat : contentFormats) { |
| 39 | 0 | Object answer = message.getContent(contentFormat); |
| 40 | 0 | if (answer != null) { |
| 41 | 0 | return answer; |
| 42 | } |
|
| 43 | 0 | } |
| 44 | 0 | return null; |
| 45 | } |
|
| 46 | ||
| 47 | public MessageImpl createCxfMessage(CxfExchange exchange) { |
|
| 48 | 0 | MessageImpl answer = (MessageImpl) exchange.getInMessage(); |
| 49 | ||
| 50 | // CXF uses the stax which is based on the stream API to parser the XML, so |
|
| 51 | // the CXF transport is also based on the stream API. |
|
| 52 | // And the interceptors are also based on the stream API, |
|
| 53 | // so lets use an InputStream to host the CXF on wire message. |
|
| 54 | 0 | CxfMessage in = exchange.getIn(); |
| 55 | 0 | Object body = in.getBody(InputStream.class); |
| 56 | 0 | if (body == null) { |
| 57 | 0 | body = in.getBody(); |
| 58 | } |
|
| 59 | 0 | answer.setContent(InputStream.class, body); |
| 60 | ||
| 61 | // no need to process headers as we reuse the CXF message |
|
| 62 | /* |
|
| 63 | // set the headers |
|
| 64 | Set<Map.Entry<String, Object>> entries = in.getHeaders().entrySet(); |
|
| 65 | for (Map.Entry<String, Object> entry : entries) { |
|
| 66 | answer.put(entry.getKey(), entry.getValue()); |
|
| 67 | } |
|
| 68 | */ |
|
| 69 | 0 | return answer; |
| 70 | } |
|
| 71 | ||
| 72 | public void storeCxfResponse(CxfExchange exchange, Message response) { |
|
| 73 | // no need to process headers as we use the CXF message |
|
| 74 | 0 | CxfMessage out = exchange.getOut(); |
| 75 | 0 | if (response != null) { |
| 76 | 0 | out.setMessage(response); |
| 77 | 0 | out.setBody(getBody(response)); |
| 78 | } |
|
| 79 | 0 | } |
| 80 | ||
| 81 | public void storeCxfResponse(CxfExchange exchange, Object response) { |
|
| 82 | 1 | CxfMessage out = exchange.getOut(); |
| 83 | 1 | if (response != null) { |
| 84 | 1 | out.setBody(response); |
| 85 | } |
|
| 86 | 1 | } |
| 87 | } |