473,796 Members | 2,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odette-j

6 New Member
When i call:

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

I recive a java.nio.Buffer OverflowExcepti on
Feb 18 '08 #1
7 2515
Nepomuk
3,112 Recognized Expert Specialist
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
Feb 18 '08 #2
louis08
6 New Member
Lines marked in bold is where the error happens.

Expand|Select|Wrap|Line Numbers
  1. package examples.odettej;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.net.InetSocketAddress;
  6. import java.nio.channels.SelectionKey;
  7. import java.nio.channels.Selector;
  8. import java.nio.channels.ServerSocketChannel;
  9. import java.nio.channels.SocketChannel;
  10. import java.util.Iterator;
  11. import java.util.Properties;
  12. import java.util.logging.Logger;
  13.  
  14. import org.fossilec.odettej.OdetteFTPEntity;
  15. import org.fossilec.odettej.OdetteFTPException;
  16. import org.fossilec.odettej.PeerAuthenticator;
  17. import org.fossilec.odettej.Session;
  18. import org.fossilec.odettej.service.TransferMode;
  19. import org.fossilec.odettej.transport.Transport;
  20. import org.fossilec.odettej.transport.tcp.TCPTransport;
  21.  
  22. public class OdetteServer implements Runnable {
  23.  
  24.     private static Logger logger = Logger.getLogger(OdetteServer.class.getName());
  25.  
  26.     private ServerSocketChannel channel = null;
  27.  
  28.     private String baseDir;
  29.  
  30.     private int listenPort;
  31.  
  32.     private boolean shouldStop;
  33.  
  34.         private Thread runner;
  35.  
  36.     public OdetteServer(String baseDir, int listenPort) {
  37.         super();
  38.         this.baseDir = baseDir;
  39.         this.listenPort = listenPort;
  40.     }
  41.  
  42.     /**
  43.      * @param args
  44.      */
  45.     public static void main(String[] args) {
  46.  
  47.     }
  48.  
  49.     public void run() {
  50.  
  51.         serverBind();
  52.  
  53.         try {
  54.             handleConnections();
  55.         } catch (IOException e) {
  56.             logger.throwing("OdetteServer", "run", e);
  57.         }
  58.  
  59.     }
  60.  
  61.     private void serverBind() {
  62.  
  63.         // create and bind (listen) to the specified port
  64.         try {
  65.             channel = ServerSocketChannel.open();
  66.             channel.socket().bind(new InetSocketAddress(listenPort));
  67.             logger.info("Odette FTP Server listening on port: " + listenPort);
  68.         } catch (IOException e) {
  69.             logger.throwing("OdetteServer", "bind", e);
  70.         }
  71.  
  72.     }
  73.  
  74.     public void handleConnections() throws IOException {
  75.  
  76.         // turn off flag on start until method stop() is called
  77.         shouldStop = false;
  78.  
  79.         // create selector
  80.         Selector selector = Selector.open();
  81.  
  82.         try {
  83.             // set channel as non-blocking mode and register the selector
  84.             channel.configureBlocking(false);
  85.             channel.register(selector, SelectionKey.OP_ACCEPT);
  86.  
  87.             while (!shouldStop) {
  88.  
  89.                 // wait for any operation avaiable
  90.                 selector.select();
  91.                 Iterator iterator = selector.selectedKeys().iterator();
  92.  
  93.                 while (iterator.hasNext()) {
  94.  
  95.                     // get avaiable operation
  96.                     SelectionKey key = (SelectionKey) iterator.next();
  97.  
  98.                     // found an accept operation on the server socket
  99.                     if (key.isAcceptable()) {
  100.                         ServerSocketChannel server = (ServerSocketChannel) key
  101.                                 .channel();
  102.  
  103.                         // create a client socket, also in non-blocking mode
  104.                         SocketChannel client = server.accept();
  105.  
  106.                         logger.info("Receiving connection from: " + client.socket().getRemoteSocketAddress());
  107.  
  108. //                        if (client != null) {
  109. //                            client.configureBlocking(false);
  110. //                            // register client socket on the selector
  111. //                            client.register(selector, SelectionKey.OP_READ);
  112. //                        }
  113.  
  114.                         startSession(client);
  115.                     }
  116.                 }
  117.             }
  118.         } catch (Exception e) {
  119.             logger.throwing("OdetteServer", "handleConnections", e);
  120.                         System.out.println(e.toString());
  121.         } finally {
  122.             // always close the selector
  123.             selector.close();
  124.         }
  125.  
  126.     }
  127.  
  128.  
  129.     private void startSession(SocketChannel client) throws OdetteFTPException {
  130.  
  131.                 try {
  132.                     client.socket().getChannel().configureBlocking(false);
  133.                 }catch(Exception e) {
  134.                     System.out.println(e.toString());
  135.                 }
  136.         final Transport transport = new TCPTransport(client);
  137.         final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
  138.         final StringBuffer userBoxId = new StringBuffer();
  139.                 session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
  140.                 session.acceptConnection(transport);
  141.  
  142.         session.setAuthenticator(new PeerAuthenticator() {
  143.  
  144.             public void init(Session context) { }
  145.  
  146.             public void authenticate(String remoteUser, String remotePassword, String address) throws OdetteFTPException {
  147.  
  148.                 userBoxId.append(remoteUser);
  149.  
  150.                 String userInboxDir = baseDir + File.separator + remoteUser + File.separator + "incoming";
  151.                 session.setReceivingSupport(new ListeningSupport(userInboxDir));
  152.  
  153.                 // no exception thrown means authentication succeed
  154.             }
  155.  
  156.         });
  157.  
  158.         // gives an independent lifecycle to this OFTP session (see the receiving support is already set)
  159.  
  160.         Thread t = new Thread(new Runnable() {
  161.             public void run() {
  162.  
  163.                 try {
  164.                     OdetteFTPEntity oftp = session.acceptConnection(transport);
  165.                     // create the OdetteApp instance here???
  166.  
  167.                 } catch (OdetteFTPException e) {
  168.                                     e.printStackTrace();
  169.                                     logger.throwing("OdetteServer", "startSession$Runnable...", e);
  170.                 }
  171.  
  172.             }
  173.         });
  174.  
  175.         t.start();
  176.     }
  177.  
  178.     public void stop() {
  179.         shouldStop = true;
  180.     }
  181. }
  182.  
  183.  
  184. public OdetteFTPEntity acceptConnection(Transport transport)
  185.             throws OdetteFTPException {
  186.  
  187.         /* incoming network connection */
  188.  
  189.         if ((state == null) || (state instanceof IdleState)) {
  190.  
  191.             boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
  192.             int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
  193.                         service = Service.getInstance(transport, sdeb, stb);
  194.  
  195.             setProperty("odette.called-address", transport.getLocalAddress());
  196.             setProperty("odette.calling-address", transport.getRemoteAddress());
  197.  
  198.             /* start session phase */
  199.             changeState(ListenerState.class);
  200.                         state.startSession();
  201.  
  202.         } else {
  203.             NotInIdleStateError();
  204.         }
  205.  
  206.         return state;
  207.     }
  208.  
  209. -------------------------------------------------
  210. package org.fossilec.odettej;
  211.  
  212. import org.fossilec.odettej.service.CommandExchangeBuffer;
  213. import org.fossilec.odettej.service.CommandIdentifier;
  214. import org.fossilec.odettej.service.EndSessionReason;
  215. import org.fossilec.odettej.service.OdetteExchangeBuffer;
  216. import org.fossilec.odettej.service.Service;
  217. import org.fossilec.odettej.service.TransferMode;
  218. import org.fossilec.odettej.transport.Transport;
  219.  
  220. abstract class AbstractState implements OdetteFTPEntity {
  221.  
  222.     private Session context;
  223.  
  224.     private PreferencesUtil prefs;
  225.  
  226.     private boolean useStrictFormat;
  227.  
  228.     protected AbstractState(Session context) {
  229.         super();
  230.  
  231.         this.context = context;
  232.         prefs = new PreferencesUtil(context.getProperties());
  233.  
  234.         useStrictFormat = prefs.isUsingStrictFormat();
  235.     }
  236.  
  237.     protected abstract void listen() throws OdetteFTPException;
  238.  
  239.     public Session getContext() {
  240.         return context;
  241.     }
  242.  
  243.     public PreferencesUtil getPreferences() {
  244.         return prefs;
  245.     }
  246.  
  247.     public Service getService() throws OdetteFTPException {
  248.         return context.getService();
  249.     }
  250.  
  251.     public void resetCredits() {
  252.         String window = context.getProperty("odette.window-size");
  253.         setCredits(Integer.parseInt(window));
  254.     }
  255.  
  256.     public void consumeCredit() {
  257.         int credits = getCredits();
  258.         credits--;
  259.  
  260.         setCredits(credits);
  261.     }
  262.  
  263.     protected abstract void setCredits(int windowSize);
  264.  
  265.     public abstract int getCredits();
  266.  
  267.     public boolean hasCredits() {
  268.         return (getCredits() > 0);
  269.     }
  270.  
  271.     protected OdetteExchangeBuffer receive() throws OdetteFTPException {
  272.         OdetteExchangeBuffer exchangeBuffer = getService().receive(
  273.                 useStrictFormat);
  274.  
  275.         if (exchangeBuffer.getIdentifier() == CommandIdentifier.ESID) {
  276.  
  277.             CommandExchangeBuffer esid = (CommandExchangeBuffer) exchangeBuffer;
  278.  
  279.             String code = esid.getParameter("ESIDREAS");
  280.             EndSessionReason reason = EndSessionReason.parse(code);
  281.  
  282.             if (reason != EndSessionReason.NORMAL_TERMINATION) {
  283.                 abnormalRelease(reason);
  284.             }
  285.         }
  286.  
  287.         return exchangeBuffer;
  288.     }
  289.  
  290.     protected void send(OdetteExchangeBuffer oeb) throws OdetteFTPException {
  291.         Service service = getService();
  292.         service.send(oeb);
  293.     }
  294.  
  295.     protected void disconnect() throws OdetteFTPException {
  296.         context.disconnect();
  297.     }
  298.  
  299.     public boolean isConnected() throws OdetteFTPException {
  300.         Service service = getService();
  301.         Transport transport = service.getTransport();
  302.  
  303.         return transport.isConnected();
  304.     }
  305.  
  306.     public void release() throws OdetteFTPException {
  307.         protocolRelease(EndSessionReason.NORMAL_TERMINATION);
  308.     }
  309.  
  310.     protected void abnormalRelease(EndSessionReason error)
  311.             throws OdetteFTPException {
  312.  
  313.         protocolRelease(error);
  314.         endSessionError(error, "abnormal release");
  315.     }
  316.  
  317.     protected void abnormalRelease(EndSessionReason error, String msg)
  318.             throws OdetteFTPException {
  319.  
  320.         protocolRelease(error);
  321.         endSessionError(error, msg);
  322.     }
  323.  
  324.     public void abort(EndSessionReason error) throws OdetteFTPException {
  325.         protocolRelease(error);
  326.     }
  327.  
  328.     private void protocolRelease(EndSessionReason reason)
  329.             throws OdetteFTPException {
  330.  
  331.         Service service = getService();
  332.  
  333.         CommandExchangeBuffer esid;
  334.  
  335.         if (reason == null) {
  336.             throw new IllegalArgumentException("Reason must not be null");
  337.         }
  338.  
  339.         /*
  340.          * Sending End Session command.
  341.          */
  342.         esid = CommandExchangeBuffer.endSession(reason);
  343.  
  344.         send(esid);
  345.  
  346.         try {
  347.             Thread.sleep(500);
  348.         } catch (Exception e) {
  349.             e.printStackTrace();
  350.         }
  351.  
  352.         service.disconnect();
  353.  
  354.         context.changeState(IdleState.class);
  355.     }
  356.  
  357.     private static void endSessionError(EndSessionReason error, String msg)
  358.             throws OdetteFTPException {
  359.         throw new EndSessionException(error, msg);
  360.     }
  361.  
  362.     protected void requestAuthentication(String ssidcode, String ssidpswd,
  363.             String remoteAddress) throws OdetteFTPException {
  364.  
  365.         Session context = getContext();
  366.  
  367.         PeerAuthenticator auth = context.getAuthenticator();
  368.  
  369.         if (auth != null) {
  370.             auth.authenticate(ssidcode, ssidpswd, remoteAddress);
  371.         }
  372.     }
  373.  
  374.     protected static boolean windowSizeViolation(int size, Session session) {
  375.         return ((size <= 0) || (size > session.getMaxWindow()));
  376.     }
  377.  
  378.     protected static boolean bufferSizeViolation(int size, Session session) {
  379.         return ((size < OdetteExchangeBuffer.MIN_OEB_LENGTH) || (size > session
  380.                 .getMaxBuffer()));
  381.     }
  382.  
  383.     protected static boolean valueOfYesNo(String parameter) {
  384.         return (parameter.equals("Y") ? true : false);
  385.     }
  386.  
  387.     protected static void checkStartSession(Session context, int sdeb,
  388.             int window, boolean compression, TransferMode mode, boolean restart)
  389.             throws OdetteFTPException {
  390.  
  391.         /* check exchange buffer size */
  392.         if (bufferSizeViolation(sdeb, context)) {
  393.             endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
  394.                     "Invalid exchange buffer size is being used: " + sdeb);
  395.         }
  396.  
  397.         /* check window size */
  398.         if (windowSizeViolation(window, context)) {
  399.             endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
  400.                     "Invalid window size is being used: " + window);
  401.         }
  402.  
  403.         /* check compression capability */
  404.         if ((!context.isCompressionCapable()) && (compression)) {
  405.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  406.                     "Implementation doesn't support compression");
  407.         }
  408.  
  409.         /* check transfer mode capability */
  410.         TransferMode capmode = context.getCapableTransferMode();
  411.         if ((capmode != TransferMode.BOTH) && (mode != capmode)) {
  412.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  413.                     "Implementation doesn't support this mode: " + mode);
  414.         }
  415.  
  416.         /* check restart capability */
  417.         if ((!context.isRestartCapable()) && (restart)) {
  418.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  419.                     "Implementation doesn't support restart");
  420.         }
  421.     }
  422.  
  423. }
  424.  
  425.  
  426. _______________________________________________
  427.  
  428. public interface OdetteFTPEntity {
  429.  
  430.     public Session getContext();
  431.  
  432.     public void startSession() throws OdetteFTPException;
  433.  
  434.     public void startFile(VirtualFile file, String destination,
  435.             String originator, String userData, String reserved)
  436.             throws OdetteFTPException;
  437.  
  438.     public void dataRegime() throws OdetteFTPException;
  439.  
  440.     public void closeFile(int recordCount, long unitCount)
  441.             throws OdetteFTPException;
  442.  
  443.     public void changeDirection() throws OdetteFTPException;
  444.  
  445.     public void endToEndResponse(String datasetName, Date fileDateTime,
  446.             String destination, String originator, String userData,
  447.             String reserved) throws OdetteFTPException;
  448.  
  449.     public void release() throws OdetteFTPException;
  450.  
  451.     public void abort(EndSessionReason error) throws OdetteFTPException;
  452.  
  453.     public boolean isConnected() throws OdetteFTPException;
  454.  
  455. }
  456.  
