Apache CXF And javax.ws.rs.core.Response - web-services

i have a methode deleteProduct:
#Override
public Response deleteProduct(String productId) {
Response response = Response
.status(Response.Status.FORBIDDEN)
.entity(new IllegalAccessError("This is a JAXB object with an error string"))
.build();
return response;
}
my problem is always i get this response :
<ns2:deleteProductResponse xmlns:ns2="http://ws.cxf.test.com/">
<return/>
</ns2:deleteProductResponse>
why i dont see my message error ?

I think you are getting confused between JAX-RS and JAX-WS . If this is SOAP-UI you are referring to, it means you are building SOAP based web services or, in other words are using SOA - service oriented architecture which works on the SOAP protocol and not HTTP. Hence HTTP Status codes or error messages based on them do not come into picture here.
However, if you are building a RESTful web service (one that is based on JAX-RS), it has everything to do with HTTP.
First, decide what framework to use based on your project requirements and then code accordingly.

Related

How to use FedEx Web Services in flutter

I'm developing an APP to track FedEx packages using flutter. Where should I integrate FedEx web service WSDL into my code so that I can send my tracking request to FedEx and get the response back?
Currently I'm testing with another api and able to get response by sending request directly to the url of this api. But FedEx web service does not work that way and I have to use their WSDL to set the url.
Beer.fromJSON(Map<String, dynamic> jsonMap) :
id = jsonMap['id'],
name = jsonMap['name'],
tagline = jsonMap['tagline'],
description = jsonMap['description'],
image_url = jsonMap['image_url'];
}
Future<Stream<Beer>> getBeers() async {
final String url = 'https://api.punkapi.com/v2/beers';
final client = new http.Client();
final streamedRest = await client.send(
http.Request('get', Uri.parse(url))
);
return streamedRest.stream
.transform(utf8.decoder)
.transform(json.decoder)
.expand((data) => (data as List))
.map((data) => Beer.fromJSON(data));
}
WSDL isn't something you import into your app, or at least not with dart. It describes the requests that can be made to the various endpoints their server supports.
Fedex's documentation does a better job explaining than I could:
A SOAP request to, or response from a service is generated according to the service’s WSDL definition.
A WSDL is an XML document that provides information about what the service does, the methods that are available, their parameters, and parameter types. It describes how to communicate with the service in order to generate a request to, or decipher a response from, the service.
The purpose of a WSDL is to completely describe a web service to a client. A WSDL generally defines where the service is available and which communication protocol is used to talk to the service. It defines everything required to write a program that will work with an XML web service.
There's a good chance that the endpoint actually uses SOAP for the communication, which dart doesn't currently fully support. You're going to have to use something like dart:xml to generate requests that match the description in the WSDL, and then you can send them with the http.Client the same way as you have done for the other API.

Servlets and Wsdl file

have a wsdl link and I know the soap request what to send and lso the response format through the membrane soap ui client
I have written a simple html page having 3 fields which i pass through request format of soap and then i get a response based on it. This passing of request and validations are done in servlet which i call through action in form. Now i have a wsdl file link.
How should I use it to make request response from the servlet .please help me with code.
EDIT : THE WSDL CONTAINS WCF BASED SOAP SERVICE .
You have to build a web service client from wsdl using wsimport java utility, then you will get a webservice handle, using that you can build a request, send a request and get a response.
for more details: http://docs.oracle.com/javaee/6/tutorial/doc/bnayn.html

Apache CXF Request/Response

I am working on an application that I want to use to catch a SOAP request when it goes into the CXFServlet. There is some processing I need to do to the SOAP envelope on the server side, before the CXFServlet processes it.
I have been presuming that the SOAP envelope, once it reaches the server side, is one of the parameters in the HTTPServletRequest object. But looking at what comes in (using a debugger, of course), I cannot find it.
Can someone tell me where the SOAP request goes when a client sends it to the server? I know that the client is sending the request using an HTTP POST, and I know that the server is using information in the request in order to access the appropriate web service method, then placing any return values from the method into a SOAP response and returning it to the client. What I need to know is where where does the CXFServlet (or one of its filters) look in order to get the SOAP information? Is it somewhere in the parameters? In the servlet context? Does a filter process the SOAP information before it gets to the CXFServlet? How can I get that envelope and do things to it before the web service method is called?
Someone please advise...
Do you want to access the original request ? If yes the actual request or response object itself can be accessed using the WebServiceContext object.
First, declare a private field for the WebServiceContext in your service implementation, and annotate it as a resource
#Resource
private WebServiceContext context;
Then, within your implementing methods, you can access the MessageContext, HttpServletRequest, and HttpServletResponse as follows:
MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
For more info about WebServiceContext see the following url :
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/WebServiceContext.html
If you need to intercept the request before it is ever processed by the CXFServlet, you should look at developing a Servlet Filter.
If you just want to process the SOAP message before CXF does, you can likely use a CXF Interceptor. The phases noted in the documentation indicate the points you can intercept the message. Depending on what you want to do/change, you may need to play around with the phases.
The source for CXF's SoapHeaderInterceptor or SoapActionInInterceptor would be good places to start looking at how to work with the SOAP message.

Common framework for POST over HTTP and SOAP over HTTP webservices

We have a bunch of services that support Post over HTTP similar to normal web app processing where in a form is sent via post and also SOAP over HTTP via the IBM soap gateway, our design is slightly messy today as we had combined a lot of processing logic tied to the transport protocol where we parse the XML contents via DOM parser and have seperate classes for Post and SOAP over HTTP, etc. We want to streamline this such that we have a common service class independent of transport that serves for both SOAP and POST over HTTP. I did find that Apache CXF supports both JAX-RS and JAX-WS via single service class. Does this mean I can use the JAX-RS similar to Form posting over HTTP and JAX-WS for the SOAP. The idea is we don't want to change any of the existing consumers client code and just stream line at the provider end. Any suggestion to this regard is welcome. Thanks.

Apache Axis - Java WS Client Code and SoapUI giving different responses

We are facing a strange issue of getting different number of records as response while making the same webservice API call from our WS client code and SOAP UI.
Lets assume the WS API is something like Foo[] getBar() and it is supposed to return 2 records.
So when we are making a call from SoapUI we get two records but when our client code makes a call it is getting only one record.
I have grabbed the request XML posted by my WS client code from logs and used it to request from SoapUI.
Can it be an issue of an old client stubs?
PS: We are using Apache Axis.