List of usage examples for javax.xml.soap SOAPBody hasFault
public boolean hasFault();
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation/* www .j a v a 2s. c om*/ * <I>getCollectionInfo(User,Owner,Collection) : Collection</I> * * @throws javax.xml.soap.SOAPException when a SOAPException error occurs */ protected void getCollectionInfo() throws SOAPException { User u = new User(""); if (sUserVisitor != null) { u.setUserId(sUserVisitor); } else { u = new User(getUserId()); } try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "getCollectionInfo"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, new Collection(collection)); smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.structure")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "get"); } else { Collection cResponse = getCollection(smResponse); description = cResponse.getDescription(); tags = Tags.decode(cResponse.getTags()); java.text.DateFormat df = new java.text.SimpleDateFormat("dd/MM/yyyy"); created = df.format(cResponse.getCreated()); } } catch (SOAPException se) { throw se; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation//from ww w . j av a2 s . c om * <I>importRecords(User,Owner,Collection,FILE) : void</I> * * @param fiImport the FileItem Zip of the Records to import * @throws java.lang.Exception when an Exception error occurs */ protected void importRecords(FileItem fiImport) throws Exception { User uRequest = new User(getUserId()); Collection cRequest = new Collection(collection); File fTemp = null; try { smRequest = mf.createMessage(); SOAPBody sbRequest = smRequest.getSOAPBody(); Name n = sf.createName("importRecords"); SOAPBodyElement sbeRequest = sbRequest.addBodyElement(n); sbeRequest.addChildElement(uRequest.toXml()); if (owner != null) { Owner oRequest = new Owner(owner); sbeRequest.addChildElement(oRequest.toXml()); } sbeRequest.addChildElement(cRequest.toXml()); String sNomFitxer = Utils.getFileName(fiImport.getName()); fTemp = File.createTempFile("attach", null); fiImport.write(fTemp); URL urlFile = new URL("file://" + fTemp.getPath()); AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile)); smRequest.addAttachmentPart(ap); smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "importRecords"); } else { } } catch (Exception e) { throw e; } finally { if (fTemp != null) { fTemp.delete(); } } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation/*from ww w . j a va 2 s .c om*/ * <I>modifyRecord(User,Owner,Collection,Record) : void</I> * * @param r the Record to modify * @param vAttachments a Vector containing the Attachments of the Record * @throws java.lang.Exception when an Exception error occurs */ protected void modifyRecord(Record r, Vector vAttachments) throws Exception { User u = new User(getUserId()); Collection c = new Collection(""); c.setName(collection); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "modifyRecord"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, c); addParam(sbeRequest, r); for (int i = 0; i < vAttachments.size(); i++) { FileItem fi = (FileItem) vAttachments.get(i); String sNomFitxer = Utils.getFileName(fi.getName()); File fTemp = File.createTempFile("attach", null); fi.write(fTemp); URL urlFile = new URL("file://" + fTemp.getPath()); AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile)); String fieldName = fi.getFieldName(); ap.setContentId(fieldName + "/" + sNomFitxer); smRequest.addAttachmentPart(ap); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "modify"); } else { } } catch (SOAPException se) { throw se; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation/*from w w w. java 2s .c om*/ * <I>addRecord(User,Owner,Collection,Record) : void</I> * * @param r the Record to add * @param vAttachments a Vector containing the Attachments of the Record * @throws java.lang.Exception when an Exception error occurs */ protected void addRecord(Record r, Vector vAttachments) throws Exception { User u = new User(getUserId()); Collection c = new Collection(""); Vector vTempFiles = new Vector(); c.setName(collection); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "addRecord"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, c); addParam(sbeRequest, r); for (int i = 0; i < vAttachments.size(); i++) { FileItem fi = (FileItem) vAttachments.get(i); String sNomFitxer = Utils.getFileName(fi.getName()); File fTemp = File.createTempFile("attach", null); fi.write(fTemp); vTempFiles.add(fTemp); URL urlFile = new URL("file://" + fTemp.getPath()); AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile)); String fieldName = fi.getFieldName(); ap.setContentId(fieldName + "/" + sNomFitxer); smRequest.addAttachmentPart(ap); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "add"); } else { } } catch (Exception e) { throw e; } finally { File fAux; for (int i = 0; i < vTempFiles.size(); i++) { fAux = (File) vTempFiles.get(i); fAux.delete(); } } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation <I>searchAll(User,Owner,Collection,Query) * : NumRecord,NumFound,[Record]</I> * * @throws javax.xml.soap.SOAPException when a SOAPException error occurs *//* w ww . j a v a2 s . com*/ protected void searchCollection() throws SOAPException { User u = new User(""); if (sUserVisitor != null) { u.setUserId(sUserVisitor); } else { u = new User(getUserId()); } Collection c = new Collection(""); c.setName(collection); getStructure(); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "searchAll"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, c); if (operation.equals("showAll")) { Query qAux = new Query(); qAux.setBeginIndex(0); qAux.setDirection("asc"); qAux.setOrderField("null"); addParam(sbeRequest, qAux); } else { int iBeginIndexAux = q.getBeginIndex(); q.setBeginIndex(0); //we ask for all the records but we keep the begin index addParam(sbeRequest, q); q.setBeginIndex(iBeginIndexAux); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "search"); String searchFault = getFault("search"); if (searchFault.equals("EMPTY_COLLECTION")) { numRecords = 0; numFound = 0; } else if (searchFault.equals("NO_RECORD_FOUND")) { numFound = 0; String sNumRecords = pmRequest.getParameter("numRecords"); if (sNumRecords != null) { numRecords = Integer.parseInt(sNumRecords); } } } else { vRecords = getRecords(smResponse); if (q.getBeginIndex() >= vRecords.size()) { q.setBeginIndex(vRecords.size() - 1); } record = (Record) vRecords.get(q.getBeginIndex()); numRecords = getIntValue(smResponse, "numRecords"); numFound = getIntValue(smResponse, "numFound"); } } catch (SOAPException se) { throw se; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation/*from w ww . j a v a 2 s .co m*/ * <I>exportCollection(User,Owner,Collection,Query) : FILE</I> * * @param response the HttpServletResponse where to return the File * @throws java.lang.Exception when an Exception error occurs */ protected void exportCollection(HttpServletResponse response) throws Exception { User u = new User(""); if (sUserVisitor != null) { u.setUserId(sUserVisitor); } else { u = new User(getUserId()); } try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "exportCollection"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, new Collection(collection)); if (operation.equals("exportAll")) { Query qAux = new Query(); qAux.setBeginIndex(0); qAux.setDirection("asc"); qAux.setOrderField("null"); addParam(sbeRequest, qAux); } else if (operation.equals("exportStructure")) { Query qAux = new Query(); qAux.setBeginIndex(0); qAux.setDirection("asc"); qAux.setOrderField("null"); Condition cAux = new Condition("null", ((FieldDef) vFieldDefs.get(0)).getName(), "=", "31051983"); /*We make a query that hopefully :) returns no records, just the structure*/ qAux.addCondition(cAux); addParam(sbeRequest, qAux); } else { addParam(sbeRequest, q); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.collection")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "export"); } else { Iterator iAttachments = smResponse.getAttachments(); //response.setContentType("application/x-zip-compressed"); response.setContentType("application/zip"); String nameOk = Utils.toValidFileName(collection); response.setHeader("Content-disposition", "filename=" + nameOk + ".zip"); if (iAttachments.hasNext()) { AttachmentPart ap = (AttachmentPart) iAttachments.next(); InputStream is = ap.getDataHandler().getInputStream(); OutputStream os = response.getOutputStream(); byte[] buff = new byte[1024]; int read = 0; while ((read = is.read(buff, 0, buff.length)) != -1) { os.write(buff, 0, read); } os.flush(); //os.close(); } } } catch (Exception e) { throw e; } }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
private void _fixFaultElements(SOAPEnvelope env) { try {//from w w w . jav a 2 s. c om // 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); }/*from w w w . j a v a 2s . c o m*/ 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 {/*w w w .j a v a2s .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; }