private Externalizer findExternalizer() { if (encoding != 0x01) return null; return ((ExternalizersConfig)GraniteContext.getCurrentInstance().getGraniteConfig()).getExternalizer(type); }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Map<String, Object> cache = context.getApplicationMap(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); String key = TideServiceInvoker.class.getName() + '.' + destinationId; return getServiceInvoker(cache, destination, key); }
protected Channel getChannel() { if (channel == null) { String channelId = context.getAMFContext().getChannelId(); if (channelId != null) channel = context.getServicesConfig().findChannelById(channelId); if (channel == null) log.debug("Could not get channel for channel id: %s", channelId); } return channel; } }
public void removeFromCache(String destinationId) { GraniteContext context = GraniteContext.getCurrentInstance(); String key = getUniqueKey(destinationId); // Synchronize on unique key. synchronized (key) { context.getApplicationMap().remove(key); Map<String, Object> sessionMap = context.getSessionMap(false); if (sessionMap != null) context.getSessionMap().remove(key); } }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Map<String, Object> cache = context.getSessionMap(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); String key = TideServiceInvoker.class.getName() + '.' + destinationId; return getServiceInvoker(cache, destination, key); }
public AMF3Serializer(OutputStream out, int capacity) { this.out = out; this.buffer = new byte[capacity]; this.position = 0; this.storedStrings = new StringIndexedCache(); this.storedObjects = new ObjectIndexedCache(); this.storedClassDescriptors = new IdentityHashMap<Class<?>, IndexedJavaClassDescriptor>(); this.writersCache = new IdentityHashMap<Class<?>, AMF3Writer>(64); GraniteContext context = GraniteContext.getCurrentInstance(); ConvertersConfig convertersConfig = (ConvertersConfig)context.getGraniteConfig(); this.converters = convertersConfig.getConverters(); this.classGetter = convertersConfig.getClassGetter(); this.xmlUtil = XMLUtilFactory.getXMLUtil(); this.externalizersConfig = (ExternalizersConfig)context.getGraniteConfig(); this.externalizeLong = (externalizersConfig.getExternalizer(Long.class.getName()) != null); this.externalizeBigInteger = (externalizersConfig.getExternalizer(BigInteger.class.getName()) != null); this.externalizeBigDecimal = (externalizersConfig.getExternalizer(BigDecimal.class.getName()) != null); String channelId = context.getAMFContext().getChannelId(); ChannelConfig channelConfig = context.getServicesConfig(); this.legacyXmlSerialization = getChannelProperty(channelId, channelConfig, "legacyXmlSerialization"); this.legacyCollectionSerialization = getChannelProperty(channelId, channelConfig, "legacyCollectionSerialization"); }
private Message handlePublishMessage(final ChannelFactory<?> channelFactory, final AsyncMessage message, final Channel channel) { GraniteContext context = GraniteContext.getCurrentInstance(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById( message.getClass().getName(), message.getDestination() return authorize((GraniteConfig)context.getGraniteConfig(), message, invocationContext);
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); GraniteContext context = GraniteContext.getCurrentInstance(); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId); destination.addRemoveListener(this); Map<String, Object> cache = getCache(destination); String key = SimpleServiceInvoker.class.getName() + '.' + destination.getId(); if (invalidKeys.contains(key)) { cache.remove(key); invalidKeys.remove(key); } SimpleServiceInvoker service = (SimpleServiceInvoker)cache.get(key); if (service == null) { service = new SimpleServiceInvoker(destination, this); cache.put(key, service); } return service; }
private Map<String, Object> getCache(Destination destination) throws ServiceException { GraniteContext context = GraniteContext.getCurrentInstance(); String scope = destination.getProperties().get("scope"); Map<String, Object> cache = null; if (scope == null || "request".equals(scope)) cache = context.getRequestMap(); else if ("session".equals(scope)) cache = context.getSessionMap(); else if ("application".equals(scope)) cache = Collections.synchronizedMap(context.getApplicationMap()); else throw new ServiceException("Illegal scope in destination: " + destination); return cache; } }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { GraniteContext context = GraniteContext.getCurrentInstance(); invoker = (EjbServiceInvoker)context.getApplicationMap().get(key); if (invoker == null) { Map<String, Object> sessionMap = context.getSessionMap(false); if (sessionMap != null) invoker = (EjbServiceInvoker)sessionMap.get(key); Destination destination = ((ServicesConfig)context.getServicesConfig()).findDestinationById( request.getClass().getName(), destinationId context.getSessionMap(true) : context.getApplicationMap();
return externalizer; if ("java".equals(GraniteContext.getCurrentInstance().getClientType())) {
/** * A security service can optionally indicate that it's able to authorize requests that are not HTTP requests * (websockets). In this case the method {@link SecurityService#authorize(AbstractSecurityContext)} will be * invoked in a {@link ServletGraniteContext} and not in a {@link HttpGraniteContext} * @return true is a {@link HttpGraniteContext} is mandated */ public boolean acceptsContext() { return GraniteContext.getCurrentInstance() instanceof ServletGraniteContext; }
@Override protected void beforeInvocation(ServiceInvocationContext context) { RemotingMessage message = (RemotingMessage)context.getMessage(); GraniteContext graniteContext = GraniteContext.getCurrentInstance(); graniteContext.getRequestMap().put(TideServiceInvoker.class.getName(), this); Converters converters = ((ConvertersConfig)graniteContext.getGraniteConfig()).getConverters(); DataEnabled dataEnabled = cClass.getAnnotation(DataEnabled.class); if (dataEnabled != null && !dataEnabled.useInterceptor()) { graniteContext.getRequestMap().put(DATAENABLED_HANDLED, true); DataContext.init(dataEnabled.topic(), dataEnabled.params(), dataEnabled.publish()); prepareDataObserver(dataEnabled);
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { GraniteContext context = GraniteContext.getCurrentInstance(); if (context == null) throw new ServletException( "No GraniteContext (" + AMFMessageFilter.class.getName() + " not configured in web.xml ?)"); AMFContextImpl amf = (AMFContextImpl)context.getAMFContext(); AMF0Message amf0Request = amf.getAMF0Request(); log.debug(">> Processing AMF0 request: %s", amf0Request); AMF0Message amf0Response = AMF0MessageProcessor.process(amf0Request); log.debug("<< Returning AMF0 response: %s", amf0Response); amf.setAmf0Response(amf0Response); } catch (Exception e) { log.error(e, "AMF message error"); throw new ServletException(e); } } }
public static void cleanupRequest(HttpServletRequest request) { GraniteContext.release(); } }
); AMFContextImpl amf = (AMFContextImpl)context.getAMFContext(); GraniteContext.release();
protected void initValidator() { Map<String, Object> applicationMap = GraniteContext.getCurrentInstance().getApplicationMap(); Boolean validatorNotAvailable = (Boolean)applicationMap.get(VALIDATOR_NOT_AVAILABLE); validator = (EntityValidator)applicationMap.get(VALIDATOR_KEY);
private Map<String, Object> getCache(Destination destination) throws ServiceException { GraniteContext context = GraniteManager.getCurrentInstance(); String scope = destination.getProperties().get("scope"); Map<String, Object> cache = null; if (scope == null || "request".equals(scope)) cache = context.getRequestMap(); else if ("session".equals(scope)) cache = context.getSessionMap(); else if ("application".equals(scope)) cache = Collections.synchronizedMap(context.getApplicationMap()); else throw new ServiceException("Illegal scope in destination: " + destination); return cache; } }
@Override public ServicesConfig getServicesConfig() { return graniteContext.getServicesConfig(); }
@Override public Map<String, Object> getApplicationMap() { return graniteContext.getApplicationMap(); }