Feb 18 '08 #3
Nepomuk
3,112 Recognized Expert Specialist
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
Feb 18 '08 #4
louis08
6 New Member
Lines marked in bold is where the error happens.

Expand|Select|Wrap|Line Numbers
  1. package examples.odettej;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.net.InetSocketAddress;
  6. import java.nio.channels.SelectionKey;
  7. import java.nio.channels.Selector;
  8. import java.nio.channels.ServerSocketChannel;
  9. import java.nio.channels.SocketChannel;
  10. import java.util.Iterator;
  11. import java.util.Properties;
  12. import java.util.logging.Logger;
  13.  
  14. import org.fossilec.odettej.OdetteFTPEntity;
  15. import org.fossilec.odettej.OdetteFTPException;
  16. import org.fossilec.odettej.PeerAuthenticator;
  17. import org.fossilec.odettej.Session;
  18. import org.fossilec.odettej.service.TransferMode;
  19. import org.fossilec.odettej.transport.Transport;
  20. import org.fossilec.odettej.transport.tcp.TCPTransport;
  21.  
  22. public class OdetteServer implements Runnable {
  23.  
  24.     private static Logger logger = Logger.getLogger(OdetteServer.class.getName());
  25.  
  26.     private ServerSocketChannel channel = null;
  27.  
  28.     private String baseDir;
  29.  
  30.     private int listenPort;
  31.  
  32.     private boolean shouldStop;
  33.  
  34.         private Thread runner;
  35.  
  36.     public OdetteServer(String baseDir, int listenPort) {
  37.         super();
  38.         this.baseDir = baseDir;
  39.         this.listenPort = listenPort;
  40.     }
  41.  
  42.     /**
  43.      * @param args
  44.      */
  45.     public static void main(String[] args) {
  46.  
  47.     }
  48.  
  49.     public void run() {
  50.  
  51.         serverBind();
  52.  
  53.         try {
  54.             handleConnections();
  55.         } catch (IOException e) {
  56.             logger.throwing("OdetteServer", "run", e);
  57.         }
  58.  
  59.     }
  60.  
  61.     private void serverBind() {
  62.  
  63.         // create and bind (listen) to the specified port
  64.         try {
  65.             channel = ServerSocketChannel.open();
  66.             channel.socket().bind(new InetSocketAddress(listenPort));
  67.             logger.info("Odette FTP Server listening on port: " + listenPort);
  68.         } catch (IOException e) {
  69.             logger.throwing("OdetteServer", "bind", e);
  70.         }
  71.  
  72.     }
  73.  
  74.     public void handleConnections() throws IOException {
  75.  
  76.         // turn off flag on start until method stop() is called
  77.         shouldStop = false;
  78.  
  79.         // create selector
  80.         Selector selector = Selector.open();
  81.  
  82.         try {
  83.             // set channel as non-blocking mode and register the selector
  84.             channel.configureBlocking(false);
  85.             channel.register(selector, SelectionKey.OP_ACCEPT);
  86.  
  87.             while (!shouldStop) {
  88.  
  89.                 // wait for any operation avaiable
  90.                 selector.select();
  91.                 Iterator iterator = selector.selectedKeys().iterator();
  92.  
  93.                 while (iterator.hasNext()) {
  94.  
  95.                     // get avaiable operation
  96.                     SelectionKey key = (SelectionKey) iterator.next();
  97.  
  98.                     // found an accept operation on the server socket
  99.                     if (key.isAcceptable()) {
  100.                         ServerSocketChannel server = (ServerSocketChannel) key
  101.                                 .channel();
  102.  
  103.                         // create a client socket, also in non-blocking mode
  104.                         SocketChannel client = server.accept();
  105.  
  106.                         logger.info("Receiving connection from: " + client.socket().getRemoteSocketAddress());
  107.  
  108. //                        if (client != null) {
  109. //                            client.configureBlocking(false);
  110. //                            // register client socket on the selector
  111. //                            client.register(selector, SelectionKey.OP_READ);
  112. //                        }
  113.  
  114.                         startSession(client);
  115.                     }
  116.                 }
  117.             }
  118.         } catch (Exception e) {
  119.             logger.throwing("OdetteServer", "handleConnections", e);
  120.                         System.out.println(e.toString());
  121.         } finally {
  122.             // always close the selector
  123.             selector.close();
  124.         }
  125.  
  126.     }
  127.  
  128.  
  129.     private void startSession(SocketChannel client) throws OdetteFTPException {
  130.  
  131.                 try {
  132.                     client.socket().getChannel().configureBlocking(false);
  133.                 }catch(Exception e) {
  134.                     System.out.println(e.toString());
  135.                 }
  136.         final Transport transport = new TCPTransport(client);
  137.         final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
  138.         final StringBuffer userBoxId = new StringBuffer();
  139.                 session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
  140.                 session.acceptConnection(transport);
  141.  
  142.         session.setAuthenticator(new PeerAuthenticator() {
  143.  
  144.             public void init(Session context) { }
  145.  
  146.             public void authenticate(String remoteUser, String remotePassword, String address) throws OdetteFTPException {
  147.  
  148.                 userBoxId.append(remoteUser);
  149.  
  150.                 String userInboxDir = baseDir + File.separator + remoteUser + File.separator + "incoming";
  151.                 session.setReceivingSupport(new ListeningSupport(userInboxDir));
  152.  
  153.                 // no exception thrown means authentication succeed
  154.             }
  155.  
  156.         });
  157.  
  158.         // gives an independent lifecycle to this OFTP session (see the receiving support is already set)
  159.  
  160.         Thread t = new Thread(new Runnable() {
  161.             public void run() {
  162.  
  163.                 try {
  164.                     OdetteFTPEntity oftp = session.acceptConnection(transport);
  165.                     // create the OdetteApp instance here???
  166.  
  167.                 } catch (OdetteFTPException e) {
  168.                                     e.printStackTrace();
  169.                                     logger.throwing("OdetteServer", "startSession$Runnable...", e);
  170.                 }
  171.  
  172.             }
  173.         });
  174.  
  175.         t.start();
  176.     }
  177.  
  178.     public void stop() {
  179.         shouldStop = true;
  180.     }
  181. }
  182.  
