i m facing following error using first time eclipse - java

this error occurred what to do run the application??
Initializing AppEngine server
25/06/2010 9:16:57 AM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
25/06/2010 9:16:59 AM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed C:\Documents and Settings\kk\workspace\First\war\WEB-INF/appengine-web.xml
25/06/2010 9:16:59 AM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed C:\Documents and Settings\kk\workspace\First\war\WEB-INF/web.xml
25/06/2010 2:47:14 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The server is running at http://localhost:8888/
edit (1) ::
when i m running the program http://localhost:8888/first
(copied from a comment to my answer)
i face Error 403 FORBIDDEN what to do now?
in the firstservlet.java i write only the following code
package first;
import java.io.IOException;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
whats the wrong??

403 Forbidden is a HTTP status code returned by a web server when a user agent requests a resource that the server does not allow them to
(wikipedia)
The server is up and running, accepted you request but can't respond because you're not allowed to access some resource. So the problem is inside the Firstapplication, maybe this aplication trys to access some file system resources and the server does not have sufficient privileges.

Related

Can rearch resource behind VPN from java app: Unexpected end of file from server

I've got a very weird problem with HTTP connection from java.
Description: from machine A(source machine) i trying to get http response from machine B(10.13.0.69).
Important part: machine B(target) is located behind VPN tunnel.
Machine B is reachable from machine A. I have no problems, if i try to access this URL from machine A OS (with curl for example):
[root#Test-LAPP01 test]# curl http://10.13.0.69:7878/testGet && echo ""
{"result":["\"AlertServer testGet ok\" "]}
Problems starts when i trying to perform same request from java program, that located at machine A: i getting SocketException: Unexpected end of file from server.
Detailed description:
[root#Test-LAPP01 test]# cat contest.java
import java.net.*;
import java.io.*;
public class contest {
public static void main(String[] args) throws Exception {
String url = "http://10.13.0.69:7878/testGet";
try {
URL alert = new URL(url);
HttpURLConnection con = (HttpURLConnection) alert.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "chrome");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
[root#Test-LAPP01 test]# curl http://10.13.0.69:7878/testGet && echo ""
{"result":["\"AlertServer testGet ok\" "]}
[root#Test-LAPP01 test]# java contest
java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:851)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:848)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at contest.main(contest.java:12)
Note 1: from java app i CAN connect to external resourses, like google.com and have no issues with that.
Note 2: It works if i place target web server that i trying to reach (Machine B - 10.13.0.69) on same subnet with source machine A. So problem is somehow related to VPN.
I already tried to debug this and launched tcpdump on both machines and now i'm confused even more: i see all network requests on both sides.
So short description: i can reach destination URL from machine, but cant from java app.
UPD: updated code with #RedBoy recommendations. Now i've see this error:
апр 25, 2018 12:47:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:47:24 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
апр 25, 2018 12:47:55 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:47:55 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
апр 25, 2018 12:48:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request to {}->http://10.13.0.69:7878: The target server failed to respond
апр 25, 2018 12:48:26 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {}->http://10.13.0.69:7878
contest main org.apache.http.NoHttpResponseException: 10.13.0.69:7878 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:165)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at contest.contest.main(contest.java:25)

Difference between running in IntelliJ and running from a JAR file

I run the following simple example for a Jersey application on a Grizzly server:
#Path("example")
public class example {
#POST
public Response someMethod(#Context Request r) {
System.out.println("Received request at : " + LocalDateTime.now());
Response response = Response.ok().build();
return response;
}
}
public class GrizzlyServerMain {
public static HttpServer startServer(String BASE_URI) throws IOException {
// Scans for JAX-RS resources and providers in the specified code-package
final ResourceConfig resourceConfig = new PackagesResourceConfig("Application");
// create and start a new instance of grizzly http server exposing the Jersey application at BASE_URI
return GrizzlyServerFactory.createHttpServer(BASE_URI, resourceConfig);
}
public static void main(String[] args) throws IOException {
String BASE_URI = "http://0.0.0.0:8000";
// Base URI the Grizzly HTTP server will listen on
startServer(BASE_URI);
//noinspection ResultOfMethodCallIgnored
System.in.read();
}
}
When I run it from IntelliJ, everything works as expected.
Connected to the target VM, address: '127.0.0.1:61163', transport:
'socket' Dec 30, 2016 4:00:07 PM
com.sun.jersey.api.core.PackagesResourceConfig init INFO: Scanning for
root resource and provider classes in the packages: Application Dec
30, 2016 4:00:08 PM com.sun.jersey.api.core.ScanningResourceConfig
logClasses INFO: Root resource classes found: class
Application.Greetings class Application.example Dec 30, 2016 4:00:08
PM com.sun.jersey.api.core.ScanningResourceConfig init INFO: No
provider classes found. Dec 30, 2016 4:00:08 PM
com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19.3
10/24/2016 03:43 PM' Dec 30, 2016 4:00:08 PM
org.glassfish.grizzly.http.server.NetworkListener start INFO: Started
listener bound to [0.0.0.0:8000] Dec 30, 2016 4:00:08 PM
org.glassfish.grizzly.http.server.HttpServer start INFO: [HttpServer]
Started
Received request at : 2016-12-30T16:00:13.097
Received request at : 2016-12-30T16:00:14.319
Received request at : 2016-12-30T16:00:15.583
Disconnected from the target VM, address:
'127.0.0.1:61163', transport: 'socket'
But when I create a JAR with all the dependencies, and as soon as I send the request from the client, I get:
WARNING: Exception during FilterChain execution
java.lang.IllegalStateException
at org.glassfish.grizzly.http.server.io.OutputBuffer.reset(OutputBuffer.java:217)
at org.glassfish.grizzly.http.server.Response.reset(Response.java:732)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:168)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:815)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:567)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:547)
at java.lang.Thread.run(Unknown Source)
Can you please tell me what could I be doing wrong?
The exception seems to have changed from IllegalStateException to IllegalArgumentException.
Have a look at Java Doc for ContainerProvider.
ContainerProvider is an SPI class and its implementation will be provided by the server you are using, in your case the Grizzly server.
As per Java Doc:
An implementation (a service-provider) identifies itself by placing a provider-configuration file (if not already present), "com.sun.jersey.spi.container.ContainerProvider" in the resource directory META-INF/services, and including the fully qualified service-provider-class of the implementation in the file..
So, I think you need to update "META-INF/services" to your jar and add the provider as "GrizzlyContainerProvider" (package qualified).
You can have a look at a similar post:
Grizzly and Jersey standalone jar

