001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.cxfbc;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    import java.util.Map.Entry;
022    
023    import org.apache.cxf.ws.addressing.AddressingProperties;
024    import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
025    import org.apache.cxf.ws.addressing.AttributedURIType;
026    import org.apache.cxf.ws.addressing.Names;
027    import org.apache.cxf.ws.addressing.RelatesToType;
028    import org.apache.cxf.wsdl.EndpointReferenceUtils;
029    
030    public final class WSAUtils {
031    
032        public static final String WSA_HEADERS_INBOUND = "javax.xml.ws.addressing.context.inbound";
033    
034        public static final String WSA_HEADERS_OUTBOUND = "javax.xml.ws.addressing.context.outbound";
035    
036        private static final org.apache.cxf.ws.addressing.ObjectFactory WSA_OBJECT_FACTORY = new org.apache.cxf.ws.addressing.ObjectFactory();
037    
038        private WSAUtils() {
039            
040        }
041        
042        public static AddressingProperties getCXFAddressingPropertiesFromMap(
043                Map<String, String> wsAddressingAsMap) {
044    
045            
046            AddressingProperties maps = new AddressingPropertiesImpl();
047            if (wsAddressingAsMap == null) {
048                return maps;
049            }
050            for (Entry<String, String> ent : wsAddressingAsMap.entrySet()) {
051                String wsaHeaderValue = ent.getValue();
052                if (Names.WSA_MESSAGEID_NAME.equals(ent.getKey())) {
053                    AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
054                            .createAttributedURIType();
055                    aAttributedURIType.setValue(wsaHeaderValue);
056                    maps.setMessageID(aAttributedURIType);
057                } else if (Names.WSA_TO_NAME.equals(ent.getKey())) {
058                    maps.setTo(EndpointReferenceUtils
059                            .getEndpointReference(wsaHeaderValue));
060                } else if (Names.WSA_FROM_NAME.equals(ent.getKey())) {
061                    maps.setTo(EndpointReferenceUtils
062                            .getEndpointReference(wsaHeaderValue));
063                } else if (Names.WSA_REPLYTO_NAME.equals(ent.getKey())) {
064                    maps.setReplyTo(EndpointReferenceUtils
065                            .getEndpointReference(wsaHeaderValue));
066                } else if (Names.WSA_FAULTTO_NAME.equals(ent.getKey())) {
067                    // System.out.println( " **WSA_FAULTTO_NAME**");
068                    maps.setFaultTo(EndpointReferenceUtils
069                            .getEndpointReference(wsaHeaderValue));
070                } else if (Names.WSA_RELATESTO_NAME.equals(ent.getKey())) {
071                    RelatesToType aRelatesToType = WSA_OBJECT_FACTORY
072                            .createRelatesToType();
073                    aRelatesToType.setValue(wsaHeaderValue);
074                    maps.setRelatesTo(aRelatesToType);
075                } else if (Names.WSA_ACTION_NAME.equals(ent.getKey())) {
076                    AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
077                            .createAttributedURIType();
078                    aAttributedURIType.setValue(wsaHeaderValue);
079                    maps.setAction(aAttributedURIType);
080                }
081            }
082            return maps;
083        }
084    
085        public static Map<String, String> getAsMap(AddressingProperties maps) {
086    
087            Map<String, String> returnMap = new HashMap<String, String>();
088    
089            if (maps.getMessageID() != null) {
090                returnMap.put(Names.WSA_MESSAGEID_NAME, maps.getMessageID()
091                        .getValue());
092            }
093            if (maps.getTo() != null) {
094                returnMap.put(Names.WSA_TO_NAME, maps.getTo().getValue());
095            }
096            if (maps.getFrom() != null) {
097                returnMap.put(Names.WSA_FROM_NAME, maps.getFrom().getAddress()
098                        .getValue());
099            }
100            if (maps.getReplyTo() != null) {
101                returnMap.put(Names.WSA_REPLYTO_NAME, maps.getReplyTo()
102                        .getAddress().getValue());
103            }
104            if (maps.getFaultTo() != null) {
105                returnMap.put(Names.WSA_FAULTTO_NAME, maps.getFaultTo()
106                        .getAddress().getValue());
107            }
108            if (maps.getRelatesTo() != null) {
109                returnMap.put(Names.WSA_RELATESTO_NAME, maps.getRelatesTo()
110                        .getValue());
111            }
112            if (maps.getAction() != null) {
113                returnMap.put(Names.WSA_ACTION_NAME, maps.getAction().getValue());
114            }
115            return returnMap;
116        }
117    }