How to handle several marshalling profiles in RestEasy? - web-services

I developed a RestFul web services application with RestEasy currently working on Resteasy 2.3.5 and JBoss 4.3.2GA.
I would like to publish chosen attributes to chosen users of my web services.
For instance here is an object User :
User:{id=123, name=Jack, password=MyNameIsJack}
When a web service user with an lambda profile ask for the object Jack my application should return :
{id=123, name=Jack}
When a web service user with an admin profile ask for the object Jack my application should return :
{id=123, name=Jack, password=MyNameIsJack}
Is there a way to do that using RestEasy Framework?
Thx

I tried the solution given by #Blaise Doughan but ObjectGraph override the existing annotation based mapping on my class.
What I wanted is to extend this mapping.
So I chose to do this by extending my annotation mapping with an xml mapping.
According to the tutorial by Blaise, you can do this using MOXy :
extending-jaxb-representing-annotations
Dont forget to write a jaxb.properties file which specify which implementation of JAXB to use : specifying-eclipselink-moxy-as-your-JAXB-implementation
It's working fine for me.
Thx Blaise !

Related

SOAP request in .net core 2 for a web service

I'm writing a project in .Net Core 2.2. As a part of it, for the payment service I have to use this web service: The Payment Web Service
My problem is that I want to make a SOAP request, and I don't exactly know how and there are no available documentation about it!
I want to use the SalePaymentRequest method. The sample code from the bank has the following code which uses in web reference: System.Web.Services.Protocols.SoapHttpClientProtocol. Apparently, it is not available in .net core.
In the Following Question there are elements like BasicHttpBinding which I really do not understand how to use! (My Bad!)
I just want to make a sale request and verify it afterwards.

How to consume credential based webservice (asmx) in Asp.net Core web application?

I am facing issue while adding asmx service in .NetCore Console application. I am using WCF Connected Service extension as add web reference is not available. So,I followed the same steps which was suggested in following link
https://blogs.msdn.microsoft.com/webdev/2016/06/26/wcf-connected-service-for-net-core-1-0-0-and-asp-net-core-1-0-0-is-now-available/
After completing all step it provided auto-generated reference class which contains all method as async method. My asmx service required username and password authentication for each method and we pass credential as first parameter of any method.
for example, using web reference my method looks like GetData(Credential credential) but here auto generated class shows this method like
GetDataAsync() so I used the below mention code to pass the credentials before calling my web service method
client.ClientCredentials.UserName.UserName = "myusername";
client.ClientCredentials.UserName.Password = "mypassword";
It's giving me Not Authorized error, after putting the breakpoints I found that credential was not getting at asmx service.
Please suggest some solution.
Previous Approach I Took:
I ran into a similar issue. I have an MVC Core web application (targeting .NET Framework 4.6.1) and was not able to add a Web Reference the way I used to be able to within previous (non-Core) applications. I was not able to get Connected Services to add a reference to an asmx and allow for the passing of credentials.
To work around this, I created an additional project (a class project also targeting .NET Framework 4.6.1). From there I was able to add a Web Reference the way one could in the past. Within this project I created a class with a publicly accessible method that calls the asmx service.
Then, within my MVC Core project, I set a reference to this additional project and am able to call the public method on the other project.
Latest and Best Approach I Have Found:
I fully updated VS 2017 as well as going to this site to get the latest WCF Connected Services extension (https://marketplace.visualstudio.com/items?itemName=WCFCORETEAM.VisualStudioWCFConnectedService).
The AuthorizationSoapHeader was easy to access and set.
MySoapClient.EndpointConfiguration endpoint = new MySoapClient.EndpointConfiguration();
MySoapClient myService = new MySoapClient(endpoint, myURL);
AuthorizationSoapHeader MyAuthHeader = new AuthorizationSoapHeader();
MyAuthHeader.AppName = FDSServiceAppName;
MyAuthHeader.AppID = Guid.Parse(MyAppID);
Entry[] entries = MyService.GetUsers().Result;
I faced the same problem and i resolved it owning to github issues :
In Reference.cs substitute
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding()
for
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
result.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Basic;
This really worked in .net core client app for soap web services

Two method error in .asmx web service

I developed a web service and i write with c#. My web service is an asmx. But in my service i have 2 method. first one is helloworld(),second method is insert_Data. All of them is webmethod. But if i want to write third method , my application give me an error. My application couldn't see any method like insert_Data or helloworld or new method is refresh.
I used to Ado.net entity data model,and can't find anything about this problem.
Thanks

How do I create a rest web service in Grails?

The idea is to call a method from a website(in php) to my application (in Grails). The application will serve data in json format.
The website and the application are hosted in two different servers. The website is on Yahoo and the application is on Rackspace.
Now, I want to create a web service in my Grails application which serves list of cities in json format.
City Class
class City {
String name
String code
}
How do i write the web service method?
Try the grails jaxrs plugin (https://github.com/krasserm/grails-jaxrs) which will do excactly what you want without any hassle.
Simply install it, create a Resource object with the introduced create-resource command and create and annotate the methods as you wish. all other things are managed by the plugin so you don't have to worry about Controller or UrlMapping...
You need only the annotation #Resource(uri='/cities') on your domain and call the url/cities.json (but, its'n RESTful)
You will want to use a few tools, first you will create a controller that deals with the requests and pushes them off to your service layer.
You can use URL Mappings to make it more RESTFul check out the doc that way all the http methods will be mapped to actions in your controller.
Also if you will be doing a fair bit of json I would recomend starting with the gson plugin it has a fuller feature set then the built in JSON support.
The link from the comment above is a great resource to read as well.
I have found that I most of the time want to support the accept header as well in which case you will need to update your config with the following code. See withFormat doc for more info.
grails.mime.use.accept.header = true

GWT: Expose the service implementation class as web service

Problem scenario is: I am writing a Google Gadget. Data presented in the gadget will come from my deployed GWT app. I am planing to call the web service from Java script to show the required data.
I need to know how I can expose the Service implementation class like GreetingServiceImpl(generated by default as sample in Eclipse GWT project) as web service.
I did tried to to expose the logic using approach suggested here(http://igorshare.wordpress.com/2009/05/20/building-gwt-web-clients-part-2-how-to-expose-rest-full-jax-rs-service-with-jersey-on-tomcat-server/).
But rather than creating the dynamic web project, I created the Google web project in Eclipse. And I am getting the 404 exception.
Any suggestions why I am getting 404 error?
Regards,
Vikram
Check this: Retrieving JSON Data