Search in sources :

Example 1 with SynapseWireLogHolder

use of org.apache.synapse.transport.http.conn.SynapseWireLogHolder in project wso2-synapse by wso2.

the class API method process.

void process(MessageContext synCtx) {
    auditDebug("Processing message with ID: " + synCtx.getMessageID() + " through the " + "API: " + name);
    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API, getName());
    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API_VERSION, versionStrategy.getVersion());
    synCtx.setProperty(RESTConstants.REST_API_CONTEXT, context);
    synCtx.setProperty(RESTConstants.SYNAPSE_REST_API_VERSION_STRATEGY, versionStrategy.getVersionType());
    // get API log for this message and attach to the message context
    ((Axis2MessageContext) synCtx).setServiceLog(apiLog);
    // Calculate REST_URL_POSTFIX from full request path
    String restURLPostfix = (String) synCtx.getProperty(RESTConstants.REST_FULL_REQUEST_PATH);
    if (!synCtx.isResponse() && restURLPostfix != null) {
        // Skip for response path
        if (!restURLPostfix.startsWith("/")) {
            restURLPostfix = "/" + restURLPostfix;
        }
        if (restURLPostfix.startsWith(context)) {
            restURLPostfix = restURLPostfix.substring(context.length());
        }
        if (versionStrategy instanceof URLBasedVersionStrategy) {
            String version = versionStrategy.getVersion();
            if (restURLPostfix.startsWith(version)) {
                restURLPostfix = restURLPostfix.substring(version.length());
            } else if (restURLPostfix.startsWith("/" + version)) {
                restURLPostfix = restURLPostfix.substring(version.length() + 1);
            }
        }
        ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(NhttpConstants.REST_URL_POSTFIX, restURLPostfix);
    }
    for (Handler handler : handlers) {
        auditDebug("Processing message with ID: " + synCtx.getMessageID() + " through " + "handler: " + handler.getClass().getName());
        boolean proceed;
        if (synCtx.isResponse()) {
            proceed = handler.handleResponse(synCtx);
        } else {
            proceed = handler.handleRequest(synCtx);
        }
        if (!proceed) {
            return;
        }
    }
    if (synCtx.isResponse()) {
        String resourceName = (String) synCtx.getProperty(RESTConstants.SYNAPSE_RESOURCE);
        if (resourceName != null) {
            Resource resource = resources.get(resourceName);
            if (resource != null) {
                resource.process(synCtx);
            }
        } else if (log.isDebugEnabled()) {
            auditDebug("No resource information on the response: " + synCtx.getMessageID());
        }
        return;
    }
    String path = RESTUtils.getFullRequestPath(synCtx);
    String subPath;
    if (versionStrategy.getVersionType().equals(VersionStrategyFactory.TYPE_URL)) {
        // for URL based
        // request --> http://{host:port}/context/version/path/to/resource
        subPath = path.substring(context.length() + versionStrategy.getVersion().length() + 1);
    } else {
        subPath = path.substring(context.length());
    }
    if ("".equals(subPath)) {
        subPath = "/";
    }
    synCtx.setProperty(RESTConstants.REST_SUB_REQUEST_PATH, subPath);
    org.apache.axis2.context.MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
    String hostHeader = getHostHeader(msgCtx);
    if (hostHeader != null) {
        synCtx.setProperty(RESTConstants.REST_URL_PREFIX, msgCtx.getIncomingTransportName() + "://" + hostHeader);
    }
    Set<Resource> acceptableResources = new LinkedHashSet<Resource>();
    for (Resource r : resources.values()) {
        if (r.canProcess(synCtx)) {
            acceptableResources.add(r);
        }
    }
    boolean processed = false;
    if (!acceptableResources.isEmpty()) {
        for (RESTDispatcher dispatcher : RESTUtils.getDispatchers()) {
            Resource resource = dispatcher.findResource(synCtx, acceptableResources);
            if (resource != null) {
                if (synCtx.getEnvironment().isDebuggerEnabled()) {
                    if (!synCtx.isResponse()) {
                        SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
                        if (wireLogHolder == null) {
                            wireLogHolder = new SynapseWireLogHolder();
                        }
                        if (synCtx.getProperty(RESTConstants.SYNAPSE_REST_API) != null && !synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString().isEmpty()) {
                            wireLogHolder.setApiName(synCtx.getProperty(RESTConstants.SYNAPSE_REST_API).toString());
                            if (resource.getDispatcherHelper() != null) {
                                if (resource.getDispatcherHelper().getString() != null && !resource.getDispatcherHelper().getString().isEmpty()) {
                                    wireLogHolder.setResourceUrlString(resource.getDispatcherHelper().getString());
                                }
                            }
                        }
                        ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
                    }
                }
                resource.process(synCtx);
                return;
            }
        }
        handleResourceNotFound(synCtx);
    } else {
        // This will get executed only in unhappy path. So ok to have the iterator.
        boolean resourceFound = false;
        boolean matchingMethodFound = false;
        for (RESTDispatcher dispatcher : RESTUtils.getDispatchers()) {
            Resource resource = dispatcher.findResource(synCtx, resources.values());
            if (resource != null) {
                resourceFound = true;
                String method = (String) msgCtx.getProperty(Constants.Configuration.HTTP_METHOD);
                matchingMethodFound = resource.hasMatchingMethod(method);
                break;
            }
        }
        if (!resourceFound) {
            handleResourceNotFound(synCtx);
        } else if (resourceFound && !matchingMethodFound) {
            // Resource found, but in that resource, requested method not allowed. So sending method not allowed http status (405)
            msgCtx.setProperty(SynapseConstants.HTTP_SC, HttpStatus.SC_METHOD_NOT_ALLOWED);
            msgCtx.removeProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
            msgCtx.setProperty("NIO-ACK-Requested", true);
        } else {
            // Resource found, and matching method also found, which means request is BAD_REQUEST(400)
            msgCtx.setProperty(SynapseConstants.HTTP_SC, HttpStatus.SC_BAD_REQUEST);
            msgCtx.setProperty("NIO-ACK-Requested", true);
        }
    }
}
Also used : SynapseWireLogHolder(org.apache.synapse.transport.http.conn.SynapseWireLogHolder) RESTDispatcher(org.apache.synapse.rest.dispatch.RESTDispatcher) URLBasedVersionStrategy(org.apache.synapse.rest.version.URLBasedVersionStrategy) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with SynapseWireLogHolder

