dangreen
11-20-2001, 10:59
PROBLEM:
As a developer, I am unable to upload configuration files, HTML documents and other ASCII-based documents to a package "pub" directory because the B2B Server was installed by and is owned by "root".
I can ask a person with "root" permission to chmod the directories, but I lose the chmod if the B2B Server reloads the package because the default permission is "root" on reload.
SOLUTION:
Build a B2B flow that accepts two string parameters ("fileContent" and "filePath") as inputs. Design the service to write "fileContent" to file at the path "filePath". Because the service is executed by the B2B Server, it is being executed by the owner of the B2B Server ("root") and will be written to the specified path.
NOTES:
1) It will be necessary to write a quick Java service to write a string to a file. I use one that looks like this:
[begin Java service to write a string to file]
//inputs: String pathToFile, String fileContent
try {
IDataHashCursor pipelineCursor = pipeline.getHashCursor();
pipelineCursor.first( "filePath" );
String filePath= (String) pipelineCursor.getValue();
pipelineCursor.first( "fileContent" );
String fileContent= (String) pipelineCursor.getValue();
File outFile = new File(filePath);
FileOutputStream outFS = new FileOutputStream(outFile);
//convert string to byte array
byte[] xmlbytes = fileContent.getBytes();
outFS.write(xmlbytes);
outFS.close();
}
catch (Exception e) {
String errMessage = e.getMessage();
IDataHashCursor pipelineCursor_1 = pipeline.getHashCursor();
pipelineCursor_1.last();
pipelineCursor_1.insertAfter( "filepath", errMessage );
}
[end Java service to write a string to file]
2) This service can be invoked via a GUI. Create a HTML form whose action is the service's URL. The inputs of the form are "fileContent" and "filePath".
As a developer, I am unable to upload configuration files, HTML documents and other ASCII-based documents to a package "pub" directory because the B2B Server was installed by and is owned by "root".
I can ask a person with "root" permission to chmod the directories, but I lose the chmod if the B2B Server reloads the package because the default permission is "root" on reload.
SOLUTION:
Build a B2B flow that accepts two string parameters ("fileContent" and "filePath") as inputs. Design the service to write "fileContent" to file at the path "filePath". Because the service is executed by the B2B Server, it is being executed by the owner of the B2B Server ("root") and will be written to the specified path.
NOTES:
1) It will be necessary to write a quick Java service to write a string to a file. I use one that looks like this:
[begin Java service to write a string to file]
//inputs: String pathToFile, String fileContent
try {
IDataHashCursor pipelineCursor = pipeline.getHashCursor();
pipelineCursor.first( "filePath" );
String filePath= (String) pipelineCursor.getValue();
pipelineCursor.first( "fileContent" );
String fileContent= (String) pipelineCursor.getValue();
File outFile = new File(filePath);
FileOutputStream outFS = new FileOutputStream(outFile);
//convert string to byte array
byte[] xmlbytes = fileContent.getBytes();
outFS.write(xmlbytes);
outFS.close();
}
catch (Exception e) {
String errMessage = e.getMessage();
IDataHashCursor pipelineCursor_1 = pipeline.getHashCursor();
pipelineCursor_1.last();
pipelineCursor_1.insertAfter( "filepath", errMessage );
}
[end Java service to write a string to file]
2) This service can be invoked via a GUI. Create a HTML form whose action is the service's URL. The inputs of the form are "fileContent" and "filePath".