Expand|Select|Wrap|Line Numbers
  1. public OdetteFTPEntity acceptConnection(Transport transport)
  2.             throws OdetteFTPException {
  3.  
  4.         /* incoming network connection */
  5.  
  6.         if ((state == null) || (state instanceof IdleState)) {
  7.  
  8.             boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
  9.             int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
  10.                         service = Service.getInstance(transport, sdeb, stb);
  11.  
  12.             setProperty("odette.called-address", transport.getLocalAddress());
  13.             setProperty("odette.calling-address", transport.getRemoteAddress());
  14.  
  15.             /* start session phase */
  16.             changeState(ListenerState.class);
  17.                         state.startSession();
  18.  
  19.         } else {
  20.             NotInIdleStateError();
  21.         }
  22.  
  23.         return state;
  24.     }
  25.  
Expand|Select|Wrap|Line Numbers
  1. -------------------------------------------------
  2.  
  3. package org.fossilec.odettej;
  4.  
  5. import org.fossilec.odettej.service.CommandExchangeBuffer;
  6. import org.fossilec.odettej.service.CommandIdentifier;
  7. import org.fossilec.odettej.service.EndSessionReason;
  8. import org.fossilec.odettej.service.OdetteExchangeBuffer;
  9. import org.fossilec.odettej.service.Service;
  10. import org.fossilec.odettej.service.TransferMode;
  11. import org.fossilec.odettej.transport.Transport;
  12.  
  13. abstract class AbstractState implements OdetteFTPEntity {
  14.  
  15.     private Session context;
  16.  
  17.     private PreferencesUtil prefs;
  18.  
  19.     private boolean useStrictFormat;
  20.  
  21.     protected AbstractState(Session context) {
  22.         super();
  23.  
  24.         this.context = context;
  25.         prefs = new PreferencesUtil(context.getProperties());
  26.  
  27.         useStrictFormat = prefs.isUsingStrictFormat();
  28.     }
  29.  
  30.     protected abstract void listen() throws OdetteFTPException;
  31.  
  32.     public Session getContext() {
  33.         return context;
  34.     }
  35.  
  36.     public PreferencesUtil getPreferences() {
  37.         return prefs;
  38.     }
  39.  
  40.     public Service getService() throws OdetteFTPException {
  41.         return context.getService();
  42.     }
  43.  
  44.     public void resetCredits() {
  45.         String window = context.getProperty("odette.window-size");
  46.         setCredits(Integer.parseInt(window));
  47.     }
  48.  
  49.     public void consumeCredit() {
  50.         int credits = getCredits();
  51.         credits--;
  52.  
  53.         setCredits(credits);
  54.     }
  55.  
  56.     protected abstract void setCredits(int windowSize);
  57.  
  58.     public abstract int getCredits();
  59.  
  60.     public boolean hasCredits() {
  61.         return (getCredits() > 0);
  62.     }
  63.  
  64.     protected OdetteExchangeBuffer receive() throws OdetteFTPException {
  65.         OdetteExchangeBuffer exchangeBuffer = getService().receive(
  66.                 useStrictFormat);
  67.  
  68.         if (exchangeBuffer.getIdentifier() == CommandIdentifier.ESID) {
  69.  
  70.             CommandExchangeBuffer esid = (CommandExchangeBuffer) exchangeBuffer;
  71.  
  72.             String code = esid.getParameter("ESIDREAS");
  73.             EndSessionReason reason = EndSessionReason.parse(code);
  74.  
  75.             if (reason != EndSessionReason.NORMAL_TERMINATION) {
  76.                 abnormalRelease(reason);
  77.             }
  78.         }
  79.  
  80.         return exchangeBuffer;
  81.     }
  82.  
  83.     protected void send(OdetteExchangeBuffer oeb) throws OdetteFTPException {
  84.         Service service = getService();
  85.         service.send(oeb);
  86.     }
  87.  
  88.     protected void disconnect() throws OdetteFTPException {
  89.         context.disconnect();
  90.     }
  91.  
  92.     public boolean isConnected() throws OdetteFTPException {
  93.         Service service = getService();
  94.         Transport transport = service.getTransport();
  95.  
  96.         return transport.isConnected();
  97.     }
  98.  
  99.     public void release() throws OdetteFTPException {
  100.         protocolRelease(EndSessionReason.NORMAL_TERMINATION);
  101.     }
  102.  
  103.     protected void abnormalRelease(EndSessionReason error)
  104.             throws OdetteFTPException {
  105.  
  106.         protocolRelease(error);
  107.         endSessionError(error, "abnormal release");
  108.     }
  109.  
  110.     protected void abnormalRelease(EndSessionReason error, String msg)
  111.             throws OdetteFTPException {
  112.  
  113.         protocolRelease(error);
  114.         endSessionError(error, msg);
  115.     }
  116.  
  117.     public void abort(EndSessionReason error) throws OdetteFTPException {
  118.         protocolRelease(error);
  119.     }
  120.  
  121.     private void protocolRelease(EndSessionReason reason)
  122.             throws OdetteFTPException {
  123.  
  124.         Service service = getService();
  125.  
  126.         CommandExchangeBuffer esid;
  127.  
  128.         if (reason == null) {
  129.             throw new IllegalArgumentException("Reason must not be null");
  130.         }
  131.  
  132.         /*
  133.          * Sending End Session command.
  134.          */
  135.         esid = CommandExchangeBuffer.endSession(reason);
  136.  
  137.         send(esid);
  138.  
  139.         try {
  140.             Thread.sleep(500);
  141.         } catch (Exception e) {
  142.             e.printStackTrace();
  143.         }
  144.  
  145.         service.disconnect();
  146.  
  147.         context.changeState(IdleState.class);
  148.     }
  149.  
  150.     private static void endSessionError(EndSessionReason error, String msg)
  151.             throws OdetteFTPException {
  152.         throw new EndSessionException(error, msg);
  153.     }
  154.  
  155.     protected void requestAuthentication(String ssidcode, String ssidpswd,
  156.             String remoteAddress) throws OdetteFTPException {
  157.  
  158.         Session context = getContext();
  159.  
  160.         PeerAuthenticator auth = context.getAuthenticator();
  161.  
  162.         if (auth != null) {
  163.             auth.authenticate(ssidcode, ssidpswd, remoteAddress);
  164.         }
  165.     }
  166.  
  167.     protected static boolean windowSizeViolation(int size, Session session) {
  168.         return ((size <= 0) || (size > session.getMaxWindow()));
  169.     }
  170.  
  171.     protected static boolean bufferSizeViolation(int size, Session session) {
  172.         return ((size < OdetteExchangeBuffer.MIN_OEB_LENGTH) || (size > session
  173.                 .getMaxBuffer()));
  174.     }
  175.  
  176.     protected static boolean valueOfYesNo(String parameter) {
  177.         return (parameter.equals("Y") ? true : false);
  178.     }
  179.  
  180.     protected static void checkStartSession(Session context, int sdeb,
  181.             int window, boolean compression, TransferMode mode, boolean restart)
  182.             throws OdetteFTPException {
  183.  
  184.         /* check exchange buffer size */
  185.         if (bufferSizeViolation(sdeb, context)) {
  186.             endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
  187.                     "Invalid exchange buffer size is being used: " + sdeb);
  188.         }
  189.  
  190.         /* check window size */
  191.         if (windowSizeViolation(window, context)) {
  192.             endSessionError(EndSessionReason.INVALID_COMMAND_DATA,
  193.                     "Invalid window size is being used: " + window);
  194.         }
  195.  
  196.         /* check compression capability */
  197.         if ((!context.isCompressionCapable()) && (compression)) {
  198.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  199.                     "Implementation doesn't support compression");
  200.         }
  201.  
  202.         /* check transfer mode capability */
  203.         TransferMode capmode = context.getCapableTransferMode();
  204.         if ((capmode != TransferMode.BOTH) && (mode != capmode)) {
  205.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  206.                     "Implementation doesn't support this mode: " + mode);
  207.         }
  208.  
  209.         /* check restart capability */
  210.         if ((!context.isRestartCapable()) && (restart)) {
  211.             endSessionError(EndSessionReason.INCOMPATIBLE_MODE,
  212.                     "Implementation doesn't support restart");
  213.         }
  214.     }
  215.  
  216. }
  217.  
  218.  
  219. _______________________________________________
  220.  
  221. public interface OdetteFTPEntity {
  222.  
  223.     public Session getContext();
  224.  
  225.     public void startSession() throws OdetteFTPException;
  226.  
  227.     public void startFile(VirtualFile file, String destination,
  228.             String originator, String userData, String reserved)
  229.             throws OdetteFTPException;
  230.  
  231.     public void dataRegime() throws OdetteFTPException;
  232.  
  233.     public void closeFile(int recordCount, long unitCount)
  234.             throws OdetteFTPException;
  235.  
  236.     public void changeDirection() throws OdetteFTPException;
  237.  
  238.     public void endToEndResponse(String datasetName, Date fileDateTime,
  239.             String destination, String originator, String userData,
  240.             String reserved) throws OdetteFTPException;
  241.  
  242.     public void release() throws OdetteFTPException;
  243.  
  244.     public void abort(EndSessionReason error) throws OdetteFTPException;
  245.  
  246.     public boolean isConnected() throws OdetteFTPException;
  247.  
  248. }
  249.  
