When I set a context-root in weblogic.xml for my application, what is the default namespace for package in struts2?
ex:
I set <context-root>/home/app/exec</context-root> and I access my app with the following uri: localhost:8081/home/app/exec/index.html insted of localhost:8081/NameOfMyApp/index.html
In the other hand I Know that in Struts2 action namespace map to folder structure.
Example on the following link: https://www.mkyong.com/struts2/struts-2-namespace-configuration-example-and-explanation/
What is the correct namespace for the situation in case that ServletContext is not the name of my app but is the context-root?
Namespace is the part that is calculated after the context path and before the action name. On the other hand a namespace is an attribute of the package that holds the actions belonging that namespace. A default action mapper is using both attributes to find the action config corresponding the namespace and action name.
For detailed explanation of default action mapper you can read javadocs DefaultActionMapper.
You can read more about action configuration and ActionMapper on the Struts docs site.
You should also know that the action mapper returns ActionMapping. However, to execute an action requires ActionConfig which is determined by the Struts using run-time configuration.
Related
I have webapp using Spring 5.1.10, running on Jetty 9.4.20. Through out the app JCL is used for logging. Jetty is configured by enabling jcl-slf4j (to capture webapp and Spring messages) and logging-logback module and editing corresponding resources/logback.xml. In that configuration file, there is defined a logger that have two MDC's in pattern: %mdc{instance:-internal} and %mdc{user:-default}. MCD key instance is set by a Filter and user by RequestInterceptor. Basically they work, as when logging statements is called by some controller, correct values for instance and user end up in log file.
The problem is that there is controller, that deals with legacy part of the system. It looks up a class file, loads this class using custom class loader, does some setup (setting some properties) then executes a method, that actually does the job. The problem is that all loaded classes that emit log messages have both MDC keys as default values (internal and default respectively) despite both values being set to correct values.
I have added log statements to filter and request interceptor and it looks like they occupy the same thread as the class being loaded. Also I have added a test log statement to controller, which is emitted after custom class is loaded, but before its method execution. The result is that despite all entities being executed within the same thread MCD works in controllers, filters and interceptors and doesn't work with loaded classes. That leads me to believe, that class loading somehow is involved.
The question is: How I can get MDC to work within classes loaded by custom class loader?
I have some data specific to each razor view and and i do not want to hard-code it to each view. So, i want to add view related compile-time data to each view.
Custom attributes do not work for me because we cannot add custom attributes to razor views.
I do not want to re-fetch/populate this data from the data source(dictionary etc.) for each request or when view reached.
So, is there any way to attach data to each view at once throughout the life time of asp.net application?
Note
Actually i want to add scripts/styles generated by webpack for each view statically. Their links include hash values so they change when source scripts/styles change. So, i just want to get them added to each view only once(equivalent to typing them into view) through out the asp.net application, not every time a view loads.
I created a demo application for you here.
You will want to use your appsettings.json file, and inject your settings into your view.
In my appsettings.json I added a section called "ViewConfiguration":
"ViewConfiguration": {
"ExampleKey": "ExampleValue"
}
Your various values will need to go into your ViewConfiguration section.
For example where I have ExampleKey, you will use a generic name like "IndexPageStyleSheet", and where I have ExampleValue, you will need to update each release with the new stylesheet path. This will only need to be updated when the filename changes.
I then created a ViewConfiguration class which stores all of the values from the appsettings.json file.
You will need to create one property per configuration line, and ensure that the name of the property matches the name of the key in your appsettings.json.
For example where my appsettings.json has ExampleKey, my ViewConfiguration class also has an ExampleKey.
public class ViewConfiguration {
public string ExampleKey { get; set; }
}
In your Startup.cs you will need to tell your IOC container to load your configuration values into your configuration object.
In my Startup.cs, my ConfigureServices method loads my "ExampleValue" into ViewConfiguration.ExampleKey automatically.
public void ConfigureServices(IServiceCollection services) {
// This line is the magic that loads the values from appsettings.json into a ViewConfiguration object.
services.Configure<ViewConfiguration>(Configuration.GetSection("ViewConfiguration"));
services.AddMvc();
}
Now, in my _ViewImports.cshtml I inject my ViewConfiguration object so that I don't need to inject it into every single page. This can be anywhere in the _ViewImports.cshtml file. If you only want to inject specific configuration per folder, you can create a new _ViewImports.cshtml file per folder and inject different configuration objects into each one. It's flexible.
#using Microsoft.Extensions.Options;
#* Please rename this variable to something more appropriate to your application: *#
#inject IOptions<ViewConfiguration> InjectedViewConfig
Now, in any page, you can simply reference the property in your ViewConfiguration object.
For example in my Index.cshtml, I reference the ViewConfiguration.ExampleKey property by referencing the strongly typed property on InjectedViewConfig.Value, and it outputs "ExampleValue" on the page.
This value could just as easily be injected into a script or css link tag as the name of a file. It's very flexible.
<h1>Value: #InjectedViewConfig.Value.ExampleKey</h1>
With further research, you will be able to inject these values from any configuration source, such as Azure application settings or Azure Key Vault. Please see this article for more details.
If you are using mvc, you can create models and add it into the views. Since you don't want to recreate for each view, you can create readonly variables.
static readonly MyModel ModelData = new MyModel { PropName = "Hello" };
public IActionResult Index () => View(ModelData);
In your view you can now strongly type the value. If you are looking to use MVVM, you can refer to ViewModel concept still exists in ASP.NET MVC Core?
Implementing IFileProvider and IFileInfo provides changing the contents of view at compile-time. So, we could replace and provide static data in views with a template engine(i.e. http://dotliquidmarkup.org/).
Check this;
https://www.mikesdotnetting.com/article/301/loading-asp-net-core-mvc-views-from-a-database-or-other-location
If I run unit tests in Visual Studio:
If I use NUnit, Test Explorer shows the method names.
If I use xUnit, Test Explorer shows the fully qualified name including namespace, class name and method name. That's a bit too long.
I would like to show the method name only. I've seen that you can specify a setting in the App.config to show just the method name, but that is based on App.config.
How do I do the same thing in .NET Core, which has a completely different configuration model?
According the official docs, you can provide the settings for your .Net Core application with json file named
xunit.runner.json or <AssemblyName>.xunit.runner.json, where <AssemblyName> is the name of your unit test assembly, without the file extension like .dll or .exe
You should only need to use this longer name format if your unit tests DLLs will all be placed into the same output folder, and you need to disambiguate the various configuration files.
The assembly-specific filename takes precedence over the non-specific filename; there is no merging of values between files.
Supported configuration items are (The configuration elements are placed inside a top-level object):
appDomain
diagnosticMessages
longRunningTestSeconds
maxParallelThreads
methodDisplay
Set this to override the default display name for test cases. If you set this to method, the display name will be just the method (without the class name); if this set this value to classAndMethod, the default display name will be the fully qualified class name and method name.
JSON schema type: enum
Default value: classAndMethod
parallelizeAssembly
parallelizeTestCollections
preEnumerateTheories
shadowCopy
Edit: as you can see in docs, there are only two options: classAndMethod and method. According the github issue #524, there is no difference from class name and namespace in Xunit API, so you need to find a workaround.
For example, this answer approach:
public class MyFactAttribute : FactAttribute
{
public MyFactAttribute([CallerMemberName] string memberName = null)
{
DisplayName = memberName;
}
}
Some useful links:
[Proposal] Support Automatic "Pretty" Display Name for Test Cases, Issue #759
Pretty Display Name Implementation for Test Cases, PR #828
NuGet package with PR
I'm working on an app that serves domain classes as json results.
Is there a way to change the default max for the results?
What I'm doing is http://site/domain-class.json and I'm only getting 10 results. I want to avoid creating all the links as http://site/domain-class.json?max=999
Is there a way to increase that default value to something different? I tried searching the source code without any luck. :(
That's not configurable using the #Resource annotation.
However, you can always generate your controller for your domain and modify the implementation of the list() method to have a different default maximum.
Here is the controller which backs a domain which is marked with the #Resource interface annotation. As you can see the default maximum value is not driven by any configuration value.
Using grails generate-controller for your domain will allow you to change that value in the generated controller for your domain.
Windows Phone 8 C# project (MyApp), migrated from WP7.1. I've added a native Windows Runtime component library (AppLib) to the solution, created a reference. There's a public sealed ref class (MyClass) in it. There's a reference to it in the C# code (in OnLoaded of the main XAML page). The whole thing compiles - meaning the metadata of the component is being generated.
When I'm trying to run, the project fails with the exception or type TypeLoadException with the following message:
Typename or Namespace was not found in metadata file. (Exception from HRESULT: 0x8000000F)
Both AppLib.DLL and AppLib.winmd can be found in the XAP. The winmd contains the information about the type, and in the right namespace, too. What else should I check?
At exception time, the AppLib.dll is not listed in the modules window of the debugger. It's as if the DLL loading fails for some reason.
I've tried with brand new class in an arbitrary namespace - same problem. Looks like the problem is on the DLL level, not on class level.
The name of the WinMD file must be a prefix of the name of the namespace in which any public and activatable types are declared. For example, if your WinMD is named AppLib.winmd, your MyClass type must be defined in namespace AppLib or some other namespace nested within that namespace, for example AppLib::Something.
It must also be declared in the "best matching" WinMD, so if your type is named A.B.MyClass and you have both A.winmd and A.B.winmd in your package, the type must be defined in A.B.winmd.
The Windows Runtime uses the name of the type to determine which WinMD file defines the type. See also my answer to "XAML cannot find reference in local namespace."