public void cleanup(MessageContext msgContext) throws AxisFault { HttpMethod httpMethod = (HttpMethod) msgContext.getProperty(HTTPConstants.HTTP_METHOD); if (httpMethod != null) { // TODO : Don't do this if we're not on the right thread! Can we confirm? log.trace("cleanup() releasing connection for " + httpMethod); httpMethod.releaseConnection(); msgContext.removeProperty(HTTPConstants.HTTP_METHOD); // guard against multiple calls } }
private static void writeJsonStream(InputStream json, MessageContext messageContext, OutputStream out) throws AxisFault { try { if (json.markSupported()) { json.reset(); } IOUtils.copy(json, out); // Write the JSON stream if (messageContext.getProperty(PRESERVE_JSON_STREAM) != null) { if (json.markSupported()) { json.reset(); } messageContext.removeProperty(PRESERVE_JSON_STREAM); } } catch (IOException e) { logger.error("#writeJsonStream. Could not write JSON stream. MessageID: " + messageContext.getMessageID() + ". Error>> " + e.getLocalizedMessage()); throw new AxisFault("Could not write JSON stream.", e); } }
@Override public void cleanup(MessageContext msgContext) throws AxisFault { HttpMethod httpMethod = (HttpMethod) msgContext.getProperty(HTTPConstants.HTTP_METHOD); if (httpMethod != null) { // TODO : Don't do this if we're not on the right thread! Can we confirm? log.trace("cleanup() releasing connection for " + httpMethod); httpMethod.releaseConnection(); msgContext.removeProperty(HTTPConstants.HTTP_METHOD); // guard against multiple calls } }
@Override public void cleanup(MessageContext msgContext) throws AxisFault { log.trace("cleanup() releasing connection"); OperationContext opContext = msgContext.getOperationContext(); if (opContext != null) { InputStream in = (InputStream)opContext.getProperty(MessageContext.TRANSPORT_IN); if (in != null) { try { in.close(); } catch (IOException ex) { // Ignore } } } // guard against multiple calls msgContext.removeProperty(HTTPConstants.HTTP_METHOD); }
@Override public void cleanup(MessageContext msgContext) throws AxisFault { log.trace("cleanup() releasing connection"); OperationContext opContext = msgContext.getOperationContext(); if (opContext != null) { InputStream in = (InputStream)opContext.getProperty(MessageContext.TRANSPORT_IN); if (in != null) { try { in.close(); } catch (IOException ex) { // Ignore } } } // guard against multiple calls msgContext.removeProperty(HTTPConstants.HTTP_METHOD); }
public void setDoingGET(boolean b) { if(b) { axis2MessageContext.setDoingREST(b); axis2MessageContext.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET); } else { axis2MessageContext.removeProperty(Constants.Configuration.HTTP_METHOD); } }
public void setDoingGET(boolean b) { if (b) { axis2MessageContext.setDoingREST(b); axis2MessageContext.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET); } else { axis2MessageContext.removeProperty(Constants.Configuration.HTTP_METHOD); } }
@Override protected InvocationResponse doProcessing(final MessageContext mc, final IUserMessageEntity um) throws PersistenceException { final String msgId = um.getMessageId(); log.trace("Change processing state to indicate start of processing of message [" + msgId + "]" ); if (!HolodeckB2BCore.getStorageManager().setProcessingState(um, ProcessingState.RECEIVED, ProcessingState.PROCESSING)) { log.warn("User message [msgId= " + msgId + "] is already being processed"); // Remove the User Message from the context to prevent further processing mc.removeProperty(MessageContextProperties.IN_USER_MESSAGE); } else log.trace("User message [msgId= " + msgId + "] is ready for processing"); return InvocationResponse.CONTINUE; } }
messageContext.removeProperty(ORG_APACHE_SYNAPSE_COMMONS_JSON_JSON_INPUT_STREAM); messageContext.removeProperty(ORG_APACHE_SYNAPSE_COMMONS_JSON_IS_JSON_OBJECT); boolean removeChildren = true; if (!removeChildren) { // don't change this.
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); }
/** * Remove property from message context * * @param key Property name * @param scope Property scope */ public void removeProperty(String key, String scope) { if (scope == null || XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) { // Removing property from default scope removeProperty(key); } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)) { // Removing property from the Axis2 Message Context Axis2MessageContext axis2smc = (Axis2MessageContext) mc; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); axis2MessageCtx.removeProperty(key); } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)) { // Removing transport headers Axis2MessageContext axis2smc = (Axis2MessageContext) mc; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); Object headers = axis2MessageCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null && headers instanceof Map) { Map headersMap = (Map) headers; headersMap.remove(key); } } }
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); }
axis2MessageCtx.removeProperty(key);
axis2MessageCtx.removeProperty(key);
messageContext.setProperty("RESPONSE", "true"); messageContext.setTo(null); axis2MC.removeProperty("NO_ENTITY_BODY"); String method = (String) axis2MC.getProperty(Constants.Configuration.HTTP_METHOD); if (method.matches("^(?!.*(POST|PUT)).*$")) { axis2MC.removeProperty(Constants.Configuration.CONTENT_TYPE); Map headers = (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); if (headers != null) {
/** * Sets the content type based on the request content type and payload factory media type. This should be called * at the end before returning from the mediate() function. * @param synCtx */ private void setContentType(MessageContext synCtx) { org.apache.axis2.context.MessageContext a2mc = ((Axis2MessageContext) synCtx).getAxis2MessageContext(); if (mediaType.equals(XML_TYPE)) { if (!XML_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE)) && !SOAP11_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE)) && !SOAP12_CONTENT_TYPE.equals(a2mc.getProperty(Constants.Configuration.MESSAGE_TYPE)) ) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, XML_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, XML_CONTENT_TYPE); handleSpecialProperties(XML_CONTENT_TYPE, a2mc); } } else if (mediaType.equals(JSON_TYPE)) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, JSON_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, JSON_CONTENT_TYPE); handleSpecialProperties(JSON_CONTENT_TYPE, a2mc); } else if (mediaType.equals(TEXT_TYPE)) { a2mc.setProperty(Constants.Configuration.MESSAGE_TYPE, TEXT_CONTENT_TYPE); a2mc.setProperty(Constants.Configuration.CONTENT_TYPE, TEXT_CONTENT_TYPE); handleSpecialProperties(TEXT_CONTENT_TYPE, a2mc); } a2mc.removeProperty("NO_ENTITY_BODY"); }
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); }
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); }
/** * 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); } }
/** * Helper method to use when no matching resource found * * @param synCtx */ private void handleResourceNotFound(MessageContext synCtx) { auditDebug("No matching resource was found for the request: " + synCtx.getMessageID()); Mediator sequence = synCtx.getSequence(RESTConstants.NO_MATCHING_RESOURCE_HANDLER); if (sequence != null) { sequence.mediate(synCtx); } else { //Matching resource with method not found org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext(); msgCtx.setProperty(SynapseConstants.HTTP_SC, HttpStatus.SC_NOT_FOUND); msgCtx.removeProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS); msgCtx.setProperty("NIO-ACK-Requested", true); } }