Feb 18 '08 #5
louis08
6 New Member
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)
Feb 18 '08 #6
BigDaddyLH
1,216 Recognized Expert Top Contributor
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.
Feb 18 '08 #7
louis08
6 New Member
This is where the error is thrown.
Expand|Select|Wrap|Line Numbers
  1. final Transport transport = new TCPTransport(client);
  2.  
  3. final Session session = Session.getInstance(new Properties(), TransferMode.BOTH);
  4.  
  5. final StringBuffer userBoxId = new StringBuffer();
  6.  
  7. session.setReceivingSupport(new ListeningSupport("C:/oftp/"));
  8.  
  9. session.acceptConnection(transport);
  10. /*Error happens here at next line*/
  11. OdetteFTPEntity oftp = session.acceptConnection(transport);
  12.  
this is the function that is called: acceptConnectio n()

Expand|Select|Wrap|Line Numbers
  1.      public OdetteFTPEntity acceptConnection(Transport transport)
  2.                   throws OdetteFTPException {
  3.  
  4.               /* incoming network connection */  
  5.               if ((state == null) || (state instanceof IdleState)) {
  6.  
  7.                   boolean stb = PreferencesUtil.getBoolean(properties, "odette.stb");
  8.                   int sdeb = PreferencesUtil.getInt(properties, "odette.buffer-size");
  9.                   service = Service.getInstance(transport, sdeb, stb); 
  10.                   setProperty("odette.called-address", transport.getLocalAddress());
  11.                   setProperty("odette.calling-address",transport.getRemoteAddress());
  12.  
  13.                  /* start session phase */
  14.                     changeState(ListenerState.class);
  15.                     /*Error happens here at next line*/
  16.                     state.startSession();
  17.  
  18.                 } else {
  19.  
  20.                   NotInIdleStateError();
  21.               }
  22.               return state;
  23.           }
  24.  
