how to set property maxConnection in cxf cilent code - connection

I am developing cxf client. I generate stub from wsdl and develope code from there. My code is something like that
URL WSDL_LOCATION = new URL(targetURL);
CustomerWS_Service CustomerWSService = new CustomerWS_Service (WSDL_LOCATION);
CustomerWS customerWS = CustomerWSService.getCustomerWSPort();
Now, i want to set some property to the connection:
max_total_connection: maximum number of connections allowed
max_connection_per_host: maximum number of connections allowed for a given host config
Some research tell me to set those properties in HttpUrlConnection. But i dont know how to do that Or atleast how to have HttpUrlConnection obj from the code.

You have to set this at Bus level. Bus properties can be configured as like below. You are not using async so don't need to put this property.
Also I would recommend to create client from JaxWsClientFactoryBean
SpringBus bus = new SpringBus();
bus.setProperty(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
bus.setProperty("org.apache.cxf.transport.http.async.SO_KEEPALIVE",Boolean.TRUE); bus.setProperty("org.apache.cxf.transport.http.async.SO_TIMEOUT",Boolean.FALSE); bus.setProperty("org.apache.cxf.transport.http.async.MAX_CONNECTIONS","totalConnections"));
bus.setProperty("org.apache.cxf.transport.http.async.MAX_PER_HOST_CONNECTIONS","connectionsPerHost"));

Related

How can I push data written by a Serilog File Sink on the disk to another Serilog sink?

We are trying to load test our infrastructure of logstash/elastic. Since the actual logs are generated by a software that uses hardware, we are unable to simulate it at scale.
I am wondering if we can store the logs using file sink and later write a program that reads the log files and send data through the actual sink. Since, we are trying different setup, it would be great if we can swap different sinks for testing. Say http sink and elastic sink.
I thought of reading the json file one line at a time and then invoking Write method on the Logger. However I am not sure how to get the properties array from the json. Also, it would be great to hear if there are better alternatives in Serilog world for my needs.
Example parsing
var events= File.ReadAllLines(#"C:\20210520.json")
.Select(line => JsonConvert.DeserializeObject<dynamic>(line));
foreach (var o in objects)
{
DateTime timeStamp = o.Timestamp;
LogEventLevel level = o.Level;
string messageTemplate = o.MessageTemplate;
string exception = o.Exception;
var properties = (o.Properties as JObject);
List<object> parameters = new List<object>();
foreach (var property in properties)
{
if(messageTemplate.Contains(property.Key))
parameters.Add(property.Value.ToString());
}
logInstance.Write(level, messageTemplate, parameters.ToArray());
count++;
}
Example Json Event written to the file
{"Timestamp":"2021-05-20T13:15:49.5565372+10:00","Level":"Information","MessageTemplate":"Text dialog with {Title} and {Message} displayed, user selected {Selected}","Properties":{"Title":"Unload Device from Test","Message":"Please unload the tested device from test jig","Selected":"Methods.Option","SinkRepository":null,"SourceRepository":null,"TX":"TX2937-002 ","Host":"Host1","Session":"Host1-2021.05.20 13.12.44","Seq":87321,"ThreadId":3}}
UPDATE
Though this works for simple events,
it is not able to handle Context properties (there is a work around though using ForContext),
also it forces all the properties to be of type string and
not to mention that destucturing (#property) is not handled properly
If you can change the JSON format to Serilog.Formatting.Compact's CLEF format, then you can use Serilog.Formatting.Compact.Reader for this.
In the source app:
// dotnet add package Serilog.Formatting.Compact
Log.Logger = new LoggerConfiguration()
.WriteTo.File(new CompactJsonFormatter(), "./logs/myapp.clef")
.CreateLogger();
In the load tester:
// dotnet add package Serilog.Formatting.Compact.Reader
using (var target = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.CreateLogger())
{
using (var file = File.OpenText("./logs/myapp.clef"))
{
var reader = new LogEventReader(file);
while (reader.TryRead(out var evt))
target.Write(evt);
}
}
Be aware though that load testing results won't be accurate for many sinks if you use repeated timestamps. You should consider re-mapping the events you read in to use current timestamps.
E.g. once you've loaded up evt:
var current = new LogEvent(DateTimeOffset.Now,
evt.Level,
evt.Exception,
evt.MessageTemplate,
evt.Properties);
target.Write(current);

Datajs: How to modify rel-attribute?

I'm trying to post linked entries in atom-format to Odata service. Only thing missing from my payload is that rel-attribute should be: "http://schemas.microsoft.com/ado/2007/08/dataservices/related/SOItems". Currently it's automatically generated to "http://schemas.microsoft.com/ado/2007/08/dataservices/related/links"
Heres my current linked entries:
<a:link href="SOItems" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/links" type="application/atom+xml;type=entry"><m:inline><a:feed><a:entry><a:author><a:name></a:name></a:author><a:content type="application/xml"><m:properties><d:OrderId>0</d:OrderId><d:Item>000020</d:Item><d:Material>M-06</d:Material><d:Plant>1200</d:Plant><d:Quantity>200.000</d:Quantity><d:Description m:null="true"></d:Description><d:UoM m:null="true"></d:UoM><d:Value m:null="true"></d:Value></m:properties></a:content></a:entry><a:entry><a:author><a:name></a:name></a:author><a:content type="application/xml"><m:properties><d:OrderId>0</d:OrderId><d:Item>000020</d:Item><d:Material>M-06</d:Material><d:Plant>1200</d:Plant><d:Quantity>200.000</d:Quantity><d:Description m:null="true"></d:Description><d:UoM m:null="true"></d:UoM><d:Value m:null="true"></d:Value></m:properties></a:content></a:entry></a:feed></m:inline></a:link>
How can I set rel-attribute for linked entry with datajs.
Thanks,
Br,
RP
the namespace of links "http://schemas.microsoft.com/ado/2007/08/dataservices/related/links" is hard code on datajs code. Currently there is no public API that the application could use to change it. However, since the datajs is open source, there are still some methods to work around this issue by modifying the datajs code:
a) Change the value of local property “odataRelatedLinksPrefix” in data.js
b) Expose the local variable “odataRelatedLinksPrefix” to be public by adding odata.odataRelatedLinksPrefix = odataRelatedLinksPrefix in data.js code. After doing this, the application could change the namespace value by calling OData.odataRelatedLinksPrefix whenever and wherever.

