Issue in connecting to a servlet with midlet - servlets

I am trying to connect to a Servlet with my j2me application and it's not happening.
Case 1:
1)Deploy the servlet on the local machine.
2)Connect to the servlet on the local machine with j2me app and wait for the servlet to return a a value
3)J2ME gets the value from the servlet and displays on the screen.
Works smooth!
Case 2:
1)Deploy the servlet on a remote machine.
2)Connect to the servlet on the remote machine with j2me app and wait for the servlet to return a a value
3)J2me gets an error saying empty response. Why?
Here is my code:
Case 1: MIDlet deployed on local machine
HttpConnection c = (HttpConnection) Connector.open("http://localhost:8999/PercentileCalculator/PercentileCalculator");
c.setRequestProperty("User-Agent","Profile/MIDP-2.0, Configuration/CLDC-1.1");
c.setRequestProperty("Content-Language","en-US");
c.setRequestMethod(HttpConnection.POST);
DataOutputStream os = (DataOutputStream)c.openDataOutputStream();
os.writeUTF("100");
os.writeUTF("Test 1");
os.writeByte(12);
os.flush();
os.close();
// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
Case 2: MIDlet deployed on remote machine
HttpConnection c = (HttpConnection) Connector.open("Url goes here");
c.setRequestProperty("User-Agent","Profile/MIDP-2.0, Configuration/CLDC-1.1");
c.setRequestProperty("Content-Language","en-US");
c.setRequestMethod(HttpConnection.POST);
DataOutputStream os = (DataOutputStream)c.openDataOutputStream();
os.writeUTF("100");
os.writeUTF("Test1");
os.writeByte(12);
os.flush(); -->Exception thrown here.
os.close();
// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
What could be the issue?
Update 1 : 12.01AM 5 may Sunday
I am able to call my remote servlet using my midlet. I wrote a sql to connect to a mysql DB and add a new row to the DB for every call the midlet makes to the remote servlet. And yes this works.
Now the issue is...why is the remote servlet not able to return values to my midlet. Why do I always get an empty response?
Update 2: 9.46 am 8 may Tuesday
In case 2, I replaced the URL with the foll:
www.google.com --> got a response from google ..some xml string
www.facebook.com --> got a response..which was actually a null pointer exception
m.facebook.com--> got a response from facebook...some xml string
www.yahoo.com ---> no response
Now I feel that my servlet needs to print an xml string and not a normal http page. Please pour in...
Update 3 8.41am 14 may Monday
I tried accessing a friends website using my j2me code. That is, I just replace the URL in case 2 with something like http://www.friend'sURL.in --> worked(got a response)
Then, I tried http://www.mywebsiteURL.in --> empty response
So, I feel there is something wrong with my server/webhosting... no idea.
UPDATE 4 22 MAY 2012 TUESDAY
On telmo's suggestion I looked into my server logs and they are as follows:
1)Log Fields
#Fields: date time s-sitename s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2)Requests from a browser using my desktop (2requests have been shown)
2012-05-21 04:39:06 W3SVC6826 BJJI-GLOBEDNS 67.227.164.68 GET /Servlet/PercentileCalculator - 80 - 116.203.33.229 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/536.5+(KHTML,+like+Gecko)+Chrome/19.0.1084.46+Safari/536.5 - - n10k.in 200 0 0 485 395 421
2012-05-21 04:39:08 W3SVC6826 BJJI-GLOBEDNS 67.227.164.68 GET /favicon.ico - 80 - 116.203.33.229 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/536.5+(KHTML,+like+Gecko)+Chrome/19.0.1084.46+Safari/536.5 - - n10k.in 200 0 0 17863 318 2203
3)Requests from my midlet (emulator on my PC) (2 requests shown)
2012-05-21 04:43:17 W3SVC6826 BJJI-GLOBEDNS 67.227.164.68 POST /Servlet/PercentileCalculator - 80 - 116.203.33.229 HTTP/1.1 Profile/MIDP-1.0,+Configuration/CLDC-1.0 - - n10k.in 200 0 0 0 196 468
2012-05-21 04:43:25 W3SVC6826 BJJI-GLOBEDNS 67.227.164.68 POST /Servlet/PercentileCalculator - 80 - 116.203.33.229 HTTP/1.1 Profile/MIDP-1.0,+Configuration/CLDC-1.0 - - n10k.in 200 0 0 0 196 453
ANALYSIS OF THE LOGS
So I tried to analyze the logs and I was not quite successful in interpreting them. The only difference that I could make out between the browser request and midlet request is:
Browser request returns response -> 200 0 0 17863 318 2203
Midlet request returns response -> 200 0 0 0 196 453
The 4th number (SC Bytes -> Bytes Sent) in case of midlet request is 0. That's all that I could make out. Could anyone help?
UPDATE 5 1st june 2012 Friday 11.33 PM
1)I created a HTML file on my server and then tried accessing it with the midlet and I could access it.
2) Next, I created a PHP page and then tried accessing that with the midlet and I could access it.
3)Then i tried accessing a JSP page and got an empty response.
4) I tried accessing all the servlets deployed on my server and always got an empty response.
5) I tried to access some servlets on the internet but could not find any.
INFERENCE
There is something fishy with the way my servlet outputs the HTML page. I have posted that piece of code here. Please assist.
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
response.setContentType("text/html");
reply = response.getWriter();
reply.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html\"><title>Nikhil D</title></head><body>hmmm</body></html>");
reply.close();
reply.flush();
}
catch(Exception e)
{
}
I am not quite able to figure out whats wrong here. Its probably the manner in which my server renders my servlets/ JSP pages. No idea!
UPDATE 6 : 13th JUNE 2012
Can't waste more time on this. Work around posted in an answer below

