用http 400代码提取肥皂体

时间:2018-04-10 01:51:25

标签: java soap javax

当Http结果出现在>之后,以下java代码抛出异常400范围。 使用javax库

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Send SOAP Message to SOAP Server
        soapResponse = soapConnection.call(createSOAPRequest(soapAction, operatorid, publicnodeid, devicetype),
                soapEndpointUrl);

        // Print the SOAP Response
        System.out.println("Response SOAP Message:");
        soapResponse.writeTo(System.out);
        System.out.println();

        soapConnection.close();
    } catch (SOAPException e) {
        System.err.println(
                "\nError occurred while sending SOAP Request to Server!\nMake sure you have the correct endpoint URL and SOAPAction!\n");
        e.printStackTrace();
        System.out.println("the error stack is" + e.getCause());

    }

在我的实际响应中有一个faultcode和faulttype,我希望捕获实际的响应主体,以便从SOAP响应主体中提取更多信息。 我怎样才能得到回复机构?

1 个答案:

答案 0 :(得分:0)

我想在soapResponse.writeTo(System.out);抛出了异常,如果外部化这个SOAP消息时出现问题,writeTo()会抛出SOAPException。您应该在使用SOAPMessage之前检查SOAPHeader或SOAPBody,找到代码并使用不同的代码执行某些操作。