Server-Sent Events (SSE) in Spring WebFlux ,SS E的使用-CSDN博客

Spring | Projects

Spring Flex

https://github.com/spring-attic/spring-flex

is Spring BlazeDS Integration .

Spring BlazeDS Integration is a top-level Spring project, and a component of the complete Spring Web stack.  The project's purpose is to make it easier to build Spring-powered 
Rich Internet Applications using Adobe Flex as the front-end client.  It aims to achieve this purpose by providing first-class support for using the open source Adobe BlazeDS 
project and its powerful remoting and messaging facilities in combination with the familiar Spring programming model.

Spring BlazeDS集成是Spring的顶级项目,也是完整Spring Web技术栈的一个组件。该项目旨在通过结合Adobe Flex作为前端客户端,更便捷地构建基于Spring的富互联网应用程序。其核心目标是通过为开源Adobe BlazeDS项目提供一流支持,将BlazeDS强大的远程调用和消息功能与开发者熟悉的Spring编程模型相融合来实现这一目的。

https://www.adobe.com/support/flex/downloads_updaters.html

-

Spring Framework's Migration from Jira to GitHub Issues

BlazeDS 4.7.2 and earlier are vulnerable to CVE-2017-5641. If you still have projects running
in production, beware they may be vulnerable if you use the AmfHttpMessageConverter.

This project is no longer maintained. However you can use BlazeDS 4.7.3+ along with the
below version of AmfHttpMessageConverter that has been updated to allow you to specify a
DeserializationValidator. Copy the below into  you project (e.g. under a different package):

https://github.com/spring-attic/spring-flex/blob/apache-flex/spring-flex-core/src/main/java/org/springframework/flex/http/AmfHttpMessageConverter.java

/*
 * Copyright 2002-2011 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.flex.http;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;

import flex.messaging.validators.DeserializationValidator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;

import flex.messaging.FlexContext;
import flex.messaging.MessageException;
import flex.messaging.io.MessageIOConstants;
import flex.messaging.io.SerializationContext;
import flex.messaging.io.SerializationException;
import flex.messaging.io.amf.ActionContext;
import flex.messaging.io.amf.ActionMessage;
import flex.messaging.io.amf.Amf3Input;
import flex.messaging.io.amf.Amf3Output;
import flex.messaging.io.amf.AmfMessageDeserializer;
import flex.messaging.io.amf.AmfMessageSerializer;
import flex.messaging.io.amf.AmfTrace;

/**
 * Implementation of {@link org.springframework.http.converter.HttpMessageConverter HttpMessageConverter}
 * that can read and write AMF using BlazeDS's AMF serialization/deserialization APIs. 
 *
 * <p>This converter can be used to bind to typed beans, or untyped {@link java.util.HashMap HashMap} instances.
 *
 * <p>By default, this converter supports {@code application/x-amf}. This can be overridden by setting the
 * {@link #setSupportedMediaTypes(List) supportedMediaTypes} property.
 *
 * @author Jeremy Grelle
 */
public class AmfHttpMessageConverter extends AbstractHttpMessageConverter<Object> {

    private static final String AMF_ERROR = "Could not read input message body as AMF";
	private static final String ACTION_MSG_ERROR = "Could not read input message body as "+ActionMessage.class.getName();
	private static final Log log = LogFactory.getLog(AmfHttpMessageConverter.class);

	private DeserializationValidator deserializationValidator;
    
    public AmfHttpMessageConverter() {
        super(MediaType.parseMediaType(MessageIOConstants.AMF_CONTENT_TYPE));
    }

	public void setDeserializationValidator(DeserializationValidator deserializationValidator) {
		this.deserializationValidator = deserializationValidator;

	}

	/**
     * {@inheritDoc}
     */
	@Override
    protected boolean supports(Class<?> clazz) {
        return true;
    }

	/**
	 * {@inheritDoc}
	 */
    @Override
    protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
        
