List of usage examples for javax.xml.soap SOAPMessage getSOAPBody
public SOAPBody getSOAPBody() throws SOAPException
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation/* ww w. j ava2 s. c o m*/ * <I>deleteRecord(User,Owner,Collection,Record) : void</I> * * @throws javax.xml.soap.SOAPException when a SOAPException error occurs */ protected void deleteRecord() throws SOAPException { User u = new User(getUserId()); Collection c = new Collection(""); Record r = new Record(); r.setId(Integer.parseInt(pmRequest.getParameter("idRecord"))); c.setName(collection); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "deleteRecord"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, c); addParam(sbeRequest, r); smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "delete"); } else { } } catch (SOAPException se) { throw se; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation <I>getStructure(User,Owner,Collection) : * [FieldDef]</I>/*from www. j a v a 2 s. co m*/ * * @throws javax.xml.soap.SOAPException when a SOAPException error occurs */ protected void getStructure() throws SOAPException { User u = new User(""); if (sUserVisitor != null) { u.setUserId(sUserVisitor); } else { u = new User(getUserId()); } vFieldDefs = new Vector(); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "getStructure"); 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, getJspProperties().getProperty("url.servlet.structure")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "get"); } else { vFieldDefs = getFieldDefs(smResponse); } } catch (SOAPException se) { throw se; } }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation <I>getPermission * (User,Owner,Collection,Record) : Guest</I> * * @throws javax.xml.soap.SOAPException when a SOAPException error occurs *//*ww w. j a v a2s. c o m*/ protected void getPermission() throws SOAPException { User u = new User(""); if (sUserVisitor != null) { u.setUserId(sUserVisitor); } else { u = new User(getUserId()); } Owner o = new Owner(owner); Collection c = new Collection(collection); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "getPermission"); addParam(sbeRequest, u); addParam(sbeRequest, o); addParam(sbeRequest, c); if (record != null) { Record r = new Record(); r.setId(record.getId()); addParam(sbeRequest, r); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.share")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "getPermission"); } else { permission = getIntValue(smResponse, "permission"); } } 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>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//w w w . j ava 2 s .c o m * <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 w ww.j ava 2 s . c o m*/ * <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 . j a v a 2 s .c o m * <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 *//*from w ww . j av a2s. 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 . jav a2 s . c om * <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; } }