1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.synapse.mediators.eip; 21 22 import org.apache.synapse.MessageContext; 23 import org.apache.synapse.endpoints.Endpoint; 24 import org.apache.synapse.mediators.base.SequenceMediator; 25 import org.apache.axis2.addressing.EndpointReference; 26 27 /** 28 * A bean class that holds the target (i.e. sequence or endpoint) information for a message 29 * as used by common EIP mediators 30 */ 31 public class Target { 32 33 /** An optional To address to be set on the message when handing over to the target */ 34 private String toAddress = null; 35 36 /** An optional Action to be set on the message when handing over to the target */ 37 private String soapAction = null; 38 39 /** The inlined target sequence definition */ 40 private SequenceMediator sequence = null; 41 42 /** The target sequence reference key */ 43 private String sequenceRef = null; 44 45 /** The inlined target endpoint definition */ 46 private Endpoint endpoint = null; 47 48 /** The target endpoint reference key */ 49 private String endpointRef = null; 50 51 /** 52 * process the message through this target (may be to mediate 53 * using the target sequence, send message to the target endpoint or both) 54 * 55 * @param synCtx - MessageContext to be mediated 56 */ 57 public void mediate(MessageContext synCtx) { 58 59 if (soapAction != null) { 60 synCtx.setSoapAction(soapAction); 61 } 62 63 if (toAddress != null) { 64 if (synCtx.getTo() != null) { 65 synCtx.getTo().setAddress(toAddress); 66 } else { 67 synCtx.setTo(new EndpointReference(toAddress)); 68 } 69 } 70 71 // since we are injecting the new messages asynchronously, we cannot process a message 72 // through a sequence and then again with an endpoint 73 if (sequence != null) { 74 synCtx.getEnvironment().injectAsync(synCtx, sequence); 75 } else if (sequenceRef != null) { 76 SequenceMediator refSequence = (SequenceMediator) synCtx.getSequence(sequenceRef); 77 if (refSequence != null) { 78 synCtx.getEnvironment().injectAsync(synCtx, refSequence); 79 } 80 } else if (endpoint != null) { 81 endpoint.send(synCtx); 82 } else if (endpointRef != null) { 83 Endpoint epr = synCtx.getConfiguration().getEndpoint(endpointRef); 84 if (epr != null) { 85 epr.send(synCtx); 86 } 87 } 88 } 89 90 /////////////////////////////////////////////////////////////////////////////////////// 91 // Getters and Setters // 92 /////////////////////////////////////////////////////////////////////////////////////// 93 94 public String getToAddress() { 95 return toAddress; 96 } 97 98 public void setToAddress(String toAddress) { 99 this.toAddress = toAddress; 100 } 101 102 public String getSoapAction() { 103 return soapAction; 104 } 105 106 public void setSoapAction(String soapAction) { 107 this.soapAction = soapAction; 108 } 109 110 public SequenceMediator getSequence() { 111 return sequence; 112 } 113 114 public void setSequence(SequenceMediator sequence) { 115 this.sequence = sequence; 116 } 117 118 public String getSequenceRef() { 119 return sequenceRef; 120 } 121 122 public void setSequenceRef(String sequenceRef) { 123 this.sequenceRef = sequenceRef; 124 } 125 126 public Endpoint getEndpoint() { 127 return endpoint; 128 } 129 130 public void setEndpoint(Endpoint endpoint) { 131 this.endpoint = endpoint; 132 } 133 134 public String getEndpointRef() { 135 return endpointRef; 136 } 137 138 public void setEndpointRef(String endpointRef) { 139 this.endpointRef = endpointRef; 140 } 141 }