So after all that research this is what I did:
1) Pass parameters from MIDlet to a PHP page on my server.
2) Forward the parameters from PHP page to my SERVLET
3) PHP page collects the result of the SERVLET
4) MIDlet reads the result from the PHP page.
Ta Dang! works!

Related

Chilkat HTTP with https

I'm currently using the Chilkat HTTP ActiveX control (version 9.3.2.0) with VB6... One of the servers where I download files from is switching over to https, but I can't get it to work... Using http it works perfectly, but when I change the URL to https it returns 0.
Here is the result of Http.LastErrorText:
ChilkatLog:
Download:
DllDate: Aug 5 2012
UnlockPrefix: **********
Username: BILL-DESKTOP:Bill
Architecture: Little Endian; 32-bit
Language: ActiveX
VerboseLogging: 0
backgroundThread: 0
url: https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl?file=gfs.t12z.pgrb2.0p25.f000&lev_10_m_above_ground=on&lev_2_m_above_ground=on&lev_entire_atmosphere=on&lev_entire_atmosphere_%5C%28considered_as_a_single_layer%5C%29=on&lev_mean_sea_level=on&lev_surface=on&var_APCP=on&var_PRMSL=on&var_TCDC=on&var_TMP=on&var_UGRD=on&var_VGRD=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.2018120712
toLocalPath: C:\Progra~1\PCGrADS\gfs\grib\gfs_pgrbf_000.grib2
localFileAlreadyExists: 0
QuickGetToOutput_Download:
qGet_1:
simpleHttpRequest_3:
httpMethod: GET
requestUrl: https://nomads.ncep.noaa.gov/cgi-bin/filter_gfs_0p25.pl?file=gfs.t12z.pgrb2.0p25.f000&lev_10_m_above_ground=on&lev_2_m_above_ground=on&lev_entire_atmosphere=on&lev_entire_atmosphere_%5C%28considered_as_a_single_layer%5C%29=on&lev_mean_sea_level=on&lev_surface=on&var_APCP=on&var_PRMSL=on&var_TCDC=on&var_TMP=on&var_UGRD=on&var_VGRD=on&leftlon=0&rightlon=360&toplat=90&bottomlat=-90&dir=%2Fgfs.2018120712
Connecting to web server...
httpServer: nomads.ncep.noaa.gov
port: 443
Using HTTPS.
ConnectTimeoutMs_1: 10000
calling ConnectSocket2
IPV6 enabled connect with NO heartbeat.
connectingTo: nomads.ncep.noaa.gov
dnsCacheLookup: nomads.ncep.noaa.gov
Resolving domain name (IPV4)
GetHostByNameHB_ipv4: Elapsed time: 140 millisec
myIP_1: 192.168.1.38
myPort_1: 55564
connect successful (1)
clientHelloMajorMinorVersion: 3.1
buildClientHello:
majorVersion: 3
minorVersion: 1
numRandomBytes: 32
sessionIdSize: 0
numCipherSuites: 10
numCompressionMethods: 1
--buildClientHello
TlsAlert:
level: fatal
descrip: handshake failure
--TlsAlert
Closing connection in response to fatal error.
Failed to read incoming handshake messages. (1)
Client handshake failed. (3)
Failed to connect to HTTP server.
connectElapsedMs: 640
--simpleHttpRequest_3
--qGet_1
--QuickGetToOutput_Download
bFileDeleted: 1
totalElapsedMs: 672
ContentLength: 0
Failed.
--Download
--ChilkatLog
What am I doing wrong?
Regards,
Bill
You were using an old version from 2012, which did not yet implement TLS 1.2. Chilkat has since added support for TLS 1.2 (for many years now) and the latest version should work fine.

