Instantiating HttpURLConnection class
Hi,
I need an instance of "HttpURLConnection" class, but it's abstract and I can't instantiate it. Could anyone please tell me how I can get an instance of it? (I need to send some information via post method to some URL. Another question is that after connecting to a URL (forgive my wording!) I need to set some name value pairs in the Header, how can I do that?
Thanks a lot
you can use below method:
new java.net.URL("your url").openConnection();
Similar Messages
-
Reg: help on instantiation of class in workflow task
Hi Geeks,
I am trying to use class for Purchase order though standard workflow is available with BO. As per the requirement the triggering event is same as in the standard workflow with BO. Once the workfow is triggered ,The data is pulled to class from BO and custom release step is defined for release in class .
I face problem with the instantiation of class in workflow task while passed the po value and defined binding for the same after reading the document posted by jocelyn dart regarding this as follows :[www. wiki.sdn.sap.com/.../UsingABAPOOmethodsinWorkflowTasks |www. wiki.sdn.sap.com/.../UsingABAPOOmethodsinWorkflowTasks ]
I am getting error as " Formal parameter " po number " not defined.Please Advice.
Regards,
Kumar.Hi,
I checked the same still no luck. I checked approx all combination.
First I created a SOA-SAR file(jar file) , I extracted it and checked all jar files were there. orabpel.jar and bpm-services.jar and log4j jar. when i deployed that jar file. but it was not working
then I put this in weblogic sever lib. it not worked.
please tell me some points -
We need to get our servers up to date with the latest ColdFusion hotfixes in order to pass our security scans and policies. We have been following the Adobe instructions for installing the hotfixes, but we’re getting the same errors each time. The CF 8 hotfix 2 works fine, but once we install hotfix 3 and/or hotfix 4, we get the following errors:
"Object Instantiation Exception.Class not found: coldfusion.security.ESAPIUtils The specific sequence of files included or processed is: C:\ColdFusion\wwwroot\WEB-INF\exception\java\lang\Exception.cfm, line: 12 "
coldfusion.runtime.java.JavaObjectClassNotFoundException:
We have dozens of servers running Windows XP, Netscape Enterprise Server 6.1 (I know, don’t laugh), ColdFusion 8,0,1,195765, and Java Version 1.6.0_04. Just about the only good thing about running XP on our servers is that it matches our development boxes, so we have almost mirrored environments for dev, test, and production. We do NOT have the CF install with the J2EE configuration.
The crazy thing is, on tech note 51180 (http://kb2.adobe.com/cps/511/cpsid_51180.html), it says that the fix for bug # 71787 (Fix for "Object Instantiation Exception" thrown when calling a Java object constructor or method with a null argument under JDK 1.6.) was added in cumulative hotfix 2. However we don’t see this problem until we go to hotfix 3 (or 4).
I’ve also been reading that other people had this same problem, and that the CF 8 hotfix 3 was not compatible with certain versions of JDK, then when you read the Adobe site for CF 8.0.1 hotfix 3, it says “Added the updated cumulative hotfix to make it compatible with jdk 1.4.x, 1.5.x and 1.6.x.”, so that makes me think that Adobe was supposed to have fixed this CF 8.0.1 hotfix 3 JDK incompatability issue - but unfortunately it's still not working for us. We have followed the instructions for removing the jar files and starting/restarting the CF server as directed, we’ve tried this 5-6 times, and still no luck.
Recommendations? Seems like this is a ColdFusion bug to me – one that says is fixed on the Adobe site, but is not fixed in our environment. Please advise, thanks.For what it's worth, we had an MXUnit user describe a similar, though not identical, problem after installing the latest hotfixes. In his case, he's getting "NoSuchMethodExceptions".
-
Can use HttpUrlConnection class to connect once to server, then inside loop
Hello there!
I want to ask if can I use an HttpUrlConnection class to connect once to server and then inside a loop and with the same instance send many request to a web service?
What about "persistence connections"?
Regards,
MarcelloIt already uses HTTP 1.1 persistent connections and a TCP connection pool behind the scenes. There is nothing to be gained from trying to re-implement that yourself and you won't succeed. HttpURLConnection can be used for exactly one request and one response. The underlying TCP connection is reused until you call disconnect(), but there's not much control you can exert over that.
-
Instantiating a class within itself ?!
Hi guys,I just started playing around with Java, trying to understand the core base of this language.
I have created a simple class and just-for-try I instantiated this class from inside itself.
public class PrivAndPublic{
PrivAndPublic o = new PrivAndPublic();
}//end of class
It doesn't give me any compiling error!
Doesn't it sound strange?!
I cannot understand how is it possible and it really seems a bug to me.
Thanks for any help!What Darcia wrote make me suppose that a class is totally created with the first line of a java file (i.e. public class PrivAndPublic{ )and initialized by the constructor (which, if omitted, comes by default with no arguments)...after all this, the class can be instantiated many times I want from inside the class itself.
(I was thinking the class needed to reach the matching close curly brace to be possible to instantiate it)
But as phyzome said I have to be careful to do not make the object call the method which I put the object in, otherwise I will cause an infinite loop...as I did try ;)
Thanx guys, see you. -
WebLogic 6.0 HttpURLConnection class won't let me connect to a proxy
I am getting a '400' error (which means the server cannot understand
the request, I believe) when I attempt to connect to a proxy server
to download the auto-configuration (.pac) file - don't ask why,
it's a long story.
My code works fine when I run it outside WebLogic from a vanilla
Java class (using Sun's standard URLConnection class), but as soon
as I put it inside a servlet in WebLogic 6.0, and it's wrapped
by the weblogic.net.http.HttpURLConnection class, I get the following
stack trace:
java.io.FileNotFoundException: Response: '400' for url: 'http://corporate-proxy-server-name:8080'
at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:351)
at com.csfb.gws.proxy.ProxyFinder.getProxyString(ProxyFinder.java:82)
at com.csfb.gws.proxy.ProxyFinder.getProxiesForIpAddress(ProxyFinder.java:46)
at com.csfb.gws.proxy.test.TestProxyFinderServlet.doPost(TestProxyFinderServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:208)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:1127)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1529)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
Does anyone have any idea why this is happening? It certainly seems
as though the WebLogic wrapper class is not working the same as
Sun's standard HttpURLConnection.
Any advice would be greatly appreciated.
Cheers
Dave
You can use something like this:
URLStreamHandler handler = new sun.net.www.protocol.http.Handler();
URL url = new URL(null, "http://yourserver", handler);
to use Sun's handler instead of WebLogic's. (you will have to edit weblogic.policy
accordingly to allow your code to specify handler).
Dave Blumenfeld <[email protected]> wrote:
> WebLogic Server automatically wraps its own HttpURLConnection class
> around the Sun one. I haven't explicitly requested that it do so.
> Don't know if I have any control over that.
> "Xiang Rao" <[email protected]> wrote:
>>
>>Why not just use Sun's HttpURLConnection if it works fine
>>for you?
>>The only thing you need to do is adding java.net to any
>>related
>>variable declaration such as java.net.HttpURLConnection
>>= (java.net.HttpURLConnection)url.openConnection().
>>
>>
>>
>>"Dave Blumenfeld" <[email protected]> wrote:
>>>
>>>I am getting a '400' error (which means the server cannot
>>>understand
>>>the request, I believe) when I attempt to connect to
>>a
>>>proxy server
>>>to download the auto-configuration (.pac) file - don't
>>>ask why,
>>>it's a long story.
>>>
>>>My code works fine when I run it outside WebLogic from
>>>a vanilla
>>>Java class (using Sun's standard URLConnection class),
>>>but as soon
>>>as I put it inside a servlet in WebLogic 6.0, and it's
>>>wrapped
>>>by the weblogic.net.http.HttpURLConnection class, I get
>>>the following
>>>stack trace:
>>>
>>>java.io.FileNotFoundException: Response: '400' for url:
>>>'http://corporate-proxy-server-name:8080'
>>>
>>> at weblogic.net.http.HttpURLConnection.getInputStream(HttpURLConnection.java:351)
>>>
>>> at com.csfb.gws.proxy.ProxyFinder.getProxyString(ProxyFinder.java:82)
>>>
>>> at com.csfb.gws.proxy.ProxyFinder.getProxiesForIpAddress(ProxyFinder.java:46)
>>>
>>> at com.csfb.gws.proxy.test.TestProxyFinderServlet.doPost(TestProxyFinderServlet.java:52)
>>>
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>>>
>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>>>
>>> at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:208)
>>>
>>> at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:1127)
>>>
>>> at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:1529)
>>>
>>> at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
>>>
>>> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>>>
>>>
>>>Does anyone have any idea why this is happening? It certainly
>>>seems
>>>as though the WebLogic wrapper class is not working the
>>>same as
>>>Sun's standard HttpURLConnection.
>>>
>>>Any advice would be greatly appreciated.
>>>Cheers
>>>Dave
>>
Dimitri
-
Why we can't instantiated System class.
Hi All,
I can't undersatnd what type of class is "System". We can't instantiated system class but we can use it like a Static class.There are number of classes like that. You don't
instantiate them because you don't need to.Objects
have state and behavior. State is captured inmember
variables. None of the functionality the Systemclass
provides requires an object to be instantiated and
maintain state in member variables. It's pure
behavior.I beg to differ. Given he fact that it has attributes
(e.g. in, out and err), it does have a state...They're static attributes, so no instance (if one existed) would have its own state that would potentially distinguish it from other instances. That's what I was talking about.
I, personally, think that static classes are rather
bad OO (it's objects doing the work, not classes),
but singletons are too burdensome to create.You mean uninstantiable classes with only static methods? (System is not a static class. Only nested classes can be static.)
If your goal is to write pure OO, then, yeah, they might be bad. But then I don't think "perfect OO" is a particularly important or useful goal. Tool for the job and all that. -
Instantiating member classes using reflection
I have checked through this forum but if the answer to this question is here I missed it.
I am trying to find out how to invoke the appropriate instantiation / constructor call to create an instance of a member class.
The following works finepublic class Succeeds {
public abstract static class AbstractMember {
Succeeds(final AbstractMember am) {
public static void main(final String[] args) {
Succeeds a = new Succeeds (new Succeeds.AbstractMember () {
}However I want to make the AbstractMember a real member class not a nested inner class and I want to instantiate the concrete subclass of AbstractMember in the constructor of Succeeds rather than outside the class. I tried the following:public class Fails {
public abstract class AbstractMember {
public class ConcreteMember extends AbstractMember {
Fails(final Class<? extends AbstractMember> c)
throws InstantiationException, IllegalAccessException {
AbstractMember am = c.newInstance() ;
public static void main(final String[] args)
throws InstantiationException, IllegalAccessException {
Fails a = new Fails (Fails.AbstractMember.ConcreteMember.class) ;
}(Please forgive the appling treatment of exceptions, I wanted to make a small example). This compiles fine but fails at runtime with an InstantiationException I assume because the nullary constructor doesn't exist for a member class because of the need to make the connection to the containing object.
So the question is is there a bit of reflection that allows me to achieve what I want?
I cannot be the first person to try doing this. I am hoping it is doable otherwise I am going to have to make the design a bit yukky.
Thanks.import java.lang.reflect.*;
public class Fixed
public abstract class AbstractMember
public class ConcreteMember extends AbstractMember
<T extends AbstractMember> Fixed(final Class<T> c) throws Exception
Constructor<T> ctor = c.getConstructor(new Class[]{getClass()});
AbstractMember am = ctor.newInstance(new Object[]{this});
public static void main(final String[] args) throws Exception
new Fixed(ConcreteMember.class);
}My exception handling is even more lax than yours. Why isn't there a class ReflectionException? I moved ConcreteMember out of AbstractMember to keep things simple. It's not entirely necessary, but I didn't want to construct an AbstractMember first. -
Instantiating Java class while WAS is starting
Is there a possibility to register Java classes within the SAP WAS which will be instantiated while the server starts up?
Hi,
to be honest, I have only a rough idea - may be you can emulate this behaviour by a web application, where in the deployment descriptor the load-on-startup flag is set ?
Barbara -
Instantiating a class by file - possible?
Hi all!
Is it possible to instantiate a class similar to Class.forName() when I only have the .class file?
Any ideas?take a look at the newInstance() method in Class:
"Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized."
http://java.sun.com/j2se/1.4/docs/api/java/lang/Class.html#newInstance() -
Instantiating a class within a class
I've got a package with 2 classes. The first, we'll call it
C1, is being instantiated within the main body of code. In turn, it
instantiates another class, C2.
Problem is, the C2 instantiation is not happening. However,
if I instantiate the class within the main code body, the
instantiations within C1 work ok. A chopped down version of my
code:
// main.swf
import stuff.*;
var myC1:C1 = new C1();
var myC2:C2 = new C2(); // remove this line and the line
below stops functioning
// C1.as
class stuff.C1 {
public function C1() {
trace('C1 instantiated');
var anotherC2 = new C2(); // this line doesn't work unless
the line above is included
// C2.as
class stuff.C2 {
public function C2() {
trace('C2 instantiated');
So if I take the classes out of the package it works also, so
I'm guessing it has something to do with the way I'm importing the
files maybe? I dunno. Any thoughts?What Darcia wrote make me suppose that a class is totally created with the first line of a java file (i.e. public class PrivAndPublic{ )and initialized by the constructor (which, if omitted, comes by default with no arguments)...after all this, the class can be instantiated many times I want from inside the class itself.
(I was thinking the class needed to reach the matching close curly brace to be possible to instantiate it)
But as phyzome said I have to be careful to do not make the object call the method which I put the object in, otherwise I will cause an infinite loop...as I did try ;)
Thanx guys, see you. -
I wanted to know why an inner or local class cannot be instantiated with the newInstance() call? When I try to do this, it gives an InstantiationException both when the class is local (commented code below) and when it is inner (uncommented code below).
class A {
public void method1() throws Exception {
System.out.println(getClass().getName());
A a = (A) getClass().newInstance();
public class TestInner {
final class B extends A {
void method2() throws Exception {
final class B extends A {
B b = new B();
b.method1();
public static void main(String[] args) throws Exception {
TestInner test = new TestInner();
test.method2();
}I wanted to know why an inner or local class cannot be
instantiated with the newInstance() call? When I tryHere's a tested and working example:
import java.lang.reflect.*;
public
class ClassReflection
public
static
void main(String[] args)
throws Exception
Class enclosingClass, innerClass;
Object enclosingObject, innerObject;
Constructor constructor;
// first create the enclosing class, otherwise it's not possible
// to invoke the constructor of the inner class.
enclosingClass = Class.forName("ClassReflection");
constructor = enclosingClass.getDeclaredConstructor(new Class[]{});
enclosingObject = constructor.newInstance(new Object[]{});
innerClass = enclosingClass.getDeclaredClasses()[1];
constructor = innerClass.getDeclaredConstructor(new Class[] {ClassReflection.class,Object.class});
constructor.setAccessible(true);
innerObject = constructor.newInstance(new Object[]{enclosingObject,null});
System.out.println(innerObject);
private
ClassReflection()
class InnerClassReflection
extends ClassReflection
private
InnerClassReflection(Object object)
System.out.println("I am an inner class");
} -
Error ( while instantiating a class)
I encountered the following errors ...plz help..Click and Clicka are two public classes which i have written ..Both of them have actionPerformed function defined ..
gui.java:14: cannot resolve symbol
symbol : class Click
location: class gui
ActionListener listner = new Click();
*^*
gui.java:18: cannot resolve symbol
symbol : class Clicka
location: class gui
ActionListener listnera = new Clicka();
*^*
*2 errors*
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.applet.*;
public class gui
public static void main(String[] args)
JFrame frame = new JFrame();
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
JButton button = new JButton("Click to Start IWRMS");
panel.add(button);
ActionListener listner = new Click();<----------------------------------------------------ERROR1
button.addActionListener(listner);
JButton buttona = new JButton("Stop Irrigation");
panel.add(buttona);
ActionListener listnera = new Clicka();<----------------------------------------------------ERROR2
buttona.addActionListener(listnera);
frame.setTitle("Intelligent Water Resource Management System");
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}now here is the class click that is have written ...
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Clicks implements ActionListener
{ String input;
public void actionPerformed(ActionEvent event)
input = JOptionPane.showInputDialog("Enter the location of hex file (example C://new.txt");
JOptionPane.showMessageDialog(null, "You have selected " + input );
Edited by: maneesh2706 on Jun 4, 2008 7:17 PM
Edited by: maneesh2706 on Jun 4, 2008 7:17 PMok..iam sorry it was a typing error...
This is class click
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class Click implements ActionListener
{ String input;
public void actionPerformed(ActionEvent event)
input = JOptionPane.showInputDialog("Enter the location of hex file (example C://new.txt");
JOptionPane.showMessageDialog(null, "You have selected " + input );
This is the class clicka
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.lang.*;
public class Clicka implements ActionListener
public void actionPerformed(ActionEvent event)
JOptionPane.showMessageDialog(null,"Duration is sent via serial port!");
fill_buffer();
public void fill_buffer( )
//code...this function is fine //
} -
Hi,
I have been hunting down a NullPointerException for half a day to come to
the following conclusion.
My constructor calls a method which uses static variables. Since an intance
of my class is created in the static block when the class is loaded, those
statics are probably not fully initialized yet and the constructor called
from the static block has those null pointer problems.
I've considered moving the initialization of the static variables from the
declaration to the static block. But your code is inserted BEFORE any other
code. Therefore not solving my problem.
Two questions:
1) what would be a solution to my problem? How can I make sure my static
variables are initialized before the enhancer generated code in the static
block calls my constructor? Short of decompiling, changing the code and
recompiling.
2) Why is the enhancing code inserted at the beginning of the static block
and not at the end? The enhancements would be more transparent that way if
the static variables are initialized in the static block.
Thanks,
EricHi Eric,
JDO calls the no-args constructor. Your application should regard this constructor as belonging
primarily to JDO. For example, you would not want to initialize persistent fields to nondefault
values since that effort is wasted by JDO's later initilization to persistent values. Typically all
you want to initialize in the no-args constructor are the transactional and unmanaged fields. This
rule means that you need initialization after construction if your application uses the no-args
constructor and wants persistent fields initialized. On the other hand, if your application really
uses constructors with arguments, and you're initializing persistent fields in the no-args
constructor either unintentionally through field initializers or intentionally as a matter of
consistency, you will find treating the no-args constructor differently helpful.
On the other hand, if Kodo puts its static initializer code first as you report, then it is a bug.
Spec Section 20.16: "The generated static initialization code is placed after any user-defined
static initialization code."
David Ezzio
Eric Borremans wrote:
>
Hi,
I have been hunting down a NullPointerException for half a day to come to
the following conclusion.
My constructor calls a method which uses static variables. Since an intance
of my class is created in the static block when the class is loaded, those
statics are probably not fully initialized yet and the constructor called
from the static block has those null pointer problems.
I've considered moving the initialization of the static variables from the
declaration to the static block. But your code is inserted BEFORE any other
code. Therefore not solving my problem.
Two questions:
1) what would be a solution to my problem? How can I make sure my static
variables are initialized before the enhancer generated code in the static
block calls my constructor? Short of decompiling, changing the code and
recompiling.
2) Why is the enhancing code inserted at the beginning of the static block
and not at the end? The enhancements would be more transparent that way if
the static variables are initialized in the static block.
Thanks,
Eric -
Instantiating MXML class in AS3
I have a simple MXML component:
-- code -- 'MyClass'
<mx:Canvas ... creationPolicy="none" ... >
<mx:HBox id="innerPanel" >
<mx:Canvas ... />
</mx:HBox>
</mx:Canvas>
-- /code --
I'm trying to instantiate this in AS3 as so:
-- code --
var myClass:MyClass = new myClass();
myClass.createComponentsFromDescriptors(true);
-- /code --
myClass is created, but no children. myClass.childDescriptors is empty.
What am I doing wrong?
thanx,
rickbUnfortunatelly nothing of the above works when you have a chain of MXML's and AS's that are instantiating eachother. Not even the combination of all of the techniques mentioned earlier.
I tried all of the above on the entire chain, and even placed callLater in the main canvas container but still creationComplete in MyMXML happens after callLater.
I tried to be creative with the bellow pseudo pseudo code, I hope you get the idea.
<MyMainCanvas>
<script>
onCreationComplete
var myClass = new MyClass();
addChild(myClass)
callLater(doSomething)
doSomething()
// does nothing as none of the properties are available from MyMXML
</script>
</MyMainCanvas>
MyClass extends Canvas
function MyClass()
var myMXML = new MyMXML();
addChild(myMXML);
<MyMXML>
<script>
onCreationComplete
// this gets called after callLater in MyMainCanvas
</script>
</MyMXML>
Maybe you are looking for
-
Autocorrection for every keyboard not working in iOS 6
Apple promised at WWDC "Autocorrection for every keyboard". I am using a Bluetooth keyboard on an iPad 2 with iOS 6 and it's not working. The same is true on iPhone 5. I have it enabled in settings and it works with the virtual keyboard.
-
DW-MX-04 Drop-down menus won't work.
I'm using Dreamweaver MX 2004 (have been for several years, so I know my way around it). I want to create drop-down or fly-outs menu's to consolidate page links into categores in order to reduce the number of link tabs I have on each page. I've bee
-
The Security Token Service is not available.
hi, 1. service check failed-- http://localhost:port/SecurityTokenServiceApplication/securitytoken.svc Gettng Error message 2. while provision it again.. Get-SPServiceApplication | ?{$_ -match "Security"} $sts.Status (result got -online) $sts.P
-
Command line -import and -codebase
I am trying to import a web start app directly into the cache. This works fine and without any problems providing I hardcode the codebase to the directory containing the application files. Now as far as I understood it, when importing a web start app
-
Since upgrading to CCM 4.2(3) we are not able to search by first name from our IP phone directory. We can, however, search by last name and extension. I have looked at the xmldirectory.asp file but cannot determine if something has changed.