use of org.apache.synapse.transport.http.conn.SynapseWireLogHolder in project wso2-synapse by wso2.

the class ProxyServiceMessageReceiver method receive.

public void receive(org.apache.axis2.context.MessageContext mc) throws AxisFault {
    boolean traceOn = proxy.getAspectConfiguration().isTracingEnabled();
    boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
    CustomLogSetter.getInstance().setLogAppender(proxy.getArtifactContainerName());
    String remoteAddr = (String) mc.getProperty(org.apache.axis2.context.MessageContext.REMOTE_ADDR);
    if (traceOrDebugOn) {
        traceOrDebug(traceOn, "Proxy Service " + name + " received a new message" + (remoteAddr != null ? " from : " + remoteAddr : "..."));
        traceOrDebug(traceOn, ("Message To: " + (mc.getTo() != null ? mc.getTo().getAddress() : "null")));
        traceOrDebug(traceOn, ("SOAPAction: " + (mc.getSoapAction() != null ? mc.getSoapAction() : "null")));
        traceOrDebug(traceOn, ("WSA-Action: " + (mc.getWSAAction() != null ? mc.getWSAAction() : "null")));
        if (traceOn && trace.isTraceEnabled()) {
            String[] cids = null;
            try {
                cids = mc.getAttachmentMap().getAllContentIDs();
            } catch (Exception ex) {
                // partially read stream could lead to corrupted attachment map and hence this exception
                // corrupted attachment map leads to inconsistent runtime exceptions and behavior
                // discard the attachment map for the fault handler invocation
                // ensure the successful completion for fault handler flow
                mc.setAttachmentMap(null);
                log.error("Synapse encountered an exception when reading attachments from bytes stream. " + "Hence Attachments map is dropped from the message context.", ex);
            }
            if (cids != null && cids.length > 0) {
                for (String cid : cids) {
                    trace.trace("With attachment content ID : " + cid);
                }
            }
            trace.trace("Envelope : " + mc.getEnvelope());
        }
    }
    MessageContext synCtx = MessageContextCreatorForAxis2.getSynapseMessageContext(mc);
    Integer statisticReportingIndex = null;
    // Statistic reporting
    boolean isStatisticsEnabled = RuntimeStatisticCollector.isStatisticsEnabled();
    if (isStatisticsEnabled) {
        statisticReportingIndex = OpenEventCollector.reportEntryEvent(synCtx, this.name, proxy.getAspectConfiguration(), ComponentType.PROXYSERVICE);
    }
    Object inboundServiceParam = proxy.getParameterMap().get(SynapseConstants.INBOUND_PROXY_SERVICE_PARAM);
    Object inboundMsgCtxParam = mc.getProperty(SynapseConstants.IS_INBOUND);
    // check whether the message is from Inbound EP
    if (inboundMsgCtxParam == null || !(boolean) inboundMsgCtxParam) {
        // check whether service parameter is set to true or null, then block this request
        if (inboundServiceParam != null && (Boolean.valueOf((String) inboundServiceParam))) {
            /*
                return because same proxy is exposed via InboundEP and service parameter(inbound.only) is set to
                true, which disable normal http transport proxy
                */
            if (!synCtx.getFaultStack().isEmpty()) {
                if (log.isDebugEnabled()) {
                    log.debug("Executing fault handler - message discarded due to the proxy is allowed only via InboundEP");
                }
                (synCtx.getFaultStack().pop()).handleFault(synCtx, new Exception("Proxy Service " + name + " message discarded due to the proxy is allowed only via InboundEP"));
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Proxy Service " + name + " message discarded due to the proxy is " + "allowed only via InboundEP");
                }
            }
            return;
        }
    }
    TenantInfoConfigurator configurator = synCtx.getEnvironment().getTenantInfoConfigurator();
    if (configurator != null) {
        configurator.extractTenantInfo(synCtx);
    }
    TransportInDescription trpInDesc = mc.getTransportIn();
    if (trpInDesc != null) {
        synCtx.setProperty(SynapseConstants.TRANSPORT_IN_NAME, trpInDesc.getName());
    }
    // get service log for this message and attach to the message context also set proxy name
    Log serviceLog = LogFactory.getLog(SynapseConstants.SERVICE_LOGGER_PREFIX + name);
    ((Axis2MessageContext) synCtx).setServiceLog(serviceLog);
    synCtx.setProperty(SynapseConstants.PROXY_SERVICE, name);
    // synCtx.setTracingState(proxy.getTraceState());
    synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_REST, mc.isDoingREST());
    synCtx.setProperty(SynapseConstants.IS_CLIENT_DOING_SOAP11, mc.isSOAP11());
    try {
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.acquireMediationFlowLock();
            debugManager.advertiseMediationFlowStartPoint(synCtx);
            if (!synCtx.isResponse()) {
                SynapseWireLogHolder wireLogHolder = (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY);
                if (wireLogHolder == null) {
                    wireLogHolder = new SynapseWireLogHolder();
                }
                if (synCtx.getProperty(SynapseConstants.PROXY_SERVICE) != null && !synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString().isEmpty()) {
                    wireLogHolder.setProxyName(synCtx.getProperty(SynapseConstants.PROXY_SERVICE).toString());
                }
                ((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY, wireLogHolder);
            }
        }
        synCtx.setProperty(SynapseConstants.RESPONSE_STATE, new ResponseState());
        List handlers = synCtx.getEnvironment().getSynapseHandlers();
        Iterator<SynapseHandler> iterator = handlers.iterator();
        while (iterator.hasNext()) {
            SynapseHandler handler = iterator.next();
            if (!handler.handleRequestInFlow(synCtx)) {
                return;
            }
        }
        Mediator mandatorySeq = synCtx.getConfiguration().getMandatorySequence();
        if (mandatorySeq != null) {
            if (log.isDebugEnabled()) {
                log.debug("Start mediating the message in the " + "pre-mediate state using the mandatory sequence");
            }
            if (!mandatorySeq.mediate(synCtx)) {
                if (log.isDebugEnabled()) {
                    log.debug("Request message for the proxy service " + name + " dropped in " + "the pre-mediation state by the mandatory sequence : \n" + synCtx);
                }
                return;
            }
        }
        // setup fault sequence - i.e. what happens when something goes wrong with this message
        proxy.registerFaultHandler(synCtx);
        boolean inSequenceResult = true;
        // Using inSequence for the incoming message mediation
        if (proxy.getTargetInSequence() != null) {
            Mediator inSequence = synCtx.getSequence(proxy.getTargetInSequence());
            if (inSequence != null) {
                traceOrDebug(traceOn, "Using sequence named : " + proxy.getTargetInSequence() + " for incoming message mediation");
                inSequenceResult = inSequence.mediate(synCtx);
            } else {
                handleException("Unable to find in-sequence : " + proxy.getTargetInSequence(), synCtx);
            }
        } else if (proxy.getTargetInLineInSequence() != null) {
            traceOrDebug(traceOn, "Using the anonymous " + "in-sequence of the proxy service for mediation");
            inSequenceResult = proxy.getTargetInLineInSequence().mediate(synCtx);
        }
        // if inSequence returns true, forward message to endpoint
        if (inSequenceResult) {
            if (proxy.getTargetEndpoint() != null) {
                Endpoint endpoint = synCtx.getEndpoint(proxy.getTargetEndpoint());
                if (endpoint != null) {
                    traceOrDebug(traceOn, "Forwarding message to the endpoint : " + proxy.getTargetEndpoint());
                    endpoint.send(synCtx);
                } else {
                    handleException("Unable to find the endpoint specified : " + proxy.getTargetEndpoint(), synCtx);
                }
            } else if (proxy.getTargetInLineEndpoint() != null) {
                traceOrDebug(traceOn, "Forwarding the message to the anonymous " + "endpoint of the proxy service");
                proxy.getTargetInLineEndpoint().send(synCtx);
            }
        }
    } catch (SynapseException syne) {
        if (!synCtx.getFaultStack().isEmpty()) {
            warn(traceOn, "Executing fault handler due to exception encountered", synCtx);
            ((FaultHandler) synCtx.getFaultStack().pop()).handleFault(synCtx, syne);
        } else {
            warn(traceOn, "Exception encountered but no fault handler found - " + "message dropped", synCtx);
        }
    } finally {
        // Statistic reporting
        if (isStatisticsEnabled) {
            CloseEventCollector.tryEndFlow(synCtx, this.name, ComponentType.PROXYSERVICE, statisticReportingIndex, true);
        }
        if (synCtx.getEnvironment().isDebuggerEnabled()) {
            SynapseDebugManager debugManager = synCtx.getEnvironment().getSynapseDebugManager();
            debugManager.advertiseMediationFlowTerminatePoint(synCtx);
            debugManager.releaseMediationFlowLock();
        }
        doPostInjectUpdates(synCtx);
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) Log(org.apache.commons.logging.Log) SynapseWireLogHolder(org.apache.synapse.transport.http.conn.SynapseWireLogHolder) TransportInDescription(org.apache.axis2.description.TransportInDescription) SynapseHandler(org.apache.synapse.SynapseHandler) SynapseDebugManager(org.apache.synapse.debug.SynapseDebugManager) SynapseException(org.apache.synapse.SynapseException) TenantInfoConfigurator(org.apache.synapse.carbonext.TenantInfoConfigurator) Endpoint(org.apache.synapse.endpoints.Endpoint) List(java.util.List) Mediator(org.apache.synapse.Mediator) MessageContext(org.apache.synapse.MessageContext)

