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    
022    import org.apache.cxf.ws.addressing.AddressingProperties;
023    import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
024    import org.apache.cxf.ws.addressing.AttributedURIType;
025    import org.apache.cxf.ws.addressing.Names;
026    import org.apache.cxf.ws.addressing.RelatesToType;
027    import org.apache.cxf.wsdl.EndpointReferenceUtils;
028    
029    public final class WSAUtils {
030    
031        public static final String WSA_HEADERS_INBOUND = "javax.xml.ws.addressing.context.inbound";
032    
033        public static final String WSA_HEADERS_OUTBOUND = "javax.xml.ws.addressing.context.outbound";
034    
035        private static final org.apache.cxf.ws.addressing.ObjectFactory WSA_OBJECT_FACTORY = new org.apache.cxf.ws.addressing.ObjectFactory();
036    
037        private WSAUtils() {
038            
039        }
040        
041        public static AddressingProperties getCXFAddressingPropertiesFromMap(
042                Map<String, String> wsAddressingAsMap) {
043    
044            
045            AddressingProperties maps = new AddressingPropertiesImpl();
046            if (wsAddressingAsMap == null) {
047                return maps;
048            }
049            for (String wsaHeaderKey : wsAddressingAsMap.keySet()) {
050    
051                String wsaHeaderValue = wsAddressingAsMap.get(wsaHeaderKey);
052                System.out.println(" WSA HEADER KEY -> " + wsaHeaderKey);
053                System.out.println(" WSA HEADER VALUE -> " + wsaHeaderKey);
054                if (Names.WSA_MESSAGEID_NAME.equals(wsaHeaderKey)) {
055                    AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
056                            .createAttributedURIType();
057                    aAttributedURIType.setValue(wsaHeaderValue);
058                    maps.setMessageID(aAttributedURIType);
059                } else if (Names.WSA_TO_NAME.equals(wsaHeaderKey)) {
060                    maps.setTo(EndpointReferenceUtils
061                            .getEndpointReference(wsaHeaderValue));
062                } else if (Names.WSA_FROM_NAME.equals(wsaHeaderKey)) {
063                    maps.setTo(EndpointReferenceUtils
064                            .getEndpointReference(wsaHeaderValue));
065                } else if (Names.WSA_REPLYTO_NAME.equals(wsaHeaderKey)) {
066                    maps.setReplyTo(EndpointReferenceUtils
067                            .getEndpointReference(wsaHeaderValue));
068                } else if (Names.WSA_FAULTTO_NAME.equals(wsaHeaderKey)) {
069                    // System.out.println( " **WSA_FAULTTO_NAME**");
070                    maps.setFaultTo(EndpointReferenceUtils
071                            .getEndpointReference(wsaHeaderValue));
072                } else if (Names.WSA_RELATESTO_NAME.equals(wsaHeaderKey)) {
073                    RelatesToType aRelatesToType = WSA_OBJECT_FACTORY
074                            .createRelatesToType();
075                    aRelatesToType.setValue(wsaHeaderValue);
076                    maps.setRelatesTo(aRelatesToType);
077                } else if (Names.WSA_ACTION_NAME.equals(wsaHeaderKey)) {
078                    AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
079                            .createAttributedURIType();
080                    aAttributedURIType.setValue(wsaHeaderValue);
081                    maps.setAction(aAttributedURIType);
082                }
083            }
084            return maps;
085        }
086    
087        public static Map<String, String> getAsMap(AddressingProperties maps) {
088    
089            Map<String, String> returnMap = new HashMap<String, String>();
090    
091            if (maps.getMessageID() != null) {
092                returnMap.put(Names.WSA_MESSAGEID_NAME, maps.getMessageID()
093                        .getValue());
094            }
095            if (maps.getTo() != null) {
096                returnMap.put(Names.WSA_TO_NAME, maps.getTo().getValue());
097            }
098            if (maps.getFrom() != null) {
099                returnMap.put(Names.WSA_FROM_NAME, maps.getFrom().getAddress()
100                        .getValue());
101            }
102            if (maps.getReplyTo() != null) {
103                returnMap.put(Names.WSA_REPLYTO_NAME, maps.getReplyTo()
104                        .getAddress().getValue());
105            }
106            if (maps.getFaultTo() != null) {
107                returnMap.put(Names.WSA_FAULTTO_NAME, maps.getFaultTo()
108                        .getAddress().getValue());
109            }
110            if (maps.getRelatesTo() != null) {
111                returnMap.put(Names.WSA_RELATESTO_NAME, maps.getRelatesTo()
112                        .getValue());
113            }
114            if (maps.getAction() != null) {
115                returnMap.put(Names.WSA_ACTION_NAME, maps.getAction().getValue());
116            }
117            return returnMap;
118        }
119    }