Unable to add a row to Solr - solr

Im trying to add a row to the Solr Index but it does not get added.
I get a response but not sure what to infer from the response.
What information the response provides here? How do I get the exception?
>>> c = SolrConnection('http://localhost:8983/solr')
>>> c
<SolrConnection (url=http://localhost:8983/solr, persistent=True, post_headers={'Content-Type': 'text/xml; charset=utf-8'}, reconnects=0)>
>>> l = [{'document_type': 'demo', 'id': 'demo11234', 'deco_name': 'test'}]
>>> c.add_many(l)
'<?xml version="1.0" encoding="UTF-8"?>\n<response>\n<lst name="responseHeader"><int name="status">0</int><int name="QTime">1</int></lst>\n</response>\n'
>>> try:
... c.add_many(l)
... except:
... print "error"
...
'<?xml version="1.0" encoding="UTF-8"?>\n<response>\n<lst name="responseHeader"><int name="status">0</int><int name="QTime">2</int></lst>\n</response>\n'

Related

How can I use loops in Karate to Create xml Request Body? [duplicate]

For a test project, I am making a call to database, and getting necessary fields which I am going to set in my xml file to make a SOAP service call.
As far as I see, the database call returns as JSON value, so that I am having some trouble to assign values to "some" parts of my xml.
Let's say I have a .xml file which is like below:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xxxxxx>
<soapenv:Header/>
<soapenv:Body>
<int:createSubscriber soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<custBean xxxxx>
<accountNumber xsi:type="xsd:string">#(accountNo)</accountNumber>
<custName xsi:type="xsd:string" xs:type="type:string">Xbox</custName>
</custBean>
<addSubscriberBean xxxxx>7
<subscriberID xsi:type="xsd:string">#(subsID)</subscriberID>
<password xsi:type="xsd:string" xs:type="type:string">0</password>
<areaID xsi:type="xsd:string" xs:type="type:string">1</areaID>
<lineOfCredit xsi:type="xsd:int" xs:type="type:int"></lineOfCredit>
<creditCycle xsi:type="xsd:int" xs:type="type:int"></creditCycle>
<points xsi:type="xsd:int" xs:type="type:int"></points>
<bandwidth xsi:type="xsd:int" xs:type="type:int"></bandwidth>
<physicalPorts xsi:type="xsd:string" xs:type="type:string">8080</physicalPorts>
<mobilePhoneNo xsi:type="xsd:string" xs:type="type:string">#(mobile)</mobilePhoneNo>
<stbCount xsi:type="xsd:int" xs:type="type:int">5</stbCount>
<oTTCount xsi:type="xsd:int" xs:type="type:int">10</oTTCount>
<subscriptionType xsi:type="xsd:string" xs:type="type:string">#(subsType)</subscriptionType>
</addSubscriberBean>
<sequenceID xxxxx>1234567840123422700</sequenceID>
</int:createSubscriber>
And then I am making a call to database, so that I am getting below response:
[
{
"ACCOUNT_NO": "123",
"SUBSCRIBER_ID": "123456",
"MOBILE": "123456789",
"SUBSCRIBER_TYPE": "XXXX"
},
{
"ACCOUNT_NO": "456",
"SUBSCRIBER_ID": "456789",
"MOBILE": "456789123",
"SUBSCRIBER_TYPE": "YYYY"
}
]
So I have 2 object returned as you can see above, which means I need to assign those values to the variables dynamically.
Couldn't find a clue to lead me to a solution where I can transform my JSON type values to assign them to my XML based variables.
Loop over the JSON and build an XML.
* def xml = <users></users>
* def fun =
"""
function(u, i) {
var base = '/users/user[' + (i + 1) + ']/';
karate.set('xml', base + 'account', u.accountNo);
karate.set('xml', base + 'mobile', u.mobile);
karate.set('xml', base + 'type', u.subsType);
}
"""
* eval karate.forEach(users, fun)

SolrException: maxNumThreadStates must be >= 1 but was: 0

SolrException: maxNumThreadStates must be >= 1 but was: 0
I get following response while trying to create core. Can anyone help on how to deal with maxNumThreadStates?
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">500</int>
<int name="QTime">629</int>
</lst><lst name="error">
<str name="msg">maxNumThreadStates must be >= 1 but was: 0</str>
<str name="trace">org.apache.solr.common.SolrException: maxNumThreadStates must be >= 1 but was: 0
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: maxNumThreadStates must be >= 1 but was: 0
at org.apache.lucene.index.DocumentsWriterPerThreadPool.<init>(DocumentsWriterPerThreadPool.java:142)
at org.apache.lucene.index.DocumentsWriterPerThreadPool.clone(DocumentsWriterPerThreadPool.java:360)
at org.apache.solr.update.SolrIndexConfig.toIndexWriterConfig(SolrIndexConfig.java:261)
at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:80)
at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:66)
at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:550)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:806)
... 38 more
</str><int name="code">500</int></lst><str name="params">name=profile.user&action=CREATE</str>
</response>

How to encode in XML on SQL Server

