List of usage examples for javax.xml.soap SOAPBody getFault
public SOAPFault getFault();
From source file:com.inbravo.scribe.rest.service.crm.ms.auth.SOAPExecutor.java
/** * Executes SOAP message//from w w w . j av a2s . com * * @param endpointUrl SOAP endpoint * @param message SOAP request * @return SOAP response message * @throws SOAPException in case of a SOAP issue * @throws IOException in case of an IO issue */ private final SOAPMessage execute(final String endpointUrl, final SOAPMessage message) throws Exception { SOAPConnection conn = null; try { /* Create new SOAP connection */ conn = SOAPConnectionFactory.newInstance().createConnection(); if (logger.isDebugEnabled()) { logger.debug("----Inside execute, going to execute SOAP message : " + message.getSOAPBody().getTextContent()); } /* Call SOAP service */ final SOAPMessage response = conn.call(message, endpointUrl); /* Get SOAP response body */ final SOAPBody body = response.getSOAPBody(); if (logger.isDebugEnabled()) { logger.debug("----Inside execute, has fault? : " + body.hasFault()); } if (body.hasFault() && body.getFault() != null) { logger.error("----Inside execute, fault : " + body.getFault().getTextContent() + ", fault reason : " + body.getFault().getFaultString()); /* Throw error */ throw new SOAPException(body.getFault().getTextContent()); } return response; } catch (final Exception e) { logger.error("----Inside execute, error recieved : " + e.getMessage() + ", error : " + e); /* Throw user error */ throw new SOAPException(e); } finally { if (conn != null) { conn.close(); } } }
From source file:com.ibm.soatf.component.soap.SOAPComponent.java
private void checkSOAPMessage(boolean ok) throws SoapComponentException { ProgressMonitor.init(2, "Loading message from file..."); String filename = new StringBuilder(serviceName).append(NAME_DELIMITER).append(operationName) .append(NAME_DELIMITER).append(RESPONSE_FILE_SUFFIX).toString(); final File file = new File(workingDir, filename); InputStream is = null;/*from w ww. ja v a 2 s . c om*/ try { final byte[] xmlMessage = FileUtils.readFileToByteArray(file); is = new ByteArrayInputStream(xmlMessage); SOAPMessage response = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL) .createMessage(new MimeHeaders(), is); ProgressMonitor.increment("Checking for fault..."); response.removeAllAttachments(); SOAPEnvelope envp = response.getSOAPPart().getEnvelope(); SOAPBody someBody = envp.getBody(); if (ok) { if (someBody.getFault() == null) { cor.addMsg("soap body is OK"); cor.markSuccessful(); } else { final String msg = "found soap fault in response body:\n" + new String(xmlMessage); cor.addMsg(msg); throw new SoapComponentException(msg); } } else { if (someBody.getFault() != null) { cor.addMsg("found soap fault in response body"); cor.markSuccessful(); } else { final String msg = "response body doesn't contain soap fault:\n" + new String(xmlMessage); cor.addMsg(msg); throw new SoapComponentException(msg); } } } catch (IOException | SOAPException ex) { throw new SoapComponentException("error while trying to parse response", ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { logger.debug("Not able to close input stream. ", ex); } } } }
From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java
/** * Assume that the InputStream has a SOAP fault message and return a String * suitable to present as an exception message * /*from ww w . j a v a 2s . com*/ * @param is InputStream that contains a SOAP message * @return String containing a formated error message * * @throws IOException * @throws SOAPException */ private String getSOAPFaultAsString(InputStream is) throws IOException, SOAPException { is.reset(); MessageFactory factory = MessageFactory.newInstance(); SOAPMessage message = factory.createMessage(null, is); SOAPBody body = message.getSOAPBody(); if (body.hasFault()) { SOAPFault fault = body.getFault(); String code, string, actor; code = fault.getFaultCode(); string = fault.getFaultString(); actor = fault.getFaultActor(); String formatedMessage = "SOAP transaction resulted in a SOAP fault."; if (code != null) formatedMessage += " Code=\"" + code + ".\""; if (string != null) formatedMessage += " String=\"" + string + ".\""; if (actor != null) formatedMessage += " Actor=\"" + actor + ".\""; return formatedMessage; } return null; }
From source file:net.sf.jasperreports.olap.xmla.JRXmlaQueryExecuter.java
/** * Parses the result-Message into this class's structure * /*from w w w . j a v a 2 s .co m*/ * @param reply * The reply-Message from the Server */ protected void parseResult(SOAPMessage reply) throws SOAPException { SOAPPart soapPart = reply.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement eElement = null; if (log.isDebugEnabled()) { log.debug("XML/A result envelope: " + prettyPrintSOAP(soapEnvelope)); } SOAPFault fault = soapBody.getFault(); if (fault != null) { handleResultFault(fault); } Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI); // Get the ExecuteResponse-Node Iterator<?> responseElements = soapBody.getChildElements(eName); if (responseElements.hasNext()) { Object eObj = responseElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "ExecuteResponse" }); } eElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "ExecuteResponse" }); } // Get the return-Node Name rName = soapEnvelope.createName("return", "", XMLA_URI); Iterator<?> returnElements = eElement.getChildElements(rName); SOAPElement returnElement = null; if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" }); } returnElement = (SOAPElement) eObj; } else { // Should be old-Microsoft XMLA-SDK. Try without m-prefix Name rName2 = soapEnvelope.createName("return", "", ""); returnElements = eElement.getChildElements(rName2); if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "return" }); } returnElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "return" }); } } // Get the root-Node Name rootName = soapEnvelope.createName("root", "", MDD_URI); SOAPElement rootElement = null; Iterator<?> rootElements = returnElement.getChildElements(rootName); if (rootElements.hasNext()) { Object eObj = rootElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "root" }); } rootElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "root" }); } // Get the OlapInfo-Node Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI); SOAPElement olapInfoElement = null; Iterator<?> olapInfoElements = rootElement.getChildElements(olapInfoName); if (olapInfoElements.hasNext()) { Object eObj = olapInfoElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "OlapInfo" }); } olapInfoElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "OlapInfo" }); } parseOLAPInfoElement(olapInfoElement); // Get the Axes Element Name axesName = soapEnvelope.createName("Axes", "", MDD_URI); SOAPElement axesElement = null; Iterator<?> axesElements = rootElement.getChildElements(axesName); if (axesElements.hasNext()) { Object eObj = axesElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "Axes" }); } axesElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "Axes" }); } parseAxesElement(axesElement); // Get the CellData Element Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI); SOAPElement cellDataElement = null; Iterator<?> cellDataElements = rootElement.getChildElements(cellDataName); if (cellDataElements.hasNext()) { Object eObj = cellDataElements.next(); if (eObj == null) { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_NULL_ELEMENT, new Object[] { "CellData" }); } cellDataElement = (SOAPElement) eObj; } else { throw new JRRuntimeException(EXCEPTION_MESSAGE_KEY_XMLA_CANNOT_RETRIEVE_ELEMENT, new Object[] { "CellData" }); } parseCellDataElement(cellDataElement); }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.olap.OLAPQueryExecuter.java
/** * Parses the result-Message into this class's structure * * @param reply//from ww w . j a va2 s . c o m * The reply-Message from the Server */ protected void parseResult(SOAPMessage reply) throws SOAPException, JRRuntimeException { SOAPPart soapPart = reply.getSOAPPart(); SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPBody soapBody = soapEnvelope.getBody(); SOAPElement eElement = null; if (log.isDebugEnabled()) { log.debug("XML/A result envelope: " + soapEnvelope.toString()); } SOAPFault fault = soapBody.getFault(); if (fault != null) { handleResultFault(fault); } Name eName = soapEnvelope.createName("ExecuteResponse", "", XMLA_URI); // Get the ExecuteResponse-Node Iterator responseElements = soapBody.getChildElements(eName); if (responseElements.hasNext()) { Object eObj = responseElements.next(); if (eObj == null) { log.error("ExecuteResponse Element is null."); throw new JRRuntimeException("ExecuteResponse Element is null."); } eElement = (SOAPElement) eObj; } else { log.error("Could not retrieve ExecuteResponse Element."); throw new JRRuntimeException("Could not retrieve ExecuteResponse Element."); } // Get the return-Node Name rName = soapEnvelope.createName("return", "", XMLA_URI); Iterator returnElements = eElement.getChildElements(rName); SOAPElement returnElement = null; if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { log.error("return Element is null."); throw new JRRuntimeException("return Element is null."); } returnElement = (SOAPElement) eObj; } else { // Should be old-Microsoft XMLA-SDK. Try without m-prefix Name rName2 = soapEnvelope.createName("return", "", ""); returnElements = eElement.getChildElements(rName2); if (returnElements.hasNext()) { Object eObj = returnElements.next(); if (eObj == null) { log.error("return Element is null."); throw new JRRuntimeException("return Element is null."); } returnElement = (SOAPElement) eObj; } else { log.error("Could not retrieve return Element."); throw new JRRuntimeException("Could not retrieve return Element."); } } // Get the root-Node Name rootName = soapEnvelope.createName("root", "", MDD_URI); SOAPElement rootElement = null; Iterator rootElements = returnElement.getChildElements(rootName); if (rootElements.hasNext()) { Object eObj = rootElements.next(); if (eObj == null) { log.error("root Element is null."); throw new JRRuntimeException("root Element is null."); } rootElement = (SOAPElement) eObj; } else { log.error("Could not retrieve root Element."); throw new JRRuntimeException("Could not retrieve root Element."); } // Get the OlapInfo-Node Name olapInfoName = soapEnvelope.createName("OlapInfo", "", MDD_URI); SOAPElement olapInfoElement = null; Iterator olapInfoElements = rootElement.getChildElements(olapInfoName); if (olapInfoElements.hasNext()) { Object eObj = olapInfoElements.next(); if (eObj == null) { log.error("OlapInfo Element is null."); throw new JRRuntimeException("OlapInfo Element is null."); } olapInfoElement = (SOAPElement) eObj; } else { log.error("Could not retrieve OlapInfo Element."); throw new JRRuntimeException("Could not retrieve OlapInfo Element."); } parseOLAPInfoElement(olapInfoElement); // Get the Axes Element Name axesName = soapEnvelope.createName("Axes", "", MDD_URI); SOAPElement axesElement = null; Iterator axesElements = rootElement.getChildElements(axesName); if (axesElements.hasNext()) { Object eObj = axesElements.next(); if (eObj == null) { log.error("Axes Element is null"); throw new JRRuntimeException("Axes Element is null"); } axesElement = (SOAPElement) eObj; } else { log.error("Could not retrieve Axes Element."); throw new JRRuntimeException("Could not retrieve Axes Element."); } parseAxesElement(axesElement); // Get the CellData Element Name cellDataName = soapEnvelope.createName("CellData", "", MDD_URI); SOAPElement cellDataElement = null; Iterator cellDataElements = rootElement.getChildElements(cellDataName); if (cellDataElements.hasNext()) { Object eObj = cellDataElements.next(); if (eObj == null) { log.error("CellData element is null"); throw new JRRuntimeException("CellData element is null"); } cellDataElement = (SOAPElement) eObj; } else { log.error("Could not retrieve CellData Element."); throw new JRRuntimeException("Could not retrieve CellData Element."); } parseCellDataElement(cellDataElement); }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
private void _fixFaultElements(SOAPEnvelope env) { try {/*from w w w . j a v a2s. com*/ // If we have a SOAP 1.2 envelope, then there's nothing to do. if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) { return; } SOAPBody body = env.getBody(); if (body != null && !body.hasFault()) { if (log.isDebugEnabled()) { log.debug("No fault found. No conversion necessary."); } return; } else if (body != null && body.hasFault()) { if (log.isDebugEnabled()) { log.debug("A fault was found. Converting the fault child elements to SOAP 1.1 format"); } SOAPFault fault = body.getFault(); Iterator itr = fault.getChildElements(); while (itr.hasNext()) { SOAPElement se = (SOAPElement) itr.next(); if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: faultcode"); } // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to // get that and add it as a text node under the original element. Node value = se.getFirstChild(); if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) { org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value; ElementImpl e = valueElement.getElement(); String content = e.getText(); SOAPElement child = fault.addChildElement( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME)); child.addTextNode(content); se.detachNode(); } } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: detail"); } se.setElementQName( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)); } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) { if (log.isDebugEnabled()) { log.debug("Converting: faultstring"); } se.setElementQName( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME)); // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to // get that and add it as a text node under the original element. Node value = se.getFirstChild(); if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) { org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value; ElementImpl e = valueElement.getElement(); String content = e.getText(); SOAPElement child = fault.addChildElement( new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME)); child.addTextNode(content); se.detachNode(); } } } } } catch (SOAPException e) { if (log.isDebugEnabled()) { log.debug("An error occured while converting fault elements: " + e.getMessage()); } throw ExceptionFactory.makeWebServiceException(e); } }
From source file:org.apache.ws.scout.transport.SaajTransport.java
public Element send(Element request, URI endpointURL) throws TransportException { if (log.isDebugEnabled()) { String requestMessage = XMLUtils.convertNodeToXMLString(request); log.debug("Request message: %s\n%s" + endpointURL + ":" + requestMessage); }/*www. ja va 2 s . c om*/ Element response = null; try { SOAPMessage message = this.createSOAPMessage(request); //Make the SAAJ Call now SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = connection.call(message, endpointURL.toURL()); SOAPBody soapBody = soapResponse.getSOAPBody(); boolean hasFault = soapBody.hasFault(); if (hasFault) { SOAPFault soapFault = soapBody.getFault(); String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString(); throw new RegistryException(faultStr); } response = getFirstChildElement(soapBody); } catch (Exception ex) { log.error("Exception::" + ex.getMessage(), ex); throw new TransportException(ex); } if (log.isDebugEnabled()) { String responseMessage = XMLUtils.convertNodeToXMLString(response); log.debug("Response message: %s" + responseMessage); } return response; }
From source file:org.belio.service.gateway.SafcomGateway.java
private boolean sendMessage(QueueType queueType, Outbox outbox) { try {/*from ww w . ja v a 2s . c om*/ String now = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); MessageDigest md = MessageDigest.getInstance("MD5"); String serviceId = outbox.getServiceID(); String endpointDef = ""; // if (queueType.equals(QueueType.BULK)) { // endpointDef = networkproperties.getProperty("safcom_mt_endpoint"); // } else { endpointDef = networkproperties.getProperty("safcom_endpoint"); // } String code = outbox.getShortCode(); String spIdString = outbox.getSdpId(); String spPasswordString = createSpPass(spIdString, now, md); String recepient = "tel:" + outbox.getMsisdn(); String actualmessage = URLDecoder.decode(URLEncoder.encode(outbox.getText(), "UTF-8"), "UTF-8"); Launcher.LOG.info("T----------------------------------------J" + actualmessage); String gencorrelator = String.valueOf(outbox.getRefNo()); // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Send SOAP Message to SOAP Server SOAPMessage messageToSend = getSoapMessageFromString(getMessage(spIdString, spPasswordString, recepient, serviceId, now, actualmessage, code, gencorrelator, endpointDef)); Calendar start = Calendar.getInstance(); SOAPMessage soapResponse = soapConnection.call(messageToSend, networkproperties.getProperty("safcom_sms")); Launcher.LOG.info( recepient + " - took " + (Calendar.getInstance().getTimeInMillis() - start.getTimeInMillis())); // SOAPMessage soapResponse = null; System.out.println("XXXXXXXXXXXXXXXXXXX====Sending Safaricom message"); // printSOAPResponse(soapResponse);//TODO log SOAPBody body = soapResponse.getSOAPBody(); if (body.hasFault()) { SOAPFault newFault = body.getFault(); // QName fcode = newFault.getFaultCodeAsQName(); // String string = newFault.getFaultString(); // String actor = newFault.getFaultActor(); // System.out.println(">>>>>>>>>>>>>"+fcode); System.out.println(">>>>>>>>>>>>>" + newFault.getFaultString()); soapConnection.close(); return false; } else { //TO DO log soapConnection.close(); return true; } } catch (Exception ex) { Launcher.LOG.info(ex.getMessage()); } return false; }
From source file:org.jboss.jaxr.juddi.transport.SaajTransport.java
/** * @see Transport#send(org.w3c.dom.Element, java.net.URL) *//*w ww. j a va 2 s .c om*/ public Element send(Element request, URL endpointURL) throws RegistryException { String requestMessage = XMLUtils.toString(request); log.debug("Request message:" + requestMessage); Element response = null; try { SOAPMessage message = this.createSOAPMessage(request); //Make the SAAJ Call now SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnectionFactory.createConnection(); SOAPMessage soapResponse = connection.call(message, endpointURL); SOAPBody soapBody = soapResponse.getSOAPBody(); boolean hasFault = soapBody.hasFault(); if (hasFault) { SOAPFault soapFault = soapBody.getFault(); String faultStr = soapFault.getFaultCode() + "::" + soapFault.getFaultString(); throw new RegistryException(faultStr); } response = getFirstChildElement(soapBody); } catch (Exception ex) { log.error("Exception::", ex); throw new RegistryException(ex); } log.debug("Response message:" + XMLUtils.getText(response)); return response; }