// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/Converter.java
// public interface Converter {
// 
// 	Object read(byte[] payload, Class<?> targetType);
// 
// 	byte[] write(Object target);
// 
// 	boolean accept(MimeType mimeType);
// 
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/JacksonConverter.java
// public class JacksonConverter extends AbstractConverter {
// 
// 	private ObjectMapper mapper = new ObjectMapper();
// 
// 	public JacksonConverter() {
// 		super(MimeTypeUtils.APPLICATION_JSON);
// 	}
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		try {
// 			return mapper.readValue(payload, targetType);
// 		}
// 		catch (IOException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		try {
// 			return mapper.writeValueAsBytes(target);
// 		}
// 		catch (JsonProcessingException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/SerializableConverter.java
// public class SerializableConverter extends AbstractConverter {
// 
// 	public SerializableConverter() {
// 		super(MimeType.valueOf("application/java-serialized-object"));
// 	}
// 
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		return SerializationUtils.deserialize(payload);
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		return SerializationUtils.serialize(target);
// 	}
// 
// 
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/util/ServiceUtils.java
// public class ServiceUtils {
// 
// 	public static byte[] toByteArray(ByteBuffer buffer){
// 		byte[] bytes = new byte[buffer.remaining()];
// 		buffer.get(bytes, 0, bytes.length);
// 		return bytes;
// 	}
// 
// 	public static Class<?> getActualType(ResolvableType type){
// 		if(Publisher.class.isAssignableFrom(type.resolve())){
// 			return type.getGeneric(0).resolve();
// 		}else{
// 			return type.resolve();
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/util/ServiceUtils.java
// public static Class<?> getActualType(ResolvableType type){
// 	if(Publisher.class.isAssignableFrom(type.resolve())){
// 		return type.getGeneric(0).resolve();
// 	}else{
// 		return type.resolve();
// 	}
// }


import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.rsocket.AbstractRSocket;
import io.rsocket.Payload;
import io.rsocket.exceptions.ApplicationException;
import io.rsocket.util.PayloadImpl;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cloud.reactive.socket.annotation.ReactiveSocket;
import org.springframework.cloud.reactive.socket.converter.Converter;
import org.springframework.cloud.reactive.socket.converter.JacksonConverter;
import org.springframework.cloud.reactive.socket.converter.SerializableConverter;
import org.springframework.cloud.reactive.socket.util.ServiceUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
import org.springframework.util.ReflectionUtils;
import static org.springframework.cloud.reactive.socket.util.ServiceUtils.getActualType;
/*
 *  Copyright 2017 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.cloud.reactive.socket;






/**
 * @author Vinicius Carvalho
 */
public class DispatcherHandler extends AbstractRSocket implements ApplicationContextAware, InitializingBean {

	private ApplicationContext applicationContext;

// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/Converter.java
// public interface Converter {
// 
// 	Object read(byte[] payload, Class<?> targetType);
// 
// 	byte[] write(Object target);
// 
// 	boolean accept(MimeType mimeType);
// 
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/JacksonConverter.java
// public class JacksonConverter extends AbstractConverter {
// 
// 	private ObjectMapper mapper = new ObjectMapper();
// 
// 	public JacksonConverter() {
// 		super(MimeTypeUtils.APPLICATION_JSON);
// 	}
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		try {
// 			return mapper.readValue(payload, targetType);
// 		}
// 		catch (IOException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		try {
// 			return mapper.writeValueAsBytes(target);
// 		}
// 		catch (JsonProcessingException e) {
// 			throw new IllegalStateException(e);
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/converter/SerializableConverter.java
// public class SerializableConverter extends AbstractConverter {
// 
// 	public SerializableConverter() {
// 		super(MimeType.valueOf("application/java-serialized-object"));
// 	}
// 
// 
// 	@Override
// 	public Object read(byte[] payload, Class<?> targetType) {
// 		return SerializationUtils.deserialize(payload);
// 	}
// 
// 	@Override
// 	public byte[] write(Object target) {
// 		return SerializationUtils.serialize(target);
// 	}
// 
// 
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/util/ServiceUtils.java
// public class ServiceUtils {
// 
// 	public static byte[] toByteArray(ByteBuffer buffer){
// 		byte[] bytes = new byte[buffer.remaining()];
// 		buffer.get(bytes, 0, bytes.length);
// 		return bytes;
// 	}
// 
// 	public static Class<?> getActualType(ResolvableType type){
// 		if(Publisher.class.isAssignableFrom(type.resolve())){
// 			return type.getGeneric(0).resolve();
// 		}else{
// 			return type.resolve();
// 		}
// 	}
// }
// 
// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/util/ServiceUtils.java
// public static Class<?> getActualType(ResolvableType type){
// 	if(Publisher.class.isAssignableFrom(type.resolve())){
// 		return type.getGeneric(0).resolve();
// 	}else{
// 		return type.resolve();
// 	}
// }


// Path: spring-cloud-sockets/src/main/java/org/springframework/cloud/reactive/socket/DispatcherHandler.java
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.rsocket.AbstractRSocket;
import io.rsocket.Payload;
import io.rsocket.exceptions.ApplicationException;
import io.rsocket.util.PayloadImpl;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cloud.reactive.socket.annotation.ReactiveSocket;
import org.springframework.cloud.reactive.socket.converter.Converter;
import org.springframework.cloud.reactive.socket.converter.JacksonConverter;
import org.springframework.cloud.reactive.socket.converter.SerializableConverter;
import org.springframework.cloud.reactive.socket.util.ServiceUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.MimeType;
import org.springframework.util.ReflectionUtils;
import static org.springframework.cloud.reactive.socket.util.ServiceUtils.getActualType;

/*
 *  Copyright 2017 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.cloud.reactive.socket;






/**
 * @author Vinicius Carvalho
 */
public class DispatcherHandler extends AbstractRSocket implements ApplicationContextAware, InitializingBean {

	private ApplicationContext applicationContext;

	private List<MethodHandler> mappingHandlers = new LinkedList<>();