(Microsoft.Practices.EnterpriseLibrary.SemanticLogging) Injection EventSource in SqlDatabaseLog.EnableEvents

I have just recently added Microsoft.Practices.EnterpriseLibrary.SemanticLogging (v6) with SqlServer silk in my MVC 4 application.
var sqlListener = SqlDatabaseLog.CreateListener("SampleEventLogger",strConnection);
sqlListener.EnableEvents(BasicLogger.Log, EventLevel.LogAlways);
this is the code in my controller
BasicLogger.Log.Critical("ERROR CRITICAL");
It works well!
...and now the impediment :)
In my MVC application I use Unity for DI and I inject into constructor ILogger interface.
Because I need to use the same reference that I have registered into unity container (otherwise doesn't work) ,so I have thought that taking the RegisteredType could be the solution.
var myRegistereType = container.Resolve<ILogger>();
sqlListener.EnableEvents(myRegistereType, EventLevel.LogAlways);
but I received an error
*There is already an instance of EventSource with Guid XXX XXX XXX XXX *
Does anyone have any idea?
thanks
There should only be one instance of an EventSource. This is why you will usually see an EventSource exposing a singleton instance (e.g. BasicLogger.Log).
If you are using Unity you will have to register the EventSource as a singleton or use another approach that results in one instance being returned. Here is one way to do it using an InjectionFactory and the Log property:
IUnityContainer container = new UnityContainer();
container.RegisterType<ILogger>(
new InjectionFactory(c => BasicLogger.Log));
var logger = container.Resolve<ILogger>();

Applying two transforms to a message on the send port

I have an urgent need to send a canonical message (M1) out of an orchestration and need to map the canonical message to another message (M2). The resulting message (M2) has to be Wrapped in another request message (M3) before sending it to a web service.
I can't perform the initial transform in the orchestration as I can only deal with the canonical schema internally.
Whats the best way to achieve this 2 stage transform outside of the orchestration?
Thanks in advance!
You could make a pipeline component that applies each map sequentially. Then configure the port to use a pipeline with this component.
private Stream ApplyMap(Stream originalStream, Type mapType)
{
var transform = TransformMetaData.For(mapType).Transform;
var argList = TransformMetaData.For(mapType).ArgumentList;
XmlReader input = XmlReader.Create(originalStream);
Stream outputStream = new VirtualStream();
using (var outputWriter = XmlWriter.Create(outputStream))
{
transform.Transform(new XPathDocument(input), argList, outputWriter, null);
}
outputStream.Flush();
outputStream.Position = 0;
XmlReader outputReader = XmlReader.Create(outputStream);
return outputReader;
}
Then in the pipeline component's Execute method:
Type mapType1 = Type.GetType("YourMapNamespace.Map1, YourAssemblyName,...");
Type mapType2 = Type.GetType("YourMapNamespace.Map2, YourAssemblyName,...");
Stream originalStream = inmsg.BodyPart.GetOriginalDataStream();
Stream mappedStream =
ApplyMap(
ApplyMap(originalStream, mapType1),
mapType2
);
inmsg.BodyPart.Data = mappedStream;
context.ResourceTracker.AddResource(mappedStream);
Note that this example does everything in memory so it could be a problem for large messages. I'll try to find a better example that uses streaming (or worse case, you can use VirtualStream to avoid keeping everything in memory)
If you can use the ESB Toolkit, the ideal approach would be to use an itinerary (Richard Seroter has a good article on that approach here). If that's not an option, here's an approach I've used in the past:
http://blogs.msdn.com/b/chrisromp/archive/2008/08/06/stacking-maps-in-biztalk-server.aspx

Is there any way to specify a service name in the app.config file?

I want to specify my service name in the app.config without needing to recomple and install/uninstall my service repeatedly.
But just retrieving service name from app.config, the service seems ignoring it. Are there any special tricks how to obtain this?
Thanks in advance.
I mean classic windows service. I don't think any code is needed here. I just want to retrieve the service name from app.config dynamically.
After searching a while on the internet and reading articles, it became clearer to me that A service name can't be specified in the app.config in so dynamic way, instead sc command can be used to perform a similar solution. You can specify other configuration variables in the app.config and use sc to rename it
sc.exe create "servicename" binPath="myservicepath.exe"
I am not sure what scenario you have in mind. You would like the name of your Windows service to change. Fair enough. When would it change?
Imagine you have found the solution and created such a Windows service. I presume in your scenario you would install it at least the first time. Then you do not want to uninstall/install it. But presumably you would like to start/stop and do other things with it. Will one of those actions cause the name of the service to change?
If so, I imagine you could launch a process that uninstalls and installs it with a different name for you transparently, based on some kind of naming logic.
I don't see how else you could do it.
Or just come up with a really generic name to cover all possibilities (which might be incredibly simple or incredibly difficult).
http://www.codeproject.com/Articles/21320/Multiple-Instance-NET-Windows-Service
<add key="ServiceName" value="I"/>
[RunInstaller(true)]
public class ServiceInstaller1 : Installer
{
internal static string ServiceNameDefault = "My Service";
internal static string ServiceName = GetConfigurationValue("ServiceName");
/// <summary>
/// Public Constructor for WindowsServiceInstaller.
/// - Put all of your Initialization code here.
/// </summary>
public ServiceInstaller1()
{
var serviceProcessInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
//# Service Account Information
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
//serviceProcessInstaller.Username = null;
//serviceProcessInstaller.Password = null;
//# Service Information
serviceInstaller.DisplayName = ServiceName;
serviceInstaller.StartType = ServiceStartMode.Manual;
//# This must be identical to the WindowsService.ServiceBase name
//# set in the constructor of WindowsService.cs
serviceInstaller.ServiceName = ServiceName;
Installers.Add(serviceProcessInstaller);
Installers.Add(serviceInstaller);
}
private static string GetConfigurationValue(string key)
{
Assembly service = Assembly.GetAssembly(typeof(Service));
Configuration config = ConfigurationManager.OpenExeConfiguration(service.Location);
if (config.AppSettings.Settings[key] != null)
return ServiceNameDefault + " " + config.AppSettings.Settings[key].Value;
else
return ServiceNameDefault;
}
}
Assuming you mean Windows Service, the answer is no. The service has to be installed in the registry, and the name is one of the registry keys.
I'm afraid that what you are trying to do its not possible. It actually seems to go against the nature of a Windows Service purpose and current behavior.
After a windows service is installed the name can't be changed without re-installing it again. What actually names the service is an element called service installer. Which by now, I assume you know what it is and where its located.
However there are ways of manipulating an installed service by using Windows Management Instrumentation (WMI). Maybe this combined with Izabela's recommendation become the right path to your solution.
I would recommend you to read the following tutorial, you might find an alternate way of achieving what you're trying to do.
http://www.serverwatch.com/tutorials/article.php/1576131/Windows-Services-Management-With-WMI-Part-1.htm

Resources