Cloudant j2se prototype throwing HTTPRequest exception

I'm trying to follow the replication guide on github for cloudant to prototype a basic one way connection between a local couchdb and and a locally running j2se app utilizing the cloudant sync library.
The local datastore file is being created, however almost immediately after running my application, I'm getting a runtime error - which at a glance I'm a little unsure of how to resolve: Asside from the cloudant code and dependancies;
This is the entire code for my app - I have apache couchdb installed on my machine and the database called 'baseball' exists already:
import com.cloudant.sync.datastore.DatastoreManager;
import com.cloudant.sync.datastore.Datastore;
import com.cloudant.sync.replication.*;
import com.cloudant.sync.notifications.*;
import com.google.common.eventbus.Subscribe;
import java.util.concurrent.CountDownLatch;
import java.io.*;
import java.net.*;
//https://github.com/cloudant/sync-android/blob/master/doc/replication.md
public class CloudApp{
public static void main(String [] args) throws Exception{
File path = new File("datastores");
System.out.println(path.getAbsolutePath());
DatastoreManager manager = new DatastoreManager(path.getAbsolutePath());
URI uri = new URI("http://127.0.0.1:5984/baseball");
Datastore ds = manager.openDatastore("my_datastore");
// Create a replictor that replicates changes from the remote
// database to the local datastore.
Replicator replicator = ReplicatorFactory.oneway(uri, ds);
// Use a CountDownLatch to provide a lightweight way to wait for completion
CountDownLatch latch = new CountDownLatch(1);
Listener listener = new Listener(latch);
replicator.getEventBus().register(listener);
replicator.start();
latch.await();
replicator.getEventBus().unregister(listener);
if (replicator.getState() != Replicator.State.COMPLETE) {
System.out.println("Error replicating FROM remote");
System.out.println(listener.error);
}
}
}
class Listener {
private final CountDownLatch latch;
public ErrorInfo error = null;
Listener(CountDownLatch latch) {
this.latch = latch;
}
#Subscribe
public void complete(ReplicationCompleted event) {
latch.countDown();
}
#Subscribe
public void error(ReplicationErrored event) {
this.error = event.errorInfo;
latch.countDown();
}
}
And this is the runtime error as well as log outputs:
[I]DatastoreManager: path: /Users/reecegriffin/Documents/workspace/Cloudant 2/datastores
[I]DatastoreManager: dbDirectory: /Users/reecegriffin/Documents/workspace/Cloudant 2/datastores/my_datastore
Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
INFO: [sqlite] DB[1]: instantiated [/Users/reecegriffin/Documents/workspace/Cloudant 2/datastores/my_datastore/db.sync]
Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
INFO: [sqlite] Internal: loaded sqlite4java-osx from /Users/reecegriffin/Documents/workspace/Cloudant 2/src/libsqlite4java-osx.jnilib
Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
INFO: [sqlite] Internal: loaded sqlite 3.7.10, wrapper 0.2
Mar 10, 2014 9:29:02 AM com.almworks.sqlite4java.Internal log
INFO: [sqlite] DB[1]: opened
Exception in thread "main" java.lang.IllegalStateException: java.lang.RuntimeException: Stub!
at com.cloudant.mazha.HttpRequests.createHttpClient(HttpRequests.java:185)
at com.cloudant.mazha.HttpRequests.<init>(HttpRequests.java:69)
at com.cloudant.mazha.CouchClient.<init>(CouchClient.java:47)
at com.cloudant.sync.replication.CouchClientWrapper.<init>(CouchClientWrapper.java:45)
at com.cloudant.sync.replication.BasicPullStrategy.<init>(BasicPullStrategy.java:90)
at com.cloudant.sync.replication.PullReplication.createReplicationStrategy(PullReplication.java:40)
at com.cloudant.sync.replication.BasicReplicator.getReplicationStrategy(BasicReplicator.java:41)
at com.cloudant.sync.replication.BasicReplicator.start(BasicReplicator.java:61)
at CloudApp.main(CloudApp.java:27)
Caused by: java.lang.RuntimeException: Stub!
at org.apache.http.params.AbstractHttpParams.<init>(AbstractHttpParams.java:5)
at org.apache.http.params.BasicHttpParams.<init>(BasicHttpParams.java:6)
at com.cloudant.mazha.HttpRequests.getHttpConnectionParams(HttpRequests.java:199)
at com.clou
dant.mazha.HttpRequests.createHttpClient(HttpRequests.java:173)
... 8 more
Many thanks for any help.
Regards,
Reece.
I noticed in some other threads regarding Stub related apache commons HTTPclient related stuff, that the android library build path order can have an effect. I was trying to run from within eclipse & sure enough - after I opened up the build path editor and moved android.jar to be last on my build path, the run time error went away.
There's some more information on the "stub!" issue in Using android.jar in Java project - RuntimeException Stub?.
We'll take a look into whether we can mitigate the effects of the build path order in code, but I'm not sure whether we'll be able to fix the issue.
This problem hasn't come up for us in tests. Perhaps this is because the Android dependency is specified last in our build.gradle file, meaning it ends up in a position in the path ordering that works.

