How to add a SOAP header via JAX-WS? - soap

Our system requires adding some header information in the SOAP message. So how does this be implemented by JAX-WS. I know one way to achieve this is adding
#WebParam(name = "login", header = true), but this solution is not what we want. We want one solution which doesn't need to change the endpoint interface.

You would need to write an interceptor which will implement SOAPHandler to intercept the request.

Related

SoapCore and Message Header

I have a customer that requires us to use a SOAP service (and yes...I tried to have that changed and no go). The soap message needs to look like this with an AuthHeader in the Header.
I've tried using SoapCore with an IMessageInspector2 and a MessageHeader attribute but no luck
Does anyone have a solution for this? I have to send the WSDL to our customer so they can code against it.

Access request headers from JWTCallerPrincipalFactory

I am using Quarkus with quarkus-smallrye-jwt and I want to access the request headers from a custom subclass of JWTCallerPrincipalFactory as explained by https://quarkus.io/guides/security-jwt#custom-factories. Is there a way to do that?
I solved it by using an implementation of HttpAuthenticationMechanism which has access to the RoutingContext as described here https://quarkus.io/guides/security-customization#httpauthenticationmechanism-customization

Rest API GET method restriction

I wanted to clarify on a usecase where i struggled to use GET method for a fetch operation.
I was asked to build a API to generate message from a predefined template. In the request i receive template-ID and the dynamic content which needs to be substituted. Dynamic content vary based on the template-ID.
I have designed like
Method = POST
URL pattern = /messagegenerator/v1/templateID
Body = Dynamic Content in the form of JSON
Response = Plain text message
Problem i faced: When i use GET method then template content should be passed in the URL which has length restriction. We wanted to prepare email message which has more dynamic content.
Ultimately this service won't create any resource but still i forced to use POST method.
Am i missing something?
Rest standard missing?
Is there any better way of doing this?
Is there any restrictions on the length of get URL parameters?
Although there is no url limit in the standard, there is this old advice about keeping your urls under 2000 characters: What is the maximum length of a URL in different browsers?
To the point: in your case sending a POST request with all data in the body is the best solution. Putting email body fragments, or anything that huge (if I understand correctly) into a url is very ugly :). Even if the request does not change anything on the server technically, you should use POST, yes.
You need to create a new API which supports http get method, because one API can't receive more than on http method.
As you pointed out, in REST the POST method is thought of creating a new resource. In your case a new resource "message" is generated indeed by posting the content even if you do not keep it on the server.
But you are using POST on a template! This should create a new template. To resolve this, add a subresource to the template resource so you can express that it is a message that is created.
I would even extend the URL by adding a "template" after the "v1" to make more explicit that it is the "template" resouce on the first level.
The only change necessary for that would be to modify the URL like this:
URL pattern = /messagegenerator/v1/template/<templateID>/message
So you could have (even if you do not implement it now):
GET on /messagegenerator/v1/template/ -> Deliver a list of templates
POST on /messagegenerator/v1/template/ -> Create a new template
DELETE on /messagegenerator/v1/template/<templateID> -> Remove a template
PUT on /messagegenerator/v1/template/<templateID> -> Modify a template
GET on /messagegenerator/v1/template/<templateID>/message -> Deliver a list of messages
POST on /messagegenerator/v1/template/<templateID>/message -> Create a new message
DELETE on /messagegenerator/v1/template/<templateID>/message/<messageID> -> Remove a message
PUT on /messagegenerator/v1/template/<templateID>/message/<messageID> -> Modify a message
So you could even manage and return old messages if you saved and assigned them an ID!

How to add SOAP method without param using ckWebServicePlugin

I used this plugin to provide SOAP webservice for application. Overall, it looks good but I stuck when creating a SOAP operation having no params.
Plugin URL: http://www.symfony-project.org/plugins/ckWebServicePlugin
I added dummy #param int $var to get a temporary solution.

How do I write a WSDL file to accept arbitrary SOAP Headers?

I have a client that wants to send a large number of SOAP Header fields to my web service. The only thing I am expected to do with these values is reflect them back.
What is the proper way to handle this? They would like me to define each of them in the WSDL, but they are quite specific and will have no meaning to any other clients.
I have some code that simply intercepts the request and copies the headers back onto the response, but I don't know how to handle this in the WSDL. Is it legitimate to simply leave them out yet? Or a generic way to say "send me anything and I'll send it back"?
At least in WSDL 1.1, it isn't required to list all the headers in the WSDL file:
It is not necessary to exhaustively list all headers that appear in the SOAP Envelope using soap:header. For example, extensions (see section 2.1.3) to WSDL may imply specific headers should be added to the actual payload and it is not required to list those headers here.
I can't find the corresponding section in the WSDL 2.0 spec, but I don't think this would have changed.