I traced it into this interface called OdetteFTPEntity

Expand|Select|Wrap|Line Numbers
  1. public interface OdetteFTPEntity {
  2.  
  3.     public Session getContext();
  4. /*Error happens here in startSession Function*/
  5.     public void startSession() throws OdetteFTPException;
  6.  
  7.     public void startFile(VirtualFile file, String destination,
  8.  
  9.            String originator, String userData, String reserved)
  10.  
  11.             throws OdetteFTPException;
  12.  
  13.     public void dataRegime() throws OdetteFTPException;
  14.  
  15.     public void closeFile(int recordCount, long unitCount)
  16.             throws OdetteFTPException;
  17.  
  18.     public void changeDirection() throws OdetteFTPException;
  19.  
  20.     public void endToEndResponse(String datasetName, Date fileDateTime,
  21.             String destination, String originator, String userData,
  22.             String reserved) throws OdetteFTPException;
  23.  
  24.     public void release() throws OdetteFTPException;
  25.  
  26.     public void abort(EndSessionReason error) throws OdetteFTPException;
  27.  
  28.     public boolean isConnected() throws OdetteFTPException;
  29.  
  30. }
  31.  
This is the error stack trace
Expand|Select|Wrap|Line Numbers
  1. java.nio.BufferOverflowException
  2. at java.nio.DirectByteBuffer.put(DirectByteBuffer.jav a:279)
  3. at org.fossilec.odettej.service.StreamTransmissionSer vice.receiveStreamTransmissionBuffer(StreamTransmi ssionService.java:87)
  4. at org.fossilec.odettej.service.StreamTransmissionSer vice.receive(StreamTransmissionService.java:64)
  5. at org.fossilec.odettej.AbstractState.receive(Abstrac tState.java:85)
  6. at org.fossilec.odettej.ListenerState.negotiateStartS ession(ListenerState.java:548)
  7. at org.fossilec.odettej.ListenerState.startSession(Li stenerState.java:114)
  8. at org.fossilec.odettej.Session.acceptConnection(Sess ion.java:266)
  9. at examples.odettej.OdetteServer.startSession(OdetteS erver.java:140)
  10. at examples.odettej.OdetteServer.handleConnections(Od etteServer.java:114)
  11. at examples.odettej.OdetteServer.run(OdetteServer.jav a:54)
  12. at javaapplication1.Main.<init>(Main.java:27)
  13. at javaapplication1.Main.main(Main.java:37)
  14. java.lang.IllegalStateException: Not in Idle state
  15. at org.fossilec.odettej.Session.NotInIdleStateError(S ession.java:310)
  16. at org.fossilec.odettej.Session.acceptConnection(Sess ion.java:272)
  17. at examples.odettej.OdetteServer$2.run(OdetteServer.j ava:164)
  18. at java.lang.Thread.run(Thread.java:595)
  19.  
I Hope this is the right way,
Thanks Louis.
Feb 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

62
11422
by: Ecohouse | last post by:
I was just wondering if there was any way to use a toolbar in Outlook 2002 in Access 2002? I want to create a custom toolbar in Access similar to the Calendar toolbar in Outlook. Any ideas?
0
1295
by: louis08 | last post by:
When i connect to the server i get a BufferOverflowException, HELP!!!! This is where the error is thrown. final Transport transport = new TCPTransport(client);
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.