java.net.BindException:在java.net.PlainSocketImpl.socketBind中已使用的地址(本机方法)

时间:2019-02-15 10:24:57

标签: java sockets tomcat soap httpclient

在我们的其中一台计算机中,有下面的Exept可以重新启动tomcat来解决它,但是我们需要您的帮助来检查代码中是否存在错误

java.net.BindException: Address already in use
    at java.net.PlainSocketImpl.socketBind(Native Method) ~[na:1.8.0_51]
    at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:382) ~[na:1.8.0_51]
    at java.net.Socket.bind(Socket.java:644) ~[na:1.8.0_51]
    at java.net.Socket.<init>(Socket.java:433) ~[na:1.8.0_51]
    at java.net.Socket.<init>(Socket.java:286) ~[na:1.8.0_51]
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79) ~[DefaultProtocolSocketFactory.class:3.0]
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121) ~[DefaultProtocolSocketFactory.class:3.0]
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706) ~[HttpConnection.class:3.0]
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386) ~[HttpMethodDirector.class:3.0]
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170) ~[HttpMethodDirector.class:3.0]
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396) ~[HttpClient.class:3.0]
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324) ~[HttpClient.class:3.0]
    at com.timwe.ma.oor.base.soap.client.SOAPClient.sendSoapRequest(SOAPClient.java:89) [SOAPClient.class:1.0.0-SNAPSHOT]
    at com.timwe.ma.oor.base.soap.client.SOAPClient.processRequest(SOAPClient.java:51) [SOAPClient.class:1.0.0-SNAPSHOT]

我们的代码:

63 private SOAPMessage sendSoapRequest(String uuid, SOAPMessage soapChargeRequestMsg) throws Exception {

65    String url = RestServiceLocatorBO.getRestEndpoint(SL_CONTEXT_ID, getBusinessKey());

    Log.debug("[{}] Soap msg destination url: {}", uuid, url);
    PostMethod post = null;
    SOAPConnection soapConnection = null;
    String soapResponseBodyStr = null;

    int result = 500;
    try {

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

        try(final StringWriter sw = new StringWriter()) {
            TransformerFactory.newInstance().newTransformer().transform(
                    new DOMSource(soapChargeRequestMsg.getSOAPPart()),
                    new StreamResult(sw));

            post = new PostMethod(url);
            RequestEntity entity = new StringRequestEntity(sw.toString(), "text/xml", "ISO-8859-1");
            post.setRequestEntity(entity);
            post.setRequestHeader("method", "Charge");
            HttpClient httpclient = new HttpClient();

89          result = httpclient.executeMethod(post);
            soapResponseBodyStr = post.getResponseBodyAsString();
        }

        Log.info("[{}] Response status code: {}, response body: {}", uuid, result, soapResponseBodyStr);

    } catch (TransformerException e) {
        throw new RuntimeException(e);
    } catch(Exception e) {
        Log.error("["+String.valueOf(uuid)+"] Could not contact external billing soap api: {}", e);
    } finally {
        post.releaseConnection();
        soapConnection.close();
    }

    SOAPMessage response = null;

    try(InputStream is = new ByteArrayInputStream(post.getResponseBodyAsString().getBytes())) {
        response = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(null, is);
    }

    return response;
}

关于日志,在这一行中发布:httpclient.executeMethod(post)。 我们的代码有什么错误吗?

0 个答案:

没有答案