cannot create core in solrj with embeddedsolrserver - solrj

this is my code:
File home = new File(System.getProperty("solr.solr.home"));
CoreContainer container = new CoreContainer(home.getAbsolutePath());
CoreAdminRequest.Create create = new CoreAdminRequest.Create();
create.setCoreName("newCoreName");
create.setCoreNodeName("newCoreName");
create.setAction(CoreAdminAction.CREATE);
create.setInstanceDir(home.getAbsolutePath());
create.process(new EmbeddedSolrServer(container, ""));
When I run this, I get "no such core: "" " exception.
If I change it to:
create.process(new EmbeddedSolrServer(container, "newCoreName"));
I get "no such core: "newCoreName" " exception.
Please help me...

We have found there are two things required to create a core:
1) There has to be a default core
2) The directory to be used for the new core should be created.
The solr.xml is as below:
<?xml version="1.0" encoding="UTF-8" ?>
<solr persistent="false">
<cores defaultCoreName="empty" adminPath="/admin/cores">
<core instanceDir="empty/" name="empty"/>
</cores>
</solr>
To create a new core do the following:
File home = new File(scfg.getIndexHome());
File solr = new File(home, "solr.xml");
String corename = "newcore";
CoreContainer container = new CoreContainer(home, solr);
//create the directory
File f = new File(home, corename); f.mkdirs();
SolrServer server = new EmbeddedSolrServer(container, "empty"); //default
//create the core
CoreAdminRequest.createCore(corename, corename, server, "solrconfig.xml", "schema.xml");
//persist it in the solr.xml
CoreAdminRequest.persist("solr.xml", server);
SolrServer servernew = new EmbeddedSolrServer(container, corename);

Related

How to sync my customer data to quickbooks through web connector?

I have Quickbooks Desktop Enterprise 18.0. I already created connection using qwc file through web connector.when I click Update selected option from web connector the result says okay. But If I include customer data in web service and click Update selected it shows error in status bar i.e Description:
Error message received from application via getLastError(): Error!.
I pasted code below Please review it and Guide if there anything wrong. Thank you.
public ArrayList buildRequest() {
string strRequestXML ="";
XmlDocument inputXMLDoc = null;
// CustomerQuery
inputXMLDoc = new XmlDocument();
inputXMLDoc.AppendChild(inputXMLDoc.CreateXmlDeclaration("1.0",null, null));
inputXMLDoc.AppendChild(inputXMLDoc.CreateProcessingInstruction("qbxml", "version=\"4.0\""));
XmlElement qbXML = inputXMLDoc.CreateElement("QBXML");
inputXMLDoc.AppendChild(qbXML);
XmlElement qbXMLMsgsRq = inputXMLDoc.CreateElement("QBXMLMsgsRq");
qbXML.AppendChild(qbXMLMsgsRq);
qbXMLMsgsRq.SetAttribute("onError", "stopOnError");
XmlElement CustomerAddRq = inputXMLDoc.CreateElement("CustomerAddRq");
qbXML.AppendChild(CustomerAddRq);
qbXMLMsgsRq.SetAttribute("requestID", "1");
XmlElement CustomerAdd = inputXMLDoc.CreateElement("CustomerAdd");
CustomerAddRq.AppendChild(CustomerAdd);
XmlElement Name = inputXMLDoc.CreateElement("Name");
CustomerAdd.AppendChild(Name);
CustomerAdd.AppendChild(Name).InnerText = "Naga";
XmlElement FirstName = inputXMLDoc.CreateElement("FirstName");
CustomerAdd.AppendChild(FirstName);
CustomerAdd.AppendChild(Name).InnerText = "Nagarajan";
XmlElement MiddleName = inputXMLDoc.CreateElement("MiddleName");
CustomerAdd.AppendChild(MiddleName);
XmlElement LastName = inputXMLDoc.CreateElement("LastName");
CustomerAdd.AppendChild(LastName);
CustomerAdd.AppendChild(Name).InnerText = "Varatharajan";
XmlElement BillAddress = inputXMLDoc.CreateElement("BillAddress");
CustomerAdd.AppendChild(BillAddress);
XmlElement Addr1 = inputXMLDoc.CreateElement("Addr1");
BillAddress.AppendChild(Addr1);
BillAddress.AppendChild(Addr1).InnerText = "33/33 st";
XmlElement City = inputXMLDoc.CreateElement("City");
BillAddress.AppendChild(City);
BillAddress.AppendChild(City).InnerText = "Chennai";
XmlElement State = inputXMLDoc.CreateElement("State");
BillAddress.AppendChild(State);
BillAddress.AppendChild(State).InnerText = "TN";
XmlElement Phone = inputXMLDoc.CreateElement("Phone");
CustomerAdd.AppendChild(Phone);
CustomerAdd.AppendChild(Phone).InnerText = "4545455";
//XmlElement customerQueryRq = inputXMLDoc.CreateElement("CustomerQueryRq");
//qbXMLMsgsRq.AppendChild(customerQueryRq);
//customerQueryRq.SetAttribute("requestID", "1");
// XmlElement maxReturned=inputXMLDoc.CreateElement("MaxReturned");
// customerQueryRq.AppendChild(maxReturned).InnerText="1";
strRequestXML = inputXMLDoc.OuterXml;
req.Add(strRequestXML);
}

