@Override public void send(MessageContext synCtx) { if (RuntimeStatisticCollector.isStatisticsEnabled()) { Integer currentIndex = null; boolean retry = (synCtx.getProperty(SynapseConstants.LAST_ENDPOINT) != null); if ((getDefinition() != null) && !retry) { currentIndex = OpenEventCollector.reportChildEntryEvent(synCtx, getReportingName(), ComponentType.ENDPOINT, getDefinition().getAspectConfiguration(), true); } try { sendMessage(synCtx); } finally { if (currentIndex != null) { CloseEventCollector.closeEntryEvent(synCtx, getReportingName(), ComponentType.MEDIATOR, currentIndex, false); } } } else { sendMessage(synCtx); } }
newCtx = MessageHelper.cloneMessageContext(synCtx); } catch (AxisFault e) { handleException("Error cloning the message context", e); return; children.size()); evaluateProperties(newCtx); newCtx.pushFaultHandler(this); childEndpoint.send(newCtx); (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child endpoints"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_FO_NONE_READY, msg);
public void sendMessage(MessageContext synCtx) { logSetter(); if (log.isDebugEnabled()) { log.debug("Sending using Recipient List " + toString()); } if (getContext().isState(EndpointContext.ST_OFF)) { informFailure(synCtx, SynapseConstants.ENDPOINT_RL_NONE_READY, "RecipientList endpoint : " + getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT + " - is inactive"); return; } List<Endpoint> children = getChildren(); //Service child endpoints if (children != null && !children.isEmpty()) { sendToEndpointList(synCtx, children); } //Service member elements if specified else if (members != null && !members.isEmpty()) { sendToApplicationMembers(synCtx); } else if (dynamicEnpointSet != null) { sendToDynamicMembers(synCtx); } else { String msg = "No child endpoints nor member elements available"; log.error(msg); throw new SynapseException(msg); } }
@Override public boolean readyToSend(){ for(Endpoint endpoint : getChildren()){ if(endpoint.readyToSend()){ if (log.isDebugEnabled()) { log.debug("Recipient List " + this.toString() + " has at least one endpoint at ready state"); } return true; } } return false; }
@Override public void send(MessageContext synCtx) { if (log.isDebugEnabled()) { log.debug("Sending using Recipient List " + toString()); } List<Endpoint> children = getChildren(); //Service child endpoints if (children != null && !children.isEmpty()) { sendToEndpointList(synCtx, children); } else if (members != null && !members.isEmpty()) { //Service member elements if specified sendToApplicationMembers(synCtx); } else if (dynamicEndpointSet != null) { sendToDynamicMembers(synCtx); } else { String msg = "No child endpoints nor members available"; log.error(msg); throw new SynapseException(msg); } }
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(); recipientListEndpoint.setName(name.getAttributeValue()); recipientListEndpoint.setChildren(endpoints); recipientListEndpoint.setMembers(members); } else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) { OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET); recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache); if (name != null) { recipientListEndpoint.setName(name.getAttributeValue()); recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet); if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) { String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements."; log.error(msg); throw new SynapseException(msg);
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(); recipientListEndpoint.setName(name.getAttributeValue()); recipientListEndpoint.setChildren(endpoints); recipientListEndpoint.setMembers(members); maxCache = Integer.parseInt(maxCacheStr); recipientListEndpoint = new RecipientListEndpoint(maxCache); if (name != null) { recipientListEndpoint.setName(name.getAttributeValue()); recipientListEndpoint.setDynamicEndpointSet(dynamicEndpointSet); if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEndpointSet() == null) { String msg = "A RecipientListEndpoint must have child/member elements, but the " + "RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' " + "does not have any child/member/dynamic endpoint elements."; log.error(msg);
/** * Test on Sending messages to different members using RecipientListEndpoint */ @Test public void testSendMessageToMembers() throws Exception { //perform init Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(); recipientListEndpoint.init(synapseEnvironment); Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext()); //set members Member member1 = new Member("localhost", 9000); Member member2 = new Member("localhost", 9001); ArrayList<Member> members = new ArrayList<>(2); members.add(member1); members.add(member2); recipientListEndpoint.setMembers(members); //test send message String samplePayload = "<test>value</test>"; Axis2MessageContext messageContext = getMessageContext(samplePayload); //message will be sent to EP using this env (which is mocked and do nothing) messageContext.setEnvironment(synapseEnvironment); messageContext.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService")); recipientListEndpoint.sendMessage(messageContext); }
/** * Test on Sending messages to a dynamic EP based on an expression * * @throws Exception on test failure */ @Test public void testSendToDynamicMembers() throws Exception { //perform init Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(2); recipientListEndpoint.init(synapseEnvironment); Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext()); //add dynamic EPs Value dynamicEPs = new Value(new SynapseXPath("//endpoints")); recipientListEndpoint.setDynamicEnpointSet(dynamicEPs); //test send message String samplePayload = "<test><endpoints>http://localhost:9000/services/SimpleStockQuoteService," + "http://localhost:9001/services/SimpleStockQuoteService" + "</endpoints><body>wso2</body></test>"; Axis2MessageContext messageContext = getMessageContext(samplePayload); //message will be sent to EP using this env (which is mocked and do nothing) messageContext.setEnvironment(synapseEnvironment); //messageContext.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService")); recipientListEndpoint.sendMessage(messageContext); }
if (recipientListEndpoint.getChildren() != null) { for (Endpoint childEndpoint : recipientListEndpoint.getChildren()) { recipientListElement.addChild(EndpointSerializer .getElementFromEndpoint(childEndpoint)); } else if (recipientListEndpoint.getMembers() != null) { for (Member member : recipientListEndpoint.getMembers()) { OMElement memberEle = fac.createOMElement( "member", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement); OMElement dynamicEpEle = fac.createOMElement( "endpoints", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement); new ValueSerializer().serializeValue(recipientListEndpoint.getDynamicEndpointSet(), "value", dynamicEpEle); dynamicEpEle.addAttribute(fac.createOMAttribute("max-cache", null, String.valueOf(recipientListEndpoint.getCurrentPoolSize()))); recipientListElement.addChild(dynamicEpEle);
if (recipientListEndpoint.getChildren() != null) { for (Endpoint childEndpoint : recipientListEndpoint.getChildren()) { recipientListElement.addChild(EndpointSerializer .getElementFromEndpoint(childEndpoint)); } else if (recipientListEndpoint.getMembers() != null) { for (Member member : recipientListEndpoint.getMembers()) { OMElement memberEle = fac.createOMElement( "member", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement); OMElement dynamicEpEle = fac.createOMElement( "endpoints", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement); new ValueSerializer().serializeValue(recipientListEndpoint.getDynamicEnpointSet(), "value", dynamicEpEle); dynamicEpEle.addAttribute(fac.createOMAttribute("max-cache", null, String.valueOf(recipientListEndpoint.getCurrentPoolSize()))); recipientListElement.addChild(dynamicEpEle);
@Override public boolean readyToSend(){ if (getContext().isState(EndpointContext.ST_OFF)) { return false; } for(Endpoint endpoint : getChildren()){ if(endpoint.readyToSend()){ if (log.isDebugEnabled()) { log.debug("Recipient List " + this.toString() + " has at least one endpoint at ready state"); } return true; } } return false; }
/** * Test on init of RecipientListEndpoint */ @Test public void testRecipientListEndpointInit() throws Exception { Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint(); recipientListEndpoint.init(synapseEnvironment); }
/** * Create a RecipientListEndpoint by config and test sending a message * @throws Exception on an issue sending out the message */ @Test public void testSendToEndpointList() throws Exception { OMElement omBody = AXIOMUtil.stringToOM("<endpoint><recipientlist xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>\n" + " </endpoint>\n" + " <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <address uri=\"http://localhost:9001/services/SimpleStockQuoteService\"/>\n" + " </endpoint>\n" + "</recipientlist></endpoint>"); RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) EndpointFactory. getEndpointFromElement(omBody,true, null); Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext()); //test send message String samplePayload = "<test><a>WSO2</a></test>"; Axis2MessageContext messageContext = getMessageContext(samplePayload); //message will be sent to EP using this env (which is mocked and do nothing) messageContext.setEnvironment(synapseEnvironment); recipientListEndpoint.init(synapseEnvironment); recipientListEndpoint.sendMessage(messageContext); }
RelayUtils.buildMessage(((Axis2MessageContext) synCtx).getAxis2MessageContext(),false); } catch (Exception e) { handleException("Error while building message", e); newCtx = MessageHelper.cloneMessageContext(synCtx); } catch (AxisFault e) { handleException("Error cloning the message context", e); evaluateProperties(newCtx); " of Recipient List endpoint " + (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " encountered an error while sending the message"; log.warn(msg); continue; //continue sending message to rest of the child endpoints. (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child endpoints"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_RL_NONE_READY, msg);
newCtx = MessageHelper.cloneMessageContext(synCtx); } catch (AxisFault e) { handleException("Error cloning the message context", e); return; evaluateProperties(newCtx); (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child members"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_FO_NONE_READY, msg);
newCtx = MessageHelper.cloneMessageContext(synCtx); } catch (AxisFault e) { handleException("Error cloning the message context", e); evaluateProperties(newCtx); (getName() != null ? getName() : SynapseConstants.ANONYMOUS_ENDPOINT) + " - no ready child members"; log.warn(msg); informFailure(synCtx, SynapseConstants.ENDPOINT_RL_NONE_READY, msg);