001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.transport;
019:
020: import java.util.Map;
021:
022: import javax.xml.bind.JAXBElement;
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.Bus;
026: import org.apache.cxf.service.model.EndpointInfo;
027: import org.apache.cxf.ws.addressing.AddressingProperties;
028: import org.apache.cxf.ws.addressing.EndpointReferenceType;
029: import org.apache.cxf.ws.addressing.ReferenceParametersType;
030: import org.apache.cxf.wsdl.EndpointReferenceUtils;
031: import static org.apache.cxf.ws.addressing.JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND;
032:
033: public abstract class AbstractMultiplexDestination extends
034: AbstractDestination implements MultiplexDestination {
035:
036: private static final QName MULTIPLEX_ID_QNAME = new QName(
037: "http://multiplex.transport.cxf.apache.org", "id");
038:
039: public AbstractMultiplexDestination(Bus b,
040: EndpointReferenceType ref, EndpointInfo ei) {
041: super (b, ref, ei);
042: }
043:
044: /**
045: * Builds an new endpoint reference using the current target reference as a template.
046: * The supplied id is endcoded using a reference parameter.
047: * This requires the ws-a interceptors to propagate the reference parameters
048: * on subsequent invokes using the returned reference.
049: * @param the id to encode in the new reference
050: * @return the new reference with the id encoded as a reference parameter
051: * @see org.apache.cxf.transport.MultiplexDestination#getAddressWithId(java.lang.String)
052:
053: */
054: public EndpointReferenceType getAddressWithId(String id) {
055: EndpointReferenceType epr = EndpointReferenceUtils
056: .duplicate(EndpointReferenceUtils.mint(reference, bus));
057: ReferenceParametersType newParams = new org.apache.cxf.ws.addressing.ObjectFactory()
058: .createReferenceParametersType();
059:
060: ReferenceParametersType existingParams = epr
061: .getReferenceParameters();
062: if (null != existingParams) {
063: newParams.getAny().addAll(existingParams.getAny());
064: }
065:
066: newParams.getAny().add(
067: new JAXBElement<String>(MULTIPLEX_ID_QNAME,
068: String.class, id));
069: epr.setReferenceParameters(newParams);
070: return epr;
071: }
072:
073: /**
074: * Obtain id from reference parameters of the ws-a to address
075: * Requires the existance of ws-a interceptors on dispatch path to provide access
076: * to the ws-a headers
077: * @param the current invocation or message context
078: * @return the id from the reference parameters of the ws-a-to address or null if not found
079: * @see org.apache.cxf.transport.MultiplexDestination#getId(java.util.Map)
080: */
081: public String getId(Map contextMap) {
082: String markedParam = null;
083: AddressingProperties maps = (AddressingProperties) contextMap
084: .get(SERVER_ADDRESSING_PROPERTIES_INBOUND);
085: if (null != maps) {
086: EndpointReferenceType toEpr = maps.getToEndpointReference();
087: if (null != toEpr) {
088: markedParam = extractStringElementFromAny(
089: MULTIPLEX_ID_QNAME, toEpr);
090: }
091: }
092: return markedParam;
093: }
094:
095: private String extractStringElementFromAny(QName elementQName,
096: EndpointReferenceType epr) {
097: String elementStringValue = null;
098: if (null != epr.getReferenceParameters()) {
099: for (Object o : epr.getReferenceParameters().getAny()) {
100: if (o instanceof JAXBElement) {
101: JAXBElement el = (JAXBElement) o;
102: if (el.getName().equals(elementQName)) {
103: elementStringValue = (String) el.getValue();
104: }
105: }
106: }
107: }
108: return elementStringValue;
109: }
110: }
|