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: AddressingProperties maps = new AddressingPropertiesImpl();
045: if (wsAddressingAsMap == null) {
046: return maps;
047: }
048: for (String wsaHeaderKey : wsAddressingAsMap.keySet()) {
049:
050: String wsaHeaderValue = wsAddressingAsMap.get(wsaHeaderKey);
051: System.out.println(" WSA HEADER KEY -> " + wsaHeaderKey);
052: System.out.println(" WSA HEADER VALUE -> " + wsaHeaderKey);
053: if (Names.WSA_MESSAGEID_NAME.equals(wsaHeaderKey)) {
054: AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
055: .createAttributedURIType();
056: aAttributedURIType.setValue(wsaHeaderValue);
057: maps.setMessageID(aAttributedURIType);
058: } else if (Names.WSA_TO_NAME.equals(wsaHeaderKey)) {
059: maps.setTo(EndpointReferenceUtils
060: .getEndpointReference(wsaHeaderValue));
061: } else if (Names.WSA_FROM_NAME.equals(wsaHeaderKey)) {
062: maps.setTo(EndpointReferenceUtils
063: .getEndpointReference(wsaHeaderValue));
064: } else if (Names.WSA_REPLYTO_NAME.equals(wsaHeaderKey)) {
065: maps.setReplyTo(EndpointReferenceUtils
066: .getEndpointReference(wsaHeaderValue));
067: } else if (Names.WSA_FAULTTO_NAME.equals(wsaHeaderKey)) {
068: // System.out.println( " **WSA_FAULTTO_NAME**");
069: maps.setFaultTo(EndpointReferenceUtils
070: .getEndpointReference(wsaHeaderValue));
071: } else if (Names.WSA_RELATESTO_NAME.equals(wsaHeaderKey)) {
072: RelatesToType aRelatesToType = WSA_OBJECT_FACTORY
073: .createRelatesToType();
074: aRelatesToType.setValue(wsaHeaderValue);
075: maps.setRelatesTo(aRelatesToType);
076: } else if (Names.WSA_ACTION_NAME.equals(wsaHeaderKey)) {
077: AttributedURIType aAttributedURIType = WSA_OBJECT_FACTORY
078: .createAttributedURIType();
079: aAttributedURIType.setValue(wsaHeaderValue);
080: maps.setAction(aAttributedURIType);
081: }
082: }
083: return maps;
084: }
085:
086: public static Map<String, String> getAsMap(AddressingProperties maps) {
087:
088: Map<String, String> returnMap = new HashMap<String, String>();
089:
090: if (maps.getMessageID() != null) {
091: returnMap.put(Names.WSA_MESSAGEID_NAME, maps.getMessageID()
092: .getValue());
093: }
094: if (maps.getTo() != null) {
095: returnMap.put(Names.WSA_TO_NAME, maps.getTo().getValue());
096: }
097: if (maps.getFrom() != null) {
098: returnMap.put(Names.WSA_FROM_NAME, maps.getFrom()
099: .getAddress().getValue());
100: }
101: if (maps.getReplyTo() != null) {
102: returnMap.put(Names.WSA_REPLYTO_NAME, maps.getReplyTo()
103: .getAddress().getValue());
104: }
105: if (maps.getFaultTo() != null) {
106: returnMap.put(Names.WSA_FAULTTO_NAME, maps.getFaultTo()
107: .getAddress().getValue());
108: }
109: if (maps.getRelatesTo() != null) {
110: returnMap.put(Names.WSA_RELATESTO_NAME, maps.getRelatesTo()
111: .getValue());
112: }
113: if (maps.getAction() != null) {
114: returnMap.put(Names.WSA_ACTION_NAME, maps.getAction()
115: .getValue());
116: }
117: return returnMap;
118: }
119: }
|