Play: Accessing static files via URL in tests - scala

I have a static xml file in the public folder which I want to access by firing
WS.url(myFileUrl)
from my tests. Any idea?

The problem is that if you want to access a static file via URL you need to have a real server running and servicing the requests. So you can add the server and specify the port as follows:
"run in a server" in new WithServer(port = 3333)) {
await(WS.url("http://localhost:3333").get).status must equalTo(OK)
}

Related

Need ServiceConfiguration.cscfg to populate web.config sessionstate and connection strings

I need to propagate connection string changes for entity framework, asp.net membership (which are both in the connectionstrings section of web.config) and session state (which is in sessonstate's sqlconnectionstring) in web.config when I adjust these settings in windows azure's service configuration.
During development we test our app as a standard asp.net webforms app, but once it is deployed it is running in azure. So we need to allow for the site running in both non-azure and an azure context. That's why we're just relying upon the values in web.config for now.Since these connection strings are not called directly in my code writing a utility class which grabs from azure service config if that is available or otherwise grabs from web.config is not a possibility for these values.
I realize that editing web.config would cause a disruption in service - and i only plan to do this during off hours.
I believe that the best approach is to wrap your configuration information in a service. Then, in the service, use RoleEnvironment to determine which settings to use. For example
public static class Config
{
public static string ConnStr
{
get
{
if (RoleEnvironment.IsAvailable)
return RoleEnvironment.GetConfigurationSettingValue("ConnStr");
return ConfigurationManager.AppSettings["ConnStr"];
}
}
}
If that doesn't work, and you need to change the actual web.config (for instance, using named connection strings), then you'll need to modify the config at runtime. In your role start, do something like the following:
var config = WebConfigurationManager.OpenWebConfiguration(null);
var connStrs = WebConfigurationManager.OpenWebConfiguration(null).GetSection("connectionStrings") as ConnectionStringsSection;
connStrs.ConnectionStrings["ConnStr"].ConnectionString = RoleEnvironment.GetConfigurationSettingValue("ConnStr");
config.Save();
To handle when the configuration changes after the role is running, just call the same code as above from the RoleEnvironment.Changing event.
Good luck,
Erick

I get a system.configuration.settingspropertynotfoundexception error in windows service

I have a windows app that uses SettingsProvider to read configuration settings and sets default values if file does not exist.
It works fine running normally.
I am trying to write a windows service that starts this app. When it is run by the service, I get System.Configuration.SettingsPropertyNotFoundException on all the setting attributes.
How can I resolve this exception when the service is running the app?
This simply means that the app can't read the .Settings file. I can think of two possible causes:
The service runs under an account that doesn't have access to the .settings file. (or .config file, depending) This is unlikely because the service can start the app, and it wouldn't make sense for it to have permissions to the app and not the settings file.
The runtime can't find the settings file. It expects the settings to be in the root startup path of the executable. Check to ensure that it exists on the machine in question.
However, a google result turned up an obvious possible cause I haven't thought of. Were the .settings added after the last compile? Compile the app in Visual Studio, and try again...
Another possible cause is if you write a custom SettingsProvider that is throwing and exception during Initialize.
In my case, I had done this:
public class CustomSettingsProvider : SettingsProvider
{
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
}
}
Since name is always passed as null, base.Initialize was throwing an ArgumentNullException. I fixed it by passing a non-null name like this:
public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name ?? GetType().Name, config);
}
In my case, the profile <configSource="Profile.config" /> code was commented out in the Web.config file.
Uncommenting the above line worked for me.

WCF Web API Configuration File to IIS

I have implemented a restful service with WCF Web API and I want to publish it in IIS.
During developing process I was using the service as Console Application and all configuration was made through API.
Now I'm trying to publish the service as ASP.NET application and the only way I see is somehow to move all configuration into web config file.
Here the coded configuration:
var cfg = HttpHostConfiguration.Create()
.AddMessageHandlers(typeof(AllowCrossDomainRequestHandler));
using (var host = new HttpConfigurableServiceHost(typeof(RESTfulService), cfg , new Uri("http://localhost:8081")))
{
var endpoint = ((HttpEndpoint)host.Description.Endpoints[0]); //Assuming one endpoint
endpoint.TransferMode = TransferMode.Streamed;
endpoint.MaxReceivedMessageSize = 1024 * 1024 * 10; // Allow files up to 10MB
host.Open();
Console.WriteLine("Host opened at {0} , press any key to end", host.Description.Endpoints[0].Address);
Console.ReadKey();
}
How should my web.config look to reflect this configuration?
Or is there any other approach instead of using ASP.NET?
Any help is appreciated.
If you want to preserve your existing config, you can put all your config set up stuff into a method, and call it from global.asax Application_Start() method. All the Global.asax methods will get called in WCF the same as they do for ASP.NET.
Or, you can wire your services to a custom ServiceHostFactory and ServiceHost that has all the configuration in it (this is the approach I am using in my current app).

MVC JavaScript Form posting issue

I Have an issue where the following code works when run in Visual Studio however I get a "The resource cannot be found." error when I deploy to the test server.
The JavaScript:
var form = document.forms[0];
form.action = '/NCR/CreateSaveNCR';
form.submit();
The Controller Code:
[HttpPost]
public ActionResult CreateSaveNCR(viewModels.NCRCreateViewModel model)
I have no idea what the issue is. Thanks..
if the resource cannot be found, and the code is identical, then it might be a path issue, is the web address http://yourdomain.com/NCR/CreateSaveNCR? or is it in a folder underneath that? You also might (uncommonly) have to restart the IIS process to get it to take in new routing info (rerun global.asax's app_start).
If you deploy to a virtual directory it will need to be included as part of the mvc url path.
Another possibility is that the file exists in the directory in dev but is not included as a project file and is left out of the "publish" deployment method if you push changes to your staging environment using that mechanism.
Never hardcode urls. Always use url helpers when dealing with urls:
form.action = '<%= Url.Action("CreateSaveNCR", "NCR") %>';

How to include jssecacert (cacert) in client jar file during client calling https wsdl

I have a jar that must be imported in the client application and enable the client to call my https wsdl web service with the help of the imported jar.
I see that when https service must be called, it must be a valid cacert file in the security folder of < java_home > location.
However I cannot make it possible to install the cacert file into clients javahome security folder just by only importing the jar to client's application.
If you have an idea about how to achieve this, any help would be appriciated, thanks in advance.
EDIT [SOLVED]:
I have solved my problem by adding this method just before the service call
public static void trustStore() {
Properties systemProps = System.getProperties();
systemProps.put("javax.net.ssl.trustStore","jssecacerts");
System.setProperties(systemProps);
}
EDIT [SOLVED]: I have solved my problem by adding this method just before the service call
public static void trustStore() { Properties systemProps = System.getProperties();
systemProps.put("javax.net.ssl.trustStore","jssecacerts");
System.setProperties(systemProps); }
You have two choices:
Provide instructions or an installer to the user that uses the keytool to import your certificate
Add the option "-Djavax.net.ssl.trustStore=..." to the command that boots your client application.