Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 2nd, 2012, 02:44 PM
amsko amsko is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 1 amsko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 42 sec
Reputation Power: 0
Angry Need help with outputstream

I have the below code which is giving me a null pointer exception at the outputstream:

try {
URL server = new URL("http", targetServer, "(my app url)");
System.out.println("Server === "+server);
HttpURLConnection conn = (HttpURLConnection) server
.openConnection();
System.out.println("Connection === "+conn);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type", "text/xml");
conn.setRequestProperty("Content-Length", Integer
.toString(payload.length));

os = conn.getOutputStream();
System.out.println("Outputstream === "+os);
os.write(payload);
os.flush();

is = conn.getInputStream();

char[] buildRespPayload = new char[2048];
int ch;
int idx = 0;

ch = is.read();
while (ch != -1) {
if (ch >= 0)
buildRespPayload[idx++] = (char) ch;
ch = is.read();
}




Below is the Stack trace:


[3/2/12 11:19:10:753 PST] 0000002d SystemOut O inside servlet.........................
[3/2/12 11:20:08:124 PST] 0000002d SystemOut O before send request...............
[3/2/12 11:20:08:124 PST] 0000002d SystemOut O inside send request....................
[3/2/12 11:20:08:124 PST] 0000002d SystemOut O Server === server url here
[3/2/12 11:20:08:124 PST] 0000002d SystemOut O Connection === sun.net.(target url)
[3/2/12 11:20:08:130 PST] 0000002d servlet service SRVE0068E: Uncaught exception created in one of the service methods of the servlet DSCISAlert in application dscatls. Exception created : java lang NullPointerException
at servlet.sendRequest(DSCISAlert.java:207)
at servlet.doGet(DSCISAlert.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:718)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:831)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.ser vice(ServletWrapper.java:1657)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:939)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl .handleRequest(ServletWrapperImpl.java:179)
at com.ibm.ws.webcontainer.webapp.WebApp.handleReques t(WebApp.java:3935)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequ est(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:931)
at com.ibm.ws.webcontainer.WSWebContainer.handleReque st(WSWebContainer.java:1583)
at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.sendToDiscriminators(NewConnectionIniti alReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialRe adCallback.complete(NewConnectionInitialReadCallba ck.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListe ner.futureCompleted(AioReadCompletionListener.java :165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallbac k(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletion Actions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture .java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHand ler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingL oop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler .java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1604)


i am using the same method and target URL for a test file from my local command prompt which gives me a blank response which is ok since i dont get an error. but if this code is executed through a URL in the browser it gives me a Error 500: java.lang.NullPointerException the stack trace for which is given above..

Plz help ASAP

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Need help with outputstream


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap