我需要一点帮助,我必须在JSP中使用SOAP进行请求,但这不能正常工作,你们可以帮我吗?
结构:
<soapenv:Envelope xmlns:soapenv="http://whatever.com" xmlns:ser="http://whatever.com">
<soapenv:Header xmlns:infra="http://whatever.com">
<infra:ContextoAcesso>
<infra:usuario>$AppState.ap_usuario$</infra:usuario>
<infra:filial>$AppState.ap_filial$</infra:filial>
</infra:ContextoAcesso>
</soapenv:Header>
<soapenv:Body>
<ser:autorizarRequest>
<ser1:codigoOpcaoUra>$AppState.ap_codigoOpcaoUra$</ser1:codigoOpcaoUra>
<ser1:numeroCartaoBeneficiario>$AppState.ap_numeroCartao$</ser1:numeroCartaoBeneficiario>
<ser1:solicitante>
<ser1:numero>$AppState.ap_solicitanteNumero$</ser1:numero>
</ser1:solicitante>
<ser1:solicitanteCRM>
<ser1:inscricao>$AppState.ap_solicitanteCRM$</ser1:inscricao>
</ser1:solicitanteCRM>
<ser1:recebedor>
<ser1:numero>$AppState.ap_recebedorNumero$</ser1:numero>
</ser1:recebedor>
<ser1:localExecucao>
<ser1:numero>$AppState.ap_localExecucao$</ser1:numero>
</ser1:localExecucao>
<ser1:executor>
<ser1:numero>$AppState.ap_executorNumero$</ser1:numero>
</ser1:executor>
<ser1:eventos>
<ser1:evento>
<ser1:estrutura>$AppState.ap_estrutura$</ser1:estrutura>
<ser1:descricao></ser1:descricao>
<ser1:quantidade>$AppState.ap_quantidade$</ser1:quantidade>
<ser1:situacao>$AppState.ap_situacao$</ser1:situacao>
</ser1:evento>
</ser1:eventos>
<ser1:estruturaCbos>$AppState.ap_estruturaCBOS$</ser1:estruturaCbos>
</ser:autorizarRequest>
</soapenv:Body>
</soapenv:Envelope>
到目前为止,我所做的是:
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
MimeHeaders headers = soapMessage.getMimeHeaders();
headers.addHeader("SOAPAction", "\"http://www.portoseguro.com.br/saude/autorizacoes/Conectividade/services/autorizar\"");
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("ser", "http://whatever.com");
envelope.addNamespaceDeclaration("ser1", "http://whatever.com");
// SOAP Header
SOAPHeader header = envelope.getHeader();
header.addNamespaceDeclaration("infra", "http://whatever.com");
SOAPElement soapContextoAcesso = header.addChildElement("ContextoAcesso", "infra");
SOAPElement soap1 = header.addChildElement("usuario", "infra");
soap1.addTextNode(usuario);
SOAPElement soap2 = header.addChildElement("filial", "infra");
soap2.addTextNode(filial);
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapAutorizarRequest = soapBody.addChildElement("autorizarRequest", "ser");
SOAPElement soap3 = soapAutorizarRequest.addChildElement("codigoOpcaoUra", "ser1");
soap3.addTextNode(codigoOpcaoUra);
SOAPElement soap4 = soapAutorizarRequest.addChildElement("numeroCartaoBeneficiario", "ser1");
soap4.addTextNode(numeroCartaoBeneficiario);
SOAPElement soapSolicitante = soapAutorizarRequest.addChildElement("solicitante", "ser1");
SOAPElement soap5 = soapSolicitante.addChildElement("numero", "ser1");
soap5.addTextNode(solicitanteNumero);
SOAPElement soapSolicitanteCRM = soapAutorizarRequest.addChildElement("solicitanteCRM", "ser1");
SOAPElement soap6 = soapSolicitanteCRM.addChildElement("inscricao", "ser1");
soap6.addTextNode(solicitanteCRM);
SOAPElement soapRecebedor = soapAutorizarRequest.addChildElement("recebedor", "ser1");
SOAPElement soap7 = soapRecebedor.addChildElement("numero", "ser1");
soap7.addTextNode(recebedorNumero);
SOAPElement soapLocalExecucao = soapAutorizarRequest.addChildElement("localExecucao", "ser1");
SOAPElement soap8 = soapLocalExecucao.addChildElement("numero", "ser1");
soap8.addTextNode(localExecucaoNumero);
SOAPElement soapExecutor = soapAutorizarRequest.addChildElement("executor", "ser1");
SOAPElement soap9 = soapExecutor.addChildElement("numero", "ser1");
soap9.addTextNode(executorNumero);
SOAPElement soapEventos = soapAutorizarRequest.addChildElement("eventos", "ser1");
SOAPElement soapEvento = soapEventos.addChildElement("evento", "ser1");
SOAPElement soap10 = soapEvento.addChildElement("estrutura", "ser1");
soap10.addTextNode(estrutura);
SOAPElement soap11 = soapEvento.addChildElement("descricao", "ser1");
SOAPElement soap12 = soapEvento.addChildElement("quantidade", "ser1");
soap12.addTextNode(quantidade);
SOAPElement soap13 = soapEvento.addChildElement("situacao", "ser1");
soap13.addTextNode(situacao);
SOAPElement soap14 = soapAutorizarRequest.addChildElement("estruturaCbos", "ser1");
soap14.addTextNode(estruturaCbos);
soapMessage.saveChanges();
return soapMessage;
该错误是由于标头的调用而引起的,我想可能是结构出错了。 我需要正确设置HEADER,并且该请求还包含密码和用户,你们有什么设置方法的线索吗?谢谢!