I want my servlet to establish a connection with solr so as to perform query. using eclipse I have created a simple JSP file for the user to input their query, then it will call the doGet() method from the servlet. From the servlet i try to use solrj to connect with solr
my solrj code is as below.
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
SolrQuery query = new SolrQuery();
query.setQuery("sony digital camera");
query.addFilterQuery("cat:electronics","store:amazon.com");
query.setFields("id","price","merchant","cat","store");
query.setStart(0);
query.set("defType", "edismax");
QueryResponse response = solr.query(query);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
Its basically just simple code available online, there is no syntax error which means that the program detects the library files. However on run time the program returns classNotFoundException error.
This prompt me thinking whether i can implement solrj on servlet. Anyone can advise me where i can exactly use the solrj code? I think that the code is right but just that i implement solrj wrongly.
Thanks in advance!
The exception is saying that your runtime classpath is wrong.
Assuming you're running this class in a servlet container, most probably what you're missing is not a Java EE jar but instead has something to do with SolrJ.
Solrj has few dependencies: you can find them in the Solr distribution or if you have confidence with Apache Maven, you can use it for individuating those jars.
In any case, once you identified those libraries, you have to put them under WEB-INF/lib of your webapp
For a list of dependencies you can read here: http://mvnrepository.com/artifact/org.apache.solr/solr-solrj/4.10.3
Related
I try to get all available collections from a MongoDB using POCO C++ driver. But I haven't found anything on web and tried using the createCommand() with selector("$query").add("listCollections", 1) without any success. It seems POCO does not have an implementation for querying all collections inside a db or does anybody know how to do this?
MongoDB driver itself has a command like getCollectionNames() but I can not find this inside POCO.
I tried using this snippet:
Poco::MongoDB::Database db("db_name");
auto command = db.createCommand();
command->selector().addNewDocument("$query").add("listCollections", 1);
Poco::MongoDB::ResponseMessage resp;
DBCONN.sendRequest(*command, resp);
I get a document back with:
Content: {"ok":0,"errmsg":"no such cmd: listCollections","bad cmd":{"$query":{"listCollections":1}}}
I've implemented a simple SOAP webservice client to test the functionality but whether my client or in iex, and regardless of the target service I always get {:ok, :undefined, :undefined}
Here is my code:
wsdl_url = "http://www.webservicex.net/convertVolume.asmx?WSDL"
action = "ChangeVolumeUnit"
parameters = ["100", "dry", "centiliter"]
Detergentex.call(wsdl_url, action, parameters)
I'm using Versions:
Elixir: 1.2.0
Detergentex: 0.0.7
My mix.exs deps:
[{:erlsom, github: "willemdj/erlsom"},{:detergentex, "0.0.7"}]
Any suggestions on what I'm missing would be greatly appreciated.
1.) It's got a dependency on the detergent package.
Have you added the dependency for detergent? If not modify your mix.exs to this:
[{:erlsom, github: "willemdj/erlsom"},{:detergentex, "0.0.7"}, {:detergent, "~> 0.3.0"}]
2.) You also need to add detergentex to the list of applications as well:
def application do
[applications: [:logger, :detergentex]]
end
3.) The fact that it's returning {:ok, :undefined, :undefined} may simply indicate an issue with the endpoint or the message you're passing. Therefore I'd try it against an endpoint you're sure is good with a message you're sure will work. Perhaps the valid parameters to the endpoint they mention in their docs have changed since the docs were prepared.
By the way, I did see that you mentioned "regardless of the target service" but given it seems that you failed to add that detergent dependency and the fact that it looks like you forgot to add detergent to the application list, I'd still try some of those other SOAP endpoints again since you've changed things.
I have a simple application with an web service created with Apache CXF. This application works when I run the server and the client (as Java applications). When I try to access the application /services URL which is mapped in web.xml, Tomcat gives me 404 error. When I run the project I receive:
org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for service {http://sendmessage/}SendMessage
If anyone has any hints related to this error I would be glad to hear them. (I searched google and couldn't find something relevant to my situation)
Thank you!
I had same error, mine was related to namespace which were different in wsdl and webservice. So I changed them to the same.
WSDL:
<wsdl:definitions name=""
targetNamespace="http://www.example.org/yourservice/"
Webservice class:
#WebService(targetNamespace = "http://www.example.org/yourservice/",
.........
Even I had a similar issue.
Fixed it by updating the jaxws:endpoint.
I added the serviceName (mapping to the name present in the WSDL file) with the name space as defined in the "targetNamespace" defined in the wsdl:definitions tag.
<jaxws:endpoint id=".." implementor="..." serviceName="s:SERVICE_NAME_IN_WSDL"
xmlns:s="TARGET_NAME_SPACE_WSDL_DEFINTIONS"></jaxws:endpoint>
edited(06Jul)
Also, I have today that, with Apache CXF 3.0.5 version this issue is not coming;
But with Apache CXF 3.1 version, this is coming.
ServiceConstructionException can occur at various stages when cxf compares the provided service, port and binding name with the wsdl it has already parsed. In this case ( and in most cases) it looks to be namespace issue.
{http://sendmessage/}SendMessage is either not present in parsed wsdl or the service name does not match with the QName present in the WSDL. There are other cases as well where binding or port does not match, one might receive the same exception. Following is a code snippit from org.apache.cxf.wsdl11.WSDLServiceFactory.create() method where it all happens.
If things are not clear why exactly it is happening your best bet is to debug this piece of code and see where it is failing and what is there in parsed wdsl definition (com.ibm.wsdl.DefinitionImpl in wsdl4j.jar).
javax.wsdl.Service wsdlService = definition.getService(serviceName);
if (wsdlService == null) {
if ((!PartialWSDLProcessor.isServiceExisted(definition, serviceName))
&& (!PartialWSDLProcessor.isBindingExisted(definition, serviceName))
&& (PartialWSDLProcessor.isPortTypeExisted(definition, serviceName))) {
try {
Map<QName, PortType> portTypes = CastUtils.cast(definition.getPortTypes());
String existPortName = null;
PortType portType = null;
for (QName existPortQName : portTypes.keySet()) {
existPortName = existPortQName.getLocalPart();
if (serviceName.getLocalPart().contains(existPortName)) {
portType = portTypes.get(existPortQName);
break;
}
}
WSDLFactory factory = WSDLFactory.newInstance();
ExtensionRegistry extReg = factory.newPopulatedExtensionRegistry();
Binding binding = PartialWSDLProcessor.doAppendBinding(definition,
existPortName, portType, extReg);
definition.addBinding(binding);
wsdlService = PartialWSDLProcessor.doAppendService(definition,
existPortName, extReg, binding);
definition.addService(wsdlService);
} catch (Exception e) {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
} else {
throw new ServiceConstructionException(new Message("NO_SUCH_SERVICE_EXC", LOG, serviceName));
}
PS: I know this issue was opened back in 2011 but recently I faced the same issue and was able to resolve it. I hope it help others who are facing this issue.
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Could not find definition for port {http://localhost:9990/project/wsdl/targetName}targetNameSoap12.
at org.apache.cxf.wsdl11.WSDLServiceFactory.create(WSDLServiceFactory.java:179)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:428)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:548)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:265)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:215)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:456)
at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:334)
... 13 more
Fixed problem, define at annotation #WebService(targetNameSpace = "targetNameSoap12") in your web service interface and in the contract WSDL.
For exemplo:
...
<wsdl:service name='targetName'>
<wsdl:port binding='tns:targetNameSoap12' name='targetNameSoap12'>
...
I just got started with embedded jetty. I'm stuck at some error messages. It's simple and straightforward few lines code, which I found online and wanted to test out.
import org.jaxen.Context;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.ServletHolder;
public class Main {
public static void main(String[] args) throws Exception {
ServletHolder sh = new ServletHolder(ServletContainer.class);
sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
sh.setInitParameter("com.sun.jersey.config.property.packages", "jerseyplusjetty");
Server server = new Server(80);
ServletContextHandler sch = new ServletContextHandler(server, "/");
sch.addServlet(sh, "/*");
server.start();
server.join();
}
}
I have all jetty jars in java build path. But I kept getting errors: The constructor ServletHolder(Class) is undefined, The constructor Server(int) is undefined, ServletContextHandler cannot be resolved to a type.
If I remove the parameter inside ServletHolder and Server, it stops complaining. e.g. if I have: ServletHolder sh = new ServletHolder(); Server server = new Server();
But that's not right. I read Jetty docs and ServletHolder class can take parameters. Am I missing something here?
Just FYI on embedded Jetty in general... I have created a github project that I humbly submit may cover most of the embedded jetty issues that keep cropping up.
I've got examples for AbstractHandlers, Servlets, Jersey Servlets, static files, webapps and what not. Still working on RoR and Sinatra, but will get there.
See https://github.com/ZenGirl/EmbeddedJettyRepository for details.
Anyone want to contribute, just ask.
The version of ServletHolder I have takes a String or a servlet in the constructor. So instead of doing
new ServletHolder(ServletContainer.class) you should do new ServletHolder(ServletContainer.class.getCanonicalName()) or new ServletHolder(new ServletContainer()).
ServletContainer is a strange name for a servlet, make sure it is actually a servlet.
Also, be aware that there are number of different versions of Jetty (you're using an old one because in the new one all the classes are in org.eclipse.jetty package), and it's easy to pick up example code that refers to a different version to the one you've got. I would get jetty 7.2.2 from maven and use the example code here.
Hey, I've got this nice little piece of code, much like all the other versions of this method of upload using WSS WebServices. I've got one major problem though - once I have uploaded a file into my doc list, and updated the list item to write a comment/description, the file is stuck there. What I mean is that this method will not overwrite the file once I've uploaded it. Nobody else out there seems to have posted this issue yet, so .. anyone?
I have another version of the method which uses a byte[] instead of a Stream .. same issue though.
Note: I have switched off the 'require documents to be checked out before they can be edited' option for the library. No luck tho .. The doc library does have versioning turned on though, with a major version being created for each update.
private void UploadStream(string fullPath, Stream uploadStream)
{
WebRequest request = WebRequest.Create(fullPath);
request.Credentials = CredentialCache.DefaultCredentials; // User must have 'Contributor' access to the document library
request.Method = "PUT";
request.Headers.Add("Overwrite", "t");
byte[] buffer = new byte[4096];
using (Stream stream = request.GetRequestStream())
{
for (int i = uploadStream.Read(buffer, 0, buffer.Length); i > 0; i = uploadStream.Read(buffer, 0, buffer.Length))
{
stream.Write(buffer, 0, i);
}
}
WebResponse response = request.GetResponse(); // Upload the file
response.Close();
}
Original credits to: http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html
EDIT -- major finding .. when I call it from my nUnit test project it works fine. It seems it only fails when I call it from my WCF application (nUnit running under logged on user account, WCF app has app pool running under that same user -- my account, which also has valid permissions in SharePoint).
Nuts. "Now where to start?!", I muses to myself.
SOLVED -- I found a little bug - the file was being created in the right place, but the update path was wrong.. I ended up finding a folder full of files with many, many new versions.. doh!
Why not use the out-of-the-box SharePoint webservice, Lists.asmx? You'll find it in
http://SITEURL/___vti_bin/Lists.asmx
Edit, I checked out the link and it seems you are calling the out of the box web service. This has got be versioning related then. Can you check out the different versions that exist in the doc lib of the specific file? see if it perhaps gets added as a minor version through the service?
Have you tried using a capital T? SharePoint's webdav header processing is not very likely to be case-sensitive, but the protocol does specify a capital T. Oh, and what is the response? A 412 error code or something altogether different?