javax.xml.soap.SOAPFault Java Examples

The following examples show how to use javax.xml.soap.SOAPFault. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SoapFaultHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private String getSoapFaultCode(SOAPMessage msg) throws SOAPException{
  	SOAPPart part = msg.getSOAPPart();
if(part !=null){
	SOAPEnvelope soapEnvelope = part.getEnvelope();
	if(soapEnvelope !=null){
	SOAPBody body = soapEnvelope.getBody();
		if(body !=null){
			SOAPFault fault=body.getFault();
			if(fault !=null && !StringUtils.isEmpty(fault.getFaultString()) && fault.getFaultString().contains("SOA-")){
				return fault.getFaultString();
			}
		}
	}
}
return null;
  }
 
Example #2
Source File: SOAP12Fault.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #3
Source File: SOAP12Fault.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #4
Source File: MessageModeOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) {
    if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) {
        Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService()
                                                         .getServiceInfos().get(0),
                                                     message.getExchange().getBus());
        Detail d = fault.getDetail();
        try {
            validateFaultDetail(d, schema, bop);
        } catch (Exception e) {
            throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver());
        }

        //We validated what we can from a fault standpoint
        message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE);
    }
}
 
Example #5
Source File: SOAP12Fault.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #6
Source File: DispatchImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void checkError() {
    if (error != null) {
        if (getBinding() instanceof SOAPBinding) {
            SOAPFault soapFault = null;
            try {
                soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding)getBinding(),
                                                             new Exception(error.toString()));
            } catch (SOAPException e) {
                //ignore
            }
            if (soapFault != null) {
                throw new SOAPFaultException(soapFault);
            }
        } else if (getBinding() instanceof HTTPBinding) {
            HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
            exception.initCause(new Exception(error.toString()));
            throw exception;
        }
        throw new WebServiceException(error.toString());
    }
}
 
Example #7
Source File: TestSOAPHandler.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SOAPFaultException createSOAPFaultExceptionWithDetail(String faultString)
    throws SOAPException {

    SOAPFault fault = SOAPFactory.newInstance().createFault();

    QName faultName = new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE,
                    "Server");
    SAAJUtils.setFaultCode(fault, faultName);
    fault.setFaultActor("http://gizmos.com/orders");
    fault.setFaultString(faultString);

    Detail detail = fault.addDetail();

    QName entryName = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry = detail.addDetailEntry(entryName);
    entry.addTextNode("Quantity element does not have a value");

    QName entryName2 = new QName("http://gizmos.com/orders/",
                    "order", "PO");
    DetailEntry entry2 = detail.addDetailEntry(entryName2);
    entry2.addTextNode("Incomplete address: no zip code");

    return new SOAPFaultException(fault);
}
 
Example #8
Source File: SOAP11Fault.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #9
Source File: SOAP12Fault.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #10
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void validate(SOAPMessageContext context, String mode) {
   try {
      SOAPBody body = context.getMessage().getSOAPBody();
      SOAPFault fault = body.getFault();
      if (fault != null) {
         return;
      }

      Node payloadNode = body.getFirstChild();
      ValidatorHelper.validate(new DOMSource(payloadNode), this.isXOPEnabled(context), this.schemaFiles);
   } catch (Exception var6) {
      dumpMessage(context.getMessage(), mode, LOG);
      LOG.error(var6.getClass().getSimpleName() + ": " + var6.getMessage());
      throw SOAPFaultFactory.newSOAPFaultException(var6.getMessage(), var6);
   }

   LOG.info("Message validation done.");
}
 