Wordpress: Internal Server Error

I must move my wordpress website from one server to another. There is no way to backup it, so I copied wp-content files and moved to the new server. Also I moved database, so in my new server I have same database, same user, same password, also I changes user and password info in wp-config.php file.
But there is a problem such:
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the
error occurred and of anything you might have done that may have
caused the error.
More information about this error may be available in the server error
log.
and here is error log:
#Software: Microsoft Internet Information Services 8.0
#Version: 1.0
#Date: 2015-06-24 22:07:41
#Fields: date time s-sitename s-computername s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs-version cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status sc-bytes cs-bytes time-taken
2015-06-24 22:07:40 W3SVC181 P3NWVPWEB067 50.62.160.227 GET /admin.php - 80 - 193.201.227.78 HTTP/1.0 Opera/9.80+(Windows+NT+6.1;+U;+ru)+Presto/2.8.131+Version/11.10 - - voskevaz.info 404 0 2 1333 179 4843
2015-06-24 22:07:40 W3SVC181 P3NWVPWEB067 50.62.160.227 GET /administrator/index.php - 80 - 193.201.227.78 HTTP/1.0 Opera/9.80+(Windows+NT+6.1;+U;+ru)+Presto/2.8.131+Version/11.10 - - voskevaz.info 404 0 2 1333 193 203
2015-06-24 22:07:43 W3SVC181 P3NWVPWEB067 50.62.160.227 GET /wp-login.php - 80 - 193.201.227.78 HTTP/1.0 Opera/9.80+(Windows+NT+6.1;+U;+ru)+Presto/2.8.131+Version/11.10 - - voskevaz.info 302 0 0 564 182 1250
I really don't know what does it mean and how to fix it.
Thanks
The lack of a 5xx response code in your log file is interesting.
In the log extract you posted above, the last line is a request for /wp-admin.php, and is served with a 302 response code, which means it was redirected somewhere else.
I'm guessing this is happening because you configured the site to only allow users to log in over a secure (HTTPS) connection. So when you visit http://··(your site)··/wp-login.php, you're being redirected to https://··(your site)··/wp-login.php. If the new site doesn't have a proper SSL certificate installed, this will cause an error. (And it looks like your site is logging HTTPS traffic somewhere else.)
To prevent this from happening, edit /wp-config.php and change define('FORCE_SSL_LOGIN', true); to define('FORCE_SSL_LOGIN', false);.

