×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    19

    Error in Http Operation

    Hi all

    i am a new to j2me application developing and i am facing a problem

    When i hit a web service i get this (Error in Http Operation) error and this problem occurs only on device. For first few URLs there is no prob but after using app for a while it started giving this error. Initially i think it is due to memory leakage but after handling all the memory issues i am still facing the same prob.

    I am using Normal Network connection class to post the data on web.

    Kindly help.
    Ab

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Error in Http Operation

    Hi bpomatrix and welcome to Nokia's Discussion Boards,

    Since you are performing several post operations, you are most likely using several OutputStreams where you are writing the posted data, and then you reading from one or more InputStreams. Are you flushing your OutputStream before reusing it? This ensures that any bytes previously written that have been buffered by the implementation of the output stream, are immediately written to their intended destination.

    Another debugging suggestion would be to retrieve the response code from your connection object right after you flush the output stream. You can find a list of possible response codes and their explanation here:
    http://library.developer.nokia.com/t...onnection.html
    Last edited by skalogir; 2012-02-04 at 15:58.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    19

    Re: Error in Http Operation

    Hi skalogir

    First of all thanks for reply. I am doing everything what u suggest and getting response code -1 and response message null.
    what i noticed while debugging in Network Connection class exception raise after control moves from

    inputStream = httpConn.openDataInputStream();

    i am confused how to get out of it..
    please suggest me something what to do

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Error in Http Operation

    Do you only retrieve data or do you also send data to the web service?
    If you are only retrieving data, does the error occur, if you retrieve data from another set of URLs?
    Which SDK are you using to compile your code and which device are you testing on?

    Could it be that the same method that performs the network operation is accessed simultaneously by multiple parts of your code, or do you ensure that any forthcoming URL retrievals are staying in queue before the current one completes?

    Are you certain that this is not a network connectivity issue of your device, i.e. you do not use an intermittent internet connection and that you can always access the URLs using the device's native web browser, without getting time outs?

    Would it be possible for you to share your code, or at least part of it, where you perform the multiple URL retrievals?
    Last edited by skalogir; 2012-02-06 at 06:57.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    19

    Re: Error in Http Operation

    Hello Sir,

    I am sending as well as retrieving the data form server side.
    I am using j2me polish.
    I have checked my device on Nokia - 6300 and Micromax and creates problem but fine on emulator and N-95.
    I have checked my network operation that is not accessed simultaneously by multiple parts of my code.
    I have also checked but myforthcoming URL retrievals are not stayed in queue before the current one completes?
    There is no timeout problem happening.
    I am not able to share my code but im telling you about detail of my usage Network Connection.

    i am new to j2me.i am working in j2me polish and this is my first project in j2me polish.my appn is working fine on emulator but when run it on device(NOKIA - 6300) then after 6-7 URL hits.It gives exception (java.IOexception:error in http operation) in one particular URL.Every time exception generate on same URL(exception generate in network connection).I am using folloeing steps in Network Connection :-
    1) open connection (using connector .open)
    2) using POST method
    3) open outputstream
    4) after converting in bytes write data
    5) flush the outputstream
    6) open datainputstream
    7) read from inputstream

    When flow reaches at particular URL (where exception occured always)then it gives error in
    5) step in flushing the outputstream
    when i commented it then again When flow reaches at particular URL (where exception occured always)then it gives error in
    6) step in open datainputstream

  6. #6
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Error in Http Operation

    Hi bpomatrix,

    What happens if, instead of J2ME Polish you use Nokia's SDK 1.0 for Java from the link below?
    http://www.developer.nokia.com/Devel..._SDK_for_Java/

    or if you need an SDK that looks more similar to your Nokia 6300, you could download Series 40 SDK 3rd Edition Feature Pack 2, from here
    http://www.developer.nokia.com/info/...form_SDKs.html

    The idea is that if you are developing an application for Nokia Devices, you are better off, using Nokia's SDKs rather than J2ME Polish.

    There is some help on getting started with setting up the SDK here:
    http://library.developer.nokia.com/t...C2D2937BC.html

    And all the libraries supported by the SDK as well as examples and guides can be found in Nokia's Java Developer Library here:
    http://library.developer.nokia.com/

    Also, given that you cannot reproduce your error on N95, this could be a software related issue. Could you update your 6300 software by using for example Nokia Suite?

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    19

    Re: Error in Http Operation

    Hello skalogir
    Thanks for ur reply . I am using j2me polish instead of Nokia SDK because i wanna to run my application on j2me supported mobiles whether it's being Nokia , Motorola or any one . So , I can't use Nokia SDK . Also i wanna to tell u that in Micromax mobile same problem occuring . Plz replied me.
    Thanks
    AB

  8. #8
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Error in Http Operation

    Hi bpomatrix and apologies for the late reply,

    I have created a sample code based on the steps you mentioned, and I attempted multiple POST operations to a publicly available Web Service. I wasn't able to use the MicroEmulator for the compilation. I used Nokia SDK 1.0 for Java instead. I tested the code with Nokia 7390 which belongs to the same platform as Nokia 6300 (Series 40 3rd FP2) and I didn't find any issues. This is the code I used:

    Code:
    import java.io.ByteArrayOutputStream;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    
    
    public final class TempConversionRestMIDlet 
    	extends MIDlet implements Runnable {
    
    	Form mainform;
    	Display display;
    	
    	protected void destroyApp(boolean unconditional)
    			throws MIDletStateChangeException {
    		// TODO Auto-generated method stub
    	}
    
    	protected void pauseApp() {
    		
    	}
    
    	protected void startApp() 
    		throws MIDletStateChangeException {
    		mainform=new Form("Multiple POSTS");
    		display=Display.getDisplay(this);
    		display.setCurrent(mainform);
    		Thread thread=new Thread(this);
    		thread.start();
    	}
    	
    	private String connect(String targetUrl, String message) 
    	{
    		String response="";
    		HttpConnection connection = null;
    		DataInputStream inputstream = null;
    	    try
    	    {
    	    	connection = (HttpConnection) Connector.open(targetUrl, Connector.READ_WRITE);
    	    	//HTTP Request
    	        connection.setRequestMethod(HttpConnection.POST);
    	        
    	        connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    	        OutputStream fos=connection.openOutputStream();
    	        fos.write(message.getBytes());
    	        fos.flush();
    	        fos.close();
    	        // HTTP Response
    	        
    	        if (connection.getResponseCode() == HttpConnection.HTTP_OK)
    	        {	 
    	        	inputstream = connection.openDataInputStream();
    	        	int length = (int) connection.getLength();
    	        	if (length >0)
    	        	{
    	        		byte incomingData[] = new byte[length];
    	        		inputstream.read(incomingData);
    	        		response = new String(incomingData);
    	        	}
    	        	else  
    	        	{
    	        		ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
    	        		int ch;
    	        		while ((ch = inputstream.read()) != -1)
    	        		{
    	        			bytestream.write(ch);
    	        		}
    	        		response = new String(bytestream.toByteArray());
    	        		bytestream.close();	            
    	        	}	          
    	        }
    	        else
    	        {
    	        	mainform.append("Bad Respose: "+connection.getResponseCode()+" for message "+message+" \n");
    	        }
    	    }	
    	    catch(IOException error)
    	    {
    	       mainform.append("Caught IOException: " + error.getMessage()+" while sending message "+message+" \n");	       
    	    }
    	    finally
    	    {
    	    	if (inputstream!= null)
    	        {
    	          try 
    	          { 
    	            inputstream.close();
    	          }
    	          catch( Exception error)
    	          {
    	             /*log error*/
    	          }
    	        }
    	        if (connection != null)
    	        {
    	          try
    	          {
    	             connection.close();
    	          }
    	          catch( Exception error)
    	          {
    	             /*log error*/
    	          }
    	        }
    	    }
    	    return response;		
    	}
    
    	private String getTempFromXML(String xml)
    	{
    		if(xml.indexOf("<string xmlns=\"http://tempuri.org/\">")<=0) {
    			return null;
    		}
    		else {
    			int start=xml.indexOf("org/\">");
    			int end=xml.lastIndexOf('<');
    			return xml.substring(start+6,end);
    		}
    			
    			
    	}
    	public void run() {
    		String result1=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=18");
    		mainform.append(getTempFromXML(result1)+"\n");
    		
    		String result2=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=19");
    		mainform.append(getTempFromXML(result2)+"\n");
    		
    		String result3=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=20");
    		mainform.append(getTempFromXML(result3)+"\n");
    		
    		String result4=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=21");
    		mainform.append(getTempFromXML(result4)+"\n");
    		
    		String result5=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=22");
    		mainform.append(getTempFromXML(result5)+"\n");
    		
    		String result6=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=23");
    		mainform.append(getTempFromXML(result6)+"\n");
    		
    		String result7=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=24");
    		mainform.append(getTempFromXML(result7)+"\n");
    		
    		String result8=connect("http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit","Celsius=25");
    		mainform.append(getTempFromXML(result8)+"\n");
    	}
    }
    I am afraid that one executable for multiple devices is not always feasible to achieve. So in that sense you might want to consider using the Nokia SDK and provide two different versions for your application.
    As as I said, it could also be a software issue and you need to update your device. Are you using the latest software for your Nokia 6300? If you try to compile the code here with a Nokia SDK and you still experience the issue, let us know the software version of your device.
    Last edited by skalogir; 2012-02-17 at 13:39.

Similar Threads

  1. 81-Error in HTTP operation
    By Herbutinde in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2012-04-09, 16:07
  2. Error in HTTP operation
    By gorec in forum Mobile Java Networking & Messaging & Security
    Replies: 12
    Last Post: 2010-05-06, 17:53
  3. Error in HTTP operation
    By gorec in forum Series 40 & S60 Platform Feedback Archive
    Replies: 1
    Last Post: 2010-04-23, 05:47
  4. Error in HTTP operation
    By fethy in forum Mobile Java General
    Replies: 10
    Last Post: 2007-08-30, 11:53
  5. Error in HTTP operation
    By developer-che in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2007-08-13, 11:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×