/** * Check if a given property is true. Will return false if the property * does not exist or is not an explicit "true" value. * * @param name name of the property to check * @return true if the property exists and is Boolean.TRUE, "true", 1, etc. */ public boolean isPropertyTrue(String name) { return isPropertyTrue(name, false); }
/** * Check if a given property is true. Will return false if the property * does not exist or is not an explicit "true" value. * * @param name name of the property to check * @return true if the property exists and is Boolean.TRUE, "true", 1, etc. */ public boolean isPropertyTrue(String name) { return isPropertyTrue(name, false); }
protected void cleanup(MessageContext msgContext, Object httpMmethod) { if (httpMmethod instanceof HttpMethod) { if (msgContext.isPropertyTrue(HTTPConstants.AUTO_RELEASE_CONNECTION)) { log.trace("AutoReleasing " + httpMmethod); ((HttpMethod) httpMmethod).releaseConnection(); } } }
@Override protected void cleanup(MessageContext msgContext, Object httpResponse) { HttpResponse response; if (httpResponse instanceof HttpResponse) { response = (HttpResponse) httpResponse; } else { log.trace("HttpResponse expected, but found - " + httpResponse); return; } if (msgContext.isPropertyTrue(HTTPConstants.CLEANUP_RESPONSE)) { log.trace("Cleaning response : " + response); HttpEntity entity = response.getEntity(); if (entity != null) { try { EntityUtils.consume(entity); } catch (IOException e) { log.error("Error while cleaning response : " + response, e); } } } }
public Axis2HttpRequest(EndpointReference epr, HttpRoute route, MessageContext msgContext) { this.epr = epr; this.route = route; this.msgContext = msgContext; this.format = NhttpUtil.getOMOutputFormat(msgContext); this.messageFormatter = MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext); this.chunked = !msgContext.isPropertyTrue(NhttpConstants.DISABLE_CHUNKING); }
private boolean isAckRequired() { // This condition is a bit complex but cannot simplify any further. if (msgContext != null) { if (msgContext.getOperationContext() != null && (!msgContext.getOperationContext().getAxisOperation().isControlOperation() || msgContext.isPropertyTrue(NhttpConstants.FORCE_SC_ACCEPTED))) { return true; } else if (msgContext.isPropertyTrue("NIO-ACK-Requested", false)) { return true; } } return false; }
public static String getContentType(String contentType, MessageContext msgContext) { String type; int index = contentType.indexOf(';'); if (index > 0) { type = contentType.substring(0, index); } else { type = contentType; } // Some services send REST responces as text/xml. We should convert it to // application/xml if its a REST response, if not it will try to use the SOAPMessageBuilder. // isDoingREST should already be properly set by HTTPTransportUtils.initializeMessageContext if (msgContext.isDoingREST() && HTTPConstants.MEDIA_TYPE_TEXT_XML.equals(type)) { if (msgContext.isServerSide()) { if (msgContext.getSoapAction() == null) { // TODO - remove this logic. //type = HTTPConstants.MEDIA_TYPE_APPLICATION_XML; } } else if (!msgContext.isPropertyTrue(Constants.Configuration.SOAP_RESPONSE_MEP)) { type = HTTPConstants.MEDIA_TYPE_APPLICATION_XML; } } return type; }
public static String getContentType(String contentType, MessageContext msgContext) { String type; int index = contentType.indexOf(';'); if (index > 0) { type = contentType.substring(0, index); } else { type = contentType; } // Some services send REST responces as text/xml. We should convert it to // application/xml if its a REST response, if not it will try to use the SOAPMessageBuilder. // isDoingREST should already be properly set by HTTPTransportUtils.initializeMessageContext if (msgContext.isDoingREST() && HTTPConstants.MEDIA_TYPE_TEXT_XML.equals(type)) { if (msgContext.isServerSide()) { if (msgContext.getSoapAction() == null) { // TODO - remove this logic. //type = HTTPConstants.MEDIA_TYPE_APPLICATION_XML; } } else if (!msgContext.isPropertyTrue(Constants.Configuration.SOAP_RESPONSE_MEP)) { type = HTTPConstants.MEDIA_TYPE_APPLICATION_XML; } } return type; }
private URI rewriteRequestURI(final URI uri) throws URISyntaxException { if (msgContext.isPropertyTrue(NhttpConstants.POST_TO_URI) || (route.getProxyHost() != null && !route.isTunnelled())) { // Must be absolute return uri; } else { // Make relative return URIUtils.rewriteURI(uri, null, true); } }
INCLUDE_OPTIONAL_HEADERS, MODULE_NAME, handlerDesc); boolean includeOptionalHeaders = msgContext.isPropertyTrue(INCLUDE_OPTIONAL_HEADERS, JavaUtils.isTrueExplicitly(Utils.getParameterValue(param))); msgContext.isPropertyTrue(ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS); boolean replaceHeaders = msgContext.isPropertyTrue(REPLACE_ADDRESSING_HEADERS);
boolean isChunkingDisabled = responseMsgContext.isPropertyTrue(PassThroughConstants.DISABLE_CHUNKING, false); if (!responseMsgContext.isPropertyTrue(PassThroughConstants.MESSAGE_BUILDER_INVOKED, false)) { try {
@Override public void execute() throws IOException { populateHostConfiguration(); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) { method.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY); if (cookiePolicy != null) { requestConfig.setCookieSpec(cookiePolicy); } method.setConfig(requestConfig.build()); response = httpClient.execute(httpHost, method, clientContext); }
/** * 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"); } }
public boolean shouldInvoke(MessageContext msgContext) throws AxisFault { Parameter param = null; boolean disableAddressing = false; Object o = msgContext.getProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES); if (o == null || !(o instanceof Boolean)) { //determine whether outbound addressing has been disabled or not. // Get default value from module.xml or axis2.xml files param = msgContext.getModuleParameter(DISABLE_ADDRESSING_FOR_OUT_MESSAGES, MODULE_NAME, handlerDesc); disableAddressing = msgContext.isPropertyTrue(DISABLE_ADDRESSING_FOR_OUT_MESSAGES, JavaUtils.isTrueExplicitly(Utils.getParameterValue(param))); } else { disableAddressing = (Boolean) o; } if (disableAddressing) { if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) { log.trace(msgContext.getLogIDString() + " Addressing is disabled. Not adding WS-Addressing headers."); } return false; } return true; }
protected HttpResponse executeMethod(AbstractHttpClient httpClient, MessageContext msgContext, URL url, HttpRequestBase method) throws IOException { HttpHost httpHost = this.getHostConfiguration(httpClient, msgContext, url); // set the custom headers, if available addCustomHeaders(method, msgContext); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) { method.addHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) { method.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) { HttpParams params = (HttpParams) msgContext .getProperty(HTTPConstants.HTTP_METHOD_PARAMS); method.setParams(params); } String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY); if (cookiePolicy != null) { method.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy); } setTimeouts(msgContext, method); HttpContext localContext = new BasicHttpContext(); // Why do we have add context here return httpClient.execute(httpHost, method, localContext); }
protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url, HttpMethod method) throws IOException { HostConfiguration config = this.getHostConfiguration(httpClient, msgContext, url); // set the custom headers, if available addCustomHeaders(method, msgContext); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) { method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) { method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) { HttpMethodParams params = (HttpMethodParams) msgContext .getProperty(HTTPConstants.HTTP_METHOD_PARAMS); method.setParams(params); } String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY); if (cookiePolicy != null) { method.getParams().setCookiePolicy(cookiePolicy); } HttpState httpState = (HttpState) msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE); setTimeouts(msgContext, method); httpClient.executeMethod(config, method, httpState); }
@Override public void execute() throws IOException { populateHostConfiguration(); // add compression headers if needed if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) { method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING, HTTPConstants.COMPRESSION_GZIP); } if (msgContext.getProperty(HTTPConstants.HTTP_METHOD_PARAMS) != null) { HttpMethodParams params = (HttpMethodParams) msgContext .getProperty(HTTPConstants.HTTP_METHOD_PARAMS); method.setParams(params); } String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY); if (cookiePolicy != null) { method.getParams().setCookiePolicy(cookiePolicy); } HttpState httpState = (HttpState) msgContext.getProperty(HTTPConstants.CACHED_HTTP_STATE); httpClient.executeMethod(config, method, httpState); }
private boolean handle202(MessageContext requestMsgContext) throws AxisFault { if (requestMsgContext.isPropertyTrue(NhttpConstants.IGNORE_SC_ACCEPTED)) { // We should not further process this 202 response - Ignore it return true; } MessageReceiver mr = requestMsgContext.getAxisOperation().getMessageReceiver(); MessageContext responseMsgCtx = requestMsgContext.getOperationContext(). getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN); if (responseMsgCtx == null || requestMsgContext.getOptions().isUseSeparateListener()) { // Most probably a response from a dual channel invocation // Inject directly into the SynapseCallbackReceiver requestMsgContext.setProperty(NhttpConstants.HTTP_202_RECEIVED, "true"); mr.receive(requestMsgContext); return true; } return false; }
if (messageCtx.isPropertyTrue(DO_ASYNC) || ((messageCtx.getParameter(DO_ASYNC) != null) && JavaUtils.isTrueExplicitly(messageCtx.getParameter(DO_ASYNC).getValue()))) {
if (messageCtx.isPropertyTrue(DO_ASYNC) || ((messageCtx.getParameter(DO_ASYNC) != null) && JavaUtils.isTrueExplicitly(messageCtx.getParameter(DO_ASYNC).getValue()))) {