Broken pipe exception on spring boot application monitored by monit

I have a spring-boot application which is monitored by monit.
Monit just check the /health endpoint spring is exposing.
Basically, monit registered the following checks :
check host hopsearch_connection with address 127.0.0.1
if failed url http://127.0.0.1:8089/health with timeout 15 seconds then alert
check host hopsearch_health with address 127.0.0.1
if failed url http://127.0.0.1:8089/health
and content != 'DOWN'
with timeout 60 seconds
then alert
and the web application return something like that :
{"status":"UP","jestHealth":{"status":"UP","lastQuerySuccess":true},"diskSpace":{"status":"UP","free":14439550976,"threshold":10485760},"rabbit":{"status":"UP","version":"3.3.2"},"redis":{"status":"UP","version":"3.0.0"},"mongo":{"status":"UP","version":"2.6.1"}}
In this spring application, I have a general #ExceptionHandler to log all unexpected errors and to display an error page :
#ExceptionHandler(Exception.class)
#ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public String handleDefaultError(Exception ex, HttpServletRequest httpRequest) {
logException(httpRequest, ex);
return "error";
}
And this #ExceptionHandler logs every call from monit :
<11>May 1 13:20:39 IP 13:20:39.339 t=http-nio-8089-exec-3 l=ERROR c=c.h.s.w.c.ErrorManager m=Error 500
----------------------------------------------------------------
Request Path=http://127.0.0.1:8089/health
Method=GET
----------------------------------------------------------------
Header :
----------------------------------------------------------------
host = 127.0.0.1:8089
accept = */*
connection = close
user-agent = monit/5.4
----------------------------------------------------------------
<11>May 1 13:20:39 IP 13:20:39.340 t=http-nio-8089- exec-3 l=ERROR c=c.h.s.w.c.ErrorManager m=Unexpected error : java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:1.8.0_25]
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[na:1.8.0_25]
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[na:1.8.0_25]
at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[na:1.8.0_25]
From monit perspective, everything is fine and the check works.
From my perspective, the application works. But I have a lot of errors dumped in the log.
I don't succeed to reproduce on my workstation with curl. This exception only happens on the server with monit.
Is it possible to ignore an error based on a specific user agent in an ExceptionHandler ? (and how ?)
It wouldn't be the best solution but I don't see any other way.
Any thoughts about that ?

Apache Traffic Server: segmentation fault on request transformation

I'm trying to write a simple encryption/decryption plugin for Apache Traffic Server. The plugin should transform requests/responses in order to encrypt/decrypt them. I decided to use LUA https://github.com/portl4t/ts-lua
function encrypt(data, eos)
if (data == '') then
return data, eos
end
if (eos == 1) then
ts.debug('End of Stream')
end
return data, eos
end
function do_remap()
ts.debug('do_remap')
if (ts.client_request.get_method() == 'POST') then
ts.hook(TS_LUA_REQUEST_TRANSFORM, encrypt)
end
ts.http.resp_cache_transformed(0)
ts.http.resp_cache_untransformed(0)
return 0
end
Everything works fine for GET and DELETE requests, but when I send a POST chunked-encoded request, ATS crashes almost every time.
Here is the stack trace:
[May 20 13:16:28.105] Server {0x7f045a1c1700} DEBUG: (http_redirect) [HttpSM::do_redirect]
[May 20 13:16:28.105] Server {0x7f045a1c1700} DEBUG: (http_redirect) [HttpTunnel::deallocate_postdata_copy_buffers]
NOTE: Traffic Server received Sig 11: Segmentation fault
bin/traffic_server - STACK TRACE:
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x7f045cd29cb0]
bin/traffic_server(_ZN6HttpSM17handle_api_returnEv+0x171)[0x5c274f]
bin/traffic_server(_ZN6HttpSM17state_api_calloutEiPv+0x883)[0x5c24cf]
bin/traffic_server(_ZN6HttpSM23do_api_callout_internalEv+0x1b7)[0x5ceaef]
bin/traffic_server(_ZN6HttpSM14do_api_calloutEv+0x26)[0x5dc18e]
bin/traffic_server(_ZN6HttpSM14set_next_stateEv+0x12f9)[0x5d6a19]
bin/traffic_server(_ZN6HttpSM32call_transact_and_set_next_stateEPFvPN12HttpTransact5StateEE+0x1ba)[0x5d5718]
bin/traffic_server(_ZN6HttpSM36state_common_wait_for_transform_readEP17HttpTransformInfoMS_FiiPvEiS2_+0x39b)[0x5c1a11]
bin/traffic_server(_ZN6HttpSM37state_request_wait_for_transform_readEiPv+0x1e1)[0x5c1483]
bin/traffic_server(_ZN6HttpSM12main_handlerEiPv+0x333)[0x5c5eeb]
bin/traffic_server(_ZN12Continuation11handleEventEiPv+0x68)[0x4f06b2]
bin/traffic_server(_ZN17TransformTerminus12handle_eventEiPv+0x2f6)[0x538d2a]
bin/traffic_server(_ZN12Continuation11handleEventEiPv+0x68)[0x4f06b2]
bin/traffic_server(_ZN7EThread13process_eventEP5Eventi+0x11e)[0x7537e2]
bin/traffic_server(_ZN7EThread7executeEv+0xc9)[0x753a27]
bin/traffic_server[0x752ca7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7e9a)[0x7f045cd21e9a]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f045c0383fd]
Segmentation fault (core dumped)
I've already tried to use one of the example plugins for request transformation and I still have the same problem. The only way to make the problem disappear is to avoid request transformation.
Is there something wrong in the way I'm transforming requests? How can I fix this segmentation fault?
Thanks

Error trying to access WCF Service

Problem had been Fixed
Following a tutorial on MSDN- I created and accessed a WCF services with the Northwind database just fine. With different data, I followed the same process: defined my ADO.NET entity model, created the data service, and enabled access to resources, but I am receiving an error. The error on the webpage only says "Request Error." I have IIS 8.0 express installed, both web.configs are similar, and WCF service is enabled.
I put a break point on InitializeService(), but it never hits that sub. I am not sure where to go from here.
IIS Log file
Software: Microsoft Internet Information Services 8.0
Version: 1.0
Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip vcs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2013-09-14 09:47:04 ::1 GET /tinytrots.svc - 50274 - ::1 Mozilla/5.0+>>(Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/29.0.1547.66+Safari/537.36 -> 307 0 0 769
2013-09-14 09:47:04 ::1 GET /tinytrots.svc/ - 50274 - ::1 Mozilla/5.0+> (Windows+NT+6.1)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/29.0.1547.66+Safari/537.36 - >500 0 0 608
IIS TraceLogFiles
ModuleName: ManagedPipelineHandler
Notification: EXECUTE_REQUEST_HANDLER
HttpStatus: 500
HttpReason: Internal Server Error
HttpSubStatus: 0
ErrorCode: The operation completed successfully.(0x0)
Event Viwer
My Application logs says "The direcoty specified for caching compressed content C:\Users\Me\AppData\Local\Temp\iisexpress\ISS Temporary Compressed Files\ Clr4IntegratedAppPool is invalid. Static compression is being disabled."
The Data Service
Public Class tinytrots
Inherits DataService(Of TinyTrotsDBEntities)
Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration)
config.SetEntitySetAccessRule("Activities", EntitySetRights.All)
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3
End Sub
End Class
Had to run this command to register the required script maps in IIS: >"%WINDIR%\Microsoft.Net\Framework\v4.0.30319\ServiceModelReg.exe" -r
http://www.msdn.microsoft.com/en-us/library/ms751527.aspx
http://www.msdn.microsoft.com/en-us/library/ms752252.aspx

Resources