org.springframework.ws.transport.WebServiceConnection类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中org.springframework.ws.transport.WebServiceConnection类的一些代码示例,展示了WebServiceConnection类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebServiceConnection类的具体详情如下:
包路径:org.springframework.ws.transport.WebServiceConnection
类名称:WebServiceConnection

WebServiceConnection介绍

[英]Represents a point-to-point connection that a client can use for sending WebServiceMessage objects directly to a remote party.

A WebServiceConnection can be obtained using a WebServiceMessageSender.
[中]表示客户端可用于将WebServiceMessage对象直接发送到远程方的点对点连接。
可以使用WebServiceMessageSender获得WebServiceConnection。

代码示例

代码示例来源:origin: spring-projects/spring-integration

@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
  TransportContext tc = TransportContextHolder.getTransportContext();
  if (tc != null) {
    try {
      this.lastUri = tc.getConnection().getUri();
    }
    catch (URISyntaxException e) {
      throw new IllegalStateException(e);
    }
  }
  else {
    throw new IllegalStateException("expected WebServiceConnection in the TransportContext");
  }
  return true;
}

代码示例来源:origin: spring-projects/spring-integration

.send(Mockito.any(WebServiceMessage.class));
}).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));

代码示例来源:origin: mdeinum/spring-utils

@Override
public void close() throws IOException {
  delegate.close();
}

代码示例来源:origin: org.springframework.ws/org.springframework.ws

private void sendOutOfBand(MessageContext messageContext, EndpointReference replyEpr) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("Request [" + messageContext.getRequest() + "] has [" + replyEpr +
        "] reply address; sending out-of-band reply [" + messageContext.getResponse() + "]");
  }
  boolean supported = false;
  for (WebServiceMessageSender messageSender : messageSenders) {
    if (messageSender.supports(replyEpr.getAddress())) {
      supported = true;
      WebServiceConnection connection = null;
      try {
        connection = messageSender.createConnection(replyEpr.getAddress());
        connection.send(messageContext.getResponse());
        break;
      }
      finally {
        messageContext.clearResponse();
        if (connection != null) {
          connection.close();
        }
      }
    }
  }
  if (!supported && logger.isWarnEnabled()) {
    logger.warn("Could not send out-of-band response to [" + replyEpr.getAddress() + "]. " +
        "Configure WebServiceMessageSenders which support this uri.");
  }
}

代码示例来源:origin: mdeinum/spring-utils

@Override
  public void send(WebServiceMessage message) throws IOException {
    delegate.send(message);
  }
}

代码示例来源:origin: spring-projects/spring-integration

public static WebServiceMessageSender createMockMessageSender(final String mockResponseMessage) throws Exception {
  WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);
  WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class);
  Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
  Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true);
  Mockito.doAnswer(invocation -> {
    Object[] args = invocation.getArguments();
    WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
    return factory.createWebServiceMessage(new ByteArrayInputStream(mockResponseMessage.getBytes()));
  }).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
  return messageSender;
}

代码示例来源:origin: mdeinum/spring-utils

@Override
public boolean hasError() throws IOException {
  return delegate.hasError();
}

代码示例来源:origin: mdeinum/spring-utils

@Override
public String getErrorMessage() throws IOException {
  return delegate.getErrorMessage();
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

private void sendOutOfBand(MessageContext messageContext, EndpointReference replyEpr) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("Request [" + messageContext.getRequest() + "] has [" + replyEpr +
        "] reply address; sending out-of-band reply [" + messageContext.getResponse() + "]");
  }
  boolean supported = false;
  for (WebServiceMessageSender messageSender : messageSenders) {
    if (messageSender.supports(replyEpr.getAddress())) {
      supported = true;
      WebServiceConnection connection = null;
      try {
        connection = messageSender.createConnection(replyEpr.getAddress());
        connection.send(messageContext.getResponse());
        break;
      }
      finally {
        messageContext.clearResponse();
        if (connection != null) {
          connection.close();
        }
      }
    }
  }
  if (!supported && logger.isWarnEnabled()) {
    logger.warn("Could not send out-of-band response to [" + replyEpr.getAddress() + "]. " +
        "Configure WebServiceMessageSenders which support this uri.");
  }
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

/** Sends the request in the given message context over the connection. */
private void sendRequest(WebServiceConnection connection, WebServiceMessage request) throws IOException {
  if (sentMessageTracingLogger.isTraceEnabled()) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    request.writeTo(os);
    sentMessageTracingLogger.trace("Sent request [" + os.toString("UTF-8") + "]");
  }
  else if (sentMessageTracingLogger.isDebugEnabled()) {
    sentMessageTracingLogger.debug("Sent request [" + request + "]");
  }
  connection.send(request);
}

代码示例来源:origin: org.springframework.ws/org.springframework.ws

return (T)handleError(connection, messageContext.getRequest());
WebServiceMessage response = connection.receive(getMessageFactory());
messageContext.setResponse(response);

代码示例来源:origin: org.springframework.ws/spring-ws-core

/**
 * Determines whether the given connection or message context has an error.
 *
 * <p>This implementation checks the {@link WebServiceConnection#hasError() connection} first. If it indicates an
 * error, it makes sure that it is not a {@link FaultAwareWebServiceConnection#hasFault() fault}.
 *
 * @param connection the connection (possibly a {@link FaultAwareWebServiceConnection}
 * @param request     the response message (possibly a {@link FaultAwareWebServiceMessage}
 * @return {@code true} if the connection has an error; {@code false} otherwise
 * @throws IOException in case of I/O errors
 */
