Пример #1
0
 /**
  * Forms a SOAP Fault and puts it in the SOAP Message's Body.
  *
  * @param faultcode fault code to be set in SOAPMEssage
  * @param faultString fault string
  * @param detail the details of the fault condition
  * @return <code>SOAPMessage</code> containing the SOAP fault
  */
 public SOAPMessage formSOAPError(String faultcode, String faultString, String detail) {
   SOAPMessage msg = null;
   SOAPEnvelope envelope = null;
   SOAPFault sf = null;
   SOAPBody body = null;
   SOAPElement se = null;
   try {
     msg = fac.createMessage();
     envelope = msg.getSOAPPart().getEnvelope();
     body = envelope.getBody();
     sf = body.addFault();
     Name qname = envelope.createName(faultcode, null, IFSConstants.SOAP_URI);
     sf.setFaultCode(qname);
     sf.setFaultString(FSUtils.bundle.getString(faultString));
     if ((detail != null) && !(detail.length() == 0)) {
       Detail det = sf.addDetail();
       se = (SOAPElement) det.addDetailEntry(envelope.createName("Problem"));
       se.addAttribute(envelope.createName("details"), FSUtils.bundle.getString(detail));
     }
   } catch (SOAPException e) {
     FSUtils.debug.error("FSSOAPService.formSOAPError:", e);
     return null;
   }
   return msg;
 }
Пример #2
0
  protected Throwable getProtocolException() {
    try {
      SOAPFault fault = SOAPVersion.SOAP_12.getSOAPFactory().createFault();
      ;
      if (reason != null) {
        for (TextType tt : reason.texts()) {
          fault.setFaultString(tt.getText());
        }
      }

      if (code != null) {
        fault.setFaultCode(code.getValue());
        fillFaultSubCodes(fault, code.getSubcode());
      }

      if (detail != null && detail.getDetail(0) != null) {
        javax.xml.soap.Detail detail = fault.addDetail();
        for (Node obj : this.detail.getDetails()) {
          Node n = fault.getOwnerDocument().importNode(obj, true);
          detail.appendChild(n);
        }
      }

      if (node != null) {
        fault.setFaultNode(node);
      }

      return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
      throw new WebServiceException(e);
    }
  }
Пример #3
0
 /**
  * Creates a SOAPFault element from SOS internal fault
  *
  * @param fault SOAPFault element
  * @param soapFault SOS internal fault
  * @throws SOAPException if an error occurs.
  */
 protected void createSOAPFault(SOAPFault fault, SoapFault soapFault) throws SOAPException {
   fault.setFaultCode(soapFault.getFaultCode());
   fault.setFaultString(soapFault.getFaultReason(), soapFault.getLocale());
   if (soapFault.getDetailText() != null) {
     fault.addDetail().setTextContent(soapFault.getDetailText());
   }
 }
Пример #4
0
 @Validated
 @Test(expected = SOAPException.class)
 public final void testAddDetailTwice() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.addDetail();
   fault.addDetail();
 }
Пример #5
0
 @Validated
 @Test
 public final void testCreateDetailEntryUsingCreateElementNS() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   Detail detail = fault.addDetail();
   detail.appendChild(fault.getOwnerDocument().createElementNS("urn:ns", "p:test"));
   Iterator<?> it = detail.getDetailEntries();
   assertTrue(it.hasNext());
   // The implementation silently replaces the Element by a DetailEntry
   DetailEntry detailEntry = (DetailEntry) it.next();
   assertEquals("urn:ns", detailEntry.getNamespaceURI());
   assertEquals("test", detailEntry.getLocalName());
 }
  public CreateCoordinationContextResponseType createCoordinationContext(
      final CreateCoordinationContextType createCoordinationContext,
      final MAP map,
      boolean isSecure) {
    final String messageId = map.getMessageID();
    synchronized (messageIdMap) {
      messageIdMap.put(
          messageId, new CreateCoordinationContextDetails(createCoordinationContext, map));
      messageIdMap.notifyAll();
    }
    String coordinationType = createCoordinationContext.getCoordinationType();
    if (TestUtil.INVALID_CREATE_PARAMETERS_COORDINATION_TYPE.equals(coordinationType)) {
      try {
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault soapFault =
            factory.createFault(
                SoapFaultType.FAULT_SENDER.getValue(),
                CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME);
        soapFault
            .addDetail()
            .addDetailEntry(CoordinationConstants.WSCOOR_ERROR_CODE_INVALID_PARAMETERS_QNAME)
            .addTextNode("Invalid create parameters");
        throw new SOAPFaultException(soapFault);
      } catch (Throwable th) {
        throw new ProtocolException(th);
      }
    }

    // we have to return a value so lets cook one up

    CreateCoordinationContextResponseType createCoordinationContextResponseType =
        new CreateCoordinationContextResponseType();
    CoordinationContext coordinationContext = new CoordinationContext();
    coordinationContext.setCoordinationType(coordinationType);
    coordinationContext.setExpires(createCoordinationContext.getExpires());
    String identifier = nextIdentifier();
    CoordinationContextType.Identifier identifierInstance =
        new CoordinationContextType.Identifier();
    identifierInstance.setValue(identifier);
    coordinationContext.setIdentifier(identifierInstance);
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.serviceName(CoordinationConstants.REGISTRATION_SERVICE_QNAME);
    builder.endpointName(CoordinationConstants.REGISTRATION_ENDPOINT_QNAME);
    builder.address(TestUtil.PROTOCOL_COORDINATOR_SERVICE);
    W3CEndpointReference registrationService = builder.build();
    coordinationContext.setRegistrationService(TestUtil11.getRegistrationEndpoint(identifier));
    createCoordinationContextResponseType.setCoordinationContext(coordinationContext);

    return createCoordinationContextResponseType;
  }