        try {
            AmfTrace trace = null;
            if (log.isDebugEnabled()) {
                trace = new AmfTrace();
            }
            
            Object result = null;
            
            if (clazz.equals(ActionMessage.class)) {
            	result = readActionMessage(inputMessage, trace);
            } else {
            	result = readObject(inputMessage, trace);
            }
            
            if (log.isDebugEnabled()) {
                log.debug("Read AMF message:\n" + trace);
            }
            return result;
        } finally {
            FlexContext.clearThreadLocalObjects();
            SerializationContext.clearThreadLocalObjects();
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void writeInternal(Object data, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    	
        try {
            AmfTrace trace = null;
            if (log.isDebugEnabled()) {
                trace = new AmfTrace();
            }
            
            outputMessage.getHeaders().setPragma("no-cache");
            outputMessage.getHeaders().setCacheControl("no-cache, no-store, max-age=0");
            outputMessage.getHeaders().setExpires(1L);
            
            if (data instanceof ActionMessage) {
            	writeActionMessage((ActionMessage) data, outputMessage, trace);
            } else {
            	writeObject(data, outputMessage, trace);
            }
            
            if (log.isDebugEnabled()) {
                log.debug("Wrote AMF message:\n" + trace);
            }
        } finally {
            FlexContext.clearThreadLocalObjects();
            SerializationContext.clearThreadLocalObjects();
        }
    }
    
    private Object readObject(HttpInputMessage inputMessage, AmfTrace trace) throws IOException {
    	SerializationContext serializationContext = new SerializationContext();
    	if (this.deserializationValidator != null) {
    		serializationContext.setDeserializationValidator(this.deserializationValidator);
		}
		SerializationContext.setSerializationContext(serializationContext); // Seems to be required
    	Amf3Input deserializer = new Amf3Input(serializationContext);
    	deserializer.setInputStream(inputMessage.getBody());
    	deserializer.setDebugTrace(trace);
    	try {
            return deserializer.readObject();
        } catch (ClassNotFoundException cnfe) {
        	throw new HttpMessageNotReadableException(AMF_ERROR, cnfe);
        } catch (MessageException se) {
        	throw new HttpMessageNotReadableException(AMF_ERROR, se);
        }
	}

	private ActionMessage readActionMessage(HttpInputMessage inputMessage, AmfTrace trace) throws IOException {
		SerializationContext serializationContext = new SerializationContext();
		if (this.deserializationValidator != null) {
			serializationContext.setDeserializationValidator(this.deserializationValidator);
		}
		SerializationContext.setSerializationContext(serializationContext); // Seems to be required
    	AmfMessageDeserializer deserializer = new AmfMessageDeserializer();
    	deserializer.initialize(serializationContext, inputMessage.getBody(), trace);
    	
    	try {
        	ActionContext context = new ActionContext();
        	ActionMessage message = new ActionMessage();
        	context.setRequestMessage(message);
            deserializer.readMessage(message, context);
            return message;
        } catch (ClassNotFoundException cnfe) {
        	throw new HttpMessageNotReadableException(ACTION_MSG_ERROR, cnfe);
        } catch (MessageException me) {
        	throw new HttpMessageNotReadableException(ACTION_MSG_ERROR, me);
        }
    }
	
	private void writeActionMessage(ActionMessage message,
			HttpOutputMessage outputMessage, AmfTrace trace) throws IOException {
		SerializationContext serializationContext = new SerializationContext();
		if (this.deserializationValidator != null) {
			serializationContext.setDeserializationValidator(this.deserializationValidator);
		}
		SerializationContext.setSerializationContext(serializationContext); // Seems to be required
    	AmfMessageSerializer serializer = new AmfMessageSerializer();
		ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
		serializer.setVersion(message.getVersion());
		serializer.initialize(serializationContext, outBuffer, trace);
        
		try {
        	ActionContext context = new ActionContext();
        	context.setVersion(message.getVersion());
        	context.setResponseMessage(message);
        	serializer.writeMessage(message);
        	outBuffer.flush();
        	outBuffer.close();
        	outputMessage.getHeaders().setContentLength(outBuffer.size());
        	outBuffer.writeTo(outputMessage.getBody());
        } catch (SerializationException se) {
        	throw new HttpMessageNotWritableException("Could not write "+message+" as AMF message.", se);
        }
	}
    
    private void writeObject(Object data, HttpOutputMessage outputMessage,
			AmfTrace trace) throws IOException {
		SerializationContext serializationContext = new SerializationContext();
		if (this.deserializationValidator != null) {
			serializationContext.setDeserializationValidator(this.deserializationValidator);
		}
		SerializationContext.setSerializationContext(serializationContext); // Seems to be required
    	ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    	Amf3Output serializer = new Amf3Output(serializationContext);
    	serializer.setOutputStream(outBuffer);
    	serializer.setDebugTrace(trace);
        try {
        	serializer.writeObject(data);
        	outBuffer.flush();
        	outBuffer.close();
        	outputMessage.getHeaders().setContentLength(outBuffer.size());
        	outBuffer.writeTo(outputMessage.getBody());
        } catch (SerializationException se) {
        	throw new HttpMessageNotWritableException("Could not write "+data+" as AMF message.", se);
        }
	}
}

BlazeDS 的前世今生

https://en.wikipedia.org/wiki/BlazeDS

BlazeDS is a server-based Java remoting and web messaging technology that allows users to connect to back-end distributed data and push data to Apache Flex and Adobe AIR Rich Internet applications (RIA). Because of its open licensing, BlazeDS is not precluded from being used with other client platforms, such as JavaScript/Ajax.

BlazeDS是一种基于服务器的Java远程调用和网络消息技术,它能让用户连接到后端分布式数据,并将数据推送至Apache Flex和Adobe AIR富互联网应用程序(RIA)。由于其开放许可协议,BlazeDS也可与其他客户端平台(如JavaScript/Ajax)配合使用。

Previously available only as part of Adobe LiveCycle Data Services ES, on December 13, 2007 Adobe announced that the technologies included in BlazeDS, along with the Action Message Format specification, were contributed to open source under the GNU Lesser General Public License (LGPL v3) with the source code being available for download from early 2008. BlazeDS can be downloaded from the official page.

此前仅作为Adobe LiveCycle Data Services ES的一部分提供,2007年12月13日,Adobe宣布将BlazeDS包含的技术及Action Message Format规范以GNU宽通用公共许可证(LGPL v3)协议开源贡献,源代码自2008年初起可供下载。BlazeDS可从官网页面下载。

The Message Service provides a complete publish/subscribe infrastructure allowing Flex clients and the server to exchange messages in real time. Remoting allows a Flex application to directly invoke methods of Java objects deployed in an application server.

消息服务提供了一套完整的发布/订阅基础设施,使Flex客户端与服务器能够实时交换消息。远程调用允许Flex应用程序直接调用部署在应用服务器中的Java对象方法。[1]

BlazeDS applications consist of client-side code and server-side code. Client-side code is typically a Flex application written in MXML and ActionScript and deployed as a SWF file. Server-side code is written in Java and deployed as Java class files or Java Archive (JAR) files.

BlazeDS应用程序由客户端代码和服务器端代码组成。客户端代码通常是使用MXML和ActionScript编写的Flex应用程序,并部署为SWF文件。服务器端代码使用Java编写,并部署为Java类文件或Java归档(JAR)文件。

Spring 继承 BlazeDS Docs

Spring BlazeDS Integration Reference Guide

Apache Flex® - Home Page

https://github.com/apache/flex-blazeds

