コード例 #1
0
ファイル: SOAP12FaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test
 public void testGetFaultNode() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.setFaultNode("urn:mynode");
   assertEquals("urn:mynode", fault.getFaultNode());
 }
コード例 #2
0
ファイル: EchoImpl.java プロジェクト: julienfromentc/jaxws
  private SOAPFaultException createSOAPFaultException() {
    try {
      String namespace = "http://example.com/auctiontraq/schemas/doclit";
      SOAPFactory soapFactory = SOAPFactory.newInstance();
      Name name = soapFactory.createName("MySOAPFault", "ns0", namespace);
      Detail detail = soapFactory.createDetail();
      DetailEntry entry = detail.addDetailEntry(name);
      entry.addNamespaceDeclaration("data", namespace);
      Name attrName1 = soapFactory.createName("myAttr", "data", namespace);
      entry.addAttribute(attrName1, "myvalue");
      SOAPElement child = entry.addChildElement("message");
      child.addTextNode("Server Exception");

      Name name2 = soapFactory.createName("ExtraInformation", "ns0", namespace);
      DetailEntry entry2 = detail.addDetailEntry(name2);

      SOAPElement child2 = entry2.addChildElement("Reason");
      child2.addTextNode("Address Not Found");

      QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "server");
      SOAPFault sf = soapFactory.createFault("SOAP Fault Exception:Address Not Found", qname);
      org.w3c.dom.Node n = sf.getOwnerDocument().importNode(detail, true);
      sf.appendChild(n);
      return new SOAPFaultException(sf);
      // printDetail(detail);
      // return new SOAPFaultException(qname,
      //       "SOAP Fault Exception:Address Not Found", null, detail);

    } catch (SOAPException e) {
      e.printStackTrace();
      // QName qname = new QName("http://schemas.xmlsoap.org/soap/envelope/", "client");
      throw new WebServiceException("Exception While Creating SOAP Fault Exception", e);
    }
  }
コード例 #3
0
ファイル: FSSOAPService.java プロジェクト: aldaris/opensso
 /**
  * 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;
 }
コード例 #4
0
ファイル: AbstractSoapEncoder.java プロジェクト: ydamigos/SOS
 /**
  * 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());
   }
 }
コード例 #5
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test(expected = SOAPException.class)
 public final void testAddDetailTwice() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.addDetail();
   fault.addDetail();
 }
コード例 #6
0
ファイル: SOAP12FaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test(expected = SOAPException.class)
 public void testSetFaultCodeAsStringCustom() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.addNamespaceDeclaration("p", "urn:ns1");
   fault.setFaultCode("p:MyFaultCode");
 }
  protected void handleResultFault(SOAPFault fault) {
    StringBuffer errorMsg = new StringBuffer();
    errorMsg.append("XML/A fault: ");

    String faultString = fault.getFaultString();
    if (faultString != null) {
      errorMsg.append(faultString);
      errorMsg.append("; ");
    }

    String faultActor = fault.getFaultActor();
    if (faultActor != null) {
      errorMsg.append("Actor: ");
      errorMsg.append(faultActor);
      errorMsg.append("; ");
    }

    String faultCode = fault.getFaultCode();
    if (faultCode != null) {
      errorMsg.append("Code: ");
      errorMsg.append(faultCode);
      errorMsg.append("; ");
    }

    throw new JRRuntimeException(errorMsg.toString());
  }
コード例 #8
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test
 public final void testGetFaultCode() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   String code = fault.getPrefix() + ":Server";
   appendFaultCodeElement(fault).setTextContent(code);
   assertEquals(code, fault.getFaultCode());
 }
コード例 #9
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test
 public final void testSetFaultString() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.setFaultString("test");
   Node child = fault.getFirstChild();
   assertTrue(child instanceof SOAPFaultElement);
   checkFaultStringElement((SOAPFaultElement) child);
 }
コード例 #10
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Test
 public final void testGetFaultCodeAsNameUnqualified() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   appendFaultCodeElement(fault).setTextContent("Test");
   Name name = fault.getFaultCodeAsName();
   assertEquals("", name.getPrefix());
   assertEquals("", name.getURI());
   assertEquals("Test", name.getLocalName());
 }
コード例 #11
0
ファイル: SOAP12FaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test
 public void testSetFaultNode() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.setFaultNode("urn:mynode");
   Element child = (Element) fault.getFirstChild();
   assertEquals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, child.getNamespaceURI());
   assertEquals("Node", child.getLocalName());
 }
コード例 #12
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Test
 public final void testGetFaultCodeAsNameQualified() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   String code = fault.getPrefix() + ":Server";
   appendFaultCodeElement(fault).setTextContent(code);
   Name name = fault.getFaultCodeAsName();
   assertEquals(fault.getPrefix(), name.getPrefix());
   assertEquals(fault.getNamespaceURI(), name.getURI());
   assertEquals("Server", name.getLocalName());
 }
コード例 #13
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @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());
 }
コード例 #14
0
  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;
  }
コード例 #15
0
  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);
    }
  }
コード例 #16
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;
  }
コード例 #17
0
 /**
  * Fault response case
  *
  * @throws Exception
  */
 public void testNonAnonymousFaultTo2() throws Exception {
   invokeAsync(
       createDispatchWithoutAddressing(),
       TestMessages.NON_ANONYMOUS_FAULT_TO_COMPLETE_FAULTY_MESSAGE,
       S11_NS,
       nonAnonAddress,
       action,
       endpointAddress,
       "testNonAnonymousReplyTo");
   // Lets see we get a response in 60 s
   SOAPMessage m =
       respMsgExchanger.exchange(null, TestMessages.CLIENT_MAX_TIMEOUT, TimeUnit.SECONDS);
   // System.out.println("****************************");
   // m.writeTo(System.out);
   // System.out.println("\n****************************");
   SOAPBody sb = m.getSOAPBody();
   assertTrue(sb.hasFault());
   SOAPFault fault = sb.getFault();
   assertEquals(fault.getFaultString(), "Negative numbers can't be added!");
 }
