File Upload not working in Struts2-Struts1 Plugin its setting NULL - file-upload

We are currently migrating our application from struts 1 to struts 2 module wise and we are making use of the struts2-strut1 plugin.
Every things seems to be working fine, expect for file we are getting the file property value as NULL.
We have checked everything see below our tag looks like
JSP code Snippet
<s:form name="uploadForm" namespace="/struts2" action="upload" enctype="multipart/form-data" method="post">
<s:file name="doc" cssClass="genTextValues"/>
<s:submit/>
</s:form>
Java Action form
public class UploadForm extends ActionForm {
private FormFile doc;
public FormFile getDoc() {
return doc;
}
// its not setting gives null in action form
public void setDoc(FormFile doc) {
this.doc = doc;
}
}
Struts.xml mapping
<interceptor name="uploadForm" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor">
<param name="scope">request</param>
<param name="className">com.form.UploadForm</param>
<param name="name">uploadForm</param>
</interceptor>
<interceptor-stack name="iUploadForm">
<interceptor-ref name="staticParams" />
<interceptor-ref name="uploadForm" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="basicStack" />
</interceptor-stack>
<action name="uploadDoc" class="org.apache.struts2.s1.Struts1Action">
<param name="className">com.test.action.UploadAction</param>
<interceptor-ref name="iUploadForm"/>
<result name="Success" type="tiles">Success</result>
</action>
We have added required jar see below:
commons-fileupload.jar
struts.jar
struts2-struts1-plugin.jar
struts2-core.jar (2.16)
commons-io2.2.jar
other required jars

There is no fileUpload interceptor in your interceptor-stack.
<interceptor-stack name="iUploadForm">
<interceptor-ref name="staticParams" />
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="uploadForm" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="basicStack" />
</interceptor-stack>

Related

Log4Net SmtpAppender not working in .netCore

I'm trying to send log messages to my gmail account but it keeps not working. I've tried changing ports and changing threshold value but it's not working. When I try writing logs in file everything is ok, so I think the problem is in log4net.config file.
My log4net configuration file contains:
<log4net>
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender">
<to value="mymail#gmail.com" />
<from value="mysendermail#gmail.com" />
<subject value="Crash log" />
<smtpHost value="smtp.gmail.com" />
<authentication value="Basic" />
<port value="465" />
<username value="myusername" />
<password value="mypass" />
<bufferSize value="1" />
<EnableSsl value="true"/>
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="DEBUG"/>
</evaluator>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d{hh:mm:ss} %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="SmtpAppender"/>
</root>
</log4net>
In my Startup.cs file I have:
var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));
And my example code is:
public class HomeController : Controller
{
private static readonly ILog log = LogManager.GetLogger(typeof(HomeController));
public HomeController()
{
}
public IActionResult Index()
{
return View();
}
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
ViewData["Title"] = "title";
log.Warn("test test", new NullReferenceException("missing"));
log.Debug("test test", new NullReferenceException("missing"));
log.Error("test test", new NullReferenceException("missing"));
log.Fatal("test test", new NullReferenceException("missing"));
return View();
}
}
Am I making something wrong. I tried everything
log4net's SmtpAppender is not supported in .net core yet.
Supported frameworks: https://logging.apache.org/log4net/release/framework-support.html
Have you tested the following port:
Gmail SMTP port (TLS): 587
Gmail SMTP port (SSL): 465 <- your current setting
what-are-the-gmail-smtp-settings

Embed code Brightcove media api

