List of usage examples for javax.xml.soap SOAPException printStackTrace
public void printStackTrace()
From source file:au.edu.anu.portal.portlets.sakaiconnector.support.WebServiceSupport.java
/** * Make a web service call to the given endpoint, calling the method and using the params supplied * @param endpoint wsdl url// w ww . ja va 2 s .c o m * @param method method to call * @param params LinkedHashMap of params: * 1. Must be in order required to be sent * 2. Must be keyed on the parameter name to be sent, must match the webservice param exactly or it will fail * 3. Should contained a single Map of items, containing 'value' and 'type' keys * 4. The type attribute will be converted and supported values are string or boolean, case insensitive * * @return the response, or null if any exception is thrown. */ public static String call(String endpoint, String method, Map<String, Map<String, String>> params) { Service service = new Service(); try { Call nc = (Call) service.createCall(); nc.setTargetEndpointAddress(endpoint); nc.removeAllParameters(); nc.setOperationName(method); List<Object> values = new ArrayList<Object>(); for (Map.Entry<String, Map<String, String>> entry : params.entrySet()) { //add value values.add(entry.getValue().get("value")); //setup the type QName qname = null; try { qname = getNameForType(entry.getValue().get("type")); } catch (SOAPException e) { e.printStackTrace(); return null; } //add the parameter nc.addParameter(entry.getKey(), qname, ParameterMode.IN); } nc.setReturnType(XMLType.XSD_STRING); return (String) nc.invoke(values.toArray()); } catch (RemoteException e) { //e.printStackTrace(); log.error("A connection error occurred: " + e.getClass() + ": " + e.getMessage()); } catch (ServiceException e) { //e.printStackTrace(); log.error("A connection error occurred: " + e.getClass() + ": " + e.getMessage()); } return null; }
From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a va 2s . co m*/ public boolean handleMessage(SOAPMessageContext context) { try { Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); logger.debug("LicenseHandler:{}", out); if (!out) { SOAPMessage message = context.getMessage(); logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message)); SOAPEnvelope enve = message.getSOAPPart().getEnvelope(); SOAPHeader header = enve.getHeader(); SOAPBody body = enve.getBody(); Node bn = body.getChildNodes().item(0); String partname = bn.getLocalName(); if ("getUser".equals(partname)) { if (header == null) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements(); if (!iterator.hasNext()) { // ? SOAPFault fault = body.addFault(); fault.setFaultString("??!"); throw new SOAPFaultException(fault); } while (iterator.hasNext()) { SOAPHeaderElement ele = iterator.next(); System.out.println(ele.getTextContent()); } } } } catch (SOAPException e) { e.printStackTrace(); } return true; }
From source file:it.cnr.icar.eric.common.soap.SOAPSender.java
/** * * Creates a SOAPMessage with bodyDoc as only child. *///from w w w .ja v a 2 s. c om public SOAPMessage createSOAPMessage(Document bodyDoc) throws JAXRException { SOAPMessage msg = null; try { MessageFactory factory = MessageFactory.newInstance(); msg = factory.createMessage(); SOAPPart sp = msg.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); //SOAPHeader sh = se.getHeader(); SOAPBody sb = se.getBody(); sb.addDocument(bodyDoc); msg.saveChanges(); } catch (SOAPException e) { e.printStackTrace(); throw new JAXRException(resourceBundle.getString("message.URLNotFound"), e); } return msg; }
From source file:org.osgpfoundation.osgp.webdemoapp.application.config.ApplicationContext.java
/** * Spring SoapMessageFactory for creating Soap Messages * @return SaajSoapMessageFactory/*w ww . j a v a 2 s . c om*/ */ private SaajSoapMessageFactory messageFactory() { final SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(); try { messageFactory.setMessageFactory(MessageFactory.newInstance()); } catch (final SOAPException e) { e.printStackTrace(); } return messageFactory; }
From source file:SendSOAPMessage.java
/** * send a simple soap message with JAXM API. *///from w w w . j ava2 s. co m public void sendMessage(String url) { try { /** * Construct a default SOAP message factory. */ MessageFactory mf = MessageFactory.newInstance(); /** * Create a SOAP message object. */ SOAPMessage soapMessage = mf.createMessage(); /** * Get SOAP part. */ SOAPPart soapPart = soapMessage.getSOAPPart(); /** * Get SOAP envelope. */ SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); /** * Get SOAP body. */ SOAPBody soapBody = soapEnvelope.getBody(); /** * Add child element with the specified name. */ SOAPElement element = soapBody.addChildElement("HelloWorld"); /** * Add text message */ element.addTextNode("Welcome to SunOne Web Services!"); soapMessage.saveChanges(); /** * Construct a default SOAP connection factory. */ SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance(); /** * Get SOAP connection. */ SOAPConnection soapConnection = connectionFactory.createConnection(); /** * Construct endpoint object. */ URLEndpoint endpoint = new URLEndpoint(url); /** * Send SOAP message. */ SOAPMessage resp = soapConnection.call(soapMessage, endpoint); /** * Print response to the std output. */ resp.writeTo(System.out); /** * close the connection */ soapConnection.close(); } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (SOAPException soape) { soape.printStackTrace(); } }
From source file:eu.europeana.uim.sugarcrmclient.plugin.SugarCRMServiceImpl.java
/** * Constructor//from w w w . j av a 2 s . c om */ public SugarCRMServiceImpl() { this.pollingListeners = new LinkedHashMap<String, PollingListener>(); BlockingInitializer initializer = new BlockingInitializer() { @Override public void initializeInternal() { MessageFactory mf = null; try { mf = MessageFactory.newInstance(); } catch (SOAPException e1) { e1.printStackTrace(); } ExtendedSaajSoapMessageFactory mfactory = new ExtendedSaajSoapMessageFactory(mf); WebServiceTemplate webServiceTemplate = new WebServiceTemplate(mfactory); JibxMarshaller marshaller = new JibxMarshaller(); marshaller.setStandalone(true); marshaller.setTargetClass(eu.europeana.uim.sugarcrmclient.jibxbindings.Login.class); marshaller.setTargetClass(eu.europeana.uim.sugarcrmclient.jibxbindings.GetEntries.class); marshaller.setEncoding("UTF-8"); marshaller.setTargetPackage("eu.europeana.uim.sugarcrmclient.jibxbindings"); try { marshaller.afterPropertiesSet(); } catch (JiBXException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println( marshaller.supports(eu.europeana.uim.sugarcrmclient.jibxbindings.GetEntries.class)); System.out.println(marshaller.supports(eu.europeana.uim.sugarcrmclient.jibxbindings.Login.class)); webServiceTemplate.setMarshaller(marshaller); webServiceTemplate.setUnmarshaller(marshaller); sugarwsClient = new SugarWsClientImpl(); String userName = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_USERNAME); String password = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_PASSWORD); String uri = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_HOST); webServiceTemplate.setDefaultUri(uri); sugarwsClient.setUsername(userName); sugarwsClient.setPassword(password); sugarwsClient.setWebServiceTemplate(webServiceTemplate); try { sugarwsClient.setSessionID( sugarwsClient.login(ClientUtils.createStandardLoginObject(userName, password))); } catch (JIXBLoginFailureException e) { sugarwsClient.setSessionID("-1"); e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); } }; initializer.initialize(SugarWsClientImpl.class.getClassLoader()); }
From source file:nl.nn.adapterframework.extensions.cxf.SOAPProviderBase.java
@Override public SOAPMessage invoke(SOAPMessage request) { String result;/*w ww .jav a 2 s .c o m*/ PipeLineSessionBase pipelineSession = new PipeLineSessionBase(); String correlationId = Misc.createSimpleUUID(); log.debug(getLogPrefix(correlationId) + "received message"); if (request == null) { String faultcode = "soap:Server"; String faultstring = "SOAPMessage is null"; String httpRequestMethod = (String) webServiceContext.getMessageContext() .get(MessageContext.HTTP_REQUEST_METHOD); if (!"POST".equals(httpRequestMethod)) { faultcode = "soap:Client"; faultstring = "Request was send using '" + httpRequestMethod + "' instead of 'POST'"; } result = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body><soap:Fault>" + "<faultcode>" + faultcode + "</faultcode>" + "<faultstring>" + faultstring + "</faultstring>" + "</soap:Fault></soap:Body></soap:Envelope>"; } else { // Make mime headers in request available as session key @SuppressWarnings("unchecked") Iterator<MimeHeader> mimeHeaders = request.getMimeHeaders().getAllHeaders(); String mimeHeadersXml = getMimeHeadersXml(mimeHeaders).toXML(); pipelineSession.put("mimeHeaders", mimeHeadersXml); // Make attachments in request (when present) available as session keys int i = 1; XmlBuilder attachments = new XmlBuilder("attachments"); @SuppressWarnings("unchecked") Iterator<AttachmentPart> attachmentParts = request.getAttachments(); while (attachmentParts.hasNext()) { try { InputStreamAttachmentPart attachmentPart = new InputStreamAttachmentPart( attachmentParts.next()); XmlBuilder attachment = new XmlBuilder("attachment"); attachments.addSubElement(attachment); XmlBuilder sessionKey = new XmlBuilder("sessionKey"); sessionKey.setValue("attachment" + i); attachment.addSubElement(sessionKey); pipelineSession.put("attachment" + i, attachmentPart.getInputStream()); log.debug(getLogPrefix(correlationId) + "adding attachment [attachment" + i + "] to session"); @SuppressWarnings("unchecked") Iterator<MimeHeader> attachmentMimeHeaders = attachmentPart.getAllMimeHeaders(); attachment.addSubElement(getMimeHeadersXml(attachmentMimeHeaders)); } catch (SOAPException e) { e.printStackTrace(); log.warn("Could not store attachment in session key", e); } i++; } pipelineSession.put("attachments", attachments.toXML()); // Transform SOAP message to string String message; try { message = XmlUtils.nodeToString(request.getSOAPPart()); log.debug(getLogPrefix(correlationId) + "transforming from SOAP message"); } catch (TransformerException e) { String m = "Could not transform SOAP message to string"; log.error(m, e); throw new WebServiceException(m, e); } // Process message via WebServiceListener ISecurityHandler securityHandler = new WebServiceContextSecurityHandler(webServiceContext); pipelineSession.setSecurityHandler(securityHandler); pipelineSession.put(IPipeLineSession.HTTP_REQUEST_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_REQUEST)); pipelineSession.put(IPipeLineSession.HTTP_RESPONSE_KEY, webServiceContext.getMessageContext().get(MessageContext.SERVLET_RESPONSE)); try { log.debug(getLogPrefix(correlationId) + "processing message"); result = processRequest(correlationId, message, pipelineSession); } catch (ListenerException e) { String m = "Could not process SOAP message: " + e.getMessage(); log.error(m); throw new WebServiceException(m, e); } } // Transform result string to SOAP message SOAPMessage soapMessage = null; try { log.debug(getLogPrefix(correlationId) + "transforming to SOAP message"); soapMessage = getMessageFactory().createMessage(); StreamSource streamSource = new StreamSource(new StringReader(result)); soapMessage.getSOAPPart().setContent(streamSource); } catch (SOAPException e) { String m = "Could not transform string to SOAP message"; log.error(m); throw new WebServiceException(m, e); } String multipartXml = (String) pipelineSession.get(attachmentXmlSessionKey); log.debug(getLogPrefix(correlationId) + "building multipart message with MultipartXmlSessionKey [" + multipartXml + "]"); if (StringUtils.isNotEmpty(multipartXml)) { Element partsElement; try { partsElement = XmlUtils.buildElement(multipartXml); } catch (DomBuilderException e) { String m = "error building multipart xml"; log.error(m, e); throw new WebServiceException(m, e); } Collection<Node> parts = XmlUtils.getChildTags(partsElement, "part"); if (parts == null || parts.size() == 0) { log.warn(getLogPrefix(correlationId) + "no part(s) in multipart xml [" + multipartXml + "]"); } else { Iterator<Node> iter = parts.iterator(); while (iter.hasNext()) { Element partElement = (Element) iter.next(); //String partType = partElement.getAttribute("type"); String partName = partElement.getAttribute("name"); String partSessionKey = partElement.getAttribute("sessionKey"); String partMimeType = partElement.getAttribute("mimeType"); Object partObject = pipelineSession.get(partSessionKey); if (partObject instanceof InputStream) { InputStream fis = (InputStream) partObject; DataHandler dataHander = null; try { dataHander = new DataHandler(new ByteArrayDataSource(fis, partMimeType)); } catch (IOException e) { String m = "Unable to add session key '" + partSessionKey + "' as attachment"; log.error(m, e); throw new WebServiceException(m, e); } AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander); attachmentPart.setContentId(partName); soapMessage.addAttachmentPart(attachmentPart); log.debug(getLogPrefix(correlationId) + "appended filepart [" + partSessionKey + "] with value [" + partObject + "] and name [" + partName + "]"); } else { //String String partValue = (String) partObject; DataHandler dataHander = new DataHandler(new ByteArrayDataSource(partValue, partMimeType)); AttachmentPart attachmentPart = soapMessage.createAttachmentPart(dataHander); attachmentPart.setContentId(partName); soapMessage.addAttachmentPart(attachmentPart); log.debug(getLogPrefix(correlationId) + "appended stringpart [" + partSessionKey + "] with value [" + partValue + "]"); } } } } return soapMessage; }
From source file:org.jboss.jaxr.juddi.transport.WS4EESaajTransport.java
private SOAPElement getSOAPElement(SOAPBody soapBody, Element elem) { String xmlns = IRegistry.UDDI_V2_NAMESPACE; SOAPElement soapElement = null; SOAPFactory factory = null;/*from w w w. j a v a2 s.c om*/ try { factory = SOAPFactory.newInstance(); //Go through the element String name = elem.getNodeName(); String nsuri = elem.getNamespaceURI(); if (nsuri == null) nsuri = xmlns; soapElement = factory.createElement(name, "ns1", nsuri); //Get Attributes if (elem.hasAttributes()) { NamedNodeMap nnm = elem.getAttributes(); int len = nnm != null ? nnm.getLength() : 0; for (int i = 0; i < len; i++) { Node n = nnm.item(i); String nodename = n.getNodeName(); String nodevalue = n.getNodeValue(); soapElement.addAttribute(factory.createName(nodename), nodevalue); } } else { soapElement.addAttribute(factory.createName("xmlns:ns1"), nsuri); } NodeList nlist = elem.getChildNodes(); int len = nlist != null ? nlist.getLength() : 0; for (int i = 0; i < len; i++) { Node node = nlist.item(i); short nodeType = node != null ? node.getNodeType() : -100; if (Node.ELEMENT_NODE == nodeType) { soapElement.addChildElement(getSOAPElement(soapBody, (Element) node)); } else if (nodeType == Node.TEXT_NODE) { soapElement.addTextNode(node.getNodeValue()); } } } catch (SOAPException e) { e.printStackTrace(); } return soapElement; }
From source file:test.functional.TestJAXMSamples.java
public void testDelayedStockQuote() throws Exception { try {/*from w w w . j a v a 2 s . c o m*/ log.info("Testing JAXM DelayedStockQuote sample."); DelayedStockQuote stockQuote = new DelayedStockQuote(); System.out.print("The last price for SUNW is " + stockQuote.getStockQuote("SUNW")); log.info("Test complete."); } catch (javax.xml.soap.SOAPException e) { Throwable t = e.getCause(); if (t != null) { t.printStackTrace(); if (t instanceof AxisFault) { AxisFault af = (AxisFault) t; if ((af.detail instanceof SocketException) || (af.getFaultCode().getLocalPart().equals("HTTP"))) { System.out.println("Connect failure caused JAXM DelayedStockQuote to be skipped."); return; } } throw new Exception("Fault returned from test: " + t); } else { e.printStackTrace(); throw new Exception("Exception returned from test: " + e); } } catch (Throwable t) { t.printStackTrace(); throw new Exception("Fault returned from test: " + t); } }