JAX-WS adds namespace in Signature of token

喜夏-厌秋 提交于 2019-12-11 19:25:41

问题


I am accessing a third party web service using JAX-WS generated client (Java) code. A call to a service that initiates a client session returns a Token in the response which, a.o., contains a Signature. The Token is required in subsequent calls to other services for authentication purposes.

I learned from using SoapUI that the WS/Endpoint requires the Token to be used as-is... meaning everything works fine when I literally copy the Token (which is one big line) from the initial response to whatever request I like to make next.

Now I am doing the same in my JAX-WS client. I retrieved a Token (I copied it from the response which I captured with Fiddler) and I tested it succesfully in a subsequent call using SoapUI.

However, when performing a subsequent call to a service using the JAX-WS client, the Signature part in the Token is changed. It should look like:

<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>

But (when capturing the request with Fiddler) it now looks like:

<Signature:Signature xmlns:Signature="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature:Signature>

Apparently this is not acceptable according to the WS/Endpoint so now I'd like to know:

  • Why is the Token marshalled back this way?
  • More importantly, how can I prevent my client from doing that?

Thanks in advance!


回答1:


Have you tested it? It should work nevertheless. The original signature used the defautl namespace (...xmldigsig) the JAXB version uses the same namespace but explicit says that the Signature element belongs to that namespae (Signature:Signature). The effect is the same, both xml express that Signature is in the http://www.w3.org/2000/09/xmldsig# namespace

You can customize the jaxby output with @XMLSchema on the package info, @XMLType on the class or inside the element. http://blog.bdoughan.com/2010/08/jaxb-namespaces.html




回答2:


By the help of @Zielu I was able to solve this by altering package-info.java (in the package of the generated files) like so:

@javax.xml.bind.annotation.XmlSchema(
      namespace = "http://namespaceofthirdparty-asingeneratedversionof package-info.java"
    , xmlns = {
          @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.w3.org/2000/09/xmldsig#", prefix = "")
    }
    , elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.where.generated.files.are;


来源:https://stackoverflow.com/questions/28705383/jax-ws-adds-namespace-in-signature-of-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!