send sms using way2sms by java program?

i would like to know how to send sms to mobile using java program connected to way2sms.i have wrote folloing program but it got error plz let me know what r required
i added way2sms.jar
import com.way2sms.SMS;
class TestSMS {
public static void main(String[] args) {
SMS smsClient=new SMS();
smsClient.send("userid","password","receiving number","message","proxy");
System.out.println("done");
}
}
I added way2sms.jar and proxy may be null or ""
i got following error:even i used valid user id and password of way2sms site..
Mar 12, 2012 10:31:26 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002
Windows RegCreateKeyEx(...) returned error code 5.
Logging in ...
Login Failed...
java.io.FileNotFoundException: http://wwwd.way2sms.com//auth.cl
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1303)done
at com.way2sms.SMS.login(SMS.java:132)
at com.way2sms.SMS.send(SMS.java:75)
at sms.TestSMS.main(TestSMS.java:10)

send SMS to mobile using java?

I would like to know how to send an SMS to mobile using way2sms via a java program. I have written one program but it has an error. Please tell me what is required for this.
Your efforts will really be highly appreciated.
package sms;
import com.way2sms.SMS;
class TestSMS {
public static void main(String[] args) {
SMS smsClient=new SMS();
smsClient.send("userid","password","receiving number","message","proxy");
System.out.println("done");
}
}
I added way2sms.jar and proxy may be null or ""
i got following error:even i used valid user id and password of way2sms site..
Mar 12, 2012 10:31:26 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002.
Windows RegCreateKeyEx(...) returned error code 5.
Logging in ...
Login Failed...
java.io.FileNotFoundException: http://wwwd.way2sms.com//auth.cl
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1303)done
at com.way2sms.SMS.login(SMS.java:132)
at com.way2sms.SMS.send(SMS.java:75)
at sms.TestSMS.main(TestSMS.java:10)

Categories