How to create PPTX file using power-point-template using Apache POI

I want to create power-point presentation using power-point-template(which may be already exists or may be generated by poi.) for creating power point template file which have a background image in the slides, I write the following code which creates template file which opens in open-office but giving error to opening in Microsoft-power-point.
The Code is
private static void generatePOTX() throws IOException, FileNotFoundException {
String imgPathStr = System.getProperty("user.dir") + "/src/resources/images/TestSameChnl_001_t.jpeg";
File imgFile = new File(imgPathStr);
File potxFile = new File(System.getProperty("user.dir") + "/src/resources/Examples/layout.potx");
FileOutputStream out = new FileOutputStream(potxFile);
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
slide.setFollowMasterBackground(false);
HSLFFill fill = slide.getBackground().getFill();
HSLFPictureData pd = ppt.addPicture(imgFile, PictureData.PictureType.JPEG);
fill.setFillType(HSLFFill.FILL_PICTURE);
fill.setPictureData(pd);
ppt.write(out);
out.close();
}
After that I tried to create a PPT file using the generated POTX file but
But it's giving error. I am trying bellow code for this.
And the code is
private static void GeneratePPTXUsingPOTX() throws FileNotFoundException, IOException {
File imgFile = new File(System.getProperty("user.dir")+"/src/resources/images/TestSameChnl_001_t.jpeg");
File potx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/layout.potx" );
File pptx_File = new File(System.getProperty("user.dir") + "/src/resources/Examples/PPTWithTemplate.pptx" );
File movieFile = new File(System.getProperty("user.dir") + "/src/resources/movie/Dummy.mp4");
FileInputStream ins = new FileInputStream(potx_File);
FileOutputStream out = new FileOutputStream(pptx_File);
HSLFSlideShow ppt = new HSLFSlideShow(ins);
List<HSLFSlide> slideList = ppt.getSlides();
int movieIdx = ppt.addMovie(movieFile.getAbsolutePath(), MovieShape.MOVIE_MPEG);
HSLFPictureData pictureData = ppt.addPicture(imgFile, PictureData.PictureType.JPEG);
MovieShape shape = new MovieShape(movieIdx, pictureData);
shape.setAnchor(new java.awt.Rectangle(300,225,420,280));
slideList.get(0).addShape(shape);
shape.setAutoPlay(true);
ppt.write(out);
out.close();
}
And the exception which is coming is as fallows:
java.lang.NullPointerException
at org.apache.poi.hslf.usermodel.HSLFPictureShape.afterInsert(HSLFPictureShape.java:185)
at org.apache.poi.hslf.usermodel.HSLFSheet.addShape(HSLFSheet.java:189)

SOAP Fault: Security requirements are not satisfied because the security header is not present in the incoming message

I am trying to integrate salesforce with exacttarget using the SOAP wsdl provided by Exacttarget.
I am able to generate apex classes , but on calling the create request , I get the error System.CalloutException: Web service callout failed.
Since I am new to apex , I am not sure if SOAP header request can be done only through http ? or can I do it through my class.
Please find below the code I am using.
exacttargetComWsdlPartnerapi.Soap soapReq = new exacttargetComWsdlPartnerapi.Soap();
exacttargetComWsdlPartnerapi.UsernameAuthentication authentication = new exacttargetComWsdlPartnerapi.UsernameAuthentication();
authentication.UserName = '******';
authentication.PassWord = '*****';
soapReq.inputHttpHeaders_x = new Map<String, String>();
soapReq.outputHttpHeaders_x = new Map<String, String>();
//String myData = 'smruti.bhargava#accenture.com.etdev:smruti#123';
//authentication = EncodingUtil.base64Encode(Blob.valueOf(myData));
soapReq.inputHttpHeaders_x.put('Authorization','Basic ' + authentication );SALESFORCE STUB
exacttargetComWsdlPartnerapi.CreateOptions optList = new exacttargetComWsdlPartnerapi.CreateOptions();
exacttargetComWsdlPartnerapi.ContainerID contnr = new exacttargetComWsdlPartnerapi.ContainerID();
exacttargetComWsdlPartnerapi.APIObject apiObj = new exacttargetComWsdlPartnerapi.APIObject();
exacttargetComWsdlPartnerapi.APIProperty apiProp = new exacttargetComWsdlPartnerapi.APIProperty();
List<exacttargetComWsdlPartnerapi.APIProperty> propList = new List<exacttargetComWsdlPartnerapi.APIProperty>();
apiProp.Name='EmailAddress';
apiprop.Value='ash123#gmail.com';
propList.add(apiProp);
apiObj.PartnerProperties=propList;
contnr.APIObject = apiObj;
optList.Container = contnr;
List<exacttargetComWsdlPartnerapi.APIObject> objList = new List<exacttargetComWsdlPartnerapi.APIObject>();
objList.add(apiObj);
exacttargetComWsdlPartnerapi.CreateResponse_element response = soapReq.Create(optList,objList);
System.debug('** Result ==>' + response);

