synchronized (responseState) { if (responseState.isRespondDone()) { log.warn("Trying to send a response to an already responded client request - " + getInputInfo( messageContext)); return true; handleException("Response State must be of type : " + ResponseState.class + ". " + SynapseConstants.RESPONSE_STATE + " must not be used as an user property name", null);
/** * Do the cleanup work, metadata updates in the return path of Message Receiver tread * after injecting the message to the engine * * @param messageContext Synapse Message Context */ public static void doPostInjectUpdates(MessageContext messageContext) { org.apache.axis2.context.MessageContext axis2Ctx = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); // If FORCE_SC_ACCEPTED is set, mark response is sent and prevent multiple response being sent if (axis2Ctx.isPropertyTrue(NhttpConstants.FORCE_SC_ACCEPTED) && Axis2Sender .preventMultipleResponses(messageContext)) { throw new SynapseException("Trying to send a 202 Accepted response to an already responded client request"); } }
if (preventMultipleResponses(smc)) { return; isMessagePayloadHasASOAPFault(messageContext)) { POXUtils.convertSOAPFaultToPOX(messageContext); doSOAPFormatConversion(smc); handleConcurrentThrottleCount(smc); handleException(getResponseMessage(messageContext), e);
/** * Send a message out from the Synapse engine to an external service * * @param endpoint the endpoint definition where the message should be sent * @param synapseInMessageContext the Synapse message context */ public static void sendOn(EndpointDefinition endpoint, org.apache.synapse.MessageContext synapseInMessageContext) { try { // Invoke Synapse Handlers Iterator<SynapseHandler> iterator = synapseInMessageContext.getEnvironment().getSynapseHandlers().iterator(); while (iterator.hasNext()) { SynapseHandler handler = iterator.next(); if (!handler.handleRequestOutFlow(synapseInMessageContext)) { return; } } Axis2FlexibleMEPClient.send( // The endpoint where we are sending to endpoint, // The Axis2 Message context of the Synapse MC synapseInMessageContext); } catch (Exception e) { handleException("Unexpected error during sending message out", e); } }
/** * Send a message out from the Synapse engine to an external service * @param endpoint the endpoint definition where the message should be sent * @param synapseInMessageContext the Synapse message context */ public static void sendOn(EndpointDefinition endpoint, org.apache.synapse.MessageContext synapseInMessageContext) { try { Axis2FlexibleMEPClient.send( // The endpoint where we are sending to endpoint, // The Axis2 Message context of the Synapse MC synapseInMessageContext); if (synapseInMessageContext.isResponse()) { // report stats for any component at response sending check point StatisticsReporter.reportForAllOnResponseSent(synapseInMessageContext); } } catch (Exception e) { handleException("Unexpected error during sending message out", e); } }
RelayUtils.buildMessage(((Axis2MessageContext) synCtx).getAxis2MessageContext(), false); } catch (Exception e) { handleException("Error while building message", e); RelayUtils.buildMessage(((Axis2MessageContext) synCtx).getAxis2MessageContext(), false); } catch (Exception e) { handleException("Error while building message", e);
public static void sendFault(MessageContext messageContext, int status) { org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext). getAxis2MessageContext(); axis2MC.setProperty(NhttpConstants.HTTP_SC, status); messageContext.setResponse(true); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MC.removeProperty("NO_ENTITY_BODY"); // Always remove the ContentType - Let the formatter do its thing axis2MC.removeProperty(Constants.Configuration.CONTENT_TYPE); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) { headers.remove(HttpHeaders.AUTHORIZATION); headers.remove(HttpHeaders.AUTHORIZATION); headers.remove(HttpHeaders.HOST); } Axis2Sender.sendBack(messageContext); }
handleException("Unexpected error sending message back", e);
public static void redirectToURL(MessageContext messageContext, String url){ org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext). getAxis2MessageContext(); axis2MessageContext.setProperty(NhttpConstants.HTTP_SC, "302"); messageContext.setResponse(true); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MessageContext.removeProperty("NO_ENTITY_BODY"); /* Always remove the ContentType - Let the formatter do its thing */ axis2MessageContext.removeProperty(Constants.Configuration.CONTENT_TYPE); Map headerMap = (Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); headerMap.put("Location", url); if(log.isDebugEnabled()){ GatewayUtils.logWithRequestInfo(log, messageContext, String.format("Sending HTTP redirect to '%s'", url)); } removeIrrelevantHeadersBeforeResponding(headerMap); Axis2Sender.sendBack(messageContext); }
Axis2Sender.sendBack(synCtx); } else if (log.isDebugEnabled()) { log.debug("No in-sequence configured. Dropping the request.");
Axis2Sender.sendBack(messageContext);
/** * This method used to send the response back from the request. * * @param messageContext messageContext of the request * @param status HTTP Status to return from the response */ public static void send(MessageContext messageContext, int status) { org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); axis2MC.setProperty(NhttpConstants.HTTP_SC, status); messageContext.setResponse(true); messageContext.setProperty(SynapseConstants.RESPONSE, "true"); messageContext.setTo(null); axis2MC.removeProperty(Constants.Configuration.CONTENT_TYPE); Axis2Sender.sendBack(messageContext); } }
public static void send401(MessageContext messageContext, String reason) { // TODO : remove reason from the method signature since we don't send a reason for 401. org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace ns = fac.createOMNamespace("http://wso2.org/appm", "appm"); OMElement payload = fac.createOMElement("error", ns); payload.setText("Unauthorized access"); OMElement firstChild = messageContext.getEnvelope().getBody().getFirstElement(); if (firstChild != null) { firstChild.insertSiblingAfter(payload); firstChild.detach(); } else { messageContext.getEnvelope().getBody().addChild(payload); } axis2MessageContext.setProperty(NhttpConstants.HTTP_SC, HttpStatus.SC_UNAUTHORIZED); messageContext.setResponse(true); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MessageContext.removeProperty("NO_ENTITY_BODY"); axis2MessageContext.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml"); axis2MessageContext.removeProperty(Constants.Configuration.CONTENT_TYPE); Axis2Sender.sendBack(messageContext); }
public static void send200(MessageContext messageContext, OMElement payload) { org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); OMElement firstChild = messageContext.getEnvelope().getBody().getFirstElement(); if (firstChild != null) { firstChild.insertSiblingAfter(payload); firstChild.detach(); } else { messageContext.getEnvelope().getBody().addChild(payload); } axis2MessageContext.setProperty(NhttpConstants.HTTP_SC, HttpStatus.SC_OK); messageContext.setResponse(true); messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MessageContext.removeProperty("NO_ENTITY_BODY"); axis2MessageContext.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml"); axis2MessageContext.removeProperty(Constants.Configuration.CONTENT_TYPE); Axis2Sender.sendBack(messageContext); }
+ " does not specifies an out-sequence - sending the response back"); Axis2Sender.sendBack(synCtx);
+ " does not specifies an out-sequence - sending the response back"); Axis2Sender.sendBack(synCtx);