URL and HttpURLConnection need to be synchronized

Hi everybody,
I'm developing a class that allows to send and to receive messages using a HttpURLConnection.
The main question is :
- I'm not sure that every time I call the method "openConnection" of an URL object, I'll get a new instance of a HttpURLConnection ?
I'll try to illustrate my problem with the next pseudo code ( I think the question I've written above arises again in the remarks of "Question1" and "Question2" of the constructor of MyURLConnection ):
* Class that tests the class I'm developing
public class ExempleURL {
String myURL = "http://myserver.aaaa.bbbb/dir1/servlet/my_servlet/"
/** This method creates a new "MyURLConnection" object with the URL "myURL". */
public StringBuffer sendMessage(StringBuffer message) throws Exception {
MyURLConnection urlCon = new MyURLConnection( myURL );
urlCon.write(message);
return urlCon.read();
* This method sends an array of "messages" and returns an array of responses. */
public StringBuffer[] testURL(StringBuffer [] arrM) throws Exception {
StringBuffer[] arrayOfResponses = new StringBuffer[ arrM.length ];
for(int i = 0; i < arrM; i++) {
arrayOfResponses[i] = sendMessage( arrM[i] );
/** The class I'm developing : this class encapsules the use of java.net.URL and
* java.net.HttpURLConnection.*/
public class MyURLConnection {
// properties : URL url; HttpURLConnection httpUrlConnection; and so on ...
/** constructor */
public MyURLConnection (String strUrl) throws MalformedURLException,IOException,Exception {
super();
// Question 1) It is creating a new instance of a URL ?
this.url = new URL(myURL);
// Question 2) It is creating a new instance of a HttpURLConnection ?
this.httpUrlConnection = (HttpURLConnection)url.openConnection();
// preparing the HttpURLConnection property.
this.httpUrlConnection.setAllowUserInteraction(true);
this.httpUrlConnection.setDoOutput(true);
this.httpUrlConnection.setDoInput(true);
this.httpUrlConnection.setDefaultUseCaches(false);
this.httpUrlConnection.setRequestMethod(this.POST);
/** This method sends the message. */
public void write(StringBuffer message) throws UnsupportedEncodingException,IOException,Exception {
OutputStreamWriter out;
out = new OutputStreamWriter( new BufferedOutputStream(
this.httpUrlConnection.getOutputStream(),
message.length()
"ASCII");
// sending the message
out.write( message.toString() );
// I'm not sure it's necessary but it works.
out.flush();
// We close the "OutputStreamWriter".
out.close();
/** This method reads the response. */
public StringBuffer read() throws IOException {
StringBuffer response = new StringBuffer("");
BufferedReader in = new BufferedReader(
new InputStreamReader(
this.httpUrlConnection.getInputStream()));
String aux;
int i = 0;
while ((aux = in.readLine()) != null) {
response.append( aux );
i++;
in.close();
return response;
} /* ****** End of pseudo-code. ****** /
Well, I think there is other question :
- Should I define the methods "write" and "read" of the MyURLConnection class as "synchronized" ?
I'm sorry, I've written a very large text but I thought this was the best way for explaining the problem. Thanks a lot !
Jose Luis Alvarez Casas

Thank you for your quick answers :)
There's only a question more ... in the pseudo-code that I showed in my first message, there is not any pause between the call of the method "write" and the method "read". I mean : should the code wait the method "write" has sent the message before it calls the method "read" ? Or by other hand, it isn't necessary because a suitable exception will arise ?
Thanks again,
Jose Luis
P.D. : I suppose that you have already got the 8 Duke Dollars :)

Similar Messages

  • Send To Others button creates an http URL and we need it to be https

    I know this is the Content Services forum, but I couldn't find a forum for Collab. Anyone know where the "Send to Others" function in Collab gets it's URL to invite someone to join a communinty? When we click the "Send To Others" button in Collab, we get a url that begins with http and we need it to begin with https to have it work properly.

    Thank you for your quick answers :)
    There's only a question more ... in the pseudo-code that I showed in my first message, there is not any pause between the call of the method "write" and the method "read". I mean : should the code wait the method "write" has sent the message before it calls the method "read" ? Or by other hand, it isn't necessary because a suitable exception will arise ?
    Thanks again,
    Jose Luis
    P.D. : I suppose that you have already got the 8 Duke Dollars :)

  • Problem in reading a PDF output file using URL and HttpURLConnection class

    When i am reading a PDF file generated from a given URL, I am getting the response code as 200 but the content length is -1. Can anyone tell me what will be the problem and solution to this.

    form the api of the URLConnection
    the content length of the resource that this connection's URL references, or -1 if the content length is not known.
    Can anyone tell me what will be the problem and solution to this.The problem is that the server does not send the content length.
    Solution is to read the whole stream until -1 is returned.
    andi

  • Cannot setup site after previously deleting it - says URL and records need to be removed but I thought I had!

    I am using adobe Muse and publishing to BC.
    I had set up the site wrongly on BC so had deleted it and the records.
    When I go to create it again it says that:
    "Domain already exists. Please delete all records associated with this domain before re-adding it."
    Any help would be gratefully appreciated.

    Hi,
    Please reach out to the support team or submit a ticket, and they will assist you further. Or let me know the domain and I will check it.

  • What urls and ports need to be allowed through our corporate proxy firewall?

    We have been paying for Creative Cloud for teams for over a month, but are unable to install any applications. Our 'Ironport' proxy keeps blocking the downloads.
    We have asked our security team to allow the following urls but to no avail!!
    ccmdl.adobe.com:80
    swupmf.adobe.com:80
    swupdl.adobe.com:80
    Are there any other addresses or ports that should be allowed?
    Thanks.

    Hi,
    For the Creative cloud you should put the following port combinations in the whitelist
    cmdls.adobe.com:443
    im s-na1.adobelogin.com:443
    na1r.services.adobe.com:443
    prod-rel-ffc-ccm.oobesaas.adobe.com:443
    lm .licenses.adobe.com :443
    You can also see the craetive cloud deployment guide as well for more information. Here is the link
    http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/creativesuite/pdfs/CC T_IT_Deployment_Guide.pdf
    Thanks
    Kapil

  • What is a url and why is it needed to use photoshop

    What is a URL and why do I need it to use photoshop on my computer?

    what problem are you seeing?

  • Help needed to figure out URL and username for the LDAP server

    Given that LDAP directory parameters as follows, how can i identify the exact parameters to be used in my LDAP service access Java code. Im using JNDI to access a LDAP server given by an Ip address (say, 10.1.1.20) and the port number (say, 389)
    Given: -D "cn=mycn,ou=mystaff,o=myorg,dc=test,dc=my,dc=org" -w secret
    Heres my sample Java code
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "<URL>");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "<PRINCIPAL>");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    ctx = new InitialDirContext(env);
    SearchControls controls = new SearchControls();
    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    results = ctx.search("ou=mystaff,o=myorg", null);Could any one please help me to recognize what will be the values to be comes to URL, and PRINCIPAL , so that i can search all the objects inside "ou"
    Note: Actually i tried several times, bt i was getting "Invalid Credentials" exception.. i doubt that is because the URL or the user name i gave was not syntactically correct. Thats y i need to verify with you all.
    Thanks in advance
    Saj

    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "<URL>");env.put(Context.PROVIDER_URL, "ldap://10.1.1.20:389");
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, "<PRINCIPAL>");env.put(Context.SECURITY_PRINCIPAL, "cn=mycn,ou=mystaff,o=myorg,dc=test,dc=my,dc=org");
    env.put(Context.SECURITY_CREDENTIALS, "secret");
    ctx = new InitialDirContext(env);
    SearchControls controls = new SearchControls();
    controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    results = ctx.search("ou=mystaff,o=myorg", null);

  • Need to keep track of URL and a count variable

    Can anyone suggest the best way to keep track of a URL and a count variable associated with each URL. I have started using 2 List objects. When I add a URL I also add a 1 in the count List Object. I am using List Objects because I must be able to sort them and search through them.
    Can anyone verify that I am going about this the correct way?
    Thanks

    I would probably use a TreeMap that referenced the counter.

  • URL,URLConnection,HttpURLConnection &&Session

    Hi,all
    I want to access a web page by URL/URLConnection/HttpURLConnection
    the page need a login user,it check the Session,if the session is null,then it redirect to the login page
    Now I have the user ID and Password ,and I can complete my login by URL Class
    but when I access the wanted page after I login,it's still return that the session is not set.
    below is the Code Segment,thanx in advance
    String urlStr = "http://buyc:8080/ecommerce/oa/login.jsp?txtUsername=sh001&txtPwd=111111&role=storeman";
    URL url = new URL(urlStr);
    HttpURLConnection hurlc =(HttpURLConnection) url.openConnection();
    hurlc.setFollowRedirects(true);
    hurlc.setInstanceFollowRedirects(true);
    hurlc.setUseCaches(true);
    hurlc.connect();//if check login successfully in login.jsp,it will redirect to a check page.
    InputStream is=hurlc.getInputStream();//
    byte tmpbyte[]=new byte[is.available()];
    int num=is.read(tmpbyte);
    String result=new String(tmpbyte);
    System.out.println("the " + num + ":" + result);

    IIRC, you use the UrlConnection's methods getHeaderField and getHeaderFields to get the cookies, and then setRequestProperty to set the cookies on subsequent connections. These methods are inherited by HttpUrlConnection.
    There may be a library out there to make this stuff easier, but I don't think it's in the standard libraries.

  • How do I get connected to a server on my network via an IP address?  When I try to open in a URL and login as a registered user with proper login it errors out saying there was a problem with connecting to the server?

    I am new to Mac...How do I get connected to a server on my network via a hyper link IP address path?  When I try to open in a URL and login as a registered user with proper login it errors out saying there was a problem with connecting to the server?

    Some of the following is going to use some technical terms — this area is inherently somewhat technical. 
    If you don't understand some part of the following reply, please ask.
    Is this your own OS X Server system on your own network, or is this some other server within some larger organization? 
    You're posting this in the OS X Server forum, which is a software package that allows OS X systems to provide web-based and many other services; to become servers.
    If it's your OS X Server on your network, then the network and DNS configurations are suspect, or the server is somehow malfunctioning or misconfigured.   This is unfortunately fairly common, as some folks do try to avoid setting up DNS services.
    If it's a larger organization and somebody else is managing the server and the network, then you'll probably need to contact the IT folks for assistance; to learn the network setup and DNS requirements, and if there's a problem with the server itself.
    The basic web URL "hyper link IP address path" — without using DNS — usually looks something the following, where you'll need to replace 10.20.30.40 with the IP address of your server:
    http://10.20.30.40
    UptimeJeff has posted a URL that specifies the AFP file system; an OS X file share.  That's used if you're connecting to an Apple storage service somewhere on your network.  You might alternatively need to specify smb://10.20.30.40 or such, if it's a Windows file server.  (There can be additional requirements for connecting to Windows Server systems, too.)
    If there's local IT staff available here, please contact them for assistance.  If these are your own local systems and your own local OS X Server system, then some information on the server will be needed.  (If you're on a NAT'd network, you'll also need to get DNS services configured and working on your local OS X Server system and your network — you'll not be able to skip this step and reference ISP DNS servers here — or things can and usually will get weird.)

  • How to add URLs and/or bookmarks to a new toolbar

    I can create a new toolbar and drag buttons from/to the 'Customize Toolbar' dialog, and that new toolbar will be visible.
    But I want to use that new toolbar for extra favorite URLs and/or bookmarks. That does not seem to be allowed.
    I _can_ drag the 'Bookmark toolbar items' icon from the Bookmarks toolbar, but that does not solve my problem, now does it?

    There is one "Bookmarks Toolbar Items" container available for storing bookmarks, and that is where bookmarks are placed if you want them on a Toolbar. I have never seen an add-on that changes that by adding a 2nd "Bookmarks Toolbar Items" container.
    I understand that you want to reduce the toolbar area at the top of the browser window, because I have been doing that for almost as long as I have been using Firefox ''(since 2002 when it was called Phoenix)''. The first thing I do is to get rid of or '''reduce the Menu Bar down to one button''' using one of the various Compact Menu extensions that have been available over the years. This is the one I currently use.<br />
    https://addons.mozilla.org/en-US/firefox/addon/compact-menu-2/ <br />
    This extension hides the Menu Bar and places a button on the left side of the Navigation Bar upon installation. Click that blue globe button or hit the '''''Alt''''' key and the the Menubar Items appear in a drop-down menu. You can even drag that small button into the [https://support.mozilla.com/en-US/kb/How+to+customize+the+toolbar Customize Palette] and use the '''''Alt''''' key to open the Menubar Items drop-down. <br />Hidden from view, but easily accessible when you need to use a Menubar Item.

  • SOAP Receiver adapter target url and method details

    Hi Friends,
    I am working on file to SOAP interface.
    I know using SOAP receiver adapter , we need to have target URL and action.
    Here, how client need to give target url and action as they are not aware of these things..please suggest.
    Also if we are generating inbound service interface,how they have to handle this from their end.
    Thanks
    Kishore

    Get the WSDL file from ur Third party client and u can use the WSDL file as an External definition in PI and WSDL file also has WSDL URL which u can use in SOAP receiver adapter.
    For INbound SOAP case-
    Generate the WSDL file in XI and give that WSDL file to ur third party client which will send the data using the WSDL URL mentioned in the file.
    refer below blog for understanding in detail:-
    How to use SOAP adapter:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40611dd6-e66e-2910-f383-e80fb44f9cd4
    chirag

  • Open a url and view the files with it's timestamp

    Hi guys,
    I need to create a flow service in SAP BC to connect to a server by it's url and display it's files with it's timestamps.
    I have never done this b4, and usinf SAP BC makes it harder for me.. Mostly I need to know how to access the server and view the files with their timestamp.
    Any guidance for me will be much appreciated.
    Thank u.

    Yes,
    It's like this. I will connect to an FTP server. Then I need to view the files it the server or folder i specify with their respective timestamps.
    I am using SAP BC and it's webMethods to create the JAVA flow service. I am only now familiarising myself with SAP BC.
    Moreover I have never done a coding to access a server and list it's file. I can do it o view in a local directory using JFrame aand stuff... But SAP BC doesn't support those..
    So If u can give me some guidelines to follow.. i would appreciate it.
    Here's what i have come up with so far
    public static final void ReadFileServer( IData pipeline ) throws ServiceException
    //define input variables
         IDataCursor idcPipeline = pipeline.getCursor();
         String path = null;
         path = (String)idcPipeline.getValue();
         // Check if url is in the pipeline
         if (idcPipeline.first("path"))
              File dir = new File(path);
              String filesFound[]=dir.list();
              long [] age;
              age = new long[filesFound.length];
              for (int i = 0; i < filesFound.length; i++)
                   age = new File(filesFound).lastModified();
              String temp = "";
              for (int i = 0; i < age.length - 1; i++)
                   for(int k = i+1; k < age.length ; k++)
                        if (age > age [k])
                        temp = filesFound;
                        filesFound = filesFound[k];
                        filesFound[k] = temp;
              for (int i = 0; i < filesFound.length; i++)
              //get url out of the pipeline
              path = (String)idcPipeline.getValue();
              //insert the FILES into the pipeline
              idcPipeline.insertAfter("filesFound", filesFound);
              idcPipeline.insertAfter("age", age);
         //If it is not in the pipeline ERROR
         else
         age = "False";
         idcPipeline.insertAfter("path", path);
         //insert the successFlag into the pipeline
         idcPipeline.insertAfter("age", age);
         //Always destroy cursors that you created
         idcPipeline.destroy();
    return;
    }

  • The value should be set for Base image URL and Image file directory

    Hi experts
    Now customer has the following issue.
    XML Publisher concurrent request, using RTF layout template with LOGO, does not generate the LOGO for Excel output.
    but in output formats PDF, it is shown normally.
    from the debug log, we can found the following error message
    ======
    [051812_054716051][][ERROR] Could not create an image. Set html-image-dir and html-image-base-uri correctly.
    ======
    so I tell the customer to do the following action plan.
    1. in XML Publisher Administrator resp > Administration expand the HTML Output section.
    2a. enter a value for 'Base image URI'
    2b. enter a value for 'Image file directory'
    Customer set the value as following and retest this issue,but he found the issue is not solved.
    Base image URI: /u01/r12/ebssnd/apps/apps_st/comn/java/classes/oracle/apps/media/XXSLI_SONY_LIFE_LOGO.gif
    Image file directory: /u01/r12/ebssnd/apps/apps_st/comn/java/classes/oracle/apps/media
    I verified 'Base image URI' and 'Image file directory' settings:
    1) Change output type to HTML.
    2) Click the Preview.
    but the image is correctly displayed on HTML, so I think the issue is caused by user's uncorrectly setting of the base image URL and/or image file directory
    but could anyone give me some advice on which value should be set for Base image URL and Image file directory
    Regards
    shuangfei

    First thing to do is to edit the post and use some tags to format the code as it is unreadable and too much!
    Read the FAQ (https://forums.oracle.com/forums/help.jspa) to find out how to do this.
    Next we need to know the jdev version you are using!
    As the code is generated I would first try to generate it again after the db change.
    Timo

  • Knowledge sharing and suggestion needed on ABAP Web dynpro.. Kindly reply..

    Hi SAP experts,
    I just want to put you all on my approach for one of the developments and needed some inputs from you great people.
    First of all Thanks for taking your time.
    I am on CRM 5.0 integrated to PCUI portal. I need to develop an ABAP Webdynpro which has to be intergrated to portal as an iView.
    Currently there is a WDA1, which displays the Service Confirmation number with a link. Once the link is clicked I have to call a different WDA2.
    The WDA2 has the following sections --
    Section one - header details of Service conf-- all input fields
    Section two - item details ( table with more than one record) - need to allow to add new items or delete items
    Section three -- item level details of the item selected in section two - all input fields
    Section four -- item table( with some data) - Here at runtime on a condition i have to display item table 1 or item table 2, dynamically i have to decide which table to display basd on Serive conf.
    When I select a new record in Section two, section three and four should change based on the item i selected on sectoin two.
    My questions ---
    1. How can i pass the Service conf number from WDA1 to WDA2, how to get the Service conf in WDA2.
        I m trying to use CALL METHOD l_portal->navigate_absolute, with URL and value. But i dont know how   
        to read this value in WDA2.
    2. I gone through this VERY GOOD Doc on creating subnodes.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/media/uuid/70d9d4b6-5c9e-2a10-dcb2-e396fddeb6e8
    Can i acheive my task by this or do i need to create new context nodes for each section and then bind_table or bind_structure ?
    3. For section four, how can i at runtime based on one IF condition decide, which table( UI element with records ) to display on view ?
    I hope this will help someone atleast on the business concept and WDA level, and with your valuable inputs I can clear my confusion on WDA.
    Kindly take some time to give ur suggestions.
    I appreciate you all, and thanks again.
    Niraja

    sadf

Maybe you are looking for

  • How can I rotate a shape around a centre point in Illustrator?

    Hi all, I'm trying to make a pattern in Illustrator and I need to repeat a shape around a centre point, a bit like placing petals around the stigma of a flower. I can do it in Photoshop by moving the centre point of the bounding box to where I want t

  • Is this bad?

    Just going thru some code and I found this line (real names removed to protect the innocent). Suffice to say that setCount() takes an int and someList is a java.util.List. setCount(someList.toArray().length); I'm trying beyond hope to believe that th

  • Payee Bank Account Details

    Hi Experts, I am developing a report of remittance advice in R12. in that i need payee bank account details(payee bank account number, Payee branch number). in front end navigation was payables resp-->suppliers-->entry in supplers query i queried for

  • "change output" feature in output type configuration

    Hi   I am trying to find a way of automatically triggering repeat output on change of delivery date in order.    In output type configuration-general data there is a are for change output the F1 helps reada like this "..........The routine in the pro

  • Extra empty lines in java code

    Hello I am experiencing a strange behaviour of SJSC 2.1 (Windows XP) after insttalling the last performance fix When manipulating components in a page, the .java file gets corrupted. An extra empty line is including after each line. Code still compil