Пример #7
0
  static SOAPFault createSoapFault(SOAPBinding binding, Exception ex) throws SOAPException {
    SOAPFault soapFault;
    try {
      soapFault = binding.getSOAPFactory().createFault();
    } catch (Throwable t) {
      // probably an old version of saaj or something that is not allowing createFault
      // method to work.  Try the saaj 1.2 method of doing this.
      try {
        soapFault = binding.getMessageFactory().createMessage().getSOAPBody().addFault();
      } catch (Throwable t2) {
        // still didn't work, we'll just throw what we have
        return null;
      }
    }

    if (ex instanceof SoapFault) {
      if (!soapFault.getNamespaceURI().equals(((SoapFault) ex).getFaultCode().getNamespaceURI())
          && SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(
              ((SoapFault) ex).getFaultCode().getNamespaceURI())) {
        // change to 1.1
        try {
          soapFault = SOAPFactory.newInstance().createFault();
        } catch (Throwable t) {
          // ignore
        }
      }
      soapFault.setFaultString(((SoapFault) ex).getReason());
      soapFault.setFaultCode(((SoapFault) ex).getFaultCode());
      soapFault.setFaultActor(((SoapFault) ex).getRole());

      Node nd = soapFault.getOwnerDocument().importNode(((SoapFault) ex).getOrCreateDetail(), true);
      nd = nd.getFirstChild();
      soapFault.addDetail();
      while (nd != null) {
        Node next = nd.getNextSibling();
        soapFault.getDetail().appendChild(nd);
        nd = next;
      }

    } else {
      String msg = ex.getMessage();
      if (msg != null) {
        soapFault.setFaultString(msg);
      }
    }
    return soapFault;
  }
  protected final Message createSoapFaultMessage(
      RuntimeContext rc, boolean attachSequenceFaultElement) {
    try {
      // TODO P1 where to set soap fault code?
      SOAPFault soapFault = rc.soapVersion.saajSoapFactory.createFault();

      // common SOAP1.1 and SOAP1.2 Fault settings
      if (faultReasonText != null) {
        soapFault.setFaultString(faultReasonText, java.util.Locale.ENGLISH);
      }

      soapFault.setFaultCode(getCode().asQName(rc.soapVersion));

      // SOAP version-specific SOAP Fault settings
      switch (rc.soapVersion) {
        case SOAP_11:
          break;
        case SOAP_12:
          soapFault.appendFaultSubcode(getSubcode(rc.rmVersion));
          soapFault.addDetail().setValue(getDetailValue());
          break;
        default:
          throw new RxRuntimeException(
              "Unsupported SOAP version: '" + rc.soapVersion.toString() + "'");
      }

      Message soapFaultMessage = Messages.create(soapFault);

      if (attachSequenceFaultElement && rc.soapVersion == SOAPVersion.SOAP_11) {
        soapFaultMessage
            .getHeaders()
            .add(
                rc.protocolHandler.createSequenceFaultElementHeader(
                    getSubcode(rc.rmVersion), getDetailValue()));
      }

      return soapFaultMessage;

    } catch (SOAPException ex) {
      throw new RxRuntimeException("Error creating a SOAP fault", ex);
    }
  }
Пример #9
0
 /**
  * Creates a SOAPFault element from SOS exception
  *
  * @param soapFault SOAPFault element
  * @param owsExceptionReport SOS exception
  * @return SOAP action URI.
  * @throws SOAPException if an error occurs.
  */
 protected String createSOAPFaultFromExceptionResponse(
     SOAPFault soapFault, OwsExceptionReport owsExceptionReport) throws SOAPException {
   // FIXME: check and fix support for ExceptionReport with multiple
   // exceptions!
   if (!owsExceptionReport.getExceptions().isEmpty()) {
     CodedException firstException = owsExceptionReport.getExceptions().iterator().next();
     if (soapFault.getNamespaceURI().equalsIgnoreCase(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) {
       QName qname = new QName(soapFault.getNamespaceURI(), "Client", soapFault.getPrefix());
       soapFault.setFaultCode(qname);
     } else {
       soapFault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
       if (firstException.getCode() != null) {
         soapFault.appendFaultSubcode(
             new QName(
                 OWSConstants.NS_OWS,
                 firstException.getCode().toString(),
                 OWSConstants.NS_OWS_PREFIX));
       } else {
         soapFault.appendFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
       }
     }
     soapFault.addFaultReasonText(
         SoapHelper.getSoapFaultReasonText(firstException.getCode()), Locale.ENGLISH);
     Detail detail = soapFault.addDetail();
     for (CodedException exception : owsExceptionReport.getExceptions()) {
       createSOAPFaultDetail(detail, exception);
     }
     return getExceptionActionURI(firstException.getCode());
   } else {
     SoapFault fault = new SoapFault();
     fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
     fault.setFaultSubcode(OWSConstants.QN_NO_APPLICABLE_CODE);
     fault.setFaultReason(DEFAULT_FAULT_REASON);
     fault.setLocale(Locale.ENGLISH);
     fault.setDetailText(MISSING_EXCEPTION_DETAIL_TEXT);
     createSOAPFault(soapFault, fault);
     return SosSoapConstants.RESP_ACTION_SOS;
   }
 }