Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am using spring 4 and testng. How #WebAppConfiguration loads the WebApplicationContext and servlets without error when I did not install servlet containers like tomcat at all. Is it possible to access the servlets by url in this situation or must install the web server?
You don't need to install a real servlet container. You can think that the servlet container created by the #WebAppConfiguration is just a fake and in-memory based servlet container but not a real container like Tomcat. It can only work by programatically invoking its method and cannot invoked by an URL.
The actual implementation of this fake Servlet container consist of MockServletContext , MockHttpServletRequest , MockHttpServletResponse , MockHttpSession and MockServletConfig etc...
The idea is that to test a HttpServlet , we first configure the HTTP request by the setting the related status of MockHttpServletRequest , then programatically invoke HttpServlet under test , and verify the result from the MockHttpServletResponse:
#ContextConfiguration
#WebAppConfiguration
public class FooServletTest {
#Autowired MockHttpServletRequest request;
#Autowired MockHttpServletResponse response;
#Test
public void test1(){
request.setParameter("user", "enigma");
//blablab.
FooServlet sut = new FooServlet();
sut.doGet(request, response);
//Then assert the response is correct by checking its status
}
}
See docs for more details.
Related
I am new to JSF/Facelets and I am creating an application that does the usual CRUD operations over a (No SQL) database. The database has an API that allows the creation of a pool of connections, and then from this object my operations can take and release connections. I suppose this pool has to be created only once for the whole application when it is deployed, be shared (as static?) and closed once the application is destroyed. Is my approach correct? What is the best practice to do this? I have no idea of where I should place my code and how I should call it.
With my old SQL database I used to configure a "testOnBorrow" and a "validationQuery" in the context.xml Resource so I didn't have to create an explicit pool programmatically.
I found two great tutorials (here and here) but I can't figure out from them where to put the code that creates the pool.
Note: I know this might be only a Servlet problem, but I am tagging it as JSF since I don't know if there is a way to do this in JSF (like an application scoped bean). Thanks.
EDIT
Looking at the fact that I cannot find a JAR with a DataSource for the database to be loaded via context.xml, perhaps my question should be more specific: where can I run code once, when a JSF application is deployed and where can I run code when a JSF application is destroyed?
You can implement a weblistner( i.e ServletContextListener). and can use contextInitialized , contextDestroyed method of that to create and destroy your connection pool
Sample :
#WebListener
public class ContextWebListner implements ServletContextListener {
#Override
public void contextInitialized(ServletContextEvent event) {
// initialize connection pool.
}
#Override
public void contextDestroyed(ServletContextEvent event) {
// Destroy connection pool.
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Regarding to this Question link.
How can i change the siteLogo to a new one?
Is it even possible to do it from a ConsoleApplication via CSOM?
It looks like there are no hooks to the site logo in the client object model like there is in the regular object model. (site.RootWeb.SiteLogoUrl = pictureUrl;)
I couldn't find a way to do it using the CSOM but you can create a new site collection scoped (for SharePoint Online) feature with an event receiver and deploy it as a solution. It worked for me and saved me manually updating 380 sites. I had the FeatureActivated method recursively set the logo on the root web of the site collection and all of the sub webs. Here is the code:
public class Feature1EventReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
{
SPWeb web = site.RootWeb;
SetLogo(web);
}
}
private void SetLogo(SPWeb web) {
web.SiteLogoUrl = "/SiteAssets/logo.png";
web.Update();
foreach (SPWeb subweb in web.Webs)
{
SetLogo(subweb);
}
}
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I get this runtime exception when trying to use my new license.
This license is invalid. Please see servicestack.net or contact team#servicestack.net for more details. The id for this license is '[MyLicenseNumber]'
Am I doing anything wrong? I have tried both ways (app.config/code) of registering the license. The application is a console app using the Servicestack.Redis nuget package.
Of course the license is a Servicestack.Redis license and of course the team#servicestack.net have been contacted without reply.
If you have followed the examples provided Subscription section of the ServiceStack.net website and it is not working then you will need to wait for your reply from team#servicestack.net, as there must be an issue with the code itself.
Things to note if you are using a console app:
You would need to include an app.config not a web.config to configure it from settings file.
To configure from code, you need to run ServiceStack.Licensing.RegisterLicense before initialising the AppHost i.e. before appHost.Init();
Web.config / App.config:
<appSettings>
<add key="servicestack:license" value="XXXX-TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gUHJvaW4gY29udmFsbGlzIHRyaXN0aXF1ZSBlcm9zIG5lYyBsYWNpbmlhLiBJbnRlZ2VyIHNlZCBqdXN0byBldSBhbnRlIHRpbmNpZHVudCBjb25zZWN0ZXR1ci4gU3VzcGVuZGlzc2UgZ3JhdmlkYSBk" />
</appSettings>
In code self hosted console application:
public static void Main()
{
ServiceStack.Licensing.RegisterLicense(#"XXXX-TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gUHJvaW4gY29udmFsbGlzIHRyaXN0aXF1ZSBlcm9zIG5lYyBsYWNpbmlhLiBJbnRlZ2VyIHNlZCBqdXN0byBldSBhbnRlIHRpbmNpZHVudCBjb25zZWN0ZXR1ci4gU3VzcGVuZGlzc2UgZ3JhdmlkYSBk");
var appHost = new AppHost();
appHost.Init();
...
}
In code ASP.NET application:
protected void Application_Start(object sender, EventArgs e)
{
ServiceStack.Licensing.RegisterLicense(#"XXXX-TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gUHJvaW4gY29udmFsbGlzIHRyaXN0aXF1ZSBlcm9zIG5lYyBsYWNpbmlhLiBJbnRlZ2VyIHNlZCBqdXN0byBldSBhbnRlIHRpbmNpZHVudCBjb25zZWN0ZXR1ci4gU3VzcGVuZGlzc2UgZ3JhdmlkYSBk");
}
The license code in the examples are fictitious, replace with your own real code
Also note that if you base64 decode the license key after the prefix of XXXX- you should see the components of the key. If your key does not have data similar to this on decoding, the value may be damaged.
{
Ref: XXXX,
Name: Your Name,
Type: Business,
Hash: ZGhmc2tqaGZkamtuamt0aDNpdGtqZmtmaGtzamZuazQzaGtmam5za2pzZGhjaWtqbjQzdWhqa3Jl,
Expiry: 2015-01-01
}
Resolved by Updating the servicestack nuget packages.
I'm not sure why that solved my issue because the new version was not a major update (4.0.5 -> 4.0.15). Perhaps it was due to a version mismatch. One of my library projects used version 4.0.12.
I got a reply from team#servicestack.net which confirmed correctness of my usage of the code and the code itself.
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Configure Property of a static class via spring .net
I want to inject the value for a property inside the static class using spring .net.
Code snippet:
Public static Abc
{
Public static IInterface IInterface{get;set;}
}
here i want to inject the IInterface value inside the Abc staic class though spring .net config.
I doubt if you can do it.
Static classes don't really work well with dependency injection.
You will be better off creating the class as a normal class and setting it up as a singleton within the container. I'm pretty sure spring.net will allow this..
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Has anyone used log4net with Biztalk? We are currently looking into using it and are trying to access pros/cons, and whether or not it would meet our needs.
I have used Log4Net with BizTalk, but i will say that out of the box i ran into issues. Every call out of BizTalk results in the current orchestration getting dehydrated (serialized) so any type you use in BizTalk would have to be serializable and the log4net logger was not.
If you absolutely have to use log4net there is a wrapper that Scott Colestock wrote here.
Assuming you are not locked in, i would just use Enterprise Logging, it offers almost the same functionality as log4net and works out of the box with BizTalk. You can find it here.
For pros and cons, i will say that offer almost exact functionality, I actually ended up creating a wrapper utility that made the Enterprise Library Logging Block look more like log4net.
public static class Logging
{
public static void LogMessage(TraceEventType eventType, string category, string message)
{
LogEntry logEntry = new LogEntry();
logEntry.Severity = eventType;
logEntry.Priority = 1;
logEntry.Categories.Add(category);
logEntry.Message = message;
Logger.Write(logEntry);
}
public static void LogError(string category, string message)
{
LogMessage(TraceEventType.Error, category,message);
}
public static void LogInfo(string category, string message)
{
LogMessage(TraceEventType.Information, category, message);
}
public static void LogVerbose(string category, string message)
{
LogMessage(TraceEventType.Verbose, category, message);
}
}
And if you need more look here .
Have you considered using ETW. This in my opinion is the way to go for instrumenting BizTalk. http://blogs.msdn.com/b/asgisv/archive/2010/05/11/best-practices-for-instrumenting-high-performance-biztalk-solutions.aspx
One of the drawbacks of using both log4net and Enterprise Logging is you need config to enable it. So you have to manage the btsntsvc.exe.config files on all servers in your biztalk group which can be an overhead.
ETW is zero config.
I've got to say that after using both log4net and MS Enterprise Library for application logging on different projects, I prefer log4net. I particularly like the way that with log4net you can centralise the configuration in a single place (e.g. database), rather than having to rely on local server app.config for the btsntsvc.exe.
This is particularly useful if you need to spin out new server instances to add to your farm - you've got enough to do without worrying about logging config. I've used log4net with both BTS2004 and BTS2006R2 and been satisfied. One thing I would recommend whichever logging framework you go with, don't fall into the trap of using the Event Log as a sink - when you scale out across 10 BTS app servers, it is a time consuming process to track errors, particularly as orchestration instances have no affinity to an app server and tend to move across your estate! Keep the event log for crucial OS and BTS service issues, rather than custom application errors - makes SCOM monitoring a lot less painless.
FYI - I too use log4net with Colestock's serializable wrapper, albeit with a few tweaks.