I am trying to embed an OSGI bundle that uses in my java application.
Below is my only java file in the bundle (I am doing it simple now):
package it.eng.test.ds.consumer;
public class Consumer {
public void activate(){
System.out.println("I'm here, in the activate ds automatic method ;)");
}
public void deactivate()
{
System.out.println("Bye Bye!");
}
}
Below is consumer.xml:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="it.eng.test.ds.consumer"
activate="activate"
deactivate="deactivate"
modified="modified"
enabled="true"
immediate="true">
<implementation class="it.eng.test.ds.consumer.Consumer"/>
</scr:component>
Below is MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ds-bundle
Bundle-SymbolicName: it.eng.test.ds.consumer
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
-Component: OSGI-INF/consumer.xml
Next, I embedded equinox in my application, started the required bundles (org.eclipse.equinox.ds and its dependencies), and finally started my bundle which is called it.eng.test.ds.consumer_1.0.0.201401071018.jar.
Below is my application code:
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class MainEmbedder {
public static void main(String[] args)
{
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();
//TODO: add some config properties
Framework framework = frameworkFactory.newFramework(config);
try {
framework.start();
} catch (BundleException e) {
e.printStackTrace();
}
BundleContext context = framework.getBundleContext();
List<Bundle> installedBundles = new LinkedList<Bundle>();
try {
installedBundles.add(context.installBundle("file:C:\\Users\\student\\Desktop\\DS-Plugins\\org.eclipse.osgi.services_3.3.100.v20120522-1822.jar"));
installedBundles.add(context.installBundle("file:C:\\Users\\student\\Desktop\\DS-Plugins\\org.eclipse.equinox.util_1.0.200.v20100503.jar"));
installedBundles.add(context.installBundle(
"file:C:\\Users\\student\\Desktop\\DS-Plugins\\org.eclipse.equinox.ds_1.4.1.v20120926-201320.jar"));
installedBundles.add(context.installBundle(
"file:C:\\Users\\student\\Desktop\\DS-Plugins\\plugins\\it.eng.test.ds.consumer_1.0.0.201401071018.jar"));
} catch (BundleException e) {
e.printStackTrace();
}
for (Bundle bundle : installedBundles) {
try {
bundle.start();
} catch (BundleException e) {
e.printStackTrace();
}
}System.out.println("after starting bundles");
}
}
When I run my app, I can see the message "after starting bundles", but I do not see the message "I'm here, in the activate ds automatic method ;)". This means that my bundle did not enter the activate method. Why is that? How can I solve this problem? Thanks.
Update:
I tried to start the bundle with Felix framework, using the below code:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.util.FelixConstants;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
public class HostApplication
{
private HostActivator m_activator = null;
private Felix m_felix = null;
public HostApplication()
{
// Create a configuration property map.
Map config = new HashMap();
config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
// Create host activator;
m_activator = new HostActivator();
List list = new ArrayList();
list.add(m_activator);
config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
try
{
// Now create an instance of the framework with
// our configuration properties.
m_felix = new Felix(config);
// Now start Felix instance.
m_felix.start();
}
catch (Exception ex)
{
System.err.println("Could not create framework: " + ex);
ex.printStackTrace();
}
// Register the application's context as an OSGi service!
BundleContext bundleContext1 = m_felix.getBundleContext();
System.out.println("6");
try {
Bundle dsBundle = bundleContext1.installBundle("file:C:\\Users\\student\\Desktop\\DS-Plugins\\org.apache.felix.scr-1.8.0.jar");
dsBundle.start();
if(dsBundle.getState()== dsBundle.ACTIVE)
System.out.println("DS Bundle is Active!");
Bundle consumerBundle = bundleContext1.installBundle("file:C:\\Users\\student\\Desktop\\DS-Plugins\\plugins\\it.eng.test.ds.consumer_1.0.0.201401071018.jar");
consumerBundle.start();
if(consumerBundle.getState()== consumerBundle.ACTIVE)
System.out.println("Consumer Bundle is Active!");
System.out.println("done!");
} catch (BundleException e) {
e.printStackTrace();
System.out.println("Not done!");
}
shutdownApplication();
}
public Bundle[] getInstalledBundles()
{
// Use the system bundle activator to gain external
// access to the set of installed bundles.
return m_activator.getBundles();
}
public void shutdownApplication()
{
// Shut down the felix framework when stopping the
// host application.
try {
m_felix.stop();
} catch (BundleException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
m_felix.waitForStop(0);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Now I get the following error:
ERROR: it.eng.test.ds.consumer (2): Component descriptor entry 'OSGI-INF/consumer.xml' not found.
I guess there is something wrong with my bundle, but it is very simple and just as I descried it above. Any ideas?
I've replayed your setup, and I've got it to work.
(A github repo is here, if all else fails)
Check if OSGI-INF/ is actually in your bundle, did you add it to build.properties (if you use PDE)
regards, Frank
I am not sure what your exact intention is but embedding osgi bundles into a standard java application is maybe not the best thing to do. I would recommend to convert your application to osgi (if possible and it's not too big). If you cannot do to that consider to emulate the bundle with the ds component, e.g. just create the component instance manually and set it's dependencies on foot. But don't mix both worlds.
Related
I try to deserialize traversal query with none() step, but it seems like there is no support for such deserialization
Tinkerpop version is 3.5.0
Here is a code that fail
import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.io.GraphReader;
import org.apache.tinkerpop.gremlin.structure.io.GraphWriter;
import org.apache.tinkerpop.gremlin.structure.io.Mapper;
import org.apache.tinkerpop.gremlin.structure.io.graphson.*;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class GraphExperimental {
private static final Mapper<ObjectMapper> GRAPHSON_MAPPER_3_0 = GraphSONMapper.build()
.version(GraphSONVersion.V3_0)
.typeInfo(TypeInfo.PARTIAL_TYPES)
.addCustomModule(GraphSONXModuleV3d0.build().create(false))
.create();
private static final GraphWriter GRAPHSON_WRITER_3_0 = GraphSONWriter.build()
.mapper(GRAPHSON_MAPPER_3_0)
.create();
private static final GraphReader GRAPHSON_READER_3_0 = GraphSONReader.build()
.mapper(GRAPHSON_MAPPER_3_0)
.create();
private GraphExperimental() {
}
public static void main(String[] args) {
Graph graph = TinkerGraph.open();
DefaultGraphTraversal<Object, Object> defaultGraphTraversal = new DefaultGraphTraversal<>(graph.traversal());
// defaultGraphTraversal.addV("A").property("mac", "1");
defaultGraphTraversal.iterate();
Bytecode bytecode = defaultGraphTraversal.getBytecode();
String serialize = writeValueAsString(bytecode);
Graph anotherGraph = TinkerGraph.open();
GraphTraversalSource anotherTraversal = anotherGraph.traversal();
Bytecode bytecodeDeserialized = readValue(serialize, Bytecode.class);
Traversal.Admin<?, ?> translate = JavaTranslator.of(anotherTraversal).translate(bytecodeDeserialized);
}
public static <T> T readValue(String value, Class<? extends T> clazz) {
try (ByteArrayInputStream in = new ByteArrayInputStream(value.getBytes("UTF-8"))) {
return GRAPHSON_READER_3_0.readObject(in, clazz);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String writeValueAsString(Object value) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
GRAPHSON_WRITER_3_0.writeObject(out, value);
return out.toString("UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
In result i catch such an exception:
Exception in thread "main" java.lang.IllegalStateException: Could not locate method: GraphTraversalSource.none()
at org.apache.tinkerpop.gremlin.jsr223.JavaTranslator.invokeMethod(JavaTranslator.java:207)
at org.apache.tinkerpop.gremlin.jsr223.JavaTranslator.translate(JavaTranslator.java:89)
at example.GraphExperimental.main(GraphExperimental.java:63)
If you just remove comment from defaultGraphTraversal.addV("A").property("mac", "1");
The code will work
So why does there is no support for such a deserialization?
Thanks a lot!!!
I would recommend that you not attempt to construct a DefaultGraphTraversal directly and to instead spawn them from a GraphTraversalSource (i.e. your g). I suppose it can work, but that class really wasn't designed to be utilized by users directly so the API could shift out from under you or an initialization behavior could change and cause you trouble.
In a sense, the direct construction is what is causing the problem here as you build traversal bytecode that isn't really valid:
gremlin> defaultGraphTraversal = new DefaultGraphTraversal<>(graph.traversal());[]
gremlin> defaultGraphTraversal.iterate();[]
gremlin> bytecode = defaultGraphTraversal.getBytecode()
==>[[], [none()]]
Since you don't spawn from a GraphTraversalSource you end up constructing a traversal that doesn't have any source instructions (i.e. the first [] in the above bytecode output). Without that, the JavaTranslator heads down a different path than it expects and tries to call none() on a GraphTraversalSource rather than on a Traversal. You obviously solve this problem when you uncomment that line that calls addV() because that is a proper start step that can act as a spawn whereas none() cannot.
Getting below Exception::
WARN main [DavDocumentBuilderFactory.createFactory] - Secure XML processing is not supported
java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
at org.apache.jackrabbit.webdav.xml.DavDocumentBuilderFactory.createFactory(DavDocumentBuilderFactory.java:50)
at org.apache.jackrabbit.webdav.xml.DavDocumentBuilderFactory.<init>(DavDocumentBuilderFactory.java:39)
at org.apache.jackrabbit.webdav.xml.DomUtil.<clinit>(DomUtil.java:60)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:203)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:72)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:61)
at com.spero.poc.WebDavClient.listOfFilesFromWebDav(WebDavClient.java:108)
at com.spero.poc.WebDavClient.main(WebDavClient.java:92)
Exception in thread "main" java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.getXmlStandalone()Z
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.setDocumentInfo(DOM2TO.java:377)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:131)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(DOM2TO.java:98)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:684)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:728)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:343)
at org.apache.jackrabbit.webdav.xml.DomUtil.transformDocument(DomUtil.java:805)
at org.apache.jackrabbit.webdav.client.methods.XmlRequestEntity.<init>(XmlRequestEntity.java:43)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:193)
at org.apache.jackrabbit.webdav.client.methods.DavMethodBase.setRequestBody(DavMethodBase.java:205)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:72)
at org.apache.jackrabbit.webdav.client.methods.PropFindMethod.<init>(PropFindMethod.java:61)
at com.spero.poc.WebDavClient.listOfFilesFromWebDav(WebDavClient.java:109)
at com.spero.poc.WebDavClient.main(WebDavClient.java:92)
Here is my code::
package com.spero.poc;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.apache.jackrabbit.webdav.DavConstants;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.MultiStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.client.methods.DavMethod;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
public class WebDavClient {
static HttpClient client = null;
public static void main(String[] args) {
// String uri = "https://www.webdavserver.com/Userab71566/Library/Content.txt";
String uri = "https://www.webdavserver.com/Userab71566/Library/";
HostConfiguration hostConfig = new HostConfiguration();
hostConfig.setHost("https://www.webdavserver.com");
HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
int maxHostConnections = 20;
params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
params.setConnectionTimeout(60000);
connectionManager.setParams(params);
HttpClientParams cParams = new HttpClientParams();
cParams.setSoTimeout(60000);
// Create the HttpClient object and eventually pass the Credentials if required:
client = new HttpClient(cParams,connectionManager);
client.setHostConfiguration(hostConfig);
// Credentials creds = new UsernamePasswordCredentials("userId", "pw");
// client.getState().setCredentials(AuthScope.ANY, creds);
try {
WebDavClient test = new WebDavClient();
test.listOfFilesFromWebDav(uri);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
client = null;
}
if(client == null)
System.out.println("Client is in null state");
}
private List<String> listOfFilesFromWebDav(String folderUrl) {
try {
PropFindMethod pFind = new PropFindMethod(folderUrl, DavConstants.PROPFIND_ALL_PROP, DavConstants.DEPTH_1);
pFind.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
client.executeMethod(pFind);
List<String> files = new ArrayList<>();
MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();
MultiStatusResponse[] responses = multiStatus.getResponses();
for (MultiStatusResponse response : responses) {
if (response.getHref().endsWith(".txt")) {
System.out.println("Data::"+response.getHref());
}
}
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DavException e) {
e.printStackTrace();
}
return null;
}
}
What version of Jackrabbit?
Looking at the source I see that the exception is actually caught and logged, and the system should proceed.
See https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-webdav/src/main/java/org/apache/jackrabbit/webdav/xml/DavDocumentBuilderFactory.java#L43
Are you really getting an exception in the code?
Thanks for the suggestion, I have gone through the logs and find out the mismatched class and jars. I have added the below system settings to my code and the Jar.
We have to resort to System.setProperty(...) calls from your code, eg:
//this would enforce the DOM implementation to be Xerces
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
//this would enforce the SAX implementation to be Xerces
System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");
//this would enforce the XSLT implementation to be Xalan
System.setProperty("javax.xml.transform.TransformerFactory","org.apache.xalan.processor.TransformerFactoryImpl");
The respective JRE implementation classes are:
com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
I search for a library, a ".zip"-archiv or another easy way to get all "eclipse-icons". I mean the icons on the top of the tabs (Error, Debug, Search, Task and so on..)
Any idea?
Eclipse actually has a special view that shows all available icons:
Window ▸ Show View ▸ Other... ▸ Plug-in Development ▸ Plug-in Image Browser
Do you want to find the plugin they are in, or download similar ones? Try http://eclipse-icons.i24.cc/
I found it was much easier to just write a little program to extract the images. The code below pulls out all *.png from the JAR files in the Eclipse plugins directory.
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ExtractEclipseIcons {
public static void main(String[] args) {
String dir="C:\\eclipse\\e47dtp\\eclipse\\plugins";
for (File file : new File(dir).listFiles()) {
if(file.getName().endsWith(".jar")) {
unpackImagesFromJAR(file);
}
}
}
private static void unpackImagesFromJAR(File file) {
try (ZipFile zip = new ZipFile(file)){
for (ZipEntry ze : Collections.list(zip.entries())) {
String name = ze.getName();
if(name.endsWith(".png")) {
try(InputStream in = zip.getInputStream(ze)){
String outname = file.getName()+"/"+name;
File outfile = new File("data/"+outname.replace('/', '_').replace('\\', '_'));
stream2File(in,outfile);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void stream2File(InputStream is, File file) throws IOException {
byte[] buffer = new byte[8 * 1024];
try {
OutputStream output = new FileOutputStream(file);
try {
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} finally {
output.close();
}
} finally {
is.close();
}
}
}
Try this tool: http://www.angusj.com/resourcehacker/
It allows you to extract/cange nearly any icon/pic inside an exe file.
I am not able to compile my DriverClass at the job.waitforcompletion(boolean) clause.It gives me a NoClassFoundException.If I catch the exception ,the run method throws the error that its expecting a int value.I am using MapReduce New API.Could anyone suggest what is the issue :
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
public class Dist_Driver extends Configured implements Tool {
public int run(String args[]) throws IOException, InterruptedException {
// Configuration phase
// Configuration conf=new Configuration();
Job job = new Job(new Configuration());
job.setJarByClass(Dist_Driver.class);
// Mapper Reducer InputFormat
job.setInputFormatClass(FileInputFormat.class);
// Mapper and Reducer Class
job.setMapperClass(Dist_Mapper.class);
job.setReducerClass(DistCache_Reducer.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setInputFormatClass(KeyValueTextInputFormat.class);
// set FileInputOutput
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
// setting number of reduce tasks and submit it
job.setNumReduceTasks(2);
// Lets check if the file exist
File f1 = new File("/home/hdfs/trials_mapreduce_progams/emp_id");
if (f1.exists())
System.out.println("The Files Exists");
else
System.out.println("The File doesnot exist");
URI path1;
try {
path1 = new URI(
"/home/hdfs/trials_mapreduce_progams/emp_lookup.txt");
DistributedCache.addCacheFile(path1, job.getConfiguration());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (job.waitForCompletion(true))
return 0;
else
return 1;
}
public static void main(String[] args) throws Exception {
int exitcode = ToolRunner.run(new Dist_Driver(), args);
System.exit(exitcode);
}
}
Just add the ClassNotFoundException to the run method signature
public int run(String args[]) throws IOException,
InterruptedException,
ClassNotFoundException {
The reason you get an error when you try and try/catch it is because if there is a ClassNotFoundException thrown during execution, there will be no return value, and the method has to return something.
If you really want to catch it, just return 1 in the catch clause, which is the error exit code
I've managed to run the code in this question here properly in a test java project with no problem, but when I am following the exact same procedure to import HtmlUnit in my webserver, i keep getting the org.apache.http.protocol.BasicHttpContext: method <init>()V not found error.
the code im trying to run:
package com.testing;
import java.io.IOException;
import java.net.MalformedURLException;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
public class testingUnit {
public static void main(final String[] args) {
final WebClient webClient = new WebClient();
webClient.setTimeout(1000);
try {
System.out.println("Querying");
webClient.getPage("https://bulksms.vsms.net/register/");
System.out.println("Success");
} catch (final FailingHttpStatusCodeException e) {
System.out.println("One");
e.printStackTrace();
} catch (final MalformedURLException e) {
System.out.println("Two");
e.printStackTrace();
} catch (final IOException e) {
System.out.println("Three");
e.printStackTrace();
} catch (final Exception e) {
System.out.println("Four");
e.printStackTrace();
}
System.out.println("Finished");
}
}
Console:
Querying
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.protocol.BasicHttpContext: method <init>()V not found
at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:273)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:797)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:776)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:152)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1439)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1358)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:307)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:373)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:358)
at com.testing.testingUnit.main(testingUnit.java:16)
Figured it out after posting the screenshot here. I had totally forgot to update the web app libraries. I did that and deleted all the outdated versions of jars I had (in the webcontent/lib folder), and the code above worked like a charm. Cheers!