コード例 #18
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);
    }
  }
コード例 #19
0
 /** Adds Fault subcodes from {@link SOAPFault} to {@link #code} */
 private void fillFaultSubCodes(SOAPFault fault) throws SOAPException {
   Iterator subcodes = fault.getFaultSubcodes();
   SubcodeType firstSct = null;
   while (subcodes.hasNext()) {
     QName subcode = (QName) subcodes.next();
     if (firstSct == null) {
       firstSct = new SubcodeType(subcode);
       code.setSubcode(firstSct);
       continue;
     }
     SubcodeType nextSct = new SubcodeType(subcode);
     firstSct.setSubcode(nextSct);
     firstSct = nextSct;
   }
 }
コード例 #20
0
ファイル: AbstractSoapEncoder.java プロジェクト: ydamigos/SOS
 /**
  * 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;
   }
 }
コード例 #21
0
  SOAP12Fault(SOAPFault fault) {
    code = new CodeType(fault.getFaultCodeAsQName());
    try {
      fillFaultSubCodes(fault);
    } catch (SOAPException e) {
      throw new WebServiceException(e);
    }

    reason = new ReasonType(fault.getFaultString());
    role = fault.getFaultRole();
    node = fault.getFaultNode();
    if (fault.getDetail() != null) {
      detail = new DetailType();
      Iterator iter = fault.getDetail().getDetailEntries();
      while (iter.hasNext()) {
        Element fd = (Element) iter.next();
        detail.getDetails().add(fd);
      }
    }
  }
コード例 #22
0
ファイル: SOAP12FaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test
 public void testGetFaultNodeNotPresent() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   assertNull(fault.getFaultNode());
 }
コード例 #23
0
 /** Recursively populate the Subcodes */
 private void fillFaultSubCodes(SOAPFault fault, SubcodeType subcode) throws SOAPException {
   if (subcode != null) {
     fault.appendFaultSubcode(subcode.getValue());
     fillFaultSubCodes(fault, subcode.getSubcode());
   }
 }
コード例 #24
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 /**
  * Test the behavior of {@link SOAPFault#getFaultCode()} if no fault code is present. Note that
  * the reference implementation throws a {@link NullPointerException} in this case and that the
  * SAAJ specification is not clear about the expected behavior. Our implementation returns <code>
  * null</code>.
  *
  * @throws Exception
  */
 @Test
 public final void testGetFaultCodeOnEmptyFault() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   assertNull(fault.getFaultCode());
 }
コード例 #25
0
ファイル: SOAPFaultTest.java プロジェクト: veithen/ddom
 @Validated
 @Test(expected = SOAPException.class)
 public final void testSetFaultCodeAsStringWithUnboundPrefix() throws Exception {
   SOAPFault fault = createEmptySOAPFault();
   fault.setFaultCode("unbound:test");
 }
コード例 #26
0
ファイル: SOAP12FaultTest.java プロジェクト: veithen/ddom
 @Override
 protected SOAPElement appendFaultCodeElement(SOAPFault fault) throws SOAPException {
   SOAPElement code =
       fault.addChildElement(new QName(fault.getNamespaceURI(), "Code", fault.getPrefix()));
   return code.addChildElement(new QName(fault.getNamespaceURI(), "Value", fault.getPrefix()));
 }