Eliminar xmlns:wsu de wsu:Created
Publicado por Jesus (6 intervenciones) el 28/11/2019 12:52:14
Tengo que generar la siguiente cabecera de SOAP:
Utilizo el siguiente codigo (una Clase que llama tiene que recibir el tipo de dato SOAPHeaderElement):
Pero a la hora de ejecutar se forma lo siguiente:
Como se ve en el Nodo <wsu:Created> tiene el atributo "xmlns:wsu=url". Me gustaria saber cómo deberia eliminarlo ya que usando para los otros nodos removeContens no han aparecido. No sé si es debido a que este pone WSU y los otros WSSE(En la herramienta PostMan lo cambie por WSSE por si las moscas y fallo. ¿Podríais ayudarme?
Cualquier duda o aclaración, decidmelo y lo reviso.
Muchas gracias
1
2
3
4
5
6
7
8
<wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-dcbb39c4-791b-45a1-ba8c-0e392c7f8602">
<wsse:Username>APP-DCTPNSE-CAN-CR1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">NgEsD3WVOn</wsse:Password>
<wsse:Nonce>ZGNiYjM5YzQtNzkxYi00NWExLWJhOGMtMGUzOTJjN2Y4NjAyXzE1NzQ5MzI1NzK=</wsse:Nonce>
<wsu:Created>2019-11-28T10:16:12Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
Utilizo el siguiente codigo (una Clase que llama tiene que recibir el tipo de dato SOAPHeaderElement):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
public static SOAPHeaderElement generateHeaderBlock(String user, String password){
SOAPHeaderElement security = null;
String WSSE = "wsse";
String WSU = "wsu";
String XMLNS = "xmlns";
String WS_SEC_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
String WS_UTI_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
String WS_SOAP_URL = "http://schemas.xmlsoap.org/soap/envelope/";
try {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
javax.xml.soap.SOAPPart sOAPPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = sOAPPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
String uuid = UUID.randomUUID().toString();
QName headerName = new QName(WS_SEC_NS, "Security");
security = new SOAPHeaderElement(headerName);
security.setActor(null);
security.setPrefix(WSSE);
SOAPElement userNameToken = security.addChildElement("UsernameToken");
userNameToken.setPrefix(WSSE);
Name userTokenElementName = envelope.createName("xmlns:wsu");
userNameToken.addAttribute(userTokenElementName, WS_UTI_NS);
Name userTokenElementName2 = envelope.createName(WSU + ":Id");
userNameToken.addAttribute(userTokenElementName2, "SecurityToken-" + uuid);
SOAPElement userName = userNameToken.addChildElement("Username");
userName.removeContents();
userName.setPrefix(WSSE);
userName.addTextNode(user);
Name contrasenaName = envelope.createName("Password", WSSE, WS_UTI_NS);
SOAPElement contrasena = userNameToken.addChildElement("Password");
contrasena.removeContents();
contrasena.setPrefix(WSSE);
contrasena.addTextNode(password);
contrasena.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
String codigoGenerado = new String(Base64.encode((uuid + "_" + (System.currentTimeMillis() / 1000)).getBytes()));
SOAPElement nonce = userNameToken.addChildElement("Nonce");
nonce.removeContents();
nonce.setPrefix(WSSE);
nonce.addTextNode(codigoGenerado);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Calendar c1 = Calendar.getInstance();
Name createdName = envelope.createName("Created", WSSE, WS_UTI_NS);
SOAPElement created = userNameToken.addChildElement("Created");
created.removeContents();
created.setPrefix(WSU);
created.addTextNode(sdf.format(c1.getTime()));
System.out.println("fecha creada: " + created.toString());
security.setMustUnderstand(true);*/
System.out.println("security completada: " + security.toString());
} catch (Exception e) {
e.printStackTrace();
}
return security;
}
Pero a la hora de ejecutar se forma lo siguiente:
1
2
3
4
5
6
7
8
<wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="SecurityToken-dcbb39c4-791b-45a1-ba8c-0e392c7f8602">
<wsse:Username>APP-DCTPNSE-CAN-CR1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">NgEsD3WVOn</wsse:Password>
<wsse:Nonce>ZGNiYjM5YzQtNzkxYi00NWExLWJhOGMtMGUzOTJjN2Y4NjAyXzE1NzQ5MzI1NzI=</wsse:Nonce>
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">2019-11-28T10:16:12Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
Cualquier duda o aclaración, decidmelo y lo reviso.
Muchas gracias
Valora esta pregunta


0