 Apache Flex SDK is an application development framework for easily building

Apache Flex SDK 是一个应用程序开发框架,用于轻松构建


    Flash-based applications for mobile devices, web browsers, and desktops.

    Apache Flex BlazeDS is the server-based Java remoting and web messaging
    technology that enables developers to easily connect to back-end distributed
    data and push data in real-time to Adobe® Flex® and Adobe AIR™ applications
    for more responsive rich Internet application (RIA) experiences.

Apache Flex BlazeDS是基于服务器的Java远程调用和网络消息技术,它能让开发者轻松连接后端分布式数据,并将数据实时推送到Adobe® Flex®和Adobe AIR™应用程序中,从而提供响应更迅速的富互联网应用(RIA)体验。

    Apache Flex BlazeDS 4.8.0 is an update to the initial release of BlazeDS
    from the Apache Software Foundation.  Prior to this, releases were provided 
    by Adobe Systems Inc. It is compatible with most code written to target Adobe
    Flex 4.6.

    For detailed information about Apache Flex please visit
    http://flex.apache.org/
 

<dependency>
        <groupId>org.apache.flex.blazeds</groupId>
        <artifactId>flex-messaging-common</artifactId>
        <version>4.8.0</version>
</dependency>
<dependency>
        <groupId>org.apache.flex.blazeds</groupId>
        <artifactId>flex-messaging-core</artifactId>
        <version>4.8.0</version>
</dependency>
<dependency>
        <groupId>org.apache.flex.blazeds</groupId>
        <artifactId>flex-messaging-proxy</artifactId>
        <version>4.8.0</version>
</dependency>
<dependency>
        <groupId>org.apache.flex.blazeds</groupId>
        <artifactId>flex-messaging-remoting</artifactId>
        <version>4.8.0</version>
</dependency>

集成 Spring Flex

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