| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| XmppBinding |
|
| 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.xmpp; |
|
| 18 | ||
| 19 | import java.util.Map; |
|
| 20 | import java.util.Set; |
|
| 21 | ||
| 22 | import org.apache.camel.Exchange; |
|
| 23 | ||
| 24 | import org.jivesoftware.smack.packet.Message; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * A Strategy used to convert between a Camel {@XmppExchange} and {@XmppMessage} to and from a |
|
| 28 | * XMPP {@link Message} |
|
| 29 | * |
|
| 30 | * @version $Revision: 563665 $ |
|
| 31 | */ |
|
| 32 | 0 | public class XmppBinding { |
| 33 | /** |
|
| 34 | * Populates the given XMPP message from the inbound exchange |
|
| 35 | */ |
|
| 36 | public void populateXmppMessage(Message message, Exchange exchange) { |
|
| 37 | 0 | message.setBody(exchange.getIn().getBody(String.class)); |
| 38 | ||
| 39 | 0 | Set<Map.Entry<String, Object>> entries = exchange.getIn().getHeaders().entrySet(); |
| 40 | 0 | for (Map.Entry<String, Object> entry : entries) { |
| 41 | 0 | String name = entry.getKey(); |
| 42 | 0 | Object value = entry.getValue(); |
| 43 | 0 | if (shouldOutputHeader(exchange, name, value)) { |
| 44 | 0 | message.setProperty(name, value); |
| 45 | } |
|
| 46 | 0 | } |
| 47 | 0 | String id = exchange.getExchangeId(); |
| 48 | 0 | if (id != null) { |
| 49 | 0 | message.setProperty("exchangeId", id); |
| 50 | } |
|
| 51 | 0 | } |
| 52 | ||
| 53 | /** |
|
| 54 | * Extracts the body from the XMPP message |
|
| 55 | * |
|
| 56 | * @param exchange |
|
| 57 | * @param message |
|
| 58 | */ |
|
| 59 | public Object extractBodyFromXmpp(XmppExchange exchange, Message message) { |
|
| 60 | 0 | return message.getBody(); |
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Strategy to allow filtering of headers which are put on the XMPP message |
|
| 65 | */ |
|
| 66 | protected boolean shouldOutputHeader(Exchange exchange, String headerName, Object headerValue) { |
|
| 67 | 0 | return true; |
| 68 | } |
|
| 69 | } |