Java + HTTP question

I have the following test, see code below.
I'm trying to write a test client which connects to a URL, asks for a certatin byte range, write the bytes to a file, within the same connection make another request for some more bytes and write it to a file.
Problem is I get the following exception(See Below),.
Any ideas?
Already connected
java.lang.IllegalStateException: Already connected
at java.net.URLConnection.setDoOutput(URLConnection.java:739)
at com.bitfone.server.ClientDeviceTest.testByteChunked(ClientDeviceTest.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
public void testByteChunked() {
HttpURLConnection connection = null;
try {
               URL firstUrl = new URL(upURL);
               connection = (HttpURLConnection)firstUrl.openConnection();
               connection.setRequestMethod("GET");
               connection.setDoInput(true);
               connection.setRequestProperty("Range", "bytes=100-200");
               connection.setRequestProperty("Connection", "keep-alive");
               connection.connect();
               InputStream is = new BufferedInputStream(connection.getInputStream());
               InputStreamReader input = new InputStreamReader(is);
               BufferedReader inStrm = new BufferedReader(input);
               String inputLine;
               FileWriter fw = new FileWriter(filename3);
               while ((inputLine = inStrm.readLine()) != null) {
                    fw.write(inputLine);
               connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Range", "bytes=301-300");
               inStrm.close();
               input.close();
               is.close();
               fw.flush();
               fw.close();
               connection.disconnect();
               logger.debug("~~ Leaving testByteChunked ~~");
} catch (MalformedURLException mue) {
logger.error(" MalformedURLException " + mue.getMessage());
               fail("A MalformedURLException occured, please make sure the URL is valid.");
} catch (ProtocolException pe) {
               logger.error(" ProtocolException " + pe.getMessage());
               fail("A ProtocolException occured, please make sure the method, (e.g POST), is valid.");
     } catch (IOException ioe) {
          logger.error(" IOException " + ioe.getMessage());
               fail("An IOException occured.");
}

Like this?
public void testByteRange() {
logger.debug("~~ Entering testByteRange ~~");
HttpURLConnection connection = null;
     HttpURLConnection reconnection = null;
try {
               URL firstUrl = new URL(upURL);
               connection = (HttpURLConnection)firstUrl.openConnection();
               connection.setRequestMethod("GET");
               connection.setDoInput(true);
               connection.setRequestProperty("Range", "bytes=1-10");
               connection.setRequestProperty("Connection", "keep-alive");
               connection.connect();
               InputStream is = new BufferedInputStream(connection.getInputStream());
               InputStreamReader input = new InputStreamReader(is);
               BufferedReader inStrm = new BufferedReader(input);
               String inputLine;
               FileWriter fw = new FileWriter(filename);
               while ((inputLine = inStrm.readLine()) != null) {
                    fw.write(inputLine);
               inStrm.close();
               input.close();
               is.close();
               fw.flush();
               fw.close();
               connection.disconnect();
               URL secondUrl = new URL(upURL);
               reconnection = (HttpURLConnection)secondUrl.openConnection();
               reconnection.setRequestMethod("GET");
               reconnection.setDoInput(true);
               reconnection.setRequestProperty("Range", "bytes=11-20");
               reconnection.setRequestProperty("Connection", "keep-alive");
               reconnection.connect();
               InputStream is1 = new BufferedInputStream(reconnection.getInputStream());
               InputStreamReader input1 = new InputStreamReader(is1);
               BufferedReader inStrm1 = new BufferedReader(input1);
               String inputLine1;
               FileWriter fw1 = new FileWriter(filename2);
               while ((inputLine1 = inStrm1.readLine()) != null) {
                    fw1.write(inputLine1);
               inStrm1.close();
               input1.close();
               is1.close();
               fw1.flush();
               fw1.close();
               reconnection.disconnect();
               logger.debug("~~ Leaving testByteRange ~~");
} catch (MalformedURLException mue) {
logger.error(" MalformedURLException " + mue.getMessage());
               fail("A MalformedURLException occured, please make sure the URL is valid.");
} catch (ProtocolException pe) {
               logger.error(" ProtocolException " + pe.getMessage());
               fail("A ProtocolException occured, please make sure the method, (e.g POST), is valid.");
     } catch (IOException ioe) {
          logger.error(" IOException " + ioe.getMessage());
               fail("An IOException occured.");
}

Similar Messages

  • Just simple question about java HTTP session mechanism...

    I have one simple question regarding the java HTTP Session Mechanism.
    1) Is there another alternative for the HTTP Session ? If have, what the alternative?
    2) I have been acknowledge that HTTP session is same as cookie system and others say have many different, where is the different..
    thanks

    1) You can always do your own session handling. But why bother when there is one there for you?
    2) The issue with sessions is how to identify the user from the request. Each session gets given a session id. The user has to send that session id with every request they make.
    The standard way is to use a session cookie, which only lasts as long as the browser session. The cookie with the JSESSIONID is sent with every request, thus the server can identify which session a user is in from their cookie.
    Of course you cannot assume that the browser will support cookies, so you need to encode all URLs with the method response.encodeURL(). That method puts the session id into the URL if the browser does not support cookies, or they have them switched off.

  • ABAP and Java HTTP Port same - PI 7.1 EHP1

    Hi,
    I have installed PI 7.1 EHP1 system.
    I realize that both ABAP and Java HTTP Ports are same.
    Is there any official note reg this or any info from SAP on the change.
    icm/server_port_0 = PROT=HTTP,PORT=51500,TIMEOUT=60,PROCTIMEOUT=600
    icm/HTTP/j2ee_0   = PREFIX=/,HOST=localhost,CONN=0-500,PORT=5$$00
    Thanks,
    Tanuj

    Hi,
    >>I realize that both ABAP and Java HTTP Ports are same.
    the changed happened in 7.1 already as far as I remember
    but I don't think it's documented anywhere except maybe the installation guide
    Regards,
    Michal Krawczyk

  • Java HTTP adapter in PI 7.3?

    Hi Experts,
    Anyone adivse me how to implement the java HTTP to File scenario via PI?especially explain me the HTTP sender side and how to test as well.
    thanks in advance.

    HTTP adapter now comes in AAE in Pi 7.3.  Except that there is no big difference between PI 7.3 and lower versions. You can go to component monitoring --> adapter engine --> test message and paste your payload and test. You are going to test in adapter engine level instead of abap stack (integration engine).

  • Java HTTP adapter - without Authentication

    Hello Experts,
    is it possible to set Java HTTP adapter on sender CC to request no login and password?
    I tried to look at documentation but didnt found any setting for that.
    Standard case is - when I create sender HTTP channel it requires Basic Http authorization/authentification using popup window to enter login/password.
    I`m on SAP PO 7.4
    Thank you
    vbalko

    Hi Vladimir -
    There is one blog which talks about how to disable basic authentication on soap adapter.
    I assume you can follow the same approach if you want to disable for HTTP adapter. But please note that it disables the authentication for all the channels.
    Please refer to William's reply in the below therad for more details.
    User Names and Passwords in SOAP adapter
    Path for HTTP Adapter WEB-Inf file is :
    /usr/sap/<<SID>>/DVEBMGS<<SYS_NO>>/j2ee/cluster/apps/sap.com/com.sap.aii.adapter.http.app/servlet_jsp/HttpAdapter/root/WEB-INF

  • Flash/java remoting question

    Hi,
    i'm new to flash remoting and am finding using it with java
    quite troublesome. I've also found using the FileReference class
    troublesome if you use java. my question is can you somehow tie the
    remoting functionality to the FileReference.upload method
    fucntionality??
    thanks in advance

    I will use the program with photo detector to test
    the response time of the LCD screenWhy Java?I second that. With a test like that, you want to reduce the experiment down to a single variable, in this case the lcd response time. Using a java program to feed the monitor input introduces a second variable, the response time of the program. The java program's timer may not be exact, the components may not be repainted completely quickly enough, etc. If this is just for your own amusement, maybe that doesn't matter, but if you want your results to have any reliability, you'll need a more accurate and controllable input source.

  • A java http server?

    Do any of you guys know about a (preferably open source) HTTP server? What i want to do is save a pdf form's data to disk. Adobe's javascript does not have the ability to save data to disk so the simplest(?) solution is to post the data to a http server which will write all the field data to disk. So i guess i have to modify the server's code so upon recieving a request will write the data to a file. Of course i could use JSP to do this job, but the machine in which this server is going to run is not very powerful. The closest to what i need is Blommers IT java HTTP Server Library (http://www.blommers-it.nl/libhttpd/) but it runs on java 1.4, and i have to use 1.3 (damn!). Any ideas?
    Thank you.

    well, finally i got to compile the library i told you about for jdk 1.3. Just a line of code needed to be changed! Anyway thanks for your answers

  • Difference between the abap stack http port and the java http port

    Hello,
    Is there a difference if a call a webservice in the SAP PI via the abap http port or the java http port?
    For abap it is:
    http://pi.host.de:8035/sap/xi/engine?type=entry
    For java:
    http://pi.host.de:53500/XISOAPAdapter/MessageServlet?
    Is it technical the same?
    Which is your prefered port and why?
    Thank you
    Best regards,
    Nils Kloth

    Hi,
    I found the blog
    Using the SOAP inbound channel of the Integration Engine
    So the main differences are:
    Advantage
    When you send SOAP messages directly to the Integration Server, you reduce the message load on the adapter engine. This can improve the performance.
    Restrictions
    The SOAP inbound channel of the Integration Server does not support attachments. SOAP messages with content type "multipart" are rejected.
    Nils

  • Can I post here(Acrobat Windows) Java Script questions here?

    Hello
    Can I post here(Acrobat Windows) Java Script questions here? If not, wht is the correct forum?
    THank you

    Back up and down to Acrobat Scripting. Bot Windows and MacIntosh Acrobat versions use the same JavaScript.
    If you are using LIVECYCLE DESIGNER use their forums. The JavaScript syntax and objects are different in LIVECYCLE DESIGNER!

  • Simple Java Sound Question...

    Can I draw waveforms while capturing data? If yes, how. If no, why.
    Thanks. I need the answer ASAP, please help.

    Hi nfactorial,
    Can I draw waveforms while capturing data?If you would like to do that in Java you would need to know about how to use the Java language in general and especially about the Java Sound and Java2D APIs.
    If yes, how.It would be too much to explain to answer such a general question. A general answer is, you need to use the Java Sound API to capture the data for which a waveform should be drawn. The Sound API delivers data as a stream of bytes typically encoded in pulse coded modulation (PCM) format. The data stream has digital samples each representing a level of sound pressure for a certain point in time. The stream of samples in the amplitude/time domain need to be transformed to a spectrum of samples in the amplitude/frequency domain, i.e. a number of PCM samples need to be mapped to the frequencies that should be displayed. This is done with the fast fourier transformation algorithm. Each set of amplitude/frequency values can then be displayed as a waveform by using some line drawing logic. The entire process would need to run constantly, i.e. as bytes are received from the sound data stream transformation and drawing is triggered.
    Related readings:
    Java Tutorial
    http://java.sun.com/docs/books/tutorial/
    Java Sound Documentation
    http://java.sun.com/j2se/1.5.0/docs/guide/sound/index.html
    Java Sound API Programmer's Guide
    http://java.sun.com/j2se/1.5.0/docs/guide/sound/programmer_guide/contents.html
    Java Sound Resources
    http.//www.jsresources.org
    Java 2D Graphics Tutorial
    http://java.sun.com/docs/books/tutorial/2d/index.html
    Wikipedia on fast fourier transformation
    http://en.wikipedia.org/wiki/Fast_fourier_transform
    HTH
    Ulrich

  • Simple java pgm - question

    Hallo,
    to the following pgm I had question:
    static void printPrimes (int max) (= wavy bracket;
    boolean(should be angular brackets) sieve = new booolean (angular br max+1
    angular br)
    int i,j;
    for (i=2; i = max;i++)sieve(angluarbr i angular br)= true
    i= 2
    while (i= <= max;) (=wavy bracket Out.println (i+ " "); // is prime
    for (j=i; j <= j+i) sieve(angular br j angularb.) = false;
    while (i <= maxAmpersandAmpersand !sieve (angular br angular br)I++;
    ) wavy br ) wavy br.
    I hope this is still kind of readable.
    Q's are:
    after the first "for" there is a new i=2, which seems to staty at 2 all the time; the following while does not change this value ( the beginning for i++ does not change this) and so seems to print 2 at all times (??)
    then the inner loop seems to count up all the doubbles of the new prime number and thrwoes it out as false at the end of it;
    the i values (increased with i++ seemsto refere at all times to the unit numbers and only indirect to the un it values, which are written/ assigned to it (??)
    I seem to wonder how the pgm can print out anythings else the 2's.
    I would appreciate any help to that.
    ml
    griz

    I hope this is still kind of readable.No, it's not. http://forum.java.sun.com/help.jspa?sec=formatting
    Why are you omitting the braces and brackets? And why don't you type "program"? Aren't we worth the additional time it takes?
    Q's are:
    after the first "for" there is a new i=2, which
    seems to staty at 2 all the time; the following
    while does not change this value Why should it? You don't tell it to.
    ( the beginning for
    i++ does not change this)It does. It just gets re-set to 2 after the for loop-
    and so seems to print 2 at
    all times (??)Yeah. What else?
    then the inner loop seems to count up all the
    doubbles of the new prime number and thrwoes it out
    as false at the end of it; That part is definitely unreadable.

  • Java certification question

    I have learning material for two modules:
    (a) Sun Java 2 Developer SCJD CX-310-252A/CX-310-027, and
    (b) Java 2 5.0 Programmer Certification 310-055.
    I know that these kind of exams were organized by the Sun Microsystems, Inc., which was bought by Oracle in 2010. So my questions are:
    1. What are the exact names and numbers for the two exams above, that Oracle gave them? On the Oracle website
    http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=42&p_org_id=28&lang=US
    I was only able to find the available Java exams starting with "1Z0" or "1Z1".
    2. Are the old (Sun) and new (Oracle) exams exactly the same, i.e., is the material that I have is sufficient to pass the new exams?
    Thank you in advance.

    Thanks for a reply!
    So, if I wanted to book exams, what are Oracle equivalents of those two modules? Searching in the list of available exams, it looks like
    (a) for Sun Java 2 Developer SCJD CX-310-252A/CX-310-027 -
    Java Standard Edition 6 Developer Certified Master Assignment (Step 1 of 2) 1Z0-855
    and Java Standard Edition 6 Developer Certified Master Essay Exam (Step 2 of 2) 1Z0-856
    (b) and for Java 2 5.0 Programmer Certification 310-055 -
    Java Standard Edition 5 Programmer Certified Professional Exam 1Z0-853.
    Is that correct?
    Also, can it be, that passing an exam is not enough to get a certification? From what I understand from searching, it is also necessary to attend an "instructor-led in-class" course, which cost around £1500 - is it true? Thanks.

  • Java server question for sockets

    Hello,
    I have a C/C++ server which works fine to communicate to Flash, but I want to use Java + Eclipse over text file editing and makefile headaches of C/C++. This will be a big project that requires organization of code, garbage collection, and nice arrays so Java is a smart choice over C/C++. I'm just hung up trying to get an echo server...
    I found this echo server code: http://pastebin.com/thiQtEz5
    It will receive data coming in, but when it sends echo data out, I don't read it in AS3(Flash). If I use a C/C++ echo server, I get data in and echo data out so I can read it in AS3(Flash).
    It seems like most Java examples use similar code, and I find them reading in, but not communicating from echo out to AS3(Flash) read in.
    If anyone has any suggestions, I'm interested. I'm new to Java, but I bet I can do cool things with it if I could get sockets working.
    ,James
    PS if it helps, I also cannot use my C/C++ echo client to send data to the Java echo server... It simply doesn't read data if there is any content. If I send a null string, it understands a null string came in though.
    PSS: Is this the right forum for AS3 questions, I couldn't find an AS3 forum

    Hi,
    It seems that you are trying to display JSP pages. All Application servers that I am aware of convert JSP pages to a servlet and use that servlet to generate a Html page. Therefore it seems that the answer to your question is Yes!

  • Java compiling question

    Hi . I have one class file for an IRC client , the compilation works fine...
    javac -O <filename>.java
    jar cvf <filename>.jar <filename>.class
    jarsigner -keystore suresh.store <filename>.jar sureshcert
    But now I want to compile it so it would work with Microsoft VM too on my web browser . What tools should I use or what are the correct commands on compilation (I'm using Java 2 SDK 1.4.2_05)?

    Hi,
    This forum is exclusively for the Sun Java Studio Creator related discussions. Could you please post your question in the appropriate forum.
    http://forum.java.sun.com/forum.jspa?forumID=31
    Thanks,
    RK.

  • SMS sending from Java Application - Questions & Help

    Hi all.
    I�ld need to develop a Java App. (migth be a descktop or a Servlet based web app.) wich must send around 3000 SMS in a massive way. My problem is basically the restrictions to obtain a gateway "short code/number" from a SMSC provider (the providers in Argentina are very monopolics and prevents such kind of servicess) so, it is very difficult to send SMS messages using http connections wich is the best way from the java perspective, I think.
    Could somebody tell me about alternative ways to solve this limitation?. Any additional suggest about learning materials will be appreciate also.
    Regards.

    Hi, I�m here again.......
    Nobody interested in help me?. I think my question isn�t pointed to a J2ME Gur�. It�s only for Java people interested in help Java people.......Please!!!

Maybe you are looking for

  • Problem with checkbox and "if" & "else if" statement

    Hi, i have got something like this: if (this.rawValue=="0" ){   app.alert("0");   this.resolveNode("Circle1").presence = "hidden";   this.resolveNode("cross").presence = "visible"; else if (this.rawValue=="1"){   app.alert("1");   this.resolveNode("C

  • IPhone Setting in Compressor 2

    I am wanting to compress some video for the iPhone with compressor two, but the presets are only in 3. I was wondering if someon knew where I could get a preset (DL) or could share the settings so I can output the best video for the iPhone. Also I wa

  • EDI for Bill Of Lading

    Hi experts. I would be implementing EDI for BOL and BOL Acknowledgement. What would be the Idoc type and Message type that I should use for these documents? Is this something do-able?

  • Powershell and Taskscheduler

    Hello We are using Sharepoint 2013 and Windows 2008R2. When running a powershell script from a batch direct from the command line the output is redirected to a file. If this is done through the task scheduler the output is not redirected to the file.

  • Prime Infrastructure Device Configuration

    I recently installed Prime Infrastructure to replace LMS and NCS, but I've encountered an issue with changing device settings.   I had a controller set up to pull configs with no issue, but I had to change the IP to move it to a different VLAN ("it"