odette-j

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • louis08
    New Member
    • Feb 2008
    • 6

    odette-j

    When i call:

    OdetteFTPEntity oftp = session.acceptC onnection(trans port);

    I recive a java.nio.Buffer OverflowExcepti on
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by louis08
    When i call:

    OdetteFTPEntity oftp = session.acceptC onnection(trans port);

    I recive a java.nio.Buffer OverflowExcepti on
    I think, we'll need a little more information - what is this "transport" , that you're using? Can you give us a little more code, so that the context is clearer?

    Greetings,
    Nepomuk

    Comment

    • louis08
      New Member
      • Feb 2008
      • 6

      #3
      code snippet

      Lines marked in bold is where the error happens.

      Code:
      package examples.odettej;
      
      import java.io.File;
      import java.io.IOException;
      import java.net.InetSocketAddress;
      import java.nio.channels.SelectionKey;
      import java.nio.channels.Selector;
      import java.nio.channels.ServerSocketChannel;
      import java.nio.channels.SocketChannel;
      import java.util.Iterator;
      import java.util.Properties;
      import java.util.logging.Logger;
      
      import org.fossilec.odettej.OdetteFTPEntity;
      import org.fossilec.odettej.OdetteFTPException;
      import org.fossilec.odettej.PeerAuthenticator;
      import org.fossilec.odettej.Session;
      import org.fossilec.odettej.service.TransferMode;
      import org.fossilec.odettej.transport.Transport;
      import org.fossilec.odettej.transport.tcp.TCPTransport;
      
      public class OdetteServer implements Runnable {
      
      	private static Logger logger = Logger.getLogger(OdetteServer.class.getName());
      
      	private ServerSocketChannel channel = null;
      
      	private String baseDir;
      
      	private int listenPort;
      
      	private boolean shouldStop;
              
              private Thread runner;
      
      	public OdetteServer(String baseDir, int listenPort) {
      		super();
      		this.baseDir = baseDir;
      		this.listenPort = listenPort;
      	}
      
      	/**
      	 * @param args
      	 */
      	public static void main(String[] args) {
      
      	}
      
      	public void run() {
      
      		serverBind();
      
      		try {
      			handleConnections();
      		} catch (IOException e) {
      			logger.throwing("OdetteServer", "run", e);
      		}
      
      	}
      
      	private void serverBind() {
      
      		// create and bind (listen) to the specified port
      		try {
      			channel = ServerSocketChannel.open();
      			channel.socket().bind(new InetSocketAddress(listenPort));
      			logger.info("Odette FTP Server listening on port: " + listenPort);
      		} catch (IOException e) {
      			logger.throwing("OdetteServer", "bind", e);
      		}
      
      	}
      
      	public void handleConnections() throws IOException {
      
      		// turn off flag on start until method stop() is called
      		shouldStop = false;
      
      		// create selector
      		Selector selector = Selector.open();
      
      		try {
      			// set channel as non-blocking mode and register the selector
      			channel.configureBlocking(false);
      			channel.register(selector, SelectionKey.OP_ACCEPT);
      
      			while (!shouldStop) {
      
      				// wait for any operation avaiable
      				selector.select();
      				Iterator iterator = selector.selectedKeys().iterator();
      
      				while (iterator.hasNext()) {
      
      					// get avaiable operation
      					SelectionKey key = (SelectionKey) iterator.next();
      
      					// found an accept operation on the server socket
      					if (key.isAcceptable()) {
      						ServerSocketChannel server = (ServerSocketChannel) key
      								.channel();
      
      						// create a client socket, also in non-blocking mode
      						SocketChannel client = server.accept();
      
      						logger.info("Receiving connection from: " + client.socket().getRemoteSocketAddress());
      
      //						if (client != null) {
      //							client.configureBlocking(false);
      //							// register client socket on the selector
      //							client.register(selector, SelectionKey.OP_READ);
      //						}
      
      						startSession(client);
      					}
      				}
      			}
      		} catch (Exception e) {
      			logger.throwing("OdetteServer", "handleConnections", e);
                              System.out.println(e.toString());
      		} finally {
      			// always close the selector
      			selector.close();
      		}
      
      	}
      
      
      	private void startSession(SocketChannel client) throws OdetteFTPException {
                      
                      try {
                          client.socket().getChannel().configureBlocking(false);
                      }catch(Exception e) {
                          System.out.println(e.toString());
                      }
      		final Transport transport = new TCPTransport(client);
      		final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
      		final StringBuffer userBoxId = new StringBuffer();
                      session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
                      session.acceptConnection(transport);
      
      		session.setAuthenticator(new PeerAuthenticator() {
      
                  public void init(Session context) { }
      
      			public void authenticate(String remoteUser, String remotePassword, String address) throws OdetteFTPException {
      
      				userBoxId.append(remoteUser);
      
      				String userInboxDir = baseDir + File.separator + remoteUser + File.separator + "incoming";
      				session.setReceivingSupport(new ListeningSupport(userInboxDir));
      
      				// no exception thrown means authentication succeed
      			}
      
      		});
      
      		// gives an independent lifecycle to this OFTP session (see the receiving support is already set)
      
      		Thread t = new Thread(new Runnable() {
      			public void run() {
      
      				try {
      					[B]OdetteFTPEntity oftp = session.acceptConnection(transport);[/B]
      					// create the OdetteApp instance here???
                                              
      				} catch (OdetteFTPException e) {
                                          e.printStackTrace();
                                          logger.throwing("OdetteServer", "startSession$Runnable...", e);
      				}
      
      			}
      		});
      
              t.start();
      	}
      
      	public void stop() {
      		shouldStop = true;
      	}
      }
      
      
      public OdetteFTPEntity acceptConnection(Transport transport)
      			throws OdetteFTPException {
      
      		/* incoming network connection */
      
      		if ((state == null) || (state instanceof IdleState)) {
      
      			boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
      			int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
                              service = Service.getInstance(transport, sdeb, stb);
      
      			setProperty("odette.called-address", transport.getLocalAddress());
      			setProperty("odette.calling-address", transport.getRemoteAddress());
      
      			/* start session phase */
      			changeState(ListenerState.class);
                              [B]state.startSession();[/B]
                              
      		} else {
      			NotInIdleStateError();
      		}
      
      		return state;
      	}
      
      -------------------------------------------------
      package org.fossilec.odettej;
      
      import org.fossilec.odettej.service.CommandExchangeBuffer;
      import org.fossilec.odettej.service.CommandIdentifier;
      import org.fossilec.odettej.service.EndSessionReason;
      import org.fossilec.odettej.service.OdetteExchangeBuffer;
      import org.fossilec.odettej.service.Service;
      import org.fossilec.odettej.service.TransferMode;
      import org.fossilec.odettej.transport.Transport;
      
      abstract class AbstractState implements OdetteFTPEntity {
      
      	private Session context;
      
      	private PreferencesUtil prefs;
      
      	private boolean useStrictFormat;
      
      	protected AbstractState(Session context) {
      		super();
      
      		this.context = context;
      		prefs = new PreferencesUtil(context.getProperties());
      
      		useStrictFormat = prefs.isUsingStrictFormat();
      	}
      
      	protected abstract void listen() throws OdetteFTPException;
      
      	public Session getContext() {
      		return context;
      	}
      
      	public PreferencesUtil getPreferences() {
      		return prefs;
      	}
      
      	public Service getService() throws OdetteFTPException {
      		return context.getService();
      	}
      
      	public void resetCredits() {
      		String window = context.getProperty("odette.window-size");
      		setCredits(Integer.parseInt(window));
      	}
      
      	public void consumeCredit() {
      		int credits = getCredits();
      		credits--;
      
      		setCredits(credits);
      	}
      
      	protected abstract void setCredits(int windowSize);
      
      	public abstract int getCredits();
      
      	public boolean hasCredits() {
      		return (getCredits() > 0);
      	}
      
      	protected OdetteExchangeBuffer receive() throws OdetteFTPException {
      		OdetteExchangeBuffer exchangeBuffer = getService().receive(
      				useStrictFormat);
      
      		if (exchangeBuffer.getIdentifier() == CommandIdentifier.ESID) {
      
      			CommandExchangeBuffer esid = (CommandExchangeBuffer) exchangeBuffer;
      
      			String code = esid.getParameter("ESIDREAS");
      			EndSessionReason reason = EndSessionReason.parse(code);
      
      			if (reason != EndSessionReason.NORMAL_TERMINATION) {
      				abnormalRelease(reason);
      			}
      		}
      
      		return exchangeBuffer;
      	}
      
      	protected void send(OdetteExchangeBuffer oeb) throws OdetteFTPException {
      		Service service = getService();
      		service.send(oeb);
      	}
      
      	protected void disconnect() throws OdetteFTPException {
      		context.disconnect();
      	}
      
      	public boolean isConnected() throws OdetteFTPException {
      		Service service = getService();
      		Transport transport = service.getTransport();
      
      		return transport.isConnected();
      	}
      
      	public void release() throws OdetteFTPException {
      		protocolRelease(EndSessionReason.NORMAL_TERMINATION);
      	}
      
      	protected void abnormalRelease(EndSessionReason error)
      			throws OdetteFTPException {
      
      		protocolRelease(error);
      		endSessionError(error, "abnormal release");
      	}
      
      	protected void abnormalRelease(EndSessionReason error, String msg)
      			throws OdetteFTPException {
      
      		protocolRelease(error);
      		endSessionError(error, msg);
      	}
      
      	public void abort(EndSessionReason error) throws OdetteFTPException {
      		protocolRelease(error);
      	}
      
      	private void protocolRelease(EndSessionReason reason)
      			throws OdetteFTPException {
      
      		Service service = getService();
      
      		CommandExchangeBuffer esid;
      
      		if (reason == null) {
      			throw new IllegalArgumentException("Reason must not be null");
      		}
      
      		/*
      		 * Sending End Session command.
      		 */
      		esid = CommandExchangeBuffer.endSession(reason);
      
      		send(esid);
      
      		try {
      			Thread.sleep(500);
      		} catch (Exception e) {
      			e.printStackTrace();
      		}
      
      		service.disconnect();
      
      		context.changeState(IdleState.class);
      	}
      
      	private static void endSessionError(EndSessionReason error, String msg)
      			throws OdetteFTPException {
      		throw new EndSessionException(error, msg);
      	}
      
      	protected void requestAuthentication(String ssidcode, String ssidpswd,
      			String remoteAddress) throws OdetteFTPException {
      
      		Session context = getContext();
      
      		PeerAuthenticator auth = context.getAuthenticator();
      
      		if (auth != null) {
      			auth.authenticate(ssidcode, ssidpswd, remoteAddress);
      		}
      	}
      
      	protected static boolean windowSizeViolation(int size, Session session) {
      		return ((size <= 0) || (size > session.getMaxWindow()));
      	}
      
      	protected static boolean bufferSizeViolation(int size, Session session) {
      		return ((size < OdetteExchangeBuffer.MIN_OEB_LENGTH) || (size > session
      				.getMaxBuffer()));
      	}
      
      	protected static boolean valueOfYesNo(String parameter) {
      		return (parameter.equals("Y") ? true : false);
      	}
      
      	protected static void checkStartSession(Session context, int sdeb,
      			int window, boolean compression, TransferMode mode, boolean restart)
      			throws OdetteFTPException {
      
      		/* check exchange buffer size */
      		if (bufferSizeViolation(sdeb, context)) {
      			endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
      					"Invalid exchange buffer size is being used: " + sdeb);
      		}
      
      		/* check window size */
      		if (windowSizeViolation(window, context)) {
      			endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
      					"Invalid window size is being used: " + window);
      		}
      
      		/* check compression capability */
      		if ((!context.isCompressionCapable()) && (compression)) {
      			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
      					"Implementation doesn't support compression");
      		}
      
      		/* check transfer mode capability */
      		TransferMode capmode = context.getCapableTransferMode();
      		if ((capmode != TransferMode.BOTH) && (mode != capmode)) {
      			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
      					"Implementation doesn't support this mode: " + mode);
      		}
      
      		/* check restart capability */
      		if ((!context.isRestartCapable()) && (restart)) {
      			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
      					"Implementation doesn't support restart");
      		}
      	}
      
      }
      
      
      _______________________________________________
      
      public interface OdetteFTPEntity {
      
      	public Session getContext();
      
      	[B]public void startSession() throws OdetteFTPException;[/B]
      
      	public void startFile(VirtualFile file, String destination,
      			String originator, String userData, String reserved)
      			throws OdetteFTPException;
      
      	public void dataRegime() throws OdetteFTPException;
      
      	public void closeFile(int recordCount, long unitCount)
      			throws OdetteFTPException;
      
      	public void changeDirection() throws OdetteFTPException;
      
      	public void endToEndResponse(String datasetName, Date fileDateTime,
      			String destination, String originator, String userData,
      			String reserved) throws OdetteFTPException;
      
      	public void release() throws OdetteFTPException;
      
      	public void abort(EndSessionReason error) throws OdetteFTPException;
      
      	public boolean isConnected() throws OdetteFTPException;
      
      }
      Last edited by louis08; Feb 18 '08, 02:16 PM. Reason: Format

      Comment

      • Nepomuk
        Recognized Expert Specialist
        • Aug 2007
        • 3111

        #4
        Originally posted by louis08
        Lines marked in bold is where the error happens...
        OK, two more things:
        • Please use CODE-tags for your code
        • What is the exact error-message that you get?
        It is a java.nio.Buffer OverflowExcepti on, right? Hm...

        For anyone else, who might want to help, here's the OdetteJ API.

        Greetings,
        Nepomuk

        Comment

        • louis08
          New Member
          • Feb 2008
          • 6

          #5
          Lines marked in bold is where the error happens.

          Code:
          package examples.odettej;
          
          import java.io.File;
          import java.io.IOException;
          import java.net.InetSocketAddress;
          import java.nio.channels.SelectionKey;
          import java.nio.channels.Selector;
          import java.nio.channels.ServerSocketChannel;
          import java.nio.channels.SocketChannel;
          import java.util.Iterator;
          import java.util.Properties;
          import java.util.logging.Logger;
          
          import org.fossilec.odettej.OdetteFTPEntity;
          import org.fossilec.odettej.OdetteFTPException;
          import org.fossilec.odettej.PeerAuthenticator;
          import org.fossilec.odettej.Session;
          import org.fossilec.odettej.service.TransferMode;
          import org.fossilec.odettej.transport.Transport;
          import org.fossilec.odettej.transport.tcp.TCPTransport;
          
          public class OdetteServer implements Runnable {
          
          	private static Logger logger = Logger.getLogger(OdetteServer.class.getName());
          
          	private ServerSocketChannel channel = null;
          
          	private String baseDir;
          
          	private int listenPort;
          
          	private boolean shouldStop;
                  
                  private Thread runner;
          
          	public OdetteServer(String baseDir, int listenPort) {
          		super();
          		this.baseDir = baseDir;
          		this.listenPort = listenPort;
          	}
          
          	/**
          	 * @param args
          	 */
          	public static void main(String[] args) {
          
          	}
          
          	public void run() {
          
          		serverBind();
          
          		try {
          			handleConnections();
          		} catch (IOException e) {
          			logger.throwing("OdetteServer", "run", e);
          		}
          
          	}
          
          	private void serverBind() {
          
          		// create and bind (listen) to the specified port
          		try {
          			channel = ServerSocketChannel.open();
          			channel.socket().bind(new InetSocketAddress(listenPort));
          			logger.info("Odette FTP Server listening on port: " + listenPort);
          		} catch (IOException e) {
          			logger.throwing("OdetteServer", "bind", e);
          		}
          
          	}
          
          	public void handleConnections() throws IOException {
          
          		// turn off flag on start until method stop() is called
          		shouldStop = false;
          
          		// create selector
          		Selector selector = Selector.open();
          
          		try {
          			// set channel as non-blocking mode and register the selector
          			channel.configureBlocking(false);
          			channel.register(selector, SelectionKey.OP_ACCEPT);
          
          			while (!shouldStop) {
          
          				// wait for any operation avaiable
          				selector.select();
          				Iterator iterator = selector.selectedKeys().iterator();
          
          				while (iterator.hasNext()) {
          
          					// get avaiable operation
          					SelectionKey key = (SelectionKey) iterator.next();
          
          					// found an accept operation on the server socket
          					if (key.isAcceptable()) {
          						ServerSocketChannel server = (ServerSocketChannel) key
          								.channel();
          
          						// create a client socket, also in non-blocking mode
          						SocketChannel client = server.accept();
          
          						logger.info("Receiving connection from: " + client.socket().getRemoteSocketAddress());
          
          //						if (client != null) {
          //							client.configureBlocking(false);
          //							// register client socket on the selector
          //							client.register(selector, SelectionKey.OP_READ);
          //						}
          
          						startSession(client);
          					}
          				}
          			}
          		} catch (Exception e) {
          			logger.throwing("OdetteServer", "handleConnections", e);
                                  System.out.println(e.toString());
          		} finally {
          			// always close the selector
          			selector.close();
          		}
          
          	}
          
          
          	private void startSession(SocketChannel client) throws OdetteFTPException {
                          
                          try {
                              client.socket().getChannel().configureBlocking(false);
                          }catch(Exception e) {
                              System.out.println(e.toString());
                          }
          		final Transport transport = new TCPTransport(client);
          		final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
          		final StringBuffer userBoxId = new StringBuffer();
                          session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
                          session.acceptConnection(transport);
          
          		session.setAuthenticator(new PeerAuthenticator() {
          
                      public void init(Session context) { }
          
          			public void authenticate(String remoteUser, String remotePassword, String address) throws OdetteFTPException {
          
          				userBoxId.append(remoteUser);
          
          				String userInboxDir = baseDir + File.separator + remoteUser + File.separator + "incoming";
          				session.setReceivingSupport(new ListeningSupport(userInboxDir));
          
          				// no exception thrown means authentication succeed
          			}
          
          		});
          
          		// gives an independent lifecycle to this OFTP session (see the receiving support is already set)
          
          		Thread t = new Thread(new Runnable() {
          			public void run() {
          
          				try {
          					[B]OdetteFTPEntity oftp = session.acceptConnection(transport);[/B]
          					// create the OdetteApp instance here???
                                                  
          				} catch (OdetteFTPException e) {
                                              e.printStackTrace();
                                              logger.throwing("OdetteServer", "startSession$Runnable...", e);
          				}
          
          			}
          		});
          
                  t.start();
          	}
          
          	public void stop() {
          		shouldStop = true;
          	}
          }
          Code:
          public OdetteFTPEntity acceptConnection(Transport transport)
          			throws OdetteFTPException {
          
          		/* incoming network connection */
          
          		if ((state == null) || (state instanceof IdleState)) {
          
          			boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
          			int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
                                  service = Service.getInstance(transport, sdeb, stb);
          
          			setProperty("odette.called-address", transport.getLocalAddress());
          			setProperty("odette.calling-address", transport.getRemoteAddress());
          
          			/* start session phase */
          			changeState(ListenerState.class);
                                  [B]state.startSession();[/B]
                                  
          		} else {
          			NotInIdleStateError();
          		}
          
          		return state;
          	}
          Code:
          -------------------------------------------------
          
          package org.fossilec.odettej;
          
          import org.fossilec.odettej.service.CommandExchangeBuffer;
          import org.fossilec.odettej.service.CommandIdentifier;
          import org.fossilec.odettej.service.EndSessionReason;
          import org.fossilec.odettej.service.OdetteExchangeBuffer;
          import org.fossilec.odettej.service.Service;
          import org.fossilec.odettej.service.TransferMode;
          import org.fossilec.odettej.transport.Transport;
          
          abstract class AbstractState implements OdetteFTPEntity {
          
          	private Session context;
          
          	private PreferencesUtil prefs;
          
          	private boolean useStrictFormat;
          
          	protected AbstractState(Session context) {
          		super();
          
          		this.context = context;
          		prefs = new PreferencesUtil(context.getProperties());
          
          		useStrictFormat = prefs.isUsingStrictFormat();
          	}
          
          	protected abstract void listen() throws OdetteFTPException;
          
          	public Session getContext() {
          		return context;
          	}
          
          	public PreferencesUtil getPreferences() {
          		return prefs;
          	}
          
          	public Service getService() throws OdetteFTPException {
          		return context.getService();
          	}
          
          	public void resetCredits() {
          		String window = context.getProperty("odette.window-size");
          		setCredits(Integer.parseInt(window));
          	}
          
          	public void consumeCredit() {
          		int credits = getCredits();
          		credits--;
          
          		setCredits(credits);
          	}
          
          	protected abstract void setCredits(int windowSize);
          
          	public abstract int getCredits();
          
          	public boolean hasCredits() {
          		return (getCredits() > 0);
          	}
          
          	protected OdetteExchangeBuffer receive() throws OdetteFTPException {
          		OdetteExchangeBuffer exchangeBuffer = getService().receive(
          				useStrictFormat);
          
          		if (exchangeBuffer.getIdentifier() == CommandIdentifier.ESID) {
          
          			CommandExchangeBuffer esid = (CommandExchangeBuffer) exchangeBuffer;
          
          			String code = esid.getParameter("ESIDREAS");
          			EndSessionReason reason = EndSessionReason.parse(code);
          
          			if (reason != EndSessionReason.NORMAL_TERMINATION) {
          				abnormalRelease(reason);
          			}
          		}
          
          		return exchangeBuffer;
          	}
          
          	protected void send(OdetteExchangeBuffer oeb) throws OdetteFTPException {
          		Service service = getService();
          		service.send(oeb);
          	}
          
          	protected void disconnect() throws OdetteFTPException {
          		context.disconnect();
          	}
          
          	public boolean isConnected() throws OdetteFTPException {
          		Service service = getService();
          		Transport transport = service.getTransport();
          
          		return transport.isConnected();
          	}
          
          	public void release() throws OdetteFTPException {
          		protocolRelease(EndSessionReason.NORMAL_TERMINATION);
          	}
          
          	protected void abnormalRelease(EndSessionReason error)
          			throws OdetteFTPException {
          
          		protocolRelease(error);
          		endSessionError(error, "abnormal release");
          	}
          
          	protected void abnormalRelease(EndSessionReason error, String msg)
          			throws OdetteFTPException {
          
          		protocolRelease(error);
          		endSessionError(error, msg);
          	}
          
          	public void abort(EndSessionReason error) throws OdetteFTPException {
          		protocolRelease(error);
          	}
          
          	private void protocolRelease(EndSessionReason reason)
          			throws OdetteFTPException {
          
          		Service service = getService();
          
          		CommandExchangeBuffer esid;
          
          		if (reason == null) {
          			throw new IllegalArgumentException("Reason must not be null");
          		}
          
          		/*
          		 * Sending End Session command.
          		 */
          		esid = CommandExchangeBuffer.endSession(reason);
          
          		send(esid);
          
          		try {
          			Thread.sleep(500);
          		} catch (Exception e) {
          			e.printStackTrace();
          		}
          
          		service.disconnect();
          
          		context.changeState(IdleState.class);
          	}
          
          	private static void endSessionError(EndSessionReason error, String msg)
          			throws OdetteFTPException {
          		throw new EndSessionException(error, msg);
          	}
          
          	protected void requestAuthentication(String ssidcode, String ssidpswd,
          			String remoteAddress) throws OdetteFTPException {
          
          		Session context = getContext();
          
          		PeerAuthenticator auth = context.getAuthenticator();
          
          		if (auth != null) {
          			auth.authenticate(ssidcode, ssidpswd, remoteAddress);
          		}
          	}
          
          	protected static boolean windowSizeViolation(int size, Session session) {
          		return ((size <= 0) || (size > session.getMaxWindow()));
          	}
          
          	protected static boolean bufferSizeViolation(int size, Session session) {
          		return ((size < OdetteExchangeBuffer.MIN_OEB_LENGTH) || (size > session
          				.getMaxBuffer()));
          	}
          
          	protected static boolean valueOfYesNo(String parameter) {
          		return (parameter.equals("Y") ? true : false);
          	}
          
          	protected static void checkStartSession(Session context, int sdeb,
          			int window, boolean compression, TransferMode mode, boolean restart)
          			throws OdetteFTPException {
          
          		/* check exchange buffer size */
          		if (bufferSizeViolation(sdeb, context)) {
          			endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
          					"Invalid exchange buffer size is being used: " + sdeb);
          		}
          
          		/* check window size */
          		if (windowSizeViolation(window, context)) {
          			endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
          					"Invalid window size is being used: " + window);
          		}
          
          		/* check compression capability */
          		if ((!context.isCompressionCapable()) && (compression)) {
          			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
          					"Implementation doesn't support compression");
          		}
          
          		/* check transfer mode capability */
          		TransferMode capmode = context.getCapableTransferMode();
          		if ((capmode != TransferMode.BOTH) && (mode != capmode)) {
          			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
          					"Implementation doesn't support this mode: " + mode);
          		}
          
          		/* check restart capability */
          		if ((!context.isRestartCapable()) && (restart)) {
          			endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
          					"Implementation doesn't support restart");
          		}
          	}
          
          }
          
          
          _______________________________________________
          
          public interface OdetteFTPEntity {
          
          	public Session getContext();
          
          	[B]public void startSession() throws OdetteFTPException;[/B]
          
          	public void startFile(VirtualFile file, String destination,
          			String originator, String userData, String reserved)
          			throws OdetteFTPException;
          
          	public void dataRegime() throws OdetteFTPException;
          
          	public void closeFile(int recordCount, long unitCount)
          			throws OdetteFTPException;
          
          	public void changeDirection() throws OdetteFTPException;
          
          	public void endToEndResponse(String datasetName, Date fileDateTime,
          			String destination, String originator, String userData,
          			String reserved) throws OdetteFTPException;
          
          	public void release() throws OdetteFTPException;
          
          	public void abort(EndSessionReason error) throws OdetteFTPException;
          
          	public boolean isConnected() throws OdetteFTPException;
          
          }

          Comment

          • louis08
            New Member
            • Feb 2008
            • 6

            #6
            java.nio.Buffer OverflowExcepti on
            at java.nio.Direct ByteBuffer.put( DirectByteBuffe r.java:279)
            at org.fossilec.od ettej.service.S treamTransmissi onService.recei veStreamTransmi ssionBuffer(Str eamTransmission Service.java:87 )
            at org.fossilec.od ettej.service.S treamTransmissi onService.recei ve(StreamTransm issionService.j ava:64)
            at org.fossilec.od ettej.AbstractS tate.receive(Ab stractState.jav a:85)
            at org.fossilec.od ettej.ListenerS tate.negotiateS tartSession(Lis tenerState.java :548)
            at org.fossilec.od ettej.ListenerS tate.startSessi on(ListenerStat e.java:114)
            at org.fossilec.od ettej.Session.a cceptConnection (Session.java:2 66)
            at examples.odette j.OdetteServer. startSession(Od etteServer.java :140)
            at examples.odette j.OdetteServer. handleConnectio ns(OdetteServer .java:114)
            at examples.odette j.OdetteServer. run(OdetteServe r.java:54)
            at javaapplication 1.Main.<init>(M ain.java:27)
            at javaapplication 1.Main.main(Mai n.java:37)
            java.lang.Illeg alStateExceptio n: Not in Idle state
            at org.fossilec.od ettej.Session.N otInIdleStateEr ror(Session.jav a:310)
            at org.fossilec.od ettej.Session.a cceptConnection (Session.java:2 72)
            at examples.odette j.OdetteServer$ 2.run(OdetteSer ver.java:164)
            at java.lang.Threa d.run(Thread.ja va:595)

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              My first reaction when I see this much code posted is to run away! Run away! But let me introduce you to my leetle friend, the SSCCE If you want people to actually read your post, it must be much, much, much, much shorter. You need to show that you are putting effort into your post by composing the shortest possible example program.

              Comment

              • louis08
                New Member
                • Feb 2008
                • 6

                #8
                This is where the error is thrown.
                Code:
                final Transport transport = new TCPTransport(client);
                
                final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
                
                final StringBuffer userBoxId = new StringBuffer();
                
                session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
                
                session.acceptConnection(transport);
                /*Error happens here at next line*/
                OdetteFTPEntity oftp = session.acceptConnection(transport);
                this is the function that is called: acceptConnectio n()

                Code:
                     public OdetteFTPEntity acceptConnection(Transport transport)
                                  throws OdetteFTPException {
                 
                              /* incoming network connection */  
                              if ((state == null) || (state instanceof IdleState)) {
                
                                  boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
                                  int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
                                  service = Service.getInstance(transport, sdeb, stb); 
                                  setProperty("odette.called-address", transport.getLocalAddress());
                                  setProperty("odette.calling-address",transport.getRemoteAddress());
                         
                                 /* start session phase */
                                    changeState(ListenerState.class);
                                    /*Error happens here at next line*/
                                    state.startSession();
                                          
                                } else {
                
                                  NotInIdleStateError();
                              }
                              return state;
                          }
                I traced it into this interface called OdetteFTPEntity

                Code:
                public interface OdetteFTPEntity {
                
                    public Session getContext();
                /*Error happens here in startSession Function*/
                    public void startSession() throws OdetteFTPException;
                
                    public void startFile(VirtualFile file, String destination,
                
                           String originator, String userData, String reserved)
                
                            throws OdetteFTPException;
                
                    public void dataRegime() throws OdetteFTPException;
                
                    public void closeFile(int recordCount, long unitCount)
                            throws OdetteFTPException;
                
                    public void changeDirection() throws OdetteFTPException;
                
                    public void endToEndResponse(String datasetName, Date fileDateTime,
                            String destination, String originator, String userData,
                            String reserved) throws OdetteFTPException;
                
                    public void release() throws OdetteFTPException;
                
                    public void abort(EndSessionReason error) throws OdetteFTPException;
                
                    public boolean isConnected() throws OdetteFTPException;
                
                }
                This is the error stack trace
                Code:
                java.nio.BufferOverflowException
                at java.nio.DirectByteBuffer.put(DirectByteBuffer.jav a:279)
                at org.fossilec.odettej.service.StreamTransmissionSer vice.receiveStreamTransmissionBuffer(StreamTransmi ssionService.java:87)
                at org.fossilec.odettej.service.StreamTransmissionSer vice.receive(StreamTransmissionService.java:64)
                at org.fossilec.odettej.AbstractState.receive(Abstrac tState.java:85)
                at org.fossilec.odettej.ListenerState.negotiateStartS ession(ListenerState.java:548)
                at org.fossilec.odettej.ListenerState.startSession(Li stenerState.java:114)
                at org.fossilec.odettej.Session.acceptConnection(Sess ion.java:266)
                at examples.odettej.OdetteServer.startSession(OdetteS erver.java:140)
                at examples.odettej.OdetteServer.handleConnections(Od etteServer.java:114)
                at examples.odettej.OdetteServer.run(OdetteServer.jav a:54)
                at javaapplication1.Main.<init>(Main.java:27)
                at javaapplication1.Main.main(Main.java:37)
                java.lang.IllegalStateException: Not in Idle state
                at org.fossilec.odettej.Session.NotInIdleStateError(S ession.java:310)
                at org.fossilec.odettej.Session.acceptConnection(Sess ion.java:272)
                at examples.odettej.OdetteServer$2.run(OdetteServer.j ava:164)
                at java.lang.Thread.run(Thread.java:595)
                I Hope this is the right way,
                Thanks Louis.

                Comment

                Working...