protected boolean hasError(WebServiceConnection connection, WebServiceMessage request) throws IOException {
  if (checkConnectionForError && connection.hasError()) {
    // could be a fault
    if (checkConnectionForFault && connection instanceof FaultAwareWebServiceConnection) {
      FaultAwareWebServiceConnection faultConnection = (FaultAwareWebServiceConnection) connection;
      return !(faultConnection.hasFault() && request instanceof FaultAwareWebServiceMessage);
    }
    else {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

/**
 * Handles an error on the given connection. The default implementation throws a {@link
 * WebServiceTransportException}.
 *
 * @param connection the erroneous connection
 * @param request     the corresponding request message
 * @return the object to be returned from {@link #sendAndReceive(String,WebServiceMessageCallback,
 *           WebServiceMessageExtractor)}, if any
 */
protected Object handleError(WebServiceConnection connection, WebServiceMessage request) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("Received error for request [" + request + "]");
  }
  throw new WebServiceTransportException(connection.getErrorMessage());
}

代码示例来源:origin: mdeinum/spring-utils

@Override
public URI getUri() throws URISyntaxException {
  return delegate.getUri();
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

WebServiceMessage request = connection.receive(getMessageFactory());
MessageContext messageContext = new DefaultMessageContext(request, getMessageFactory());
receiver.receive(messageContext);
    faultConnection.setFaultCode(faultResponse.getFaultCode());
  connection.send(messageContext.getResponse());

代码示例来源:origin: spring-projects/spring-ws

private void sendOutOfBand(MessageContext messageContext, EndpointReference replyEpr) throws IOException {
  if (logger.isDebugEnabled()) {
    logger.debug("Request [" + messageContext.getRequest() + "] has [" + replyEpr +
        "] reply address; sending out-of-band reply [" + messageContext.getResponse() + "]");
  }
  boolean supported = false;
  for (WebServiceMessageSender messageSender : messageSenders) {
    if (messageSender.supports(replyEpr.getAddress())) {
      supported = true;
      WebServiceConnection connection = null;
      try {
        connection = messageSender.createConnection(replyEpr.getAddress());
        connection.send(messageContext.getResponse());
        break;
      }
      finally {
        messageContext.clearResponse();
        if (connection != null) {
          connection.close();
        }
      }
    }
  }
  if (!supported && logger.isWarnEnabled()) {
    logger.warn("Could not send out-of-band response to [" + replyEpr.getAddress() + "]. " +
        "Configure WebServiceMessageSenders which support this uri.");
  }
}

代码示例来源:origin: org.springframework.ws/org.springframework.ws

/** Sends the request in the given message context over the connection. */
private void sendRequest(WebServiceConnection connection, WebServiceMessage request) throws IOException {
  if (sentMessageTracingLogger.isTraceEnabled()) {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    request.writeTo(os);
    sentMessageTracingLogger.trace("Sent request [" + os.toString("UTF-8") + "]");
  }
  else if (sentMessageTracingLogger.isDebugEnabled()) {
    sentMessageTracingLogger.debug("Sent request [" + request + "]");
  }
  connection.send(request);
}

代码示例来源:origin: org.springframework.ws/spring-ws-core

return (T) handleError(connection, messageContext.getRequest());
WebServiceMessage response = connection.receive(getMessageFactory());
messageContext.setResponse(response);

代码示例来源:origin: org.springframework.ws/spring-ws-core

/**
 * Close the given {@link WebServiceConnection} and ignore any thrown exception. This is useful for typical
 * {@code finally} blocks.
 *
 * @param connection the web service connection to close (may be {@code null})
 */
public static void closeConnection(WebServiceConnection connection) {
  if (connection != null) {
    try {
      connection.close();
    }
    catch (IOException ex) {
      logger.debug("Could not close WebServiceConnection", ex);
    }
    catch (Throwable ex) {
      logger.debug("Unexpected exception on closing WebServiceConnection", ex);
    }
  }
}

代码示例来源:origin: spring-projects/spring-ws

/**
 * Determines whether the given connection or message context has an error.
 *
 * <p>This implementation checks the {@link WebServiceConnection#hasError() connection} first. If it indicates an
 * error, it makes sure that it is not a {@link FaultAwareWebServiceConnection#hasFault() fault}.
 *
 * @param connection the connection (possibly a {@link FaultAwareWebServiceConnection}
 * @param request     the response message (possibly a {@link FaultAwareWebServiceMessage}
 * @return {@code true} if the connection has an error; {@code false} otherwise
 * @throws IOException in case of I/O errors
 */
protected boolean hasError(WebServiceConnection connection, WebServiceMessage request) throws IOException {
  if (checkConnectionForError && connection.hasError()) {
    // could be a fault
    if (checkConnectionForFault && connection instanceof FaultAwareWebServiceConnection) {
      FaultAwareWebServiceConnection faultConnection = (FaultAwareWebServiceConnection) connection;
      return !(faultConnection.hasFault() && request instanceof FaultAwareWebServiceMessage);
    }
    else {
      return true;
    }
  }
  return false;
}

相关文章