I am trying to find out a way to access the publishing code of a video on my media api through brightcove, just like the one that you can get on there cloud studio for a player like this one below.
<!-- Start of Brightcove Player -->
<div style="display:none">
</div>
<!--
By use of this code snippet, I agree to the Brightcove Publisher T and C
found at https://accounts.brightcove.com/en/terms-and-conditions/.
-->
<script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<object id="myExperience" class="BrightcoveExperience">
<param name="bgcolor" value="#FFFFFF" />
<param name="width" value="960" />
<param name="height" value="445" />
<param name="playerID" value="2164048951001" />
<param name="playerKey" value="AQ~~,AAABzJDWv4k~,nrw5-YJoyhvZYIpODobX62cNFZVSM1ri" />
<param name="isVid" value="true" />
<param name="isUI" value="true" />
<param name="dynamicStreaming" value="true" />
</object>
<!--
This script tag will cause the Brightcove Players defined above it to be created as soon
as the line is read by the browser. If you wish to have the player instantiated only after
the rest of the HTML is processed and the page load is complete, remove the line.
-->
<script type="text/javascript">brightcove.createExperiences();</script>
I would like to make this an option in my video metadata section of my api, does anyone have any suggestions where to start. Thanks.
I'm not sure you can gather the publishing code of an asset via the BC API but it isn't necessary. What you can do is use variables to replace the only items of that snippet which may change - primarily playerID and playerKey and videoPlayer value (which will indicate which player to use and which video to insert) but also potentially width and height settings.
Let's say you are looking to dynamically swap out the video (assuming you will always use the same player), you could do something like this:
function get_player($video_id){
$player = '<script language="JavaScript" type="text/javascript" src="http://admin.brightcove.com/js/BrightcoveExperiences.js"></script>
<object id="myExperience" class="BrightcoveExperience">
<param name="bgcolor" value="#FFFFFF" />
<param name="width" value="960" />
<param name="height" value="445" />
<param name="playerID" value="2164048951001" />
<param name="playerKey" value="AQ~~,AAABzJDWv4k~,nrw5-YJoyhvZYIpODobX62cNFZVSM1ri" />
<param name="isVid" value="true" />
<param name="isUI" value="true" />
<param name="dynamicStreaming" value="true" />
<param name="#videoPlayer" value="'.$video_id.'" />
</object><script type="text/javascript">brightcove.createExperiences();</script>';
return $player;
}
And then just call the function using the id of the video you want to display in this player. The same could be applied for swapping out players and sizes.
echo get_player('my_video_id');
the #videoPlayer param tells the player which video to load.
This documentation may help.

How to embed a flash file in a Rails Project

I am trying to embed a flash file onto the homepage of my Ruby application. The homepage is in /app/view/home, and the flash file is in the projects /public/flash/myflash.swf.
When I load the home page, I don't see anything, although the text is bumped below a square of the proper size I defined the file as.
The code I am using to try and load the file is
<div id="flashContent">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="346" height="383" id="Blox" align="middle">
<param name="movie" value="/flash/Blox.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="false" />
<param name="wmode" value="window" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
</object>
</div>
I am thinking that either I am calling the file wrong by using value=/flash/Blox.swf, or that I am storing my flash file in the wrong place period.
How can I get my flash file to load? Any help is appreciated!
I was able to fix the problem by including and <embed src> tag in the object. Not the best solution, but it worked for what I needed.

how to replace string in file using msbuild?

