Servlet Receives IOException
Hi,
Listed below is an exception that comes normally when we launch
our application on WebLogic. We have hosted the application on
a Unix Box with the following config.
Here are the details:
Unix Box(RAM 1 GB, CPU 1 400 MHZ,HD 70 GB).
AppServer(weblogic5.1.0)
Java Heap --> -ms30m -mx60m
Tue Mar 13 11:19:14 GMT+05:30 2001:<E> <ServletContext-General>
Servlet failed with Exception
java.io.IOException: Broken pipe
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(SocketOutputStream.java:87)
at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:88)
at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:336)
at weblogic.servlet.internal.ServletResponseImpl.writeHeaders(ServletResponseImpl.java:603)
at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:101)
at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:430)
at weblogic.servlet.FileServlet.sendFile(FileServlet.java:199)
at weblogic.servlet.FileServlet.service(FileServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:105)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
Tue Mar 13 11:19:16 GMT+05:30 2001:<E> <ServletContext-General>
Servlet failed with Exception
java.io.IOException: Broken pipe
at java.net.SocketOutputStream.socketWrite(Native Method)
at java.net.SocketOutputStream.write(SocketOutputStream.java:87)
at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:88)
at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:336)
at weblogic.servlet.internal.ServletResponseImpl.writeHeaders(ServletResponseImpl.java:603)
at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:101)
at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:430)
at weblogic.servlet.FileServlet.sendFile(FileServlet.java:199)
at weblogic.servlet.FileServlet.service(FileServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
Rajah,
These message doesn't indicate anything wrong. This is a known issue in wls5.1.
Basically these messages are indicating that browser stopped receiving response while server is still writing
response. (May be because user clicked on browser stop or network failure.......)
Thanks,
Kumar.
Rajah wrote:
> Hi,
>
> Listed below is an exception that comes normally when we launch
> our application on WebLogic. We have hosted the application on
> a Unix Box with the following config.
>
> Here are the details:
>
> Unix Box(RAM 1 GB, CPU 1 400 MHZ,HD 70 GB).
> AppServer(weblogic5.1.0)
>
> Java Heap --> -ms30m -mx60m
>
> Tue Mar 13 11:19:14 GMT+05:30 2001:<E> <ServletContext-General>
> Servlet failed with Exception
> java.io.IOException: Broken pipe
> at java.net.SocketOutputStream.socketWrite(Native Method)
> at java.net.SocketOutputStream.write(SocketOutputStream.java:87)
> at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:88)
> at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:336)
> at weblogic.servlet.internal.ServletResponseImpl.writeHeaders(ServletResponseImpl.java:603)
> at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:101)
> at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:430)
> at weblogic.servlet.FileServlet.sendFile(FileServlet.java:199)
> at weblogic.servlet.FileServlet.service(FileServlet.java:56)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
> at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:105)
> at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:742)
> at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:686)
> at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:247)
> at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
> at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
> at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>
> Tue Mar 13 11:19:16 GMT+05:30 2001:<E> <ServletContext-General>
> Servlet failed with Exception
> java.io.IOException: Broken pipe
> at java.net.SocketOutputStream.socketWrite(Native Method)
> at java.net.SocketOutputStream.write(SocketOutputStream.java:87)
> at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:88)
> at weblogic.servlet.internal.ResponseHeaders.writeHeaders(ResponseHeaders.java:336)
> at weblogic.servlet.internal.ServletResponseImpl.writeHeaders(ServletResponseImpl.java:603)
> at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:101)
> at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:430)
> at weblogic.servlet.FileServlet.sendFile(FileServlet.java:199)
> at weblogic.servlet.FileServlet.service(FileServlet.java:56)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
Similar Messages
-
Servlet receiving UTF-16 parameter
I am attempting to build a servlet to receive a parameter encoded in UTF-16. At this stage, I am able to receive and process UTF-8 parameters but not UTF-16. I believe this is due to the request.getParameter() method not finding the encoded parameter name. My servlet code is:
request.setCharacterEncoding("UTF-16");
String xmlStr = request.getParameter("xml");When I send the encoded request I do:
System.out.println("Parameters:");
for (Enumeration e = request.getParameterNames() ; e.hasMoreElements() ;)
String s = (String)e.nextElement();
System.out.println(s);
for (int i=0; i< s.length(); i++)
System.out.println(s.codePointAt(i));
}and via the Tomcat stdout log get:
Parameters:
30720
27904
27648
which would indicate it received the parameter xml yet the request.getParameter("xml") returns null.
How can I retrieve the encoded parameter value?I believe the previous problem was a combination of two issues:
1) The UTF-16 was being encoded in little endian, Java was reading it as big endian.
2) The JVM appears to append the character <fffd> to each query parameter and each value. This is defined in Unicode to be a 'Replacement Character' and since it is included as part of the parameter causes that parameter not to match that being searched for.
My new issue is this:
I can find and thus retrieve the xml parameter from the request, however, it appears to take no notice of the encoding specified. I have printed the bytes contained in the complete input string and verified they contain the null (00) character for the half width latin characters. However, once request.getParameter() is called, these characters are lost and the resultant string is invalid UTF-16.
So <xml> goes from x00 x3c, x00 x78, x00 x6d, x00 x6e, x00 x3e (10 bytes) to x3c, x78, x6d, x6e, x3e (5 bytes)
How can I correctly parse my request parameter as being UTF-16 encoded? -
Servlet throws IOException when browser is "stopped"
Hello,
I have a servlet running on the Sun ONE Web server 6.1 that throws this error message: "java.io.IOException: WEB8004: Error flushing the output stream".
Through my testing, it seems as if this is caused by the user pressing the stop button before the output can be completely commited to the client. Strangely enough the error seems to thrown when IE is the browser but not when Firefox is. My guess is that what is happening is the client connection is closed when stop is pressed in IE and the server cannot write to the client anymore so the error is thrown.
I was wondering if anyone has any insight into how to prevent this from getting thrown. I realize that this error is not a major thing and probably doesn't need to be worried about, but it is quite annoying because webmaster gets emailed anytime an exception is thrown so cutting down on pointless exceptions is something we like to do :)
Thanks in advance.You could also try hitting the browser's refresh button many times as quickly as possible; it should also give similar errors. Or keep Control-R (reload) pressed down and let the keyboard's auto-repeat do its work.
When the browser is in the process of fetching a page and decides it isn't interested in the page after all, it closes the TCP/IP connection to the server. The server will get an IOException. Nothing you can do about that. Write a catch block that ignores IOException when flushing a web page. Or maybe log "error sending page, the user probably hit the reload button", without the stack trace, into an audit log. -
Servlet receiving response????
We would like to set up a servlet that sends a request to an outside
website, receives the response from that website, parses the html stream and
then displays HTML to the browser.
Does anyone know where we can find any documentation or examples on this or
does anyone have any ideas that may get us started in the right direction?
Thanks!
Paul
Do a Google search on URLConnection example
Mike
"Paul Zila" <[email protected]> wrote:
>We would like to set up a servlet that sends a request to an outside
>website, receives the response from that website, parses the html stream
>and
>then displays HTML to the browser.
>
>Does anyone know where we can find any documentation or examples on this
>or
>does anyone have any ideas that may get us started in the right direction?
>
>Thanks!
>Paul
>
>
-
Why my servlet receives NoClassDefFoundError : javax/servlet/http/HttpSession
I developed an application which has one servlet.
The war context-root that has the servlet is 'workflowclient'.
When invoking the servlet with URL "http://localhost/workflowclient/WfAgentManagerSRMIServlet, an exception with NoClassDefFoundException is raised.
Why ?
The fortune example operates well.
Please let me know how to solve this problem.Hi,
I would like to go through your code, if it isn't properietry, please send me the codes so that I can have a look and test at my end to provide you results.
Thanks & Regards
Ganesh .R
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support -
How to Use Weblogic6.1 JAAS Sample in Servlet???
Hi there,
I am now developing JAAS security service based on weblogic. Here is the problem I met with:
1. There is no problem when invoking JAAS sample from application.
But Subject.doAs() is denied when moving the application to servlet.
2. It is said that when invoking JAAS from servlet,
an authenticated subject will be returned using:
Subject subjectTest = loginContext.getSubject();
How can I store the subject into the session and be called later?
3. getUserPrincipal(), isUserInRole() are two important
methods in authenticaion on web services.
How is the user principal and role stored in the session?
4. Where can I find some tutorials on invoking JAAS service from servlet?
Thanks.
============================================================
This is my source code
package examples.security.jaas;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.*;
import java.util.*;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.TextOutputCallback;
import javax.security.auth.callback.TextInputCallback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.AccountExpiredException;
import javax.security.auth.login.CredentialExpiredException;
public class SampleServlet extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
doPost(req, res);
System.out.println("1\n");
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();
System.out.println("2\n");
String username = req.getParameter("username");
String password = req.getParameter("password");
String url = req.getParameter("url");
LoginContext loginContext = null;
Context ctx = null;
try
// Set server url for SampleLoginModule
Properties property = new Properties(System.getProperties());
property.put("weblogic.security.jaas.ServerURL", "http://localhost:7001");
System.setProperties(property);
property = new Properties(System.getProperties());
property.put("weblogic.security.SSL.ignoredHostnameVerification", "TRUE");
System.setProperties(property);
// Set configuration class name to load SampleConfiguration
property = new Properties(System.getProperties());
property.put("weblogic.security.jaas.Configuration", "examples.security.jaas.SampleConfig");
System.setProperties(property);
// Set configuration file name to load sample configuration policy file
property = new Properties(System.getProperties());
property.put("weblogic.security.jaas.Policy", "Sample.policy");
System.setProperties(property);
// Create LoginContext; specify username/password login module
loginContext = new LoginContext("SamplePolicy", new MyCallbackHandler());
catch(SecurityException se)
se.printStackTrace();
System.exit(-1);
catch(LoginException le)
le.printStackTrace();
System.exit(-1);
System.out.println("SampleServlet:" + username + "\n");
// Attempt authentication
try
// If we return without an exception, authentication succeeded
loginContext.login();
catch(FailedLoginException fle)
out.println("Authentication Failed, " + fle.getMessage());
System.exit(-1);
catch(AccountExpiredException aee)
out.println("Authentication Failed: Account Expired");
System.exit(-1);
catch(CredentialExpiredException cee)
out.println("Authentication Failed: Credentials Expired");
System.exit(-1);
catch(Exception e)
out.println("Authentication Failed: Unexpected Exception, " + e.getMessage());
e.printStackTrace();
System.exit(-1);
// Retrieve authenticated subject, perform SampleAction as Subject
out.println("Authentication succeeded " );
System.out.println("===============start to trace333\n");
Subject subject = loginContext.getSubject();
System.out.println("Subject:"+subject.toString()+"\n");
System.out.println("Subject.getclass:" + subject.getClass().getName());
SampleAction sampleAction = new SampleAction();
Subject.doAs(subject, sampleAction);
System.out.println("4\n");
// System.exit(0);
========================================================
void doPost(
HttpServletRequest req,
HttpServletResponse resp) {
Principal p =
req.getUserPrincipal();
auditCall(p.getName());
if (req.isUserInRole(
"ManagersRole")) {
// Do some Manager stuff
} else if
(ctx.isUserInRole(
"SalesRole")) {
// Do some Sales stuff
I'll describe where JAAS fits in to the web app model but please note that some of this should be automatically handled by your Servlet container.
Servlet engine (or your MVC servlet controller) receives a request for a protected resource.
It then checks for the existence of an "authenticated" token in the HttpSession.
If that token doesn't exist then it forwards the user to the login page.
The user fills in the form, and the login servlet receives the username and password at which point the JAAS Login Module is called with two callback objects: one that returns the username and one that returns the password.
The JAAS Module checks to see if the credentials are valid, if not, it throws an authentication exception.
Once control is returned to the Login Servlet, the Login Servlet would add the authenticated "Subject" to the HttpSession and if necessary, an authentication "token".
So, JAAS is really only called ONCE, not for every web request, and it's called
by the "logical" Login Servlet AFTER the user submits their login information.
JAAS is not used to check for whether the user is authenticated already or not.
the weblogic 6.1 server side exception
username: joeuser
password: joepass
<May 25, 2002 11:05:20 PM PDT> <Error> <HTTP> <[WebAppServletContext(2169486,exa
mplesWebApp,/examplesWebApp)] Servlet failed with Exception
java.lang.SecurityException: Attempting Privileged Action With Unauthenticated S
ubject
at javax.security.auth.Subject.doAs(Subject.java:74)
at examples.security.jaas.SampleClient.startWeb(SampleClient.java:200)
at jsp_servlet.__poc1._jspService(__poc1.java:92)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:265)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:200)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:2495)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2204)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>If anyone of you, has got any answers related to the above mentioned problem, Post it here, Will folks from SUN respond to this at any time.
Regards
Jayendran -
Sending a file from Applet to servlet HELP me Please
Sorry, i have the problem this is my code Applet & Servlet but it seems working asynchronously if you have some ideas please reply me i send bytes on outputstream but the inputstream of servlet receive nothing bytes but write my system.out.print on screen server:
Applet:
URL servletURL = new URL(codebase, "/InviaFile/servlet/Ricevi");
HttpURLConnection urlConnection = (HttpURLConnection) servletURL.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setUseCaches(false);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
urlConnection.setRequestProperty("Content-length", String.valueOf(100));
urlConnection.connect();
if(urlConnection.HTTP_BAD_REQUEST == HttpURLConnection.HTTP_BAD_REQUEST){
/*System.out.println("Cattiva Richiesta: "+urlConnection.getContentEncoding());
System.out.println("Tipo di metodo: "+urlConnection.getRequestMethod());
System.out.println("Tipo di Risposta: "+urlConnection.getResponseCode());
System.out.println("Tipo di messaggio: "+urlConnection.getResponseMessage());
System.out.println("Tipo di contenuto: "+urlConnection.getContentType());
System.out.println("Tipo di lunghezza contenuto: "+urlConnection.getContentLength());
System.out.println("Tipo di doinput: "+urlConnection.getDoInput());
System.out.println("Tipo di doouput: "+urlConnection.getDoOutput());
System.out.println("Tipo di URL: "+urlConnection.getURL());
System.out.println("Tipo di propriet� richiesta: "+urlConnection.getRequestProperty("Content-Type"));
System.out.println("Entra if");
DataOutputStream dout = new DataOutputStream(urlConnection.getOutputStream());
InputStream is = urlConnection.getInputStream();
if(ritornaFile("C:/Ms.tif", dout))System.out.println("Finita lettura");
dout.close();
urlConnection.disconnect();
System.out.println("Fine Applet");
}catch(Exception e) { System.err.println(e.getMessage());e.printStackTrace();}
public boolean ritornaFile(String file, OutputStream ots)throws Exception{
FileInputStream f = null;
try{
f = new FileInputStream(file);
byte[] buf = new byte[4 * 1024];
int byteLetti;
while((byteLetti = f.read()) != -1){ots.writeByte(buf, 0, byteLetti);ots.flush();
while((byteLetti = f.read()) != -1){ots.write(byteLetti);ots.flush();
System.out.println("byteLetti= "+byteLetti);
return true;
}catch(Exception ex){
System.err.println(ex.getMessage());
return false;
}finally{
if(f != null)f.close();
Servlet:
HttpSession ses = request.getSession(true);
System.out.println("Passa servlet "+request.getMethod());
System.out.println("Passa servlet "+ses.getId());
ServletInputStream servletinputstream = request.getInputStream();
DataInputStream dis = new DataInputStream(request.getInputStream());
int c = dis.available();
System.out.println("c="+c);
//ServletOutputStream servletoutputstream
//response.getOutputStream();
response.setContentType("application/octet-stream");
System.out.println("URI= "+request.getRequestURI());
System.out.println("pathTranslated: "+request.getPathTranslated());
System.out.println("RemoteUser: "+request.getRemoteUser());
System.out.println("UserInRole: "+String.valueOf(request.isUserInRole("")));
System.out.println("pathInfo: "+request.getPathInfo());
System.out.println("Protocollo: "+request.getProtocol());
System.out.println("RemoteAddr:"+request.getRemoteAddr());
System.out.println("RemoteHost:"+request.getRemoteHost());
System.out.println("SessionID:"+request.getRequestedSessionId());
System.out.println("Schema:"+request.getScheme());
System.out.println("SeesionValido:"+String.valueOf(request.isRequestedSessionIdValid()));
System.out.println("FromURL:"+String.valueOf(request.isRequestedSessionIdFromURL()));
int i = request.getContentLength();
System.out.println("i: "+i);
ritornaFile(servletinputstream, "C:"+File.separator+"Pluto.tif");
System.out.println("GetMimeType= "+getServletContext().getMimeType("Ms.tif"));
InputStream is = request.getInputStream();
int in = is.available();
System.out.println("Legge dallo stream in="+in);
DataInputStream diss = new DataInputStream(servletinputstream);
int ins = diss.read();
System.out.println("Legge dallo stream ins="+ins);
int disins = diss.available();
System.out.println("Legge dallo stream disins="+disins);
is.close();
System.out.println("Fine Servlet");
catch(Exception exception) {
System.out.println("IOException occured in the Server: " + exception.getMessage());exception.printStackTrace();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
processRequest(request, response);
/** Returns a short description of the servlet.
public String getServletInfo() {
return "Short description";
public void ritornaFile(InputStream its, String fileDest )throws Exception{
FileOutputStream f = null;
try{
f = new FileOutputStream(fileDest);
byte[] buf = new byte[2 * 1024];
int byteLetti;
while((byteLetti = its.read()) != -1){
f.write(buf, 0, byteLetti);
f.flush();
System.out.println("Byteletti="+byteLetti);
}catch(Exception ex){
System.err.println(ex.getMessage());
}finally{
if(f != null)f.close();Hi all,
Can anyone help me.I am trying to send an audio file from a applet to servlet with HTTP method(no raw sockets), also the servlet shld be able to save the file on the server.Any suggestions welcome.USing audiostream class from javax.sound.sampled.
The part of applet code which calls servlet is :
URL url = new URL("http://" + host + "/" + context + "/servlet/UserUpdateWorkLogAudio?userid=" + userId.replace(' ', '+') + "&FileName=" + filename.replace(' ', '+'));
URLConnection myConnection = url.openConnection();
myConnection.setUseCaches(false);
myConnection.setDoOutput(true);
urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
myConnection.connect();
out = new BufferedOutputStream(myConnection.getOutputStream());
AudioSystem.write(audioInputStream, fileType,out); // IS THIS RIGHT APPROACH?
************************end of applet code**********************
************************servlet code******************************
try
{BufferedInputStream in = new BufferedInputStream(request.getInputStream());
????????What code shld i write here to get the audio file stream
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
*********************************************end***********************
Thanks
Joe. -
WLS 7.0 sp2 - Servlet Problems with SOAP messages
I'm using Weblogic 7.0 SP2 and trying to create a Servlet to receive SOAP wrapped
XML messages. I'm getting the following error. Is this a problem with WLS7.0sp2's
support of JAXM? The System.out.println's indicate I have successfully received
the incoming SOAP request and then successfully formatted the SOAP response, but
upon returning saving the response it appears to blow up. Does anyone have any
suggestions?
I need to do the following in a servlet:
- receive an incoming SOAP request with an embedded XML message
- perform some processing
- return a SOAP response with an embedded XML message
Should I be using JAXM? Or can I do this same task easily with JAX-RPC?
<Feb 24, 2004 4:10:42 PM AST> <Error> <HTTP> <101017> <[ServletContext(id=260434
7,name=isd.war,context-path=)] Root cause of ServletException
java.lang.Error: NYI
at weblogic.webservice.core.soap.SOAPMessageImpl.saveRequired(SOAPMessag
eImpl.java:360)
at javax.xml.messaging.JAXMServlet.doPost(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:1058)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:401)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:306)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:5445)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:780)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3105)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2588)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
>
I've stripped the code down so that all it does is verifies the incoming SOAP/XML
request and creates a hard-coded response... be gentle... I'm a novice at this
import javax.xml.soap.*;
import javax.servlet.*;
import javax.servlet.http.*;
// import javax.xml.transform.*;
import java.util.*;
import java.io.*;
public class RegisterServlet extends HttpServlet
static MessageFactory fac = null;
static
try
fac = MessageFactory.newInstance();
catch (Exception ex)
ex.printStackTrace();
public void init(ServletConfig servletConfig) throws ServletException
super.init(servletConfig);
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException
try
System.out.println("** Note: doPost() Entering req = " + req);
// Get all the headers from the HTTP request
MimeHeaders headers = getHeaders(req);
// Get the body of the HTTP request
InputStream is = req.getInputStream();
// Now internalize the contents of a HTTP request
// and create a SOAPMessage
SOAPMessage msg = fac.createMessage(headers, is);
System.out.println("** Note: doPost() Step A");
SOAPMessage reply = null;
reply = onMessage(msg);
System.out.println("** Note: doPost() Step B reply = " + reply);
if (reply != null)
* Need to call saveChanges because we're
* going to use the MimeHeaders to set HTTP
* response information. These MimeHeaders
* are generated as part of the save.
if (reply.saveRequired())
System.out.println("** Note: doPost() Step C reply.saveRequired()");
reply.saveChanges();
resp.setStatus(HttpServletResponse.SC_OK);
putHeaders(reply.getMimeHeaders(), resp);
// Write out the message on the response stream
OutputStream os = resp.getOutputStream();
System.out.println("** Note: doPost() Step D os = " + os);
reply.writeTo(os);
os.flush();
else
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
catch (Exception ex)
throw new ServletException("** Error: SAAJ POST failed: " + ex.getMessage());
static MimeHeaders getHeaders(HttpServletRequest req)
Enumeration enum = req.getHeaderNames();
MimeHeaders headers = new MimeHeaders();
while (enum.hasMoreElements())
String headerName = (String)enum.nextElement();
String headerValue = req.getHeader(headerName);
StringTokenizer values =
new StringTokenizer(headerValue, ",");
while (values.hasMoreTokens())
headers.addHeader(headerName,
values.nextToken().trim());
return headers;
static void putHeaders(MimeHeaders headers, HttpServletResponse res)
Iterator it = headers.getAllHeaders();
while (it.hasNext())
MimeHeader header = (MimeHeader)it.next();
String[] values = headers.getHeader(header.getName());
if (values.length == 1)
res.setHeader(header.getName(),
header.getValue());
else
StringBuffer concat = new StringBuffer();
int i = 0;
while (i < values.length)
if (i != 0)
concat.append(',');
concat.append(values[i++]);
res.setHeader(header.getName(), concat.toString());
// This is the application code for handling the message.
public SOAPMessage onMessage(SOAPMessage message)
SOAPMessage replymsg = null;
try
System.out.println("** Note: OnMessage() Entering msg = " + message);
//Extract the ComputerPart element from request message and add to reply SOAP
message.
SOAPEnvelope reqse = message.getSOAPPart().getEnvelope();
SOAPBody reqsb = reqse.getBody();
//System.out.println("** Note: OnMessage() Step B");
System.out.println("** Note: OnMessage () Step A Soap Request Message Body = "
+ reqsb);
//Create a reply mesage from the msgFactory of JAXMServlet
System.out.println("** Note: OnMessage () Step B");
replymsg = fac.createMessage();
SOAPPart sp = replymsg.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPBody sb = se.getBody();
System.out.println("** Note: OnMessage () Step C Soap Reply Before Message Body
= " + sb);
se.getBody().addBodyElement(se.createName("RegisterResponse")).addChildElement(se.createName("ErrorCode")).addTextNode("000");
System.out.println("** Note: OnMessage () Step D Soap Reply After Message Body
= " + sb);
replymsg.saveChanges();
System.out.println("** Note: OnMessage() Exiting replymsg = " + (replymsg));
catch (Exception ex)
ex.printStackTrace();
return replymsg;
Michael,
I got the same error on WLS8.1/Win2K professional and apache FOP (old version).
After digging into the WLS code and FOP(old version). i found the conflict happens
on
the "org.xml.sax.parser" system property. In WLS code, they hard coded like the
following when startup weblogic server:
System.setProperty("org.xml.sax.parser", "weblogic.xml.jaxp.RegistryParser");
But the FOP code try to use the "org.xml.sax.parser" system property to find the
sax parser then conlict happens.
Here is the response from BEA support :
"I consulted with our developers regarding the question of whether we can change
the hard-coded value for the java system property: org.xml.sax.parser by using
a configuration parameter and I found that unfortunately there is no specific
setting to change the value. As you had mentioned in your note the org.xml.sax.parser
system property can be changed programmatically in your application code."
I solve my problem by using newer apache FOP (it never use the system property:org.xml.sax.parser
any more) and XML Registy for WLS8.1.
Good luck.
David Liu
Point2 Technologies Inc.
"p_michael" <[email protected]> wrote:
>
Help.
When we migrated from WLS 6.1 to WLS 7.0 SP2 when encountered a problem
with XML
parsing that did not previously exist.
We get the error "weblogic.xml.jaxp.RegistryParser is not a SAX driver".
What does this mean? And, what should we do about it.
p_michael -
ServletInputStream in Servlet Forwarding empty
Please help me, i think i have a problem.
After reading and checking "request"
seem that the xml message soap included in "request" disappear.
I have to forwarding it to another servlet.
Is too late? I have lost it?
Where is it ?
I use the RequestDispatcher.forward() method for forwarding
but (i'm sure) the second servlet receives the "request.getInputStream()" empty.
Who can help me?
Thanks in advance
my code :
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletInputStream in = request.getInputStream();
byte[] fre=null;
String xml="";
while (in.available()>0) {
try {
fre = new byte[in.available()];
in.read(fre);
xml = xml + new String(fre);
} catch (Exception exc) {
exc.printStackTrace();
if (ckeck(xml)) {
request.getRequestDispatcher("myservlet2").forward(request,response);
}You have already read the input stream. Once read, and it gets read, it can not be re-read. If you want the information in both places, read it in the first servlet and store it in a scope that the other servlet can read (like as a request attribute:
byte[] fre=null;
String xml="";
while (in.available()>0) {
try {
fre = new byte[in.available()];
in.read(fre);
xml = xml + new String(fre);
} catch (Exception exc) {
exc.printStackTrace();
request.setAttribute("xml", xml);
if (ckeck(xml)) {
request.getRequestDispatcher("myservlet2").forward(request,response);
//... then in myservlet2
String xml = (String)request.getAttribute("xml"); -
Applet servlet communication problem again
applet send the data to servlet, servlet receive the data and send a message back to applet, but there is an exception error.
// servlet
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection theConnection;
boolean check = false;
// Get the value of a request parameter; the name is case-sensitive
String name = "key1";
String value = request.getParameter(name);
try{
//Loading Sun's JDBC ODBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
theConnection = DriverManager.getConnection("jdbc:odbc:database1", "", "");
Statement theStatement=theConnection.createStatement();
String sql = "SELECT col_name FROM table_name WHERE col_name ='"+value+"''";
ResultSet rs = theStatement.executeQuery(sql);
if(rs.next()){
check = true;
theStatement.close();//Close statement
theConnection.close(); //Close database Connection
}catch (ClassNotFoundException e) {
System.err.println("ClassNotFoundException : " +e);
asdf.write(e.toString().getBytes("US-ASCII"));
} catch (SQLException e) {
System.err.println("SQL exception : " +e);
asdf.write(e.toString().getBytes("US-ASCII"));
if(check){
try{
ObjectOutputStream objStream = null;
objStream = new ObjectOutputStream(response.getOutputStream());
String message = "your input is already exist in col_name in table_name ";
objStream.writeObject(message);
objStream.flush();
objStream.close();
catch(Exception ex){
asdf.write(ex.toString().getBytes("US-ASCII"));
//applet
private void recordSeg() throws ClassNotFoundException, MalformedURLException, IOException{
* Try to connect to the servlet
try {
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("hello", "UTF-8");
// Send data to sqlServlet
URL url = new URL(http://localhost:8084/JSP/sqlServlet");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
wr.close();
rd.close();
} catch (Exception e) {
//receive data from sqlServlet
try{
URL url = new URL(server + "JSP/sqlServlet");
URLConnection servletConnection = url.openConnection();
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches(false);
/ *+++++++++error line (java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8084/JSP/sqlServlet) */
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
String temp_s = inputFromServlet.readObject().toString();
inputFromServlet.close();
catch(Exception ex){
errField.append("Exception ~~~~~~~~~ " +ex+ "\n");
}Sorry, I have put the code tab but ...................................
applet send the data to servlet, servlet receive the data and send a message back to applet, but there is an exception error.
//servlet
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection theConnection;
boolean check = false;
// Get the value of a request parameter; the name is case-sensitive
String name = "key1";
String value = request.getParameter(name);
try{
//Loading Sun's JDBC ODBC Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
theConnection = DriverManager.getConnection("jdbc:odbc:database1", "", "");
Statement theStatement=theConnection.createStatement();
String sql = "SELECT col_name FROM table_name WHERE col_name ='"+value+"''";
ResultSet rs = theStatement.executeQuery(sql);
if(rs.next()){
check = true;
theStatement.close();//Close statement
theConnection.close(); //Close database Connection
}catch (ClassNotFoundException e) {
System.err.println("ClassNotFoundException : " +e);
asdf.write(e.toString().getBytes("US-ASCII"));
} catch (SQLException e) {
System.err.println("SQL exception : " +e);
asdf.write(e.toString().getBytes("US-ASCII"));
if(check){
try{
ObjectOutputStream objStream = null;
objStream = new ObjectOutputStream(response.getOutputStream());
String message = "your input is already exist in col_name in table_name ";
objStream.writeObject(message);
objStream.flush();
objStream.close();
catch(Exception ex){
asdf.write(ex.toString().getBytes("US-ASCII"));
//applet
private void recordSeg() throws ClassNotFoundException, MalformedURLException, IOException{
* Try to connect to the servlet
try {
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("hello", "UTF-8");
// Send data to sqlServlet
URL url = new URL(http://localhost:8084/JSP/sqlServlet");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
wr.close();
rd.close();
} catch (Exception e) {
//receive data from sqlServlet
try{
URL url = new URL(server + "JSP/sqlServlet");
URLConnection servletConnection = url.openConnection();
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches(false);
/ /+error line (java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8084/JSP/sqlServlet)
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
String temp_s = inputFromServlet.readObject().toString();
inputFromServlet.close();
catch(Exception ex){
errField.append("Exception ~~~~~~~~~ " +ex+ "\n");
} -
Sending xml file from client to servlet
Hi,
I am writing the server component of an applcation, such that it will receive xml files from the clients(standalone application similar to javaSwing stuff but it's coded in C#), and the servlet will have to extract the data from the xml file and update the mySql database. it will also fulfill the client's request for xmlFiles (and extract data from DB, format to xml file and send back to client)
I'm new to implementing the servlet receiving files from clients so would need some help.
I've got 3 questions to ask:
1) How does the servlet receive/returns the xml file from the client as a series of httpPost request/response. Do i send a File or the file's contents as a String to/from the client?
2) Is it also a must to use socket for the file transfers? I have read in other posts about sockets as well as HttpURLConnection but i don't quite understand.
3) When I send a file back to the client(client is standalone application written in C# whereas server is coded in java), what do i specify for the HttpResponse.setContentType() in my servlet? (i'm returning the xml file to client)
Would really appreciate for any help rendered. If you have any useful links, would appreciate them too. Thanks a lot.
KarenI've got 3 questions to ask:
1) How does the servlet receive/returns the xml file
from the client as a series of httpPost
request/response. Do i send a File or the file's
contents as a String to/from the client?The server will listen on some port for requests. The client has to open a socket to this server to send the file as string to the server.
see http://java.sun.com/docs/books/tutorial/networking/index.html
>
2) Is it also a must to use socket for the file
transfers? I have read in other posts about sockets as
well as HttpURLConnection but i don't quite
understand.You use HttpURLConnection to make a request using the http protocol, instead of opening a socket and then writing the html headers yourself.
3) When I send a file back to the client(client is
standalone application written in C# whereas server is
coded in java), what do i specify for the
HttpResponse.setContentType() in my servlet? (i'm
returning the xml file to client)Its up to your receiving program how to interpret this though, so you probably dont need this. -
How to upload a file in servlet ?
hi i am new to this concept ..............
i need upload a file in mysql database .........
i created a form ...
<html>
<form method="post" action="http://localhost:8080/examples/servlet/UploadFile" enctype="multipart/form-data">
File
<input type="file" name="upload"/>
<input type="submit" value="load" />
</form>
</html>
what servlet receives from request ? how it will be stored in database ...
i need a detail explanation ...
ThanksThe apache jakarta commons FileUpload project has sample code for how to upload a file.
To store the file in the database you would use a preparedStatement. You can use anyone of the following methods ; setBlob, setBinaryStream, setBytes.
The datatype of the column storing the document depend on the databse. SQL Server used image and postgres uses bytea -
How to display XML file in browser using Servlets?
Hi My XML file is like this:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:purchase_order_MT xmlns:ns0="http://filetohttp.com">
<ORDER_HEADER_IN>
<purchase_date/>
<purchase_group/>
<purchase_org/>
</ORDER_HEADER_IN>
<vendor/>
<ORDER_ITEMS_IN>
<item>
<storage_location/>
<plant/>
<quantity/>
<material/>
</item>
</ORDER_ITEMS_IN>
<ORDER_SCHEDULES_IN>
<item>
<delivery_date/>
</item>
</ORDER_SCHEDULES_IN>
</ns0:purchase_order_MT>
My Servlet receives this XML file and it should display the above XML as it is, How to do that?
Please help me I have posted same question in many forums but i got no proper reply.
Thanks a lotIf you only need to display it, consider your HttpServletRequest just as byte stream. :) Just read from ServletInputStream and write it back into ServletOutputStream of HttpServletResponse.
If you want to process incoming XML, please give some details first, what exactly you want to do. :) -
Get Thread information in a Servlet
Hi,
I'm wondering if there is a way to get the running thread information in a Servlet, Something like an ID. For example, each time the Servlet receives a new request, the Servlet container will create a new thread to run the code, I want to know and log the information of this Thread.
Any ideas?
Thanks in advanceNot sure why you want to know what thread it is. The container multi-threads for you. If you want to store a value for use later in the thread, use ThreadLocal. If you want to spin off other threads, J2EE frowns on this, but you can do so. I'm not at all clear why the name or ID is important, since it is normally arbitrary and implementation-dependent on the J2EE container. If you are simply trying to log which thread is doing what, Log4J and the Logging API allow you to specify a pattern that will include the thread name without any coding on your part. So, I am having trouble understanding why you think you have this requirement.
- Saish -
How to get XML file using servlets that XI sent to my J2EE appl?
Hi All!
I have a scenario like XI sends xml file to j2ee application. In my J2EE application my servlet receives this xml. Will the xml file be in my HTTPServletRequest object? if so how to get that file from Request object.
Please help me its urgent, Any code help is highly appreciated.
My xml file will be like this:
<ns0:Http_Message_Type_Demo
xmlns:ns0="http://abcdemo.com">
<Name>ABC</Name>
<RollNo>123</RollNo>
<Address>a-4</Address>
</ns0:Http_Message_Type_Demo>
somebody should help me!please
ThanksHi,
You can use HTTPServletRequest object to get the XML payload.
BufferedReader reader = request.getReader(); //gets XML payload
String line = reader.readLine(); // to read the XML payload line by line
(request is the HTTPServletRequest object)
Regards,
Uma
Maybe you are looking for
-
Purchase Order - service specification - outline hierarchy
When creating a purchase order for services, I am entering services lines in the SERVICES TAB, I would like to structure the services in the service specification into a hierarchy of outline levels. How I can do this? How can I activate the Service
-
Dear Friends Goodmorning, We have One company , and Two company codes, A and B One company Code (A) Make a Purchases in F-43 Another Company Code (B) will make a payment: F-53 What is the Configuration Need? Please help me what is the configuration
-
Sandard Smart Form output into PDF format.
Hi to all, Any one please guide me, how to convert sandard Smart Form output into PDF format. Regards, Thanesh
-
Has anyone used JBuilder 9 to compile to a "stand-alone native executable"? We are considering JBuilder 9, and this would be useful in some small utility projects. I'm just wondering if it works like the marketing propaganda says it does. Does it rea
-
This is the message I get when I try to run Photoshop 64 bit. I can run the other Photoshop just fine. I am not sure what caused it or why it is happening. It ran just fine for about 3 months and bam it just stopped. I think it might be from an updat