Java Code Examples for org.apache.synapse.transport.passthru.util.RelayUtils#buildMessage()
The following examples show how to use
org.apache.synapse.transport.passthru.util.RelayUtils#buildMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ODataPassThroughHandler.java From micro-integrator with Apache License 2.0 | 6 votes |
@Override public boolean handleRequestInFlow(MessageContext messageContext) { try { org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) messageContext).getAxis2MessageContext(); Object isODataService = axis2MessageContext.getProperty("IsODataService"); // In this if block we are skipping proxy services, inbound related message contexts & api. if (axis2MessageContext.getProperty("TransportInURL") != null && isODataService != null) { RelayUtils.buildMessage(axis2MessageContext); ODataServletRequest request = new ODataServletRequest(axis2MessageContext); ODataServletResponse response = new ODataServletResponse(axis2MessageContext); ODataEndpoint.process(request, response); setContent(axis2MessageContext, response); setHeaders(axis2MessageContext, response); messageContext.setTo(null); messageContext.setResponse(true); Axis2Sender.sendBack(messageContext); } return true; } catch (Exception e) { this.handleException("Error occurred in integrator handler.", e, messageContext); return true; } }
Example 2
Source File: APIResource.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Builds the message by consuming the input stream. * * @param synCtx the Synapse Message Context */ public final void buildMessage(MessageContext synCtx) { try { RelayUtils.buildMessage(((Axis2MessageContext) synCtx).getAxis2MessageContext(), false); } catch (Exception e) { throw new SynapseException("Error while building the message. " + e.getMessage(), e); } }
Example 3
Source File: LogsHandler.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private long buildRequestMessage(org.apache.synapse.MessageContext messageContext) { long requestSize = 0; org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); String contentLength = (String) headers.get(HttpHeaders.CONTENT_LENGTH); if (contentLength != null) { requestSize = Integer.parseInt(contentLength); } else { // When chunking is enabled try { RelayUtils.buildMessage(axis2MC); } catch (IOException | XMLStreamException ex) { // In case of an exception, it won't be propagated up,and set response size to 0 log.error(REQUEST_BODY_SIZE_ERROR, ex); } SOAPEnvelope env = messageContext.getEnvelope(); if (env != null) { SOAPBody soapbody = env.getBody(); if (soapbody != null) { byte[] size = soapbody.toString().getBytes(Charset.defaultCharset()); requestSize = size.length; } } } return requestSize; }
Example 4
Source File: LogsHandler.java From carbon-apimgt with Apache License 2.0 | 5 votes |
private long buildResponseMessage(org.apache.synapse.MessageContext messageContext) { long responseSize = 0; org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext) .getAxis2MessageContext(); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); String contentLength = (String) headers.get(HttpHeaders.CONTENT_LENGTH); if (contentLength != null) { responseSize = Integer.parseInt(contentLength); } else { // When chunking is enabled try { RelayUtils.buildMessage(axis2MC); } catch (IOException | XMLStreamException ex) { // In case of an exception, it won't be propagated up,and set response size to 0 log.error(REQUEST_BODY_SIZE_ERROR, ex); } } SOAPEnvelope env = messageContext.getEnvelope(); if (env != null) { SOAPBody soapbody = env.getBody(); if (soapbody != null) { byte[] size = soapbody.toString().getBytes(Charset.defaultCharset()); responseSize = size.length; } } return responseSize; }
Example 5
Source File: BotDetectionMediator.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Override public boolean mediate(MessageContext messageContext) { org.apache.axis2.context.MessageContext msgContext = ((Axis2MessageContext) messageContext). getAxis2MessageContext(); String clientIP = DataPublisherUtil.getClientIp(msgContext); if (isThrottledOut(clientIP)) { messageContext.setProperty("BOT_THROTTLED_OUT", true); messageContext.setProperty("BOT_IP", clientIP); return true; } String messageBody; long currentTime = System.currentTimeMillis(); String messageId = messageContext.getMessageID(); String apiMethod = (String) msgContext.getProperty("HTTP_METHOD"); try { RelayUtils.buildMessage(msgContext); SOAPEnvelope messageEnvelop = msgContext.getEnvelope(); if (messageEnvelop != null && messageEnvelop.getBody() != null) { messageBody = String.valueOf(messageEnvelop.getBody()); } else { messageBody = "Empty Message"; } } catch (Exception e) { messageBody = "Malformed Message"; } String headerSet = getPassedHeaderSet(msgContext); log.info(String.format("MessageId : %s | Request Method : %s | Message Body : %s | client Ip : %s | " + "Headers set : %s", messageId, apiMethod, messageBody, clientIP, headerSet)); /** * check whether analytics enabled or not */ if (!enabled) { return true; } BotDataDTO botDataDTO = new BotDataDTO(); botDataDTO.setCurrentTime(currentTime); botDataDTO.setMessageID(messageId); botDataDTO.setApiMethod(apiMethod); botDataDTO.setHeaderSet(headerSet); botDataDTO.setMessageBody(messageBody); botDataDTO.setClientIp(clientIP); publisher.publishEvent(botDataDTO); return true; }
Example 6
Source File: GraphQLAPIHandler.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public boolean handleRequest(MessageContext messageContext) { try { String payload; Parser parser = new Parser(); org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext). getAxis2MessageContext(); String requestPath = messageContext.getProperty(REST_SUB_REQUEST_PATH).toString(); if (requestPath != null && !requestPath.isEmpty()) { String[] queryParams = ((Axis2MessageContext) messageContext).getProperties(). get(REST_SUB_REQUEST_PATH).toString().split(QUERY_PATH_STRING); if (queryParams.length > 1) { payload = URLDecoder.decode(queryParams[1], UNICODE_TRANSFORMATION_FORMAT); } else { RelayUtils.buildMessage(axis2MC); OMElement body = axis2MC.getEnvelope().getBody().getFirstElement(); if (body != null && body.getFirstElement() != null) { payload = body.getFirstElement().getText(); } else { if (log.isDebugEnabled()) { log.debug("Invalid query parameter " + queryParams[0]); } handleFailure(messageContext, "Invalid query parameter"); return false; } } messageContext.setProperty(APIConstants.GRAPHQL_PAYLOAD, payload); } else { handleFailure(messageContext, "Request path cannot be empty"); return false; } // Validate payload with graphQLSchema Document document = parser.parseDocument(payload); if (validatePayloadWithSchema(messageContext, document)) { supportForBasicAndAuthentication(messageContext); // Extract the operation type and operations from the payload for (Definition definition : document.getDefinitions()) { if (definition instanceof OperationDefinition) { OperationDefinition operation = (OperationDefinition) definition; if (operation.getOperation() != null) { String httpVerb = ((Axis2MessageContext) messageContext).getAxis2MessageContext(). getProperty(HTTP_METHOD).toString(); messageContext.setProperty(HTTP_VERB, httpVerb); ((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(HTTP_METHOD, operation.getOperation().toString()); String operationList = getOperationList(messageContext, operation); messageContext.setProperty(APIConstants.API_ELECTED_RESOURCE, operationList); if (log.isDebugEnabled()) { log.debug("Operation list has been successfully added to elected property"); } return true; } } else { handleFailure(messageContext, "Operation definition cannot be empty"); return false; } } } else { return false; } } catch (IOException | XMLStreamException | InvalidSyntaxException e) { log.error(e.getMessage()); handleFailure(messageContext, e.getMessage()); } return false; }
Example 7
Source File: DataProcessAndPublishingAgent.java From carbon-apimgt with Apache License 2.0 | 4 votes |
protected void buildMessage(org.apache.axis2.context.MessageContext axis2MessageContext) throws IOException, XMLStreamException { RelayUtils.buildMessage(axis2MessageContext); }