I want to replace a string such "how r u" in file test.xml with a string "i am fine" in another file xy.xml.using regular expression in ms build.
ie i have to read string from one file(xy.xml) and replace it in another file test.xml.
so please provide necessary steps to solve this issue with example
This is no longer required... you can now inject C# into the project/build file...
Define a custom task and parameters as follows:
<UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
File.WriteAllText(
OutputFilename,
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
);
]]>
</Code>
</Task>
</UsingTask>
Then simply call it like any other MSBuild task
<Target Name="AfterBuild">
<ReplaceFileText
InputFilename="$(OutputPath)File.exe.config"
OutputFilename="$(OutputPath)File.exe.config"
MatchExpression="\$version\$"
ReplacementText="1.0.0.2" />
</Target>
The above example replaces "$version$" with "1.0.0.2" in the "File.exe.config" located in the output directory.
There is very simple approach to just replace string in a file:
<Target Name="Replace" AfterTargets="CoreCompile">
<PropertyGroup>
<InputFile>c:\input.txt</InputFile>
<OutputFile>c:\output.txt</OutputFile>
</PropertyGroup>
<WriteLinesToFile
File="$(OutputFile)"
Lines="$([System.IO.File]::ReadAllText($(InputFile)).Replace('from','to'))"
Overwrite="true"
Encoding="Unicode"/>
</Target>
See https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2019
to explore inlinable C# code. [System.Text.RegularExpressions.Regex] included into the list.
The answer from #csharptest.net is good, but it doesn't work on DotNetCore. I would have added this as a comment, but I don't have enough reputation.
On DotNetCore you have to update:
Task Factory to "RoslynCodeTaskFactory"
Task Assembly to "$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
Remove the reference to "System.Core"
The consuming Target has to specify the "AfterTargets" attribute as "Build"
Everything else should be the same:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
<UsingTask
TaskName="ReplaceFileText"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
File.WriteAllText(
OutputFilename,
Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="AfterBuildStep" AfterTargets="Build">
<ReplaceFileText
InputFilename="$(OutputPath)File.exe.config"
OutputFilename="$(OutputPath)File.exe.config"
MatchExpression="\$version\$"
ReplacementText="1.0.0.2" />
</Target>
</Project>
EDIT: This answer is obsolete. Use solution below...
Use ReadLinesFromFile task to get replacement string from the xy.xml file. Check this
Then use value from xy.xml as a replacement string for FileUpdate task. Check this
And put it all together ;)
You can use the task FileUpdate from MSBuild Community Tasks as explained in the article
http://geekswithblogs.net/mnf/archive/2009/07/03/msbuild-task-to-replace-content-in-text-files.aspx
If you prefer not using third party (community) binaries, nor embedding code into your msbuild project, I'd suggest creating a simple task library which implements File.WriteAllText and can later host other tasks :
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class FileWriteAllText : Task
{
[Required]
public string Path { get; set; }
[Required]
public string Contents { get; set; }
public override bool Execute()
{
File.WriteAllText(Path, Contents);
return true;
}
}
Then you can replace, append, etc. in msbuild :
<UsingTask TaskName="FileWriteAllText" AssemblyFile="MyTasks.dll" />
<FileWriteAllText Path="test.xml"
Contents="$([System.Text.RegularExpressions.Regex]::Replace(
$([System.IO.File]::ReadAllText('test.xml')), 'how r u', 'i am fine'))" />
I ran the both replacements against same file that sits on a Unix drive and used the unc path to it \server\path...:
<ReplaceFileText
InputFilename="$(fileToUpdate)"
OutputFilename="$(fileToUpdate)"
MatchExpression="15.0.0"
ReplacementText="15.3.1"/>
<FileUpdate Files="$(fileToUpdate2)"
Regex="15.0.0"
ReplacementText="15.3.1" />
and the cs custom action above does not add the bom; however the FileUpdate did:
%head -2 branding.h branding2.h
==> branding.h <==
#/* branding.h
#** This file captures common branding strings in a format usable by both sed and C-preprocessor.
==> branding2.h <==
#/* branding.h
#** This file captures common branding strings in a format usable by both sed and C-preprocessor.
Thanks csharptest.net - I was doing doing exec's with perl subtitute commands for unix builds.
An updated to answer from James
<UsingTask TaskName="ReplaceTextInFiles" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.$(VsBuildTaskBinarySuffix).dll">
<ParameterGroup>
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementExpression ParameterType="System.String" Required="true" />
<InputFile ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" />
<IsTextReplaced ParameterType="System.Boolean" Output="True"/>
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
bool isMatchFound = false;
string filecontent = "";
string path = InputFile.ItemSpec;
Log.LogMessage(MessageImportance.High, "[ReplaceTextInFiles]: Match= " + MatchExpression);
Log.LogMessage(MessageImportance.High, "[ReplaceTextInFiles]: Replace= " + ReplacementExpression);
IsTextReplaced = false;
using(StreamReader rdr = new StreamReader(path))
{
filecontent = rdr.ReadToEnd();
if (Regex.Match(filecontent, MatchExpression).Success)
{
filecontent = Regex.Replace(filecontent, MatchExpression, ReplacementExpression);
isMatchFound = true;
}
}
if(isMatchFound){
using(StreamWriter wrtr = new StreamWriter(path))
{
wrtr.Write(filecontent);
IsTextReplaced = true;
Log.LogMessage(MessageImportance.Normal, "[ReplaceTextInFiles]: Replaced text in file:" + path);
}
}
]]>
</Code>
</Task>

Silverlight Webpart Custom Initialization Parameters in Sharepoint 2010

I have a xap file which accepts custom parameters.I have tested it in a HTML page.It works.
"<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="SmoothStreamingPlayer.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<param name="InitParams" value="selectedcaptionstream=textstream_eng,mediaurl=http://ie1adtvmvrb1s:12345/LiveSmoothVideo.isml/manifest" />
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>"
Here I am passing Intialization parameters like this
selectedcaptionstream=textstream_eng,mediaurl=http://ie1adtvmvrb1s:12345/LiveSmoothVideo.isml/manifest
I am trying to place the same intialization parameters in Silverlight Webpart in Sharepoint 2010. But It didn't load the Xap filele to.I am not able to figure out what is going wrong
When you add the SP Silverlight WP, one of the parameters in the tool part is under "Other Settings > Custom Initialization Parameters" you can define them there.