Example 3 with SynapseWireLogHolder

use of org.apache.synapse.transport.http.conn.SynapseWireLogHolder in project wso2-synapse by wso2.

the class SynapseDebugManager method acquireMediationFlowPointProperties.

public void acquireMediationFlowPointProperties(String propertyOrProperties, String propertyContext, JSONObject property_arguments) throws IOException {
    if ((!(this.medFlowState == MediationFlowState.SUSPENDED)) & (propertyContext != null & !propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_WIRE))) {
        this.advertiseCommandResponse(createDebugCommandResponse(false, SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_UNABLE_TO_ACQUIRE_MESSAGE_CONTEXT_PROPERTIES).toString());
        return;
    }
    try {
        if (propertyOrProperties.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTIES)) {
            if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_ALL)) {
                JSONObject data_axis2 = getAxis2Properties();
                JSONObject data_synapse = new JSONObject(((Axis2MessageContext) synCtx).getProperties());
                JSONObject data_axis2_prop = new JSONObject();
                JSONObject data_synapse_prop = new JSONObject();
                data_axis2_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2, data_axis2);
                data_synapse_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_SYNAPSE, data_synapse);
                JSONArray data_array = new JSONArray();
                data_array.put(data_axis2_prop);
                data_array.put(data_synapse_prop);
                debugInterface.getPortListenWriter().println(data_array.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2)) {
                JSONObject data_axis2 = getAxis2Properties();
                JSONObject data_axis2_prop = new JSONObject();
                data_axis2_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2, data_axis2);
                debugInterface.getPortListenWriter().println(data_axis2_prop.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_SYNAPSE) || propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_DEFAULT)) {
                JSONObject data_synapse = new JSONObject(((Axis2MessageContext) synCtx).getProperties());
                JSONObject data_synapse_prop = new JSONObject();
                data_synapse_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_SYNAPSE, data_synapse);
                debugInterface.getPortListenWriter().println(data_synapse_prop.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2CLIENT)) {
                JSONObject data_axis2 = new JSONObject(((Axis2MessageContext) synCtx).getAxis2MessageContext().getOptions().getProperties());
                JSONObject data_axis2_prop = new JSONObject();
                data_axis2_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2CLIENT, data_axis2);
                debugInterface.getPortListenWriter().println(data_axis2_prop.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_TRANSPORT)) {
                JSONObject data_axis2 = new JSONObject((Map) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
                JSONObject data_axis2_prop = new JSONObject();
                data_axis2_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2TRANSPORT, data_axis2);
                debugInterface.getPortListenWriter().println(data_axis2_prop.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_OPERATION)) {
                JSONObject data_axis2 = new JSONObject(((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().getProperties());
                JSONObject data_axis2_prop = new JSONObject();
                data_axis2_prop.put(SynapseDebugCommandConstants.DEBUG_COMMAND_RESPONSE_PROPERTY_CONTEXT_AXIS2OPERATION, data_axis2);
                debugInterface.getPortListenWriter().println(data_axis2_prop.toString());
                debugInterface.getPortListenWriter().flush();
            }
        } else if (propertyOrProperties.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY)) {
            if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2)) {
                JSONObject data_axis2 = getAxis2Properties();
                Object result = null;
                if (data_axis2.has(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME))) {
                    result = data_axis2.get(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME));
                }
                JSONObject json_result = new JSONObject();
                json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME), result);
                debugInterface.getPortListenWriter().println(json_result.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_SYNAPSE) || propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_DEFAULT)) {
                JSONObject data_synapse = new JSONObject(((Axis2MessageContext) synCtx).getProperties());
                Object result = null;
                if (data_synapse.has(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME))) {
                    result = data_synapse.getJSONObject(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME));
                }
                JSONObject json_result = new JSONObject();
                json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME), result);
                debugInterface.getPortListenWriter().println(json_result.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_AXIS2CLIENT)) {
                JSONObject data_axis2 = new JSONObject(((Axis2MessageContext) synCtx).getAxis2MessageContext().getOptions().getProperties());
                Object result = null;
                if (data_axis2.has(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME))) {
                    result = data_axis2.get(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME));
                }
                JSONObject json_result = new JSONObject();
                json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME), result);
                debugInterface.getPortListenWriter().println(json_result.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_TRANSPORT)) {
                JSONObject data_axis2 = new JSONObject((Map) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
                Object result = null;
                if (data_axis2.has(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME))) {
                    result = data_axis2.get(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME));
                }
                JSONObject json_result = new JSONObject();
                json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME), result);
                debugInterface.getPortListenWriter().println(json_result.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_OPERATION)) {
                JSONObject data_axis2 = new JSONObject(((Axis2MessageContext) synCtx).getAxis2MessageContext().getOperationContext().getProperties());
                Object result = null;
                if (data_axis2.has(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME))) {
                    result = data_axis2.get(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME));
                }
                JSONObject json_result = new JSONObject();
                json_result.put(property_arguments.getString(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_NAME), result);
                debugInterface.getPortListenWriter().println(json_result.toString());
                debugInterface.getPortListenWriter().flush();
            } else if (propertyContext.equals(SynapseDebugCommandConstants.DEBUG_COMMAND_PROPERTY_CONTEXT_WIRE)) {
                SynapseWireLogHolder synapseWireLogHolder = (synCtx != null) ? (SynapseWireLogHolder) ((Axis2MessageContext) synCtx).getAxis2MessageContext().getProperty(SynapseDebugInfoHolder.SYNAPSE_WIRE_LOG_HOLDER_PROPERTY) : null;
                JSONObject wireLog = createWireLogResponse(synapseWireLogHolder);
                debugInterface.getPortListenWriter().println(wireLog.toString());
                debugInterface.getPortListenWriter().flush();
                log.debug("wirelog sent to devstudio - " + wireLog.toString());
            }
        }
    } catch (JSONException ex) {
        log.error("Failed to acquire property in the scope: " + propertyContext, ex);
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) SynapseWireLogHolder(org.apache.synapse.transport.http.conn.SynapseWireLogHolder) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) JSONObject(org.codehaus.jettison.json.JSONObject) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 4 with SynapseWireLogHolder

