예제 #1
0
  @Test
  public void testEscapeAction() throws Exception {
    String result = SoapUtils.escapeAction("action");
    Assert.assertEquals("Invalid SOAP action", "\"action\"", result);

    result = SoapUtils.escapeAction("\"action\"");
    Assert.assertEquals("Invalid SOAP action", "\"action\"", result);

    result = SoapUtils.escapeAction("");
    Assert.assertEquals("Invalid SOAP action", "\"\"", result);

    result = SoapUtils.escapeAction(null);
    Assert.assertEquals("Invalid SOAP action", "\"\"", result);
  }
    @Override
    protected Soap createMessage(byte[] rawXml, SOAPMessage soap, String charset) throws Exception {
      if (soap.getSOAPHeader() != null) {
        SoapHeader header = unmarshalHeader(SoapHeader.class, soap.getSOAPHeader());
        if (header.getCentralService() != null) {
          if (header.getService() != null) {
            throw new CodedException(
                X_MALFORMED_SOAP,
                "Message header must contain either service id" + " or central service id");
          }

          ServiceId serviceId = GlobalConf.getServiceId(header.getCentralService());
          header.setService(serviceId);

          SOAPEnvelope envelope = soap.getSOAPPart().getEnvelope();
          envelope.removeChild(soap.getSOAPHeader());

          Node soapBody = envelope.removeChild(soap.getSOAPBody());
          envelope.removeContents(); // removes newlines etc.

          Marshaller marshaller =
              JaxbUtils.createMarshaller(SoapHeader.class, new SoapNamespacePrefixMapper());
          marshaller.marshal(header, envelope);

          envelope.appendChild(soapBody);

          byte[] newRawXml = SoapUtils.getBytes(soap);
          return super.createMessage(newRawXml, soap, charset);
        }
      }
      return super.createMessage(rawXml, soap, charset);
    }
예제 #3
0
  @Test
  public void testSetActionInContentType() throws Exception {
    String soapAction = "http://springframework.org/spring-ws/Action";
    String contentType = "application/soap+xml";

    String result = SoapUtils.setActionInContentType(contentType, soapAction);
    Assert.assertEquals(
        "Invalid SOAP action", soapAction, SoapUtils.extractActionFromContentType(result));

    String anotherSoapAction = "http://springframework.org/spring-ws/AnotherAction";
    String contentTypeWithAction =
        "application/soap+xml; action=http://springframework.org/spring-ws/Action";
    result = SoapUtils.setActionInContentType(contentTypeWithAction, anotherSoapAction);
    Assert.assertEquals(
        "Invalid SOAP action", anotherSoapAction, SoapUtils.extractActionFromContentType(result));
  }
예제 #4
0
  @Test
  public void testExtractActionFromContentType() throws Exception {
    String soapAction = "http://springframework.org/spring-ws/Action";

    String contentType = "application/soap+xml; action=" + soapAction;
    String result = SoapUtils.extractActionFromContentType(contentType);
    Assert.assertEquals("Invalid SOAP action", soapAction, result);

    contentType = "application/soap+xml; action   = " + soapAction;
    result = SoapUtils.extractActionFromContentType(contentType);
    Assert.assertEquals("Invalid SOAP action", soapAction, result);

    contentType = "application/soap+xml; action=" + soapAction + " ; charset=UTF-8";
    result = SoapUtils.extractActionFromContentType(contentType);
    Assert.assertEquals("Invalid SOAP action", soapAction, result);

    contentType = "application/soap+xml; charset=UTF-8; action=" + soapAction;
    result = SoapUtils.extractActionFromContentType(contentType);
    Assert.assertEquals("Invalid SOAP action", soapAction, result);
  }
  private Object translate(Response resp) {
    Object rtnValue = null;

    if (!resp.generatedFault()) {
      Parameter ret = resp.getReturnValue();
      rtnValue = SoapUtils.fromByteArray((byte[]) ret.getValue());
    } else {
      outputFault(d_methodName, resp);
    }

    return rtnValue;
  }
  private void checkConsistency() throws Exception {
    log.trace("checkConsistency()");
    try {
      SoapUtils.checkConsistency(requestSoap, response.getSoap());
    } catch (CodedException e) {
      log.error("Inconsistent request-response", e);
      // The error code includes ServiceFailed because it indicates
      // faulty response from service (problem on the other side).
      throw new CodedException(
              X_INCONSISTENT_RESPONSE, "Response from server proxy is not consistent with request")
          .withPrefix(X_SERVICE_FAILED_X);
    }

    checkRequestHash();
  }