/*
(non-Javadoc)

@see org.restcomm.protocols.ss7.map.api.MAPServiceBase#isServingService(org
.mobicents.protocols.ss7.map.api.MAPApplicationContext)
965383
public ServingCheckData isServingService(MAPApplicationContext dialogApplicationContext) {

        int vers = dialogApplicationContext.getApplicationContextVersion().getVersion();

        switch (dialogApplicationContext.getApplicationContextName()) {
            case locationSvcEnquiryContext:
            case locationSvcGatewayContext:
                if (vers == 3) {
                    return new ServingCheckDataImpl(ServingCheckResult.AC_Serving);
                } else if (vers > 3) {
                    long[] altOid = dialogApplicationContext.getOID();
                    altOid[7] = 3;
                    ApplicationContextName alt = TcapFactory.createApplicationContextName(altOid);
                    return new ServingCheckDataImpl(ServingCheckResult.AC_VersionIncorrect, alt);
                } else {
                    return new ServingCheckDataImpl(ServingCheckResult.AC_VersionIncorrect);
                }
        }

        return new ServingCheckDataImpl(ServingCheckResult.AC_NotServing);
    }
645126
public static void putRegisteredService(final RequestContext context, final RegisteredService registeredService) {
        context.getFlowScope().put(PARAMETER_REGISTERED_SERVICE, registeredService);
    }
157404
private void updateServiceCache(String serviceName, ConcurrentHashMap<String, List<URL>> serviceUrls, boolean needNotify) {
        if (serviceUrls != null && !serviceUrls.isEmpty()) {
            List<URL> urls = serviceCache.get(serviceName);
            if (urls == null) {
                if(logger.isDebugEnabled()) {
                    try {
                        logger.debug("serviceUrls = " + Config.getInstance().getMapper().writeValueAsString(serviceUrls));
                    } catch(Exception e) {
                    }
                }
                serviceCache.put(serviceName, serviceUrls.get(serviceName));
            }
            for (Map.Entry<String, List<URL>> entry : serviceUrls.entrySet()) {
                boolean change = true;
                if (urls != null) {
                    List<URL> newUrls = entry.getValue();
                    if (newUrls == null || newUrls.isEmpty() || ConsulUtils.isSame(newUrls, urls)) {
                        change = false;
                    } else {
                        serviceCache.put(serviceName, newUrls);
                    }
                }
                if (change && needNotify) {
                    notifyExecutor.execute(new NotifyService(entry.getKey(), entry.getValue()));
                    logger.info("light service notify-service: " + entry.getKey());
                    StringBuilder sb = new StringBuilder();
                    for (URL url : entry.getValue()) {
                        sb.append(url.getUri()).append(";");
                    }
                    logger.info("consul notify urls:" + sb.toString());
                }
            }
        }
    }
762140
public static void putServiceTicketInRequestScope(final RequestContext context, final ServiceTicket ticketValue) {
        context.getRequestScope().put(PARAMETER_SERVICE_TICKET_ID, ticketValue.getId());
    }
762867
@Override
    public void setApplicationContext(ApplicationContext appContext) throws BeansException {
        try (InputStream is = originalResource.getInputStream();) {
            ConfigurableListableBeanFactory beanFactory = ((AbstractRefreshableApplicationContext) appContext)
                    .getBeanFactory();
            StringBuilder sb = new StringBuilder();
            Iterator<String> iter = IOUtils.lineIterator(is, "UTF-8");
            boolean transformed = false;
            
            while (iter.hasNext()) {
                String line = iter.next();
                
                if (line.contains("${")) {
                    transformed = true;
                    line = beanFactory.resolveEmbeddedValue(line);
                }
                
                sb.append(line);
            }
            
            transformedResource = !transformed ? originalResource : new ByteArrayResource(sb.toString().getBytes());
        } catch (IOException e) {
            throw MiscUtil.toUnchecked(e);
        }
    }
1322890
@Override
    public void setApplicationContext(ApplicationContext appContext) throws BeansException {
        if (this.appContext != null) {
            throw new ApplicationContextException("Attempt to reinitialize application context.");
        }
        
        this.appContext = appContext;
    }
284763
public static boolean isAuthorizedGrantTypeForService(final J2EContext context, final OAuthRegisteredService registeredService) {
        return isAuthorizedGrantTypeForService(
            context.getRequestParameter(OAuth20Constants.GRANT_TYPE),
            registeredService);
    }
865138
@Reference(name = "contextService", service = WSContextService.class)
    protected void setContextService(ServiceReference<WSContextService> ref) {
        contextServiceRef.setReference(ref);
    }
1242121
@Override
    public void afterServiceInvoke(Object serviceObject, boolean isSingleton, Object context) {
        @SuppressWarnings("unchecked")
        Map<Class<?>, ManagedObject<?>> newContext = (Map<Class<?>, ManagedObject<?>>) (context);

        ManagedObject<?> mo = newContext.get(serviceObject.getClass());
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "afterServiceInvoke mo=" + mo + " isSingleton=" + isSingleton + " newContext={0}", newContext);
        }
        if (!isSingleton) {
            if (mo != null) {
                mo.release();
            }
            newContext.put(serviceObject.getClass(), null);
        }

    }
378290
protected final void configureWebAppContext(WebAppContext context,
			ServletContextInitializer... initializers) {
		Assert.notNull(context, "Context must not be null");
		context.setTempDirectory(getTempDirectory());
		if (this.resourceLoader != null) {
			context.setClassLoader(this.resourceLoader.getClassLoader());
		}
		String contextPath = getContextPath();
		context.setContextPath(StringUtils.hasLength(contextPath) ? contextPath : "/");
		context.setDisplayName(getDisplayName());
		configureDocumentRoot(context);
		if (isRegisterDefaultServlet()) {
			addDefaultServlet(context);
		}
		if (shouldRegisterJspServlet()) {
			addJspServlet(context);
			context.addBean(new JasperInitializer(context), true);
		}
		addLocaleMappings(context);
		ServletContextInitializer[] initializersToUse = mergeInitializers(initializers);
		Configuration[] configurations = getWebAppContextConfigurations(context,
				initializersToUse);
		context.setConfigurations(configurations);
		context.setThrowUnavailableOnStartupException(true);
		configureSession(context);
		postProcessWebAppContext(context);
	}
311779
@Override
    public ManagedService addingService(ServiceReference<ManagedService> reference) {
        String[] pids = getServicePid(reference);
        if (pids == null) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "handleRegistration(): Invalid service.pid type: " + reference);
            }
            return null;
        }

        ManagedService ms = context.getService(reference);
        if (ms == null)
            return null;

        synchronized (caFactory.getConfigurationStore()) {
            for (String pid : pids) {
                add(reference, pid, ms);
            }
        }

        return ms;
    }
564393
public void submitContextAndService(final String evaluatorConfiguration,
                                      final String contextConfiguration,
                                      final String serviceConfiguration) {
    launchWithConfigurationString(evaluatorConfiguration, contextConfiguration,
        Optional.of(serviceConfiguration), Optional.<String>empty());
  }
122446
@Override
    public boolean regiserService(NaviRpcExporter exporter) {
        Class<?> interf = exporter.getServiceInterface();
        Object bean = exporter.getServiceBean();
        List<AppIdToken> appIdTokens = getAuthIfPossible(bean);
        String interfSimpleName = interf.getSimpleName();
        try {
            exporters.put(exporter.getName(), exporter);
            if (interf.isAssignableFrom(bean.getClass())) {
                Method[] ms = ReflectionUtil.getAllInstanceMethods(bean.getClass());
                for (Method m : ms) {
                    if (methodResolver.isSupport(m)) {
                        MethodWrapper methodWrapper = new MethodWrapper(interf.getName(),
                                m.getName(), MethodUtil.getArgsTypeName(m));
                        MethodWrapper defaultMethodWrapper = new MethodWrapper(interf.getName(),
                                m.getName(), StringUtil.EMPTY);
                        String key = methodWrapper.toString();
                        MethodDescriptor<String> desc = new MethodDescriptor<String>();
                        desc.setServiceId(key).setMethod(m).setTarget(bean)
                                .setArgumentClass(m.getParameterTypes())
                                .setReturnClass(m.getReturnType()).setInterfClass(interf).setAppIdTokens(appIdTokens);
                        serviceRegistry.addServiceDescriptor(key, desc);
                        serviceRegistry.addServiceDescriptor(defaultMethodWrapper.toString(), desc);
                        if (LOG.isDebugEnabled()) {
                            LOG.debug(String.format(
                                    "Register service key=[%s], %s %s#%s(%s) successfully", key, m
                                            .getReturnType().getSimpleName(), interf.getName(), m
                                            .getName(), StringUtil.toString4Array(m
                                            .getParameterTypes())));
                        }
                    }
                }
                LOG.info("Find rpc service configured, interface is "
                        + interfSimpleName + " , implementation is "
                        + AopUtils.getTargetClass(bean).getName());
                return true;
            } else {
                LOG.error("The interface " + interfSimpleName + " is not compatible with the bean "
                        + bean.getClass().getName());
            }
        } catch (Exception e) {
            LOG.error(
                    "The interface " + interfSimpleName + " is configured wrongly."
                            + e.getMessage(), e);
        }
        return false;
    }
499292
protected void configureMessageEndpoint(ApplicationContext context) {
        if (context.containsBean(MESSAGE_ENDPOINT_BEAN_NAME)) {
            WebServiceEndpoint messageEndpoint = context.getBean(MESSAGE_ENDPOINT_BEAN_NAME, WebServiceEndpoint.class);

            EndpointAdapter endpointAdapter = webServiceServer.getEndpointAdapter();
            if (endpointAdapter != null) {
                messageEndpoint.setEndpointAdapter(endpointAdapter);
            }

            WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration();
            endpointConfiguration.setHandleMimeHeaders(webServiceServer.isHandleMimeHeaders());
            endpointConfiguration.setHandleAttributeHeaders(webServiceServer.isHandleAttributeHeaders());
            endpointConfiguration.setKeepSoapEnvelope(webServiceServer.isKeepSoapEnvelope());
            endpointConfiguration.setMessageConverter(webServiceServer.getMessageConverter());
            messageEndpoint.setEndpointConfiguration(endpointConfiguration);

            if (StringUtils.hasText(webServiceServer.getSoapHeaderNamespace())) {
                messageEndpoint.setDefaultNamespaceUri(webServiceServer.getSoapHeaderNamespace());
            }

            if (StringUtils.hasText(webServiceServer.getSoapHeaderPrefix())) {
                messageEndpoint.setDefaultPrefix(webServiceServer.getSoapHeaderPrefix());
            }
        }
    }
90810
public static RegisteredService getRegisteredService(final RequestContext context) {
        return context != null ? (RegisteredService) context.getFlowScope().get(PARAMETER_REGISTERED_SERVICE) : null;
    }
572894
public Object addingService(ServiceReference reference)
    {
        HttpService httpService = (HttpService) context.getService(reference);

        this.properties = this.updateDictionaryConfig(this.properties, true);
        try {
            String alias = this.getAlias();
            String servicePid = this.properties.get(BundleConstants.SERVICE_PID);
            if (servlet == null)
            {
                servlet = this.makeServlet(alias, this.properties);
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).init(context, servicePid, this.properties);
            }
            else
                if (servlet instanceof WebappServlet)
                    ((WebappServlet) servlet).setProperties(properties);
            if (servicePid != null)   // Listen for configuration changes
                serviceRegistration = context.registerService(ManagedService.class.getName(), new HttpConfigurator(context, servicePid), this.properties);

            httpService.registerServlet(alias, servlet, this.properties, httpContext);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return httpService;
    }
474708
public static boolean availableApplicationContextVersion(MAPApplicationContextName contextName, int contextVersion) {
        switch (contextName) {

        // -- Mobility Services
        // --- Location management services
            case networkLocUpContext:
            case locationCancellationContext:
            case gprsLocationUpdateContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case interVlrInfoRetrievalContext:
            case msPurgingContext:
                if (contextVersion >= 2 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case mmEventReportingContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // --- Handover services
            case handoverControlContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;

                // --- Authentication management services
            case infoRetrievalContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case authenticationFailureReportContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // --- IMEI management services
            case equipmentMngtContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;

                // --- Subscriber management services
            case subscriberDataMngtContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;

                // --- Fault recovery services
            case resetContext:
                if (contextVersion >= 1 && contextVersion <= 2)
                    return true;
                else
                    return false;

                // --- Subscriber Information services
            case anyTimeEnquiryContext:
            case subscriberInfoEnquiryContext:
            case anyTimeInfoHandlingContext:
            case subscriberDataModificationNotificationContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // -- oam
            case tracingContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case imsiRetrievalContext:
                if (contextVersion == 2)
                    return true;
                else
                    return false;

                // -- Call Handling Services
            case locationInfoRetrievalContext:
            case roamingNumberEnquiryContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case callControlTransferContext:
                if (contextVersion >= 3 && contextVersion <= 4)
                    return true;
                else
                    return false;
            case groupCallControlContext:
            case groupCallInfoRetrievalContext:
            case reportingContext:
            case istAlertingContext:
            case ServiceTerminationContext:
            case resourceManagementContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // -- Supplementary services
            case networkFunctionalSsContext:
                if (contextVersion >= 1 && contextVersion <= 2)
                    return true;
                else
                    return false;
            case networkUnstructuredSsContext:
                if (contextVersion == 2)
                    return true;
                else
                    return false;
            case ssInvocationNotificationContext:
            case callCompletionContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // -- short message service
            case shortMsgGatewayContext:
            case shortMsgMORelayContext:
            case shortMsgMTRelayContext:
            case mwdMngtContext:
                if (contextVersion >= 1 && contextVersion <= 3)
                    return true;
                else
                    return false;
            case shortMsgMTVgcsRelayContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;
            case shortMsgAlertContext:
                if (contextVersion >= 1 && contextVersion <= 2)
                    return true;
                else
                    return false;

                // -- Network-Requested PDP Context Activation services
            case gprsLocationInfoRetrievalContext:
                if (contextVersion >= 3 && contextVersion <= 4)
                    return true;
                else
                    return false;
            case failureReportContext:
            case gprsNotifyContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;

                // -- Location Service (lms)
            case locationSvcEnquiryContext:
            case locationSvcGatewayContext:
                if (contextVersion == 3)
                    return true;
                else
                    return false;
        }

        return false;
    }