use of org.apache.synapse.transport.http.conn.SynapseWireLogHolder in project wso2-synapse by wso2.

the class SynapseDebugManager method update.

@Override
public void update(Observable o, Object arg) {
    if (synEnv.isDebuggerEnabled()) {
        try {
            // create wirelogs json object and send it to developer studio(this is sent via event port)
            SynapseWireLogHolder synapseWireLogHolder = (SynapseWireLogHolder) arg;
            JSONObject wireLog = createWireLogResponse(synapseWireLogHolder);
            debugInterface.getPortSendWriter().println(wireLog);
            debugInterface.getPortSendWriter().flush();
            log.debug("wire log event got triggered and sent the event to developer studio");
        } catch (JSONException ex) {
            log.error("Failed to create debug event in JSON format", ex);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) SynapseWireLogHolder(org.apache.synapse.transport.http.conn.SynapseWireLogHolder) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

SynapseWireLogHolder (org.apache.synapse.transport.http.conn.SynapseWireLogHolder)4 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 List (java.util.List)1 TransportInDescription (org.apache.axis2.description.TransportInDescription)1 Log (org.apache.commons.logging.Log)1 Mediator (org.apache.synapse.Mediator)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseHandler (org.apache.synapse.SynapseHandler)1 TenantInfoConfigurator (org.apache.synapse.carbonext.TenantInfoConfigurator)1 SynapseDebugManager (org.apache.synapse.debug.SynapseDebugManager)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 RESTDispatcher (org.apache.synapse.rest.dispatch.RESTDispatcher)1 URLBasedVersionStrategy (org.apache.synapse.rest.version.URLBasedVersionStrategy)1 JSONArray (org.codehaus.jettison.json.JSONArray)1