public static Object deserialize(InputStream inputStream, MuleContext muleContext) { if (muleContext == null) { throw new IllegalArgumentException("The MuleContext must not be null"); } return deserialize(inputStream, muleContext.getExecutionClassLoader(), muleContext); }
public static Object deserialize(byte[] objectData, MuleContext muleContext) { if (muleContext == null) { throw new IllegalArgumentException("The MuleContext must not be null"); } return deserialize(objectData, muleContext.getExecutionClassLoader(), muleContext); }
/** * {@inheritDoc} */ @Override public <T> T deserialize(byte[] bytes) throws SerializationException { return deserialize(bytes, muleContext.getExecutionClassLoader()); }
/** * {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <T> T deserialize(InputStream inputStream) throws SerializationException { return deserialize(inputStream, muleContext.getExecutionClassLoader()); }
static public String replaceClasspathInStringForCurrentPath(String path, Class<?> clazz, MuleContext muleContext) throws FileNotFoundException { if (path == null || !path.contains("classpath:")) { return path; } path = path.replace("classpath:", ""); URL resource = clazz.getClassLoader().getResource(path); if (resource != null) { return resource.getPath(); } else { /* * The Application ClassLoader of a Mule Application runs as a Child classLoader of the Plugin, so the getClass().getClassLoader() * will not see the App classLoader. * The only way to get it is asking for the MuleContext and requesting the execution ClassLoader */ ClassLoader executionClassLoader = muleContext != null ? muleContext.getExecutionClassLoader() : null; if (executionClassLoader != null) { resource = executionClassLoader.getResource(path); if (resource != null) { return resource.getPath(); } } } throw new FileNotFoundException("Can not locate the file " + path); } }
@Override public ClassLoader getExecutionClassLoader() { return messageReceiver.getEndpoint().getMuleContext().getExecutionClassLoader(); }
protected ServiceDescriptor createServiceDescriptor(ServiceType type, String name, Properties overrides) throws ServiceException { //Stripe off and use the meta-scheme if present String scheme = name; if (name.contains(":")) { scheme = name.substring(0, name.indexOf(":")); } Properties props = SpiUtils.findServiceDescriptor(type, scheme); if (props == null) { throw new ServiceException(CoreMessages.failedToLoad(type + " " + scheme)); } return ServiceDescriptorFactory.create(type, name, props, overrides, muleContext, muleContext.getExecutionClassLoader()); }
@Override public void initialise() throws InitialisationException { if (name == null) { name = UUID.getUUID(); } if (expirationInterval <= 0) { throw new IllegalArgumentException(CoreMessages.propertyHasInvalidValue("expirationInterval", new Integer(expirationInterval)).toString()); } if (scheduler == null) { this.scheduler = new ScheduledThreadPoolExecutor(1); scheduler.setThreadFactory(new DaemonThreadFactory(name + "-Monitor", context.getExecutionClassLoader())); scheduler.scheduleWithFixedDelay(this, 0, expirationInterval, TimeUnit.MILLISECONDS); } }
protected void registerConfigurationService() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { ObjectName on = jmxSupport.getObjectName(String.format("%s:%s", jmxSupport.getDomainName(muleContext, !containerMode), MuleConfigurationServiceMBean.DEFAULT_JMX_NAME)); MuleConfigurationServiceMBean service = new MuleConfigurationService(muleContext.getConfiguration()); ClassloaderSwitchingMBeanWrapper mBean = new ClassloaderSwitchingMBeanWrapper(service, MuleConfigurationServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering configuration with name: " + on); mBeanServer.registerMBean(mBean, on); }
protected void registerMuleService() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { ObjectName on = jmxSupport.getObjectName(String.format("%s:%s", jmxSupport.getDomainName(muleContext, !containerMode), MuleServiceMBean.DEFAULT_JMX_NAME)); if (muleContext.getConfiguration().isContainerMode() && mBeanServer.isRegistered(on)) { // while in container mode, a previous stop() action leaves MuleContext MBean behind for remote start() operation return; } MuleService service = new MuleService(muleContext); ClassloaderSwitchingMBeanWrapper serviceMBean = new ClassloaderSwitchingMBeanWrapper(service, MuleServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering mule with name: " + on); mBeanServer.registerMBean(serviceMBean, on); }
protected void registerStatisticsService() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { ObjectName on = jmxSupport.getObjectName(String.format("%s:%s", jmxSupport.getDomainName(muleContext, !containerMode), StatisticsServiceMBean.DEFAULT_JMX_NAME)); StatisticsService service = new StatisticsService(); service.setMuleContext(muleContext); service.setEnabled(isEnableStatistics()); ClassloaderSwitchingMBeanWrapper mBean = new ClassloaderSwitchingMBeanWrapper(service, StatisticsServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering statistics with name: " + on); mBeanServer.registerMBean(mBean, on); }
private static Properties getErrorMappings(String protocol, final MuleContext muleContext) { Properties m = errorMappings.get(getErrorMappingCacheKey(protocol,muleContext)); if (m != null) { return m; } else { String name = SpiUtils.SERVICE_ROOT + ServiceType.EXCEPTION.getPath() + "/" + protocol + "-exception-mappings.properties"; Properties p = PropertiesUtils.loadAllProperties(name, muleContext.getExecutionClassLoader()); errorMappings.put(getErrorMappingCacheKey(protocol, muleContext), p); registerAppDisposeListener(muleContext); return p; } }
protected Comparator<File> getComparator() throws Exception { Object comparatorClassName = getEndpoint().getProperty(COMPARATOR_CLASS_NAME_PROPERTY); if (comparatorClassName != null) { Object reverseProperty = this.getEndpoint().getProperty(COMPARATOR_REVERSE_ORDER_PROPERTY); boolean reverse = false; if (reverseProperty != null) { reverse = Boolean.valueOf((String) reverseProperty); } Class<?> clazz = endpoint.getMuleContext().getExecutionClassLoader().loadClass(comparatorClassName.toString()); Comparator<?> comparator = (Comparator<?>)clazz.newInstance(); return reverse ? new ReverseComparator(comparator) : (Comparator<File>)comparator; } return null; } }
protected void registerServiceServices() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { for (String rawName : muleContext.getRegistry().lookupByType(Service.class).keySet()) { final String escapedName = jmxSupport.escape(rawName); final String jmxName = String.format("%s:%s%s", jmxSupport.getDomainName(muleContext, !containerMode), ServiceServiceMBean.DEFAULT_JMX_NAME_PREFIX, escapedName); ObjectName on = jmxSupport.getObjectName(jmxName); ServiceServiceMBean serviceMBean = new ServiceService(rawName, muleContext); ClassloaderSwitchingMBeanWrapper wrapper = new ClassloaderSwitchingMBeanWrapper(serviceMBean, ServiceServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering service with name: " + on); mBeanServer.registerMBean(wrapper, on); } }
protected void registerConnectorServices() throws MalformedObjectNameException, NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException { for (String rawName : muleContext.getRegistry().lookupByType(Connector.class).keySet()) { Connector connector = muleContext.getRegistry().lookupObject(rawName); ConnectorServiceMBean service = new ConnectorService(connector); final String name = jmxSupport.escape(rawName); final String jmxName = String.format("%s:%s%s", jmxSupport.getDomainName(muleContext, !containerMode), ConnectorServiceMBean.DEFAULT_JMX_NAME_PREFIX, name); if (logger.isDebugEnabled()) { logger.debug("Attempting to register service with name: " + jmxName); } ObjectName oName = jmxSupport.getObjectName(jmxName); ClassloaderSwitchingMBeanWrapper mBean = new ClassloaderSwitchingMBeanWrapper(service, ConnectorServiceMBean.class, muleContext.getExecutionClassLoader()); mBeanServer.registerMBean(mBean, oName); logger.info("Registered Connector Service with name " + oName); } }
protected void registerApplicationServices() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { FlowConstructStatistics appStats = muleContext.getStatistics().getApplicationStatistics(); if (appStats != null) { final String rawName = appStats.getName(); final String name = jmxSupport.escape(rawName); final String jmxName = String.format("%s:type=%s,name=%s", jmxSupport.getDomainName(muleContext, !containerMode), appStats.getFlowConstructType(), name); ObjectName on = jmxSupport.getObjectName(jmxName); FlowConstructServiceMBean fcMBean = new ApplicationService(appStats.getFlowConstructType(), rawName, muleContext,appStats); ClassloaderSwitchingMBeanWrapper wrapper = new ClassloaderSwitchingMBeanWrapper(fcMBean, FlowConstructServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering application statistics with name: " + on); mBeanServer.registerMBean(wrapper, on); } }
protected void registerModelServices() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { for (String registryName: muleContext.getRegistry().lookupByType(Model.class).keySet()) { Model model = muleContext.getRegistry().lookupObject(registryName); ModelServiceMBean service = new ModelService(model); String rawName = registryName + "(" + service.getType() + ")"; String name = jmxSupport.escape(rawName); final String jmxName = String.format("%s:%s%s", jmxSupport.getDomainName(muleContext, !containerMode), ModelServiceMBean.DEFAULT_JMX_NAME_PREFIX, name); ObjectName on = jmxSupport.getObjectName(jmxName); ClassloaderSwitchingMBeanWrapper mBean = new ClassloaderSwitchingMBeanWrapper(service, ModelServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering model with name: " + on); mBeanServer.registerMBean(mBean, on); } }
@Override public void handleRequest(HttpRequestContext requestContext, HttpResponseReadyCallback responseCallback) { try { final HttpMessageProcessorTemplate httpMessageProcessorTemplate = new HttpMessageProcessorTemplate(createEvent(requestContext), messageProcessor, responseCallback, responseBuilder, errorResponseBuilder); final HttpMessageProcessContext messageProcessContext = new HttpMessageProcessContext(DefaultHttpListener.this, flowConstruct, config.getWorkManager(), muleContext.getExecutionClassLoader()); messageProcessingManager.processMessage(httpMessageProcessorTemplate, messageProcessContext); } catch (HttpRequestParsingException | IllegalArgumentException e) { logger.warn("Exception occurred parsing request:", e); sendErrorResponse(BAD_REQUEST, e.getMessage(), responseCallback); } catch (RuntimeException e) { logger.warn("Exception occurred processing request:", e); sendErrorResponse(INTERNAL_SERVER_ERROR, SERVER_PROBLEM, responseCallback); } finally { RequestContext.clear(); } }
protected void registerFlowConstructServices() throws NotCompliantMBeanException, MBeanRegistrationException, InstanceAlreadyExistsException, MalformedObjectNameException { for (String rawName : muleContext.getRegistry().lookupByType(AbstractFlowConstruct.class).keySet()) { AbstractFlowConstruct flowConstruct = muleContext.getRegistry().lookupObject(rawName); final String name = jmxSupport.escape(rawName); final String jmxName = String.format("%s:type=%s,name=%s", jmxSupport.getDomainName(muleContext, !containerMode), flowConstruct.getConstructType(), name); ObjectName on = jmxSupport.getObjectName(jmxName); FlowConstructServiceMBean fcMBean = new FlowConstructService(flowConstruct.getConstructType(), rawName, muleContext, flowConstruct.getStatistics()); ClassloaderSwitchingMBeanWrapper wrapper = new ClassloaderSwitchingMBeanWrapper(fcMBean, FlowConstructServiceMBean.class, muleContext.getExecutionClassLoader()); logger.debug("Registering service with name: " + on); mBeanServer.registerMBean(wrapper, on); } }
protected <T> T deserialize(MuleMessage message, byte[] bytes) { T object = objectSerializerLocator.getObjectSerializer(message).deserialize(bytes, message.getMuleContext().getExecutionClassLoader()); if (object instanceof DeserializationPostInitialisable) { try { DeserializationPostInitialisable.Implementation.init(object, message.getMuleContext()); } catch (Exception e) { throw new SerializationException("Could not initialise session after deserialization", e); } } return object; }