Is there a way to access webservicecontext in the following format
SomeUtil.getWebserviceContext() instead of
#Resource
private WebServiceContext wsContext;
Thanks
You can actually just do:
new org.apache.cxf.jaxws.context.WebServiceContextImpl()
and use that. That's the object that is injected and it just wraps a thread local.
Migrating from old CXF 2.2 to 2.7.0, I was unable to access to the WebServiceContext, this line works fine:
new org.apache.cxf.jaxws.context.WebServiceContextImpl()
Related
I would like to know if it's possible to configure the library during runtime (Saml2Configuration). We want to have the ability to set the configuration options and get them from DB.
Thank you
Yes no problem. You can populate the Saml2Configuration at runtime on load or in the controller just before setting the Saml2Configuration object in the constructor.
Here an example from FoxIDs https://github.com/ITfoxtec/FoxIDs/blob/master/src/FoxIDs/Logic/Saml/SamlAuthnDownLogic.cs#L70
I´m following the Quickstarts from IdentityServer4. When I implement the "Switching to Hybrid Flow and adding API Access back" tutorial, I found that the method to get the access token in line:
ViewContext.HttpContext.Authentication.GetTokenAsync("access_token")
is not available. Someone knows what method I must to use? Thanks.
The problem was that in my MVC controller I had the using Microsoft.AspNetCore.Authorization;. This library allows use the [Authorize] attribute but has his own HttpContext.Authentication namespace. The solution is add using Microsoft.AspNetCore.Authentication and now I can access to the GetTokenAsync method.
I am coding a MVC 5 internet application, and am wishing to use Hangfire for recurring tasks.
How can I setup Hangfire to use SQL Server storage without specifying this in the Startup.Auth ConfigureAuth(IAppBuilder app) function.
Here is a resource link for SQL Server configuration: http://docs.hangfire.io/en/latest/configuration/using-sql-server.html
This resource states that:
If you want to use Hangfire outside of web application, where OWIN
Startup class is not applicable, create an instance of the
SqlServerStorage manually and pass it to the JobStorage.Current static
property. Parameters are the same.
The example code is as follows:
JobStorage.Current = new SqlServerStorage("connection string or its name");
I have tried the following code (with my own connection string), yet the dashboard is not available. I have called the code above from a controller function.
Is there something that I have not done correct? How can I setup Hangfire to use SQL Server storage without using the Startup.Auth class?
Thanks in advance.
I think this is your problem:
I have called the code above from a controller function.
You should be setting this up once on application startup - either in the Configuration method of an OWIN Startup class (followed by an app.UseHangFireServer();), or in the Application_Start method of your Global.asax.cs if you really don't want to use OWIN. Either way, the line you're looking for is right there in the documentation you reference:
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(#"connection string or connection string name");
HOWEVER, as far as I know, if you want to use the dashboard you must configure that part via OWIN along with an authorization filter. See http://docs.hangfire.io/en/latest/configuration/using-dashboard.html
So really, I don't know if any downside of using the OWIN configuration for all of this. It's the more modern platform, and since you mention this is for an MVC5 app it's unlikely that you have legacy concerns.
We are using Play 2.1.1 and its built-in JPA integration (JPA.em()
etc).
How can we dynamically change the db.pass property? Play.application().configuration() seems
to be immutable as of Play 2.1. (or we're at least not aware of the mutators)
If we are able to change db.pass, how can we reload the DB configuration so that JPA.em() returns an EntityManager using the new password?
What we are trying to avoid is having to recreate the EntityManager using
EntityManagerFactory. We want to continue to let Play manage that in
the JPA helper class.
Background
The system has a default DB configuration for running locally. When deployed to a server, the DB password is dynamically set on the running application using the following script:
#!/bin/bash
stty -echo
read -p "Password: " PASS
stty echo
curl -k https://127.0.0.1:8443/someUrl/pwd --data "password=$PASS"
The application receives this data and then recreates the Hibernate
SessionFactory. Our new Play app will be required to do something
similar.
The key is to use the ConfigFactory to create a new Config entry. This new Config contains an entry for password with the value coming from your http call to your password service.
A new Configuration is created using the new Config, which in turn falls back to the original Config from the original Configuration.
Basically the new password entry supersedes the original.
It sound long winded when you say it, but the code is pretty readable.
public class Global extends GlobalSettings {
// inject http client to make call for password
#Override
public Configuration onLoadConfig(Configuration configuration, File file, ClassLoader classLoader) {
final Config config = ConfigFactory.parseString(String.format("db.default.user=%s", callPasswordService()));
return new Configuration(config.withFallback(configuration.getWrappedConfiguration().underlying()));
}
}
To answer my own question, at first we solved the problem of updating the immutable configuration at runtime by overriding Configuration.onLoadConfig with the following:
If configuration indicates that production.level is PROD
Read the password from stdin
Create a new configuration by converting the old one to a map and building a new one with ConfigFactory.parseMap, with the new parameter as well
Return super.onLoadConfig
However, this still didn't address that the problem of reloading the DB configuration. In the end, my colleague created a Play! plugin which essentially a copy of some JPA classes with the added capability of being reloaded with a Map of configuration properties.
Update
The "hook" is the additional static method which the plugin adds to the JPA class (e.g. reloadWithProperties). This method creates a new data source which is then rebound in JNDI.
I'm trying to use Guice to inject properties of a JSF managed bean. This is all running on Google App Engine (which may or may not be important)
I've followed the instructions here:
http://code.google.com/docreader/#p=google-guice&s=google-guice&t=GoogleAppEngine
One problem is in the first step. I can't subclass the Servlet module and setup my servlet mappings there because Faces is handled by the javax.faces.webapp.FacesServlet which subclasses Servlet, not HttpServlet. So, I tried leaving my servlet configuration in the web.xml file and simply instantiating a new ServletModel() along with my business module when creating the injector in the context listener described in the second step.
Having done all that, along with the web.xml configuration, my managed bean isn't getting any properties injected. The method is as follows
#ManagedBean
#ViewScoped
public class ViewTables implements Serializable
{
private DataService<Table> service;
#Inject
public void setService( DataService<Table> service )
{
this.service = service;
}
public List<Table> getTables()
{
return service.getAll();
}
}
So, I'm wondering if there is a trick to get Guice injecting into a JSF managed bean? I obviously can't use the constructor injection because JSF needs a no-arg constructor to create the bean.
Check the following JSF-Guice integration framework/advice:
http://code.google.com/p/jsf-sugar/
http://notdennisbyrne.blogspot.com/2007/09/integrating-guice-and-jsf.html
http://cagataycivici.wordpress.com/2007/03/26/integrating_guice_and_jsf/
http://snippets.dzone.com/posts/show/7171
You can also create an HTTP servlet that then simple delegates the request on to a FacesServlet (like a wrapper). This should give you the same effect using Guice Servlet.
How about this approach, works well for us:
http://uudashr.blogspot.com/2008/12/guicing-jsf-with-guice.html
being the developer of jsf sugar I really would like to know the problem you had using it. We are already using it in production here so there shouldn't be any "show stoppers", maybe something is just not well documented? Just drop me a mail: murbanek(at)gmx_net (replace the _ with a .) .
check out http://code.google.com/p/guice2jsf/, and website starchu.blogspot.com, it has excellent library that provides Guice and JSF 2.0 integration
As information in this post are getting out of date but the question is still relevant, I'd like to share my findings about this topic. I wrote a little tutorial including a runnable sample project on how to setup a fully guice powered web stack. You can find it here: https://github.com/skuzzle/guice-jsf