You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2018/07/31 22:22:03 UTC
svn commit: r1837187 - in /turbine/fulcrum/trunk/parser: ./
src/java/org/apache/fulcrum/parser/ src/test/
Author: tv
Date: Tue Jul 31 22:22:03 2018
New Revision: 1837187
URL: http://svn.apache.org/viewvc?rev=1837187&view=rev
Log:
INCOMAPTIBLE: Update dependency servlet-api to 3.1
INCOMAPTIBLE: Remove dependency on fulcrum-upload.
All FileItems are now Parts.
Require Java-8
Modified:
turbine/fulcrum/trunk/parser/pom.xml
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParameterParser.java
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParameterParser.java
turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParserService.java
turbine/fulcrum/trunk/parser/src/test/TestComponentConfig.xml
turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml
Modified: turbine/fulcrum/trunk/parser/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/pom.xml?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/pom.xml (original)
+++ turbine/fulcrum/trunk/parser/pom.xml Tue Jul 31 22:22:03 2018
@@ -25,7 +25,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.fulcrum</groupId>
<artifactId>fulcrum-parser</artifactId>
- <version>1.0.4-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<name>Fulcrum Parser Service</name>
<inceptionYear>2005</inceptionYear>
<description>This Service functions as a repository for Parser components.</description>
@@ -80,33 +80,21 @@
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.4</version>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.1.0</version>
+ <scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
- <groupId>org.apache.fulcrum</groupId>
- <artifactId>fulcrum-upload</artifactId>
- <version>1.0.5</version>
- <optional>true</optional>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.fulcrum</groupId>
<artifactId>fulcrum-pool</artifactId>
<version>1.0.4</version>
</dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.4</version>
- <type>jar</type>
- <scope>runtime</scope>
- </dependency>
<!-- testing dependencies -->
<dependency>
@@ -129,6 +117,8 @@
</build>
<properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
<turbine.site.path>fulcrum/fulcrum-parser</turbine.site.path>
</properties>
Modified: turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParameterParser.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParameterParser.java?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParameterParser.java (original)
+++ turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParameterParser.java Tue Jul 31 22:22:03 2018
@@ -1,6 +1,5 @@
package org.apache.fulcrum.parser;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,18 +19,16 @@ package org.apache.fulcrum.parser;
* under the License.
*/
-
-import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.List;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
import org.apache.avalon.framework.service.ServiceException;
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang3.ArrayUtils;
/**
* DefaultParameterParser is a utility object to handle parsing and
@@ -103,6 +100,7 @@ public class DefaultParameterParser
/**
* Disposes the parser.
*/
+ @Override
public void dispose()
{
this.request = null;
@@ -115,6 +113,7 @@ public class DefaultParameterParser
*
* @return the parsed servlet request or null.
*/
+ @Override
public HttpServletRequest getRequest()
{
return request;
@@ -133,6 +132,7 @@ public class DefaultParameterParser
*
* @param request An HttpServletRequest.
*/
+ @Override
public void setRequest(HttpServletRequest request)
{
clear();
@@ -150,44 +150,18 @@ public class DefaultParameterParser
&& contentType != null
&& contentType.startsWith("multipart/form-data"))
{
- if (getLogger().isDebugEnabled())
- {
- getLogger().debug("Running the Fulcrum Upload Service");
- }
-
try
{
- List<FileItem> fileItems = parserService.parseUpload(request);
+ List<Part> parts = parserService.parseUpload(request);
- if (fileItems != null)
+ if (parts != null)
{
- for (FileItem fi : fileItems)
+ for (Part p : parts)
{
- if (fi.isFormField())
- {
- getLogger().debug("Found an simple form field: " + fi.getFieldName() +", adding value " + fi.getString());
-
- String value = null;
- try
- {
- value = fi.getString(getCharacterEncoding());
- }
- catch (UnsupportedEncodingException e)
- {
- getLogger().error(getCharacterEncoding()
- + " encoding is not supported."
- + "Used the default when reading form data.");
- value = fi.getString();
- }
- add(fi.getFieldName(), value);
- }
- else
- {
- getLogger().debug("Found an uploaded file: " + fi.getFieldName());
- getLogger().debug("It has " + fi.getSize() + " Bytes and is " + (fi.isInMemory() ? "" : "not ") + "in Memory");
- getLogger().debug("Adding FileItem as " + fi.getFieldName() + " to the params");
- add(fi.getFieldName(), fi);
- }
+ getLogger().debug("Found an uploaded file: " + p.getName());
+ getLogger().debug("It has " + p.getSize() + " Bytes");
+ getLogger().debug("Adding Part as " + p.getName() + " to the params");
+ add(p.getName(), p);
}
}
}
@@ -258,6 +232,7 @@ public class DefaultParameterParser
*
* @param uploadData A byte[] with data.
*/
+ @Override
public void setUploadData ( byte[] uploadData )
{
this.uploadData = uploadData;
@@ -268,60 +243,47 @@ public class DefaultParameterParser
*
* @return uploadData A byte[] with data.
*/
+ @Override
public byte[] getUploadData ()
{
return this.uploadData;
}
-
/**
- * Add a FileItem object as a parameters. If there are any
- * FileItems already associated with the name, append to the
+ * Add a Part object as a parameters. If there are any
+ * Parts already associated with the name, append to the
* array. The reason for this is that RFC 1867 allows multiple
* files to be associated with single HTML input element.
*
* @param name A String with the name.
- * @param value A FileItem with the value.
- * @deprecated Use add(String name, FileItem item)
+ * @param value A Part with the value.
*/
- public void append(String name, FileItem value)
+ @Override
+ public void add( String name, Part value )
{
- add(name, value);
- }
-
-
- /**
- * Add a FileItem object as a parameters. If there are any
- * FileItems already associated with the name, append to the
- * array. The reason for this is that RFC 1867 allows multiple
- * files to be associated with single HTML input element.
- *
- * @param name A String with the name.
- * @param value A FileItem with the value.
- */
- public void add(String name, FileItem value)
- {
- FileItem[] items = this.getFileItems(name);
- items = (FileItem []) ArrayUtils.add(items, value);
+ Part[] items = this.getParts(name);
+ items = ArrayUtils.add(items, value);
parameters.put(convert(name), items);
}
-
/**
- * Return a FileItem object for the given name. If the name does
- * not exist or the object stored is not a FileItem, return null.
+ * Return a Part object for the given name. If the name does
+ * not exist or the object stored is not a Part, return null.
*
* @param name A String with the name.
- * @return A FileItem.
+ * @return A Part.
*/
- public FileItem getFileItem(String name)
+ @Override
+ public Part getPart(String name)
{
try
{
- FileItem value = null;
+ Part value = null;
Object object = parameters.get(convert(name));
if (object != null)
- value = ((FileItem[])object)[0];
+ {
+ value = ((Part[])object)[0];
+ }
return value;
}
catch ( ClassCastException e )
@@ -331,18 +293,19 @@ public class DefaultParameterParser
}
/**
- * Return an array of FileItem objects for the given name. If the
- * name does not exist or the object stored is not a FileItem
+ * Return an array of Part objects for the given name. If the
+ * name does not exist or the object stored is not a Part
* array, return null.
*
* @param name A String with the name.
- * @return A FileItem[].
+ * @return A Part[].
*/
- public FileItem[] getFileItems(String name)
+ @Override
+ public Part[] getParts(String name)
{
try
{
- return (FileItem[])parameters.get(convert(name));
+ return (Part[])parameters.get(convert(name));
}
catch ( ClassCastException e )
{
Modified: turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java (original)
+++ turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/DefaultParserService.java Tue Jul 31 22:22:03 2018
@@ -1,6 +1,5 @@
package org.apache.fulcrum.parser;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,10 +19,13 @@ package org.apache.fulcrum.parser;
* under the License.
*/
-
+import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
+import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
@@ -33,13 +35,10 @@ import org.apache.avalon.framework.logge
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.FileItemIterator;
-import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.fulcrum.parser.ValueParser.URLCaseFolding;
import org.apache.fulcrum.pool.PoolException;
import org.apache.fulcrum.pool.PoolService;
-import org.apache.fulcrum.upload.UploadService;
/**
@@ -66,11 +65,6 @@ public class DefaultParserService
private String parameterEncoding = PARAMETER_ENCODING_DEFAULT;
/**
- * The upload service component to use
- */
- private UploadService uploadService = null;
-
- /**
* The pool service component to use
*/
private PoolService poolService = null;
@@ -78,6 +72,7 @@ public class DefaultParserService
/**
* Get the character encoding that will be used by this ValueParser.
*/
+ @Override
public String getParameterEncoding()
{
return parameterEncoding;
@@ -91,6 +86,7 @@ public class DefaultParserService
* @param value A String to be processed.
* @return A new String converted to the case as specified by URL_CASE_FOLDING and trimmed.
*/
+ @Override
public String convert(String value)
{
return convertAndTrim(value);
@@ -104,6 +100,7 @@ public class DefaultParserService
* @return a new String.
*
*/
+ @Override
public String convertAndTrim(String value)
{
return convertAndTrim(value, getUrlFolding());
@@ -118,9 +115,13 @@ public class DefaultParserService
* @param value A String to be processed.
* @return A new String converted to lowercase and trimmed.
*/
+ @Override
public String convertAndTrim(String value, URLCaseFolding fold)
{
- if(value == null) return "";
+ if(value == null)
+ {
+ return "";
+ }
String tmp = value.trim();
@@ -157,6 +158,7 @@ public class DefaultParserService
*
* @return The current Folding Value
*/
+ @Override
public URLCaseFolding getUrlFolding()
{
return folding;
@@ -167,50 +169,29 @@ public class DefaultParserService
*
* @return The current automaticUpload Value
*/
+ @Override
public boolean getAutomaticUpload()
{
return automaticUpload;
}
/**
- * Use the UploadService if available to parse the given request
- * for uploaded files
- *
- * @return A list of {@link org.apache.commons.fileupload.FileItem}s
- *
- * @throws ServiceException if parsing fails or the UploadService
- * is not available
- */
- public List<FileItem> parseUpload(HttpServletRequest request) throws ServiceException
- {
- if (uploadService == null)
- {
- throw new ServiceException(ParserService.ROLE, "UploadService is not available.");
- }
- else
- {
- return uploadService.parseRequest(request);
- }
- }
-
- /**
- * Use the UploadService if available to parse the given request
- * for uploaded files using the streaming API
+ * Parse the given request for uploaded files
*
- * @return A {@link org.apache.commons.fileupload.FileItemIterator}
+ * @return A list of {@link javax.servlet.http.Part}s
*
- * @throws ServiceException if parsing fails or the UploadService
- * is not available
+ * @throws ServiceException if parsing fails
*/
- public FileItemIterator getItemIterator(HttpServletRequest request) throws ServiceException
+ @Override
+ public List<Part> parseUpload(HttpServletRequest request) throws ServiceException
{
- if (uploadService == null)
+ try
{
- throw new ServiceException(ParserService.ROLE, "UploadService is not available.");
+ return new ArrayList<Part>(request.getParts());
}
- else
+ catch (IOException | ServletException e)
{
- return uploadService.getItemIterator(request);
+ throw new ServiceException(ParserService.ROLE, "Could not parse upload request", e);
}
}
@@ -222,6 +203,7 @@ public class DefaultParserService
*
* @throws InstantiationException if the instance could not be created
*/
+ @Override
public <P extends ValueParser> P getParser(Class<P> ppClass) throws InstantiationException
{
P vp = null;
@@ -260,6 +242,7 @@ public class DefaultParserService
*
* @param parser
*/
+ @Override
public void putParser(ValueParser parser)
{
parser.clear();
@@ -269,6 +252,7 @@ public class DefaultParserService
/**
* Avalon component lifecycle method
*/
+ @Override
public void configure(Configuration conf) throws ConfigurationException
{
String foldString = conf.getChild(URL_CASE_FOLDING_KEY).getValue(URLCaseFolding.NONE.name()).toLowerCase();
@@ -301,26 +285,9 @@ public class DefaultParserService
/**
* Avalon component lifecycle method
*/
+ @Override
public void service(ServiceManager manager) throws ServiceException
{
- if (manager.hasService(UploadService.ROLE))
- {
- uploadService = (UploadService)manager.lookup(UploadService.ROLE);
- }
- else
- {
- /*
- * Automatic parsing of uploaded file items was requested but no
- * UploadService is available
- */
- if (getAutomaticUpload())
- {
- throw new ServiceException(ParserService.ROLE,
- AUTOMATIC_KEY + " = true requires " +
- UploadService.ROLE + " to be available");
- }
- }
-
if (manager.hasService(PoolService.ROLE))
{
poolService = (PoolService)manager.lookup(PoolService.ROLE);
Modified: turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParameterParser.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParameterParser.java?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParameterParser.java (original)
+++ turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParameterParser.java Tue Jul 31 22:22:03 2018
@@ -1,6 +1,5 @@
package org.apache.fulcrum.parser;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,10 +19,8 @@ package org.apache.fulcrum.parser;
* under the License.
*/
-
import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.fileupload.FileItem;
+import javax.servlet.http.Part;
/**
* ParameterParser is an interface to a utility to handle parsing and
@@ -88,37 +85,36 @@ public interface ParameterParser
*
* @return uploadData A byte[] with data.
*/
- byte[] getUploadData ();
+ byte[] getUploadData();
/**
- * Add a FileItem object as a parameters. If there are any
- * FileItems already associated with the name, append to the
+ * Add a Part object as a parameters. If there are any
+ * Parts already associated with the name, append to the
* array. The reason for this is that RFC 1867 allows multiple
* files to be associated with single HTML input element.
*
* @param name A String with the name.
- * @param value A FileItem with the value.
+ * @param value A Part with the value.
*/
- void append( String name, FileItem value );
-
+ void add( String name, Part value );
/**
- * Return a FileItem object for the given name. If the name does
- * not exist or the object stored is not a FileItem, return null.
+ * Return a Part object for the given name. If the name does
+ * not exist or the object stored is not a Part, return null.
*
* @param name A String with the name.
- * @return A FileItem.
+ * @return A Part.
*/
- FileItem getFileItem(String name);
+ Part getPart(String name);
/**
- * Return an array of FileItem objects for the given name. If the
- * name does not exist or the object stored is not a FileItem
+ * Return an array of Part objects for the given name. If the
+ * name does not exist or the object stored is not a Part
* array, return null.
*
* @param name A String with the name.
- * @return A FileItem[].
+ * @return A Part[].
*/
- FileItem[] getFileItems(String name);
+ Part[] getParts(String name);
}
Modified: turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParserService.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParserService.java?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParserService.java (original)
+++ turbine/fulcrum/trunk/parser/src/java/org/apache/fulcrum/parser/ParserService.java Tue Jul 31 22:22:03 2018
@@ -1,6 +1,5 @@
package org.apache.fulcrum.parser;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -20,16 +19,14 @@ package org.apache.fulcrum.parser;
* under the License.
*/
-
import java.util.List;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.Part;
import org.apache.avalon.framework.service.ServiceException;
-import org.apache.commons.fileupload.FileItem;
import org.apache.fulcrum.parser.ValueParser.URLCaseFolding;
-
/**
* ParserService defines the methods which are needed by the parser objects
* to get their necessities.
@@ -118,15 +115,13 @@ public interface ParserService
boolean getAutomaticUpload();
/**
- * Use the UploadService if available to parse the given request
- * for uploaded files
+ * Parse the given request for uploaded files
*
- * @return A list of {@link org.apache.commons.upload.FileItem}s
+ * @return A list of {@link javax.servlet.http.Part}s
*
- * @throws ServiceException if parsing fails or the UploadService
- * is not available
+ * @throws ServiceException if parsing fails
*/
- List<FileItem> parseUpload(HttpServletRequest request) throws ServiceException;
+ List<Part> parseUpload(HttpServletRequest request) throws ServiceException;
/**
* Get a {@link ValueParser} instance from the service. Use the
Modified: turbine/fulcrum/trunk/parser/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/TestComponentConfig.xml?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/parser/src/test/TestComponentConfig.xml Tue Jul 31 22:22:03 2018
@@ -22,5 +22,4 @@
<parameterEncoding>utf-8</parameterEncoding>
<automaticUpload>true</automaticUpload>
</parser>
- <upload repository="target" sizeMax="1048576" sizeThreshold="10240"/>
</componentConfig>
Modified: turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml?rev=1837187&r1=1837186&r2=1837187&view=diff
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml (original)
+++ turbine/fulcrum/trunk/parser/src/test/TestRoleConfig.xml Tue Jul 31 22:22:03 2018
@@ -20,11 +20,6 @@
<!-- This configuration file for Avalon components is used for testing the TestComponent -->
<role-list>
<role
- name="org.apache.fulcrum.upload.UploadService"
- shorthand="upload"
- default-class="org.apache.fulcrum.upload.DefaultUploadService"
- />
- <role
name="org.apache.fulcrum.pool.PoolService"
shorthand="parser"
default-class="org.apache.fulcrum.pool.DefaultPoolService"