/** * Removes all Synapse proxy services from the Axis2 configuration. * * @throws AxisFault if an error occurs undeploying proxy services */ private void undeployProxyServices() throws AxisFault { log.info("Undeploying Proxy services..."); for (ProxyService proxy : synapseConfiguration.getProxyServices()) { configurationContext.getAxisConfiguration().removeService(proxy.getName()); } }
/** Constructor. Creates a new Reactor and starts it. */ public static void start() throws Exception { rtspService = new RtspService(); rtspService.start(); rtpClientService = new RtpClientService(); rtpClientService.start(); rtpServerService = new RtpServerService(); rtpServerService.start(); }
/** Adds all Synapse proxy services to the Axis2 configuration. */ private void deployProxyServices() { boolean failSafeProxyEnabled = SynapseConfigUtils.isFailSafeEnabled(SynapseConstants.FAIL_SAFE_MODE_PROXY_SERVICES); log.info("Deploying Proxy services..."); String thisServerName = serverConfigurationInformation.getServerName(); if (thisServerName == null || "".equals(thisServerName)) { thisServerName = serverConfigurationInformation.getHostName(); if (thisServerName == null || "".equals(thisServerName)) { thisServerName = "localhost"; } } for (ProxyService proxy : synapseConfiguration.getProxyServices()) { // start proxy service if either, pinned server name list is empty // or pinned server list has this server name List pinnedServers = proxy.getPinnedServers(); if (pinnedServers != null && !pinnedServers.isEmpty()) { if (!pinnedServers.contains(thisServerName)) { log.info( "Server name not in pinned servers list." + " Not deploying Proxy service : " + proxy.getName()); continue; } } try { AxisService proxyService = proxy.buildAxisService( synapseConfiguration, configurationContext.getAxisConfiguration()); if (proxyService != null) { log.info("Deployed Proxy service : " + proxy.getName()); if (!proxy.isStartOnLoad()) { proxy.stop(synapseConfiguration); } } else { log.warn("The proxy service " + proxy.getName() + " will NOT be available"); } } catch (SynapseException e) { if (failSafeProxyEnabled) { log.warn( "The proxy service " + proxy.getName() + " cannot be deployed - " + "Continue in Proxy Service fail-safe mode."); } else { handleException("The proxy service " + proxy.getName() + " : Deployment Error"); } } } }
public static void stop() { try { // registry.unbindAll(); if (rtspService != null) rtspService.stop(); if (rtpClientService != null) rtpClientService.stop(); if (rtpServerService != null) rtpServerService.stop(); } catch (Exception e) { log.debug("Error shutting down: " + e); } log.info("Shutdown completed"); if (isStandalone) Runtime.getRuntime().halt(0); }
@Override protected void handlePost(HttpRequest request, String data) { String uri = request.getPath(); if (uri.startsWith(JSCOVERAGE_STORE)) { File reportDir = configuration.getReportDir(); if (uri.length() > JSCOVERAGE_STORE.length()) { reportDir = new File(reportDir, uri.substring(JSCOVERAGE_STORE.length())); } try { List<ScriptLinesAndSource> unloadJSData = null; if (configuration.isIncludeUnloadedJS()) unloadJSData = unloadedSourceProcessor.getEmptyCoverageData(uris); jsonDataSaver.saveJSONData(reportDir, data, unloadJSData); ioService.generateJSCoverFilesForWebServer(reportDir, configuration.getVersion()); sendResponse(HTTP_STATUS.HTTP_OK, MIME.TEXT_PLAIN, "Coverage data stored at " + reportDir); } catch (Throwable t) { t.printStackTrace(); String message = format("Error saving coverage data. Try deleting JSON file at %s\n", reportDir); sendResponse(HTTP_STATUS.HTTP_OK, MIME.TEXT_PLAIN, message); } } else { if (configuration.isProxy()) proxyService.handleProxyPost(request, data, os); else super.handlePost(request, data); } }
private void handleException(String msg, MessageContext msgContext) { log.error(msg); if (msgContext.getServiceLog() != null) { msgContext.getServiceLog().error(msg); } if (proxy.getAspectConfiguration().isTracingEnabled()) { trace.error(msg); } throw new SynapseException(msg); }
@Override protected void handleGet(HttpRequest request) throws IOException { String uri = request.getPath(); try { if (uri.equals("/jscoverage.js")) { sendResponse( HTTP_STATUS.HTTP_OK, request.getMime(), ioService.generateJSCoverageServerJS()); } else if (uri.startsWith("/jscoverage.html")) { String reportHTML = ioService.generateJSCoverageHtml(configuration.getVersion()); sendResponse(HTTP_STATUS.HTTP_OK, request.getMime(), reportHTML); } else if (uri.startsWith("/jscoverage")) { sendResponse(HTTP_STATUS.HTTP_OK, request.getMime(), ioService.getResourceAsStream(uri)); } else if (uri.endsWith(".js") && !configuration.skipInstrumentation(uri.substring(1))) { String jsInstrumented; if (configuration.isProxy()) { String originalJS = proxyService.getUrl(request.getUrl()); jsInstrumented = instrumenterService.instrumentJSForWebServer( configuration.getCompilerEnvirons(), originalJS, uri, configuration.isIncludeBranch()); } else { if (configuration.isIncludeUnloadedJS()) uris.add(uri.substring(1)); jsInstrumented = instrumenterService.instrumentJSForWebServer( configuration.getCompilerEnvirons(), new File(wwwRoot, uri), uri, configuration.isIncludeBranch()); } sendResponse(HTTP_STATUS.HTTP_OK, MIME.JS, jsInstrumented); } else { if (configuration.isProxy()) proxyService.handleProxyGet(request, os); else super.handleGet(request); } } catch (Throwable e) { StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); sendResponse( HTTP_STATUS.HTTP_INTERNAL_SERVER_ERROR, MIME.TEXT_PLAIN, stringWriter.toString()); } }
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 = mc.getAttachmentMap().getAllContentIDs(); 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(); } } }
@Override protected void handleHead(HttpRequest request) { if (configuration.isProxy()) proxyService.handleProxyHead(request, os); else super.handleHead(request); }