How can i request a new api that was added in publisher-api.yaml - wso2-api-manager

I add a new api in the file below:
carbon-apimgt\components\apimgt\org.wso2.carbon.apimgt.rest.api.publisher.v1\src\main\resources\publisher-api.yaml
Maven build success and generate some new files which are definded in the publisher-api.yaml.
I use postman to invoke this api but get a null response , why? How can i reuqest it?

When you update the publisher-api.yaml with a new resource, you have to build two components.
carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1
carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common
This will generate the required DTOs and interfaces for the implementation of the new resource.
Then you have to implement the logic behind the new resource. carbon-apimgt/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/impl will now have a new java file and you can add the logic.

Related

Service Fabric Web API Versioning issue

I'm working on a service fabric project with multiple stateless services. When i try to add versioning as in the code below
[Authorize]
[ApiVersion("2.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class SessionController : Controller
{
...
}
it's not working when calling the service later using Postman or using some client winforms app i made just to call this service. And when i say it's not working i mean it's not looking for a specific version i placed in the controller.
e.g.
I'm calling http://localhost:1234/api/v1.0/session/set-session and as you can see in my controller i only have version 2.0. Now my API gets hit this way or another no matter what version number i put in.
I added code to the Startup.cs
services.AddApiVersioning(options => {
options.DefaultApiVersion = new ApiVersion(2, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
options.ApiVersionReader = new HeaderApiVersionReader("x-api-version");
});
Specific API call looks like this:
[HttpPost]
[Route("set-session")]
public async Task<IActionResult> SetSession([FromBody] SessionModel model)
{ ... }
Can anyone tell me what am i missing or maybe api versioning is not supported in service fabric at all?
Thanks.
Does your solution work locally? Based on what I see, I would suspect - no. This should have nothing to do with Service Fabric at all.
Issue 1
I see that your base class inherits from Controller, which is allowed, but is usually ControllerBase. No concern there, just FYI. The crux of the problem is likely that your controller has not applied the [ApiController] attribute. API Versioning defines IApiControllerSpecification and IApiControllerFilter, which is used to filter which controllers should be considered an API. This is important for developers building applications that have the UI and API parts mixed. A controller is a controller in ASP.NET Core and it was difficult to distinguish these two in the early days. There is now a built-in IApiControllerSpecification that considers any controller with [ApiController] applied to be an API. This can be changed, replaced, or completely disabled using ApiVersioningOptions.UseApiBehavior = false.
If your library/application is only APIs, you can decorate all controllers at once using:
[assembly: ApiController]
Since your controller is not currently being considered an API, all requests matching the route are being directed there. The value 1.0 is being considered an arbitrary string rather than an API version. This is why it matches at all instead of HTTP 400. I suspect you must only have one API and it is defined as 2.0; otherwise, I would expect an AmbiguousActionException.
Issue 2
Your example shows that you are trying to version by URL segment, but you've configured the options to only consider the header x-api-version. This option should be configured with one of the following:
URL Segment (only)
options.ApiVersionReader = new UrlSegmentApiVersionReader();
URL Segment and Header
// registration order is irrelevant
options.ApiVersionReader = ApiVersionReader.Combine(
new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("x-api-version"));
Default (Query String and URL Segment)
// NOTE: this is the configuration
// options.ApiVersionReader = ApiVersionReader.Combine(
// new QueryStringApiVersionReader(),
// new UrlSegmentApiVersionReader());
Side Note
As defined, using the URL segment and header versioning methodologies don't make sense. You have a single route which requires an API version. A client will always have to include the API version in every request so there is no point to also supporting a header.
If you define 2 routes, then it makes sense:
[Route("api/[controller]")] // match by header
[Route("api/v{version:apiVersion}/[controller]")] // match by url segment
Versioning by URL segment, while common, is the least RESTful. It violates the Uniform Interface constraint. This issue demonstrates yet another problem with that approach. Query string, header, media type, or any combination thereof will all work with the single route template of: [Route("api/[controller]")]
Observation 1
You have configured options.AssumeDefaultVersionWhenUnspecified = true. This will have no effect when versioning by URL segment. It is impossible to provide a default value of route parameter in the middle of a template. The same would be true for api/value/{id}/subvalues if {id} is not specified.
This option will have an effect if you:
Add a second route template that doesn't have the API version parameter
You update your versioning strategy to not use a URL segment
It should be noted that is a highly abused feature. It is meant to grandfather in existing services that didn't previously have explicit versioning because adding it will break existing clients. You should be cognizant of that if that isn't your use case.

Corda receive attachments from RESTful api

I am building a project using Corda.
I use RESTful api to invoke flows to create and update a state. But how can I upload a pdf file to node using attachment function in Corda?
Any help is appreiciated
If you are using spring servers then use below logic :
create an api that uses the multipart request and include the below
code in it.
msg = proxy.uploadAttachment(new ByteArrayInputStream(getZippedBytes(file))).toString();//msg returns the unique hashid for this attachment.
//getZippedBytes(file)) returns the byte[]
If you're using the built-in webserver, you need to encode the attachment as multipart/form-data and post it to NODE_WEBSERVER_ADDRESS/upload/attachment.
See an example here: https://github.com/corda/samples/blob/release-V3/blacklist/src/main/resources/blacklistWeb/index.html.

Best way to upload files with Restangular + Api-platform (Symfony2)

I use api-platform for the first time and I am looking for the best way to upload files.
My situation :
An entity "Post" with a OneToMany relation "Media" (SonataMedia) on server side, I'm working on the create view (Angular + Restangular).
All fields (except file type fields) are functional (persist OK). Now, for the file type fields, what do I have to do?
Asynchronous upload? in this case how to link files upload with my entity (which is not persisted yet)
upload files on form entity submit?
In every case, what it needs to send to server? How Api-platform manages it?
There is no builtin file upload support as time of writing in API Platform. You need to write your own code to handle uploads.
However, some work is some work being done to natively add this feature and you can already use it.
Basically, the idea is:
Encode the file to upload as data: URI client-side (using JavaScript)
Send this data URI (basically a base64 string) as a typical string entity property using Restangular (or any other HTTP client)
Decode the data: URI server-side to a regular file using the Symfony Serializer
Store this regular file on the server: it's up to you to store it on the filesystem or in more advanced backends such as Mongo GridFS or Amazon S3
Client-side
To get a data: URI client-side from a selected file, you can rely on the readAsDataURL of the FileReader JavaScript API: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsDataURL.
Send the resulting string as usual using Restangular.
Server-side
The API Platform normalization system is built on top of the Symfony Serializer. I've contributed a data: URI normalizer and denormalizer in Symfony: https://github.com/symfony/symfony/pull/16164
It is not merged yet but you can copy it in your own project during the meantime.
Register the normalizer:
services:
data_uri_normalizer:
class: 'AppBundle\Serializer\DataUriNormalizer'
tags:
- { name: serializer.normalizer }
Then create (and register) a new normalizer decorating the ItemNormalizer of API Platform to transform your property containing the file encoded as a data: URI to a standard \SplFileObject using the DataUriNormalizer::denormalize() method.
In a future version of API Platform (planned for the v2.1 with Symfony 3.1) all this logic will be automatically available and registered.

How to Get WCF RIA service URL

I have created a WFC RIA Service based on ASP.Net Website and adding the nuget packages for RIA service. I have also created a Service named "FactoryService" by extending DomainService class.
I have tested the service by creating a GridView with DomainDataSource pointing to the service. The service is working.
Now I want to access the service from other clients as I have enabled SOAP endpoint. But I cannot find the service's url to the svc file. I need this url to add service reference to my other projects. How do I find the service url?
I have tried the following urls and all returns 404. (namespace "WebApplication3", DomainService class "FactoryService").
- http://localhost:15066/WebApplication3-FactoryService.svc
- http://localhost:15066/services/WebApplication3-FactoryService.svc
- http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc
- http://localhost:15066/FactoryService.svc
- http://localhost:15066/services/FactoryService.svc
- http://localhost:15066/ClientBin/FactoryService.svc
I have found the problem. In the DomainService class, I missed to annotate it with [EnableClientAccess()].
A domain service class must be marked with the
EnableClientAccessAttribute attribute to make the service available to
the client project. The EnableClientAccessAttribute attribute is
automatically applied to a domain service when you select the Enable
client access check box in the Add New Domain Service Class dialog
box.
As I'm using VS2013, the wizard is not available and missed to annotate it with the attribute.
Normally it has the following form
Base-Address + ClientBin + FullName of DomainService (Namespace+TypeName separated by -)
So in your case it should look like
http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc
When you access this link in a Browser you will be provided a page that looks similar to this
Service
You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?wsdl
You can also access the service description as a single file:
http://localhost:15066/ClientBin/WebApplication3-FactoryService.svc?singleWsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:
C#
class Test
{
static void Main()
{
HelloClient client = new HelloClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
Visual Basic
Class Test
Shared Sub Main()
Dim client As HelloClient = New HelloClient()
' Use the 'client' variable to call operations on the service.
' Always close the client.
client.Close()
End Sub
End Class

Could not find default endpoint element that references contract 'Service' error in consuming web Services in asp.net mvc

I have a problem when calling web Services in ASP.net MVC , I do the following
add the web service by add service reference to solution, and I include the service.cs file to the solution also, but when I try to create object in home controller , I have the following error
Could not find default endpoint element that references contract 'Service' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
can any one help me please
thanks
There's a couple things going on here. First, you're using SVCUTIL to generate a proxy and configuration settings for a non-WCF service - .asmx is legacy. I was able to generate a proxy and config settings, but to overcome the error you got you need to call one of the overloaded versions of WeatherHttpClient.
I'm not 100% sure, but this is what I think based on what I observed.
The reason is because there are two endpoints defined in the configuration file (one for SOAP 1.1 and one for SOAP 1.2), and since both endpoints are named there is no default endpoint to choose from.
When I used var x = new WeatherHttpClient(new BasicHttpBinding("WeatherSoap"), new EndpointAddress("http://wsf.cdyne.com/WeatherWS/Weather.asmx")); I was able to create the proxy just fine.
However, when I called GetCityForecastByZip I got the following error:
Server did not recognize the value of HTTP Header SOAPAction: http://ws.cdyne.com/WeatherWS/WeatherHttpGet/GetCityForecastByZIPRequest.
So then I used WSDL.exe to generate the proxy a la .ASMX style. I included that in my project, and the following code returned a result (after including a reference to System.Web.Services - I was using a console app):
var x = new Weather();
ForecastReturn result = x.GetCityForecastByZip("91504");`
I would suggest for simplicity using WSDL.exe to generate the proxy for your service, as it seems to be simpler.
I will also add that I've done very little MVC, but I don't think this is an MVC issue. I hope this helps you.

Resources