Enable xsd validation using CXF - cxf

Please,how can i enable xsd validation inside server using cxf.
You find below my code used to publish web services:
JaxWsServerFactoryBean Factory = new JaxWsServerFactoryBean();
Factory .setServiceClass(Class.forName(serviceName);
Factory .setAddress("/jaxws" + url);
Factory .create();
So,where i can add xsd validation?
Thanks in advance.

Something like this should work:
java.util.Map<String, Object> props = new java.util.HashMap<>();
props.put("schema-validation-enabled", "true");
Factory.setProperties(props);
See: http://cxf.apache.org/faq.html#FAQ-HowcanIturnonschemavalidationforjaxwsendpoint?

Related

AddHttpClient in Blazor Server Side

I'm trying to create an httpclient in Blazor Server side which would create the least amount of configuration effort every time I call my webapi.
Essentially I would like achieve the following:
Named HTTPClient I can automatically call when I call a function in my webapi.
The webapi requires a bearer token, which I get by calling AcquireTokenSilent
Would be great if I don't have to specify the httpclient when I call the api
The webapi has been added as a service reference, so there is scaffold classes created under the namespace myapp.server.api
To start this off, I created the following in startup:
services.AddHttpClient<myapp.server.api.swaggerClient>(c =>
{
c.BaseAddress = new Uri("https://api.myapp.com/");
AzureADB2COptions opt = new AzureADB2COptions();
Configuration.Bind("AzureAdB2C", opt);
IConfidentialClientApplication cca =
ConfidentialClientApplicationBuilder.Create(opt.ClientId)
.WithRedirectUri(opt.RedirectUri)
.WithClientSecret(opt.ClientSecret)
.WithB2CAuthority(opt.Authority)
.WithClientName("myWebapp")
.WithClientVersion("0.0.0.1")
.Build();
IHttpContextAccessor pp;
string signedInUserID = context.User.FindFirst(ClaimTypes.NameIdentifier).Value;
new MSALStaticCache(signedInUserID, pp.HttpContext).EnablePersistence(cca.UserTokenCache);
var accounts = cca.GetAccountsAsync().Result;
AuthenticationResult result = null;
result = cca.AcquireTokenSilent(opt.ApiScopes.Split(' '), accounts.FirstOrDefault()).ExecuteAsync().Result;
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
});
My hope is to be able to call my api in my views in this way:
myapp.server.api.swaggerClient t = new myapp.server.api.swaggerClient();
currentCount = t.WeatherForecastAsync().Result.FirstOrDefault().Summary;
calling a new instance of swaggerclient requires me to specify an httpclient, so my hopes is to inject the httpclient I am configuring on a global level for that type can be injected automatically.
The pieces I need help with:
Given that I have specified my httpclient scoped to a specific type, would it call automatically if I call a function in my webapi? (Does not seem to fire when debugging)
To get the bearer token, I need to get the current userID, which is in the authstateprovider... seeing that this is in Startup, is getting it from DI even possible?
Any easy way to inject the httpclient on the constructor of my webapi classes? would I be able to get the httpclient in the constructor so that I essentially have a parameterless constructor not asking for httpclient?
Concerning your first question, inject the Web API HttpClient like this in your view:
#inject myapp.server.api.swaggerClient MyClient
and then in the code block:
currentCount = MyClient.WeatherForecastAsync().Result.FirstOrDefault().Summary;
You should be able to debug the code inside AddHttpClient.

Set SOAP addressing header in server side CXF service implemenion

I have web service implemented in Apache CXF. Is there way how can I set SOAP header to request (server side) using AddressingProperties?
This works for me:
List<Header> headers = new ArrayList<Header>();
Header messageIDHeader = new Header(new QName("http://www.w3.org/2005/08/addressing", "MessageID", "wsa"), some_messageID, new JAXBDataBinding(String.class));
headers.add(messageIDHeader);
Header relatesToHeader = new Header(new QName("http://www.w3.org/2005/08/addressing", "RelatesTo", "wsa"), some_relatesTo_ID, new JAXBDataBinding(String.class));
headers.add(relatesToHeader);
wsContext.getMessageContext().put(Header.HEADER_LIST, headers);
But I would like to use org.apache.cxf.ws.addressing.AddressingProperties - something like this:
RelatesToType soapRelatesTo = new RelatesToType();
soapRelatesTo.setValue(some_relatesTo_ID);
soapAddressingHeaders.setRelatesTo(soapRelatesTo);
AttributedURIType soapMsgId = new AttributedURIType();
soapMsgId.setValue(some_messageID);
soapAddressingHeaders.setMessageID(soapMsgId);
How can I pass that to request? I am not able to set it through MessageContext
Adding soapAddressingHeaders to MessageContext
messageContext.put("http://www.w3.org/2005/08/addressing", soapAddressingHeaders);
works correctly but I forgot to enable WS-A addressing for CXF:
<jaxws:features>
<wsa:addressing xmlns:wsa="http://cxf.apache.org/ws/addressing"/>
</jaxws:features>

confused between Api Controller and oData Controller to use with angular's ngresource

i have an angular application that calls web api . it was working all fine with web api controller and ngresource until i required to get count of results.
to get just the count of a result i need to use $inlinecount which only seems to be working with oDataController . with oDataControlelr in place my promises dont work.
$scope.totalCount = storeCommandResource.query({ $inlinecount: "allpages", $top: 0 });
i get
Error: [$resource:badcfg] query
please guide.
its look like i can use oDatacontroller with a model builder setup like this
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<StoreCommand>("StoreCommandsRest");
config.Routes.MapODataServiceRoute(routeName: "OData", routePrefix: "api", model: builder.GetEdmModel());
config.AddODataQueryFilter();
and all i needed to change was query to get
$scope.totalCount = storeCommandResource.get({ $inlinecount: "allpages", $top: 0 });
then i am reading my returned count like
response["odata.count"]

CakePHP 3.x: how to extend the Request class

I have a plugin and I wish to extend the Request class (Cake\Network\Request), to add new methods and properties that can be used by the controllers of my plugin.
How to do?
Thanks.
Create your extended request class and simply pass an instance of it to the dispatcher in your apps webroot/index.php front controller:
https://github.com/cakephp/app/blob/3.0.0/webroot/index.php#L35
// ....
use App\Network\MyCustomRequest;
$dispatcher = DispatcherFactory::create();
$dispatcher->dispatch(
MyCustomRequest::createFromGlobals(), // there it goes
new Response()
);

cxf: wsdl2java created a class that extends Service (javax.xml.ws.Service)

I am new to java WS and WSDL.
I used wsdl2java to create java classes for my web service client and there was a class created with <Service Name>Service extends javax.xml.ws.Service
Please let me know what is the use of the class
I think of this as a 'locator' or 'factory' which can be used for making client-side (proxy) instances of the service. For example (where 'Example' is the Service Name):
ExampleService locator = new ExampleService();
locator.addPort( ExampleService.Example, SOAPBinding.SOAP11HTTP_BINDING
, "http://myserver:8080/myapp/services/example" );
// now get the instance
Example example = locator.getExample();
Though with CXF you can use utilities such as the JaxWsProxyFactoryBean and ignore the <Service Name>Service class. Eg:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(Example.class);
factory.setAddress("http://myserver:8080/myapp/services/example");
factory.setUsername("user");
factory.setPassword("password");
Example example = (Example) factory.create();

Resources