I am generating XML as follows:
SET #xml = (
SELECT
PersonalMessage AS [Personal_Message]
FROM #TemporaryDB
FOR XML PATH ('Order'), ROOT ('Orders'), ELEMENTS
);
Next I add encoding info:
SELECT N'<?xml version="1.0" encoding="utf-8"?>' + Convert(nvarchar(max), #XML)
And when I save my XML with bcp I get something like this:
<?xml version="1.0" encoding="utf-8"?>
<Orders><Order>
<Personal_Message>Liebe X1 und X2,
"Wir wuenschten wir koennten heute mit euch zusammen sitzen. Das holen wir bald wieder nach."
Eure & Ina </Personal_Message></Order></Orders>
But I want something like this:
<?xml version="1.0" encoding="utf-8"?>
<Orders><Order>
<Personal_Message>Liebe X1 und X2,

 "Wir wuenschten wir koennten heute mit euch zusammen sitzen. Das holen wir bald wieder nach." 

Eure & Ina </Personal_Message></Order></Orders>
So I want to change C/R to 
 and for example " to ".
Please, advise me. How can I do this?
You might have to replace it
SET #xml = (
SELECT
Replace(Replace(Replace(PersonalMessage,char(13),'
'),char(10),''),'"','"') AS [Personal_Message]
FROM #TemporaryDB
FOR XML PATH ('Order'), ROOT ('Orders'), ELEMENTS
);

Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0] in solr

I am getting exception while adding batch to solrInstance. I have tested my code in different servers. It is working properly all other servers except one server.
my code is
SolrServer solrInstance = solrInstance1;
final Collection<SolrInputDocument> batch = new ArrayList<SolrInputDocument>();
for (Doctor doctor : doctorsList) {
SolrInputDocument doc = new SolrInputDocument();
String docID = doctor.getId();
doc.addField( "_id", docID, 1.0f );
batch.add(doc);
}
if (batch.size() > 0) {
UpdateResponse upres = solrInstance.add( batch );
upres = solrInstance.commit( true, true );
}
getting exception like`
` org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Unexpected EOF in prolog
at [row,col {unknown-source}]: [1,0]
Can any one please help me. Is there any server setting required to submit batch

How to authenticate user in ONVIF?

we have network IP camera that supports ONVIF protocol. When I tried to get its PTZ configuration it gives Auth error. I am implementing this in C. Following are the request and response.
Request:
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\""
"xmlns:tds=\"http://www.onvif.org/ver20/ptz/wsdl\">"
"<soap:Body>"
"<tds:GetNodes/>"
"</soap:Body>"
"</soap:Envelope>"
Response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa5="http://www.w3.org/2005/08/addressing"
xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:ptzimg2="http://www.onvif.org/ver10/schema"
xmlns:ptzimg3="http://www.w3.org/2005/05/xmlmime"
xmlns:ptzimg4="http://docs.oasis-open.org/wsn/b-2"
xmlns:ptzimg5="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:ptzimg6="http://docs.oasis-open.org/wsn/t-1"
xmlns:ptzimg1="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:ptzimg7="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:Code>
<SOAP-ENV:Value>
SOAP-ENV:Sender
</SOAP-ENV:Value>
<SOAP-ENV:Subcode>
<SOAP-ENV:Value>
ter:NotAuthorized
</SOAP-ENV:Value>
</SOAP-ENV:Subcode>
</SOAP-ENV:Code>
<SOAP-ENV:Reason>
<SOAP-ENV:Text xml:lang="en">
Sender Not Authorized
</SOAP-ENV:Text>
</SOAP-ENV:Reason>
<SOAP-ENV:Node>
http://www.w3.org/2003/05/soap-envelope/node/ultimateReceiver
</SOAP-ENV:Node>
<SOAP-ENV:Role>
http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver
</SOAP-ENV:Role>
<SOAP-ENV:Detail>
The action requested requires authorization and the sender is not authorized
</SOAP-ENV:Detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
How can I authenticate user? Thanks
those commands which required authentication. Their authentication headers can be added like this.
snprintf(postData, sizeof(postData),
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\""
"xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401"
"-wss-wssecurity-secext-1.0.xsd\""
"xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-"
"200401-wss-wssecurity-utility-1.0.xsd\""
"xmlns:tds=\"http://www.onvif.org/ver20/ptz/wsdl\">"
"<SOAP-ENV:Header><wsse:Security><wsse:UsernameToken>"
"<wsse:Username>%s</wsse:Username>"
"<wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-"
"200401-wss-username-token-profile-1.0#PasswordDigest\">"
"%s</wsse:Password><wsse:Nonce>%s</wsse:Nonce>"
"<wsu:Created>%s</wsu:Created></wsse:UsernameToken>"
"</wsse:Security></SOAP-ENV:Header><SOAP-ENV:Body>"
"<tds:GetNodes>"
"</SOAP-ENV:Body></SOAP-ENV:Envelope>",
username, base64EncDigest, nonce_char, time_char);
You can use gSoap with WSSE plugin to generate C++ client proxy from OnVif WDSL that you require.
Do that greatly simplified my work. Here is an example of calling GetVideoEncoderConfiguration and reading response.
_media__GetVideoEncoderConfigurations query;
_media__GetVideoEncoderConfigurationsResponse response;
soap_wsse_add_Security(&mediaProxy);
soap_wsse_add_UsernameTokenDigest(&mediaProxy, NULL, m_username.c_str(), m_password.c_str());
if(mediaProxy.GetVideoEncoderConfigurations(&query, &response) == SOAP_OK)
{
LogSuccess("GetVideoEncoderConfigurations");
for(auto it = response.Configurations.begin(); it != response.Configurations.end(); ++it)
{
onvif__VideoEncoderConfiguration* videoConf = *it;
log(I3) << "Name= " << videoConf->Name << ", Encoding=" << videoConf->Encoding << ", Resolution=" << videoConf->Resolution->Width << "x" << videoConf->Resolution->Height;
}
}
else
LogError("GetVideoEncoderConfigurations", soap_faultdetail(&mediaProxy));
So no manually creating soap messages. gSOAP generated code takes care of that in lower layer. Of course, it takes mi 2 days to generate working code with wsse support, but still it was probably 10 times faster the to do it manualy. If you are interested in further information you can contact me.

Resources