Example #11
Source File: GenericResponse.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void getSOAPException() throws SOAPException {
   if (this.message != null && this.message.getSOAPBody() != null) {
      SOAPFault fault = this.message.getSOAPBody().getFault();
      if (fault != null) {
         try {
            LOG.error("SOAPFault: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Node)fault)));
         } catch (TechnicalConnectorException var3) {
            LOG.debug("Unable to dump SOAPFault. Reason [" + var3.getMessage() + "]", var3);
         }

         throw new SOAPFaultException(fault);
      }
   } else {
      throw new SOAPException("No message SOAPmessage recieved");
   }
}
 
Example #12
Source File: SOAP11Fault.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #13
Source File: SOAP11Fault.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected Throwable getProtocolException() {
    try {
        SOAPFault fault = SOAPVersion.SOAP_11.getSOAPFactory().createFault(faultstring, faultcode);
        fault.setFaultActor(faultactor);
        if(detail != null){
            Detail d = fault.addDetail();
            for(Element det : detail.getDetails()){
                Node n = fault.getOwnerDocument().importNode(det, true);
                d.appendChild(n);
            }
        }
        return new ServerSOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #14
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void validate(SOAPMessageContext context, String mode) {
   try {
      SOAPBody body = context.getMessage().getSOAPBody();
      SOAPFault fault = body.getFault();
      if (fault != null) {
         return;
      }

      Node payloadNode = body.getFirstChild();
      ValidatorHelper.validate(new DOMSource(payloadNode), this.isXOPEnabled(context), this.schemaFiles);
   } catch (Exception var6) {
      dumpMessage(context.getMessage(), mode, LOG);
      LOG.error(var6.getClass().getSimpleName() + ": " + var6.getMessage());
      throw SOAPFaultFactory.newSOAPFaultException(var6.getMessage(), var6);
   }

   LOG.info("Message validation done.");
}
 
Example #15
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private void validate(SOAPMessageContext context, String mode) {
   try {
      SOAPBody body = context.getMessage().getSOAPBody();
      SOAPFault fault = body.getFault();
      if (fault != null) {
         return;
      }

      Node payloadNode = body.getFirstChild();
      ValidatorHelper.validate(new DOMSource(payloadNode), this.isXOPEnabled(context), this.schemaFiles);
   } catch (Exception var6) {
      dumpMessage(context.getMessage(), mode, LOG);
      LOG.error(var6.getClass().getSimpleName() + ": " + var6.getMessage());
      throw SOAPFaultFactory.newSOAPFaultException(var6.getMessage(), var6);
   }

   LOG.info("Message validation done.");
}
 
Example #16
Source File: GenericResponse.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void getSOAPException() throws SOAPException {
   if (this.message != null && this.message.getSOAPBody() != null) {
      SOAPFault fault = this.message.getSOAPBody().getFault();
      if (fault != null) {
         try {
            LOG.error("SOAPFault: " + ConnectorXmlUtils.flatten(ConnectorXmlUtils.toString((Node)fault)));
         } catch (TechnicalConnectorException var3) {
            LOG.debug("Unable to dump SOAPFault. Reason [" + var3.getMessage() + "]", var3);
         }

         throw new SOAPFaultException(fault);
      }
   } else {
      throw new SOAPException("No message SOAPmessage recieved");
   }
}
 
Example #17
Source File: SOAPFactory1_2Impl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createFault(String reasonText, QName faultCode)
    throws SOAPException {
     if (faultCode == null) {
        throw new IllegalArgumentException("faultCode argument for createFault was passed NULL");
    }
    if (reasonText == null) {
        throw new IllegalArgumentException("reasonText argument for createFault was passed NULL");
    }
    Fault1_2Impl fault = new Fault1_2Impl(createDocument(), null);
    fault.setFaultCode(faultCode);
    fault.setFaultString(reasonText);
    return fault;
}
 
Example #18
Source File: SecurityTokenServiceImpl.java    From steady with Apache License 2.0 5 votes vote down vote up
private void throwUnsupportedOperation(String string) {
    try {
        SOAPFault fault = SAAJFactoryResolver.createSOAPFactory(null).createFault();
        fault.setFaultString("Unsupported operation " + string);
        throw new SOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new Fault(e);
    }
}
 
Example #19
Source File: SecurityTokenServiceImpl.java    From steady with Apache License 2.0 5 votes vote down vote up
private void throwUnsupportedOperation(String string) {
    try {
        SOAPFault fault = SAAJFactoryResolver.createSOAPFactory(null).createFault();
        fault.setFaultString("Unsupported operation " + string);
        throw new SOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new Fault(e);
    }
}
 
Example #20
Source File: EndpointArgumentsBuilder.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #21
Source File: BodyImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPFault addFault(Name faultCode, String faultString)
    throws SOAPException {

    SOAPFault fault = addFault();
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString);
    return fault;
}
 
Example #22
Source File: EndpointArgumentsBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private SOAPFaultException createDuplicateHeaderException() {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault();
        fault.setFaultCode(soapVersion.faultCodeClient);
        fault.setFaultString(ServerMessages.DUPLICATE_PORT_KNOWN_HEADER(headerName));
        return new SOAPFaultException(fault);
    } catch(SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #23
Source File: SOAP12Fault.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Recursively populate the Subcodes
 */
private void fillFaultSubCodes(SOAPFault fault, SubcodeType subcode) throws SOAPException {
    if(subcode != null){
        fault.appendFaultSubcode(subcode.getValue());
        fillFaultSubCodes(fault, subcode.getSubcode());
    }
}
 
Example #24
Source File: SOAPFaultBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static Message createSOAPFaultMessage(SOAPVersion soapVersion, SOAPFault fault) {
    switch (soapVersion) {
        case SOAP_11:
            return JAXBMessage.create(JAXB_CONTEXT, new SOAP11Fault(fault), soapVersion);
        case SOAP_12:
            return JAXBMessage.create(JAXB_CONTEXT, new SOAP12Fault(fault), soapVersion);
        default:
            throw new AssertionError();
    }
}
 
Example #25
Source File: WsaTubeHelper.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
    QName subcode = addVer.mapRequiredTag;
    QName subsubcode = addVer.mapRequiredTag;
    String faultstring = addVer.getMapRequiredText();

    try {
        SOAPFactory factory;
        SOAPFault fault;
        if (soapVer == SOAPVersion.SOAP_12) {
            factory = SOAPVersion.SOAP_12.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
            fault.appendFaultSubcode(subcode);
            fault.appendFaultSubcode(subsubcode);
            getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
        } else {
            factory = SOAPVersion.SOAP_11.getSOAPFactory();
            fault = factory.createFault();
            fault.setFaultCode(subsubcode);
        }

        fault.setFaultString(faultstring);

        return fault;
    } catch (SOAPException se) {
        throw new WebServiceException(se);
    }
}
 
Example #26
Source File: SOAPFactory1_1Impl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SOAPFault createFault(String reasonText, QName faultCode)
    throws SOAPException {
    if (faultCode == null) {
        throw new IllegalArgumentException("faultCode argument for createFault was passed NULL");
    }
    if (reasonText == null) {
        throw new IllegalArgumentException("reasonText argument for createFault was passed NULL");
    }
    Fault1_1Impl fault = new Fault1_1Impl(createDocument());
    fault.setFaultCode(faultCode);
    fault.setFaultString(reasonText);
    return fault;
}
 
Example #27
Source File: MUTube.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param notUnderstoodHeaders
 * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault.
 *         notUnderstoodHeaders are added in the fault detail.
 */
final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault(
            MUST_UNDERSTAND_FAULT_MESSAGE_STRING,
            soapVersion.faultCodeMustUnderstand);
        fault.setFaultString("MustUnderstand headers:" +
            notUnderstoodHeaders + " are not understood");
        return new SOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #28
Source File: MUTube.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param notUnderstoodHeaders
 * @return SOAPfaultException with SOAPFault representing the MustUnderstand SOAP Fault.
 *         notUnderstoodHeaders are added in the fault detail.
 */
final SOAPFaultException createMUSOAPFaultException(Set<QName> notUnderstoodHeaders) {
    try {
        SOAPFault fault = soapVersion.getSOAPFactory().createFault(
            MUST_UNDERSTAND_FAULT_MESSAGE_STRING,
            soapVersion.faultCodeMustUnderstand);
        fault.setFaultString("MustUnderstand headers:" +
            notUnderstoodHeaders + " are not understood");
        return new SOAPFaultException(fault);
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
}
 
Example #29
Source File: JPlagServerAccessHandler.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Manually builds up a JPlagException SOAP message and replaces the
 * original one with it
 */
public void replaceByJPlagException(SOAPMessageContext smsg, String desc, String rep) {
	try {
		SOAPMessage msg = smsg.getMessage();
		SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

		/*
		 * Remove old header andy body
		 */

		SOAPHeader oldheader = envelope.getHeader();
		if (oldheader != null)
			oldheader.detachNode();
		SOAPBody oldbody = envelope.getBody();
		if (oldbody != null)
			oldbody.detachNode();

		SOAPBody sb = envelope.addBody();
		SOAPFault sf = sb.addFault(envelope.createName("Server", "env", SOAPConstants.URI_NS_SOAP_ENVELOPE),
				"jplagWebService.server.JPlagException");
		Detail detail = sf.addDetail();
		DetailEntry de = detail.addDetailEntry(envelope.createName("JPlagException", "ns0", JPLAG_WEBSERVICE_BASE_URL + "types"));

		SOAPElement e = de.addChildElement("exceptionType");
		e.addTextNode("accessException");

		e = de.addChildElement("description");
		e.addTextNode(desc);

		e = de.addChildElement("repair");
		e.addTextNode(rep);
	} catch (SOAPException x) {
		x.printStackTrace();
	}
}
 
Example #30
Source File: SOAPFactory1_2Impl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public SOAPFault createFault(String reasonText, QName faultCode)
    throws SOAPException {
     if (faultCode == null) {
        throw new IllegalArgumentException("faultCode argument for createFault was passed NULL");
    }
    if (reasonText == null) {
        throw new IllegalArgumentException("reasonText argument for createFault was passed NULL");
    }
    Fault1_2Impl fault = new Fault1_2Impl(createDocument(), null);
    fault.setFaultCode(faultCode);
    fault.setFaultString(reasonText);
    return fault;
}