don't pass directory path to client, use prefix instead

This commit is contained in:
Norbert Renner 2014-05-22 12:54:26 +02:00
parent 6f9cef9b3f
commit 3df98310fb
2 changed files with 16 additions and 4 deletions

View file

@ -16,6 +16,9 @@ public class ProfileUploadHandler
// maximum number of characters (file size limit for custom profiles) // maximum number of characters (file size limit for custom profiles)
private static final int MAX_LENGTH = 100000; private static final int MAX_LENGTH = 100000;
// prefix for custom profile id to distinguish from default profiles
public static final String CUSTOM_PREFIX = "custom_";
private ServiceContext serviceContext; private ServiceContext serviceContext;
public ProfileUploadHandler( ServiceContext serviceContext) public ProfileUploadHandler( ServiceContext serviceContext)
@ -29,8 +32,8 @@ public class ProfileUploadHandler
try try
{ {
String id = getOrCreateCustomProfileDir() + "/" + System.currentTimeMillis(); String id = "" + System.currentTimeMillis();
File file = new File ( id + ".brf" ); File file = new File( getOrCreateCustomProfileDir(), id + ".brf" );
fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( file ) ) ); fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream( file ) ) );
//StringWriter sw = new StringWriter(); bw = new BufferedWriter(sw); //StringWriter sw = new StringWriter(); bw = new BufferedWriter(sw);
@ -40,7 +43,7 @@ public class ProfileUploadHandler
fileWriter.flush(); fileWriter.flush();
//System.out.println("data: |" + sw.toString() + "|"); //System.out.println("data: |" + sw.toString() + "|");
response.write("profileid=" + id); response.write("profileid=" + CUSTOM_PREFIX + id);
} }
finally finally
{ {

View file

@ -8,6 +8,7 @@ import btools.router.OsmNodeNamed;
import btools.router.OsmTrack; import btools.router.OsmTrack;
import btools.router.RoutingContext; import btools.router.RoutingContext;
import btools.server.ServiceContext; import btools.server.ServiceContext;
import java.io.File;
/** /**
* URL query parameter handler for web and standalone server. Supports all * URL query parameter handler for web and standalone server. Supports all
@ -38,7 +39,15 @@ public class ServerHandler extends RequestHandler {
{ {
RoutingContext rc = new RoutingContext(); RoutingContext rc = new RoutingContext();
rc.localFunction = params.get( "profile" ); String profile = params.get( "profile" );
// when custom profile replace prefix with directory path
if ( profile.startsWith( ProfileUploadHandler.CUSTOM_PREFIX ) )
{
String customProfile = profile.substring( ProfileUploadHandler.CUSTOM_PREFIX.length() );
profile = new File( serviceContext.customProfileDir, customProfile ).getPath();
}
rc.localFunction = profile;
rc.setAlternativeIdx(Integer.parseInt(params.get( "alternativeidx" ))); rc.setAlternativeIdx(Integer.parseInt(params.get( "alternativeidx" )));
List<OsmNodeNamed> nogoList = readNogoList(); List<OsmNodeNamed> nogoList = readNogoList();