GATE Embedded runtime

I want to use "GATE" through web. Then I decide to create a SOAP web service in java with help of GATE Embedded.
But for the same document and saved Pipeline, I have a different run-time duration, when GATE Embedded runs as a java web service.
The same code has a constant run-time when it runs as a Java Application project.
In the web service, the run-time will be increasing after each execution until I get a Timeout error.
Does any one have this kind of experience?
This is my Code:
#WebService(serviceName = "GateWS")
public class GateWS {
#WebMethod(operationName = "gateengineapi")
public String gateengineapi(#WebParam(name = "PipelineNumber") String PipelineNumber, #WebParam(name = "Documents") String Docs) throws Exception {
try {
System.setProperty("gate.home", "C:\\GATE\\");
System.setProperty("shell.path", "C:\\cygwin2\\bin\\sh.exe");
Gate.init();
File GateHome = Gate.getGateHome();
File FrenchGapp = new File(GateHome, PipelineNumber);
CorpusController FrenchController;
FrenchController = (CorpusController) PersistenceManager.loadObjectFromFile(FrenchGapp);
Corpus corpus = Factory.newCorpus("BatchProcessApp Corpus");
FrenchController.setCorpus(corpus);
File docFile = new File(GateHome, Docs);
Document doc = Factory.newDocument(docFile.toURL(), "utf-8");
corpus.add(doc);
FrenchController.execute();
String docXMLString = null;
docXMLString = doc.toXml();
String outputFileName = doc.getName() + ".out.xml";
File outputFile = new File(docFile.getParentFile(), outputFileName);
FileOutputStream fos = new FileOutputStream(outputFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
OutputStreamWriter out;
out = new OutputStreamWriter(bos, "utf-8");
out.write(docXMLString);
out.close();
gate.Factory.deleteResource(doc);
return outputFileName;
} catch (Exception ex) {
return "ERROR: -> " + ex.getMessage();
}
}
}
I really appreciate any help you can provide.
The problem is that you're loading a new instance of the pipeline for every request, but then not freeing it again at the end of the request. GATE maintains a list internally of every PR/LR/controller that is loaded, so anything you load with Factory.createResource or PersistenceManager.loadObjectFrom... must be freed using Factory.deleteResource once it is no longer needed, typically using a try-finally:
FrenchController = (CorpusController) PersistenceManager.loadObjectFromFile(FrenchGapp);
try {
// ...
} finally {
Factory.deleteResource(FrenchController);
}
But...
Rather than loading a new instance of the pipeline every time, I would strongly recommend you explore a more efficient approach to load a smaller number of instances of the pipeline but keep them in memory to serve multiple requests. There is a fully worked-through example of this technique in the training materials on the GATE wiki, in particular module number 8 (track 2 Thursday).

SharePoint web services: test if file exists

I'm using SharePoint web services in C#. I have my code working to check files and check them out using the Lists web service. I need to test to see if a file exists; I can find lots of examples for doing this using the object model API, but I can't seem to find a straightforward way of doing this using web services.
Try the Lists.GetListItems with a suitable CAML query.
A CAML query like
<Query><Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">Filename.rtf</Value></Eq></Where></Query>
should work; the field 'FileLeafRef' is where the filename is stored.
This code may do, it's a little rough, but demonstrates how to get a list of files based on the title.
public static bool PageExists(string listName, string webPath, string pageTitle)
{
string pageId = "";
IntranetLists.Lists lists = new IntranetLists.Lists();
lists.UseDefaultCredentials = true;
lists.Url = webPath + "/_vti_bin/lists.asmx";
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + pageTitle + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
XmlNode listQuery = doc.SelectSingleNode("//Query");
XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
Guid g = GetWebID(webPath);
XmlNode items = lists.GetListItems(listName, string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, g.ToString());
}
return items.Count > 0;
}
public static XmlNodeList XpathQuery(XmlNode xmlToQuery, string xPathQuery)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlToQuery.OuterXml);
XmlNamespaceManager mg = new XmlNamespaceManager(doc.NameTable);
mg.AddNamespace("sp", "http://schemas.microsoft.com/sharepoint/soap/");
mg.AddNamespace("z", "#RowsetSchema");
mg.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
mg.AddNamespace("y", "http://schemas.microsoft.com/sharepoint/soap/ois");
mg.AddNamespace("w", "http://schemas.microsoft.com/WebPart/v2");
mg.AddNamespace("d", "http://schemas.microsoft.com/sharepoint/soap/directory");
return doc.SelectNodes(xPathQuery, mg);
}
I also had similiar problems with this.
I have tried the following FieldRefs without success: "Name", "FileLeafRef" and "LinkFilenameNoMenu".
The post located at http://www.johanolivier.blogspot.com details what I had to do to get it working.