View Javadoc
1   /*
2    * This file is part of Waarp Project (named also Waarp or GG).
3    *
4    *  Copyright (c) 2019, Waarp SAS, and individual contributors by the @author
5    *  tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    *
8    *  All Waarp Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   *
13   * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   *
17   *  You should have received a copy of the GNU General Public License along with
18   * Waarp . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package org.waarp.gateway.kernel.session;
21  
22  import io.netty.handler.codec.http.HttpMethod;
23  import org.waarp.common.command.exception.CommandAbstractException;
24  import org.waarp.common.file.DirInterface;
25  import org.waarp.common.file.FileParameterInterface;
26  import org.waarp.common.file.Restart;
27  import org.waarp.common.file.SessionInterface;
28  import org.waarp.common.file.filesystembased.FilesystemBasedOptsMLSxImpl;
29  import org.waarp.gateway.kernel.HttpPage.PageRole;
30  import org.waarp.gateway.kernel.commonfile.CommonDirImpl;
31  import org.waarp.gateway.kernel.commonfile.FilesystemBasedFileParameterImpl;
32  import org.waarp.gateway.kernel.database.DbConstantGateway;
33  
34  /**
35   *
36   */
37  public class HttpSession implements SessionInterface {
38    protected HttpAuthInterface httpAuth;
39    protected long logid = DbConstantGateway.ILLEGALVALUE;
40    protected CommonDirImpl dir;
41    HttpMethod method;
42    private String cookieSession;
43    private PageRole currentCommand;
44    protected String filename;
45  
46    /**
47     *
48     */
49    public HttpSession() {
50      // nothing
51    }
52  
53    /**
54     * @return the method
55     */
56    public final HttpMethod getMethod() {
57      return method;
58    }
59  
60    /**
61     * @param method the method to set
62     */
63    public final void setMethod(final HttpMethod method) {
64      this.method = method;
65    }
66  
67    /**
68     * @param httpAuth the httpAuth to set
69     */
70    public final void setHttpAuth(final HttpAuthInterface httpAuth) {
71      this.httpAuth = httpAuth;
72      dir = new CommonDirImpl(this, new FilesystemBasedOptsMLSxImpl());
73      try {
74        dir.changeDirectoryNotChecked(httpAuth.getUser());
75        dir.changeDirectoryNotChecked(httpAuth.getAccount());
76      } catch (final CommandAbstractException ignored) {
77        // nothing
78      }
79    }
80  
81    @Override
82    public final HttpAuthInterface getAuth() {
83      return httpAuth;
84    }
85  
86    @Override
87    public final void clear() {
88      if (httpAuth != null) {
89        httpAuth.clear();
90      }
91    }
92  
93    @Override
94    public final int getBlockSize() {
95      return 8192; // HttpChunk size
96    }
97  
98    @Override
99    public final FileParameterInterface getFileParameter() {
100     return FilesystemBasedFileParameterImpl.fileParameterInterface;
101   }
102 
103   @Override
104   public final Restart getRestart() {
105     return null;
106   }
107 
108   @Override
109   public final String getUniqueExtension() {
110     return ".postu";
111   }
112 
113   /**
114    * @return the logid
115    */
116   public final long getLogid() {
117     return logid;
118   }
119 
120   /**
121    * @param logid the logid to set
122    */
123   public final void setLogid(final long logid) {
124     this.logid = logid;
125   }
126 
127   @Override
128   public final DirInterface getDir() {
129     return dir;
130   }
131 
132   /**
133    * @return the currentCommand
134    */
135   public final PageRole getCurrentCommand() {
136     return currentCommand;
137   }
138 
139   /**
140    * @param currentCommand the currentCommand to set
141    */
142   public final void setCurrentCommand(final PageRole currentCommand) {
143     this.currentCommand = currentCommand;
144   }
145 
146   /**
147    * @return the cookieSession
148    */
149   public final String getCookieSession() {
150     return cookieSession;
151   }
152 
153   /**
154    * @param cookieSession the cookieSession to set
155    */
156   public final void setCookieSession(final String cookieSession) {
157     this.cookieSession = cookieSession;
158   }
159 
160   /**
161    * @return the filename
162    */
163   public final String getFilename() {
164     return filename;
165   }
166 
167   /**
168    * @param filename the filename to set
169    */
170   public final void setFilename(final String filename) {
171     this.filename = filename;
172   }
173 
174   @Override
175   public String toString() {
176     return "Command: " + currentCommand.name() + " Filename: " + filename +
177            " LogId: " + logid;
178   }
179 }