BufferedReader readLine() not returning null
I'm trying write an SMTP client using Socket.
I'm sending EHLO command to the SMTP server is is returning multiline response. When I tried to read this multiline response using the BufferedReader in a while loop, it is never returning null.
Following is my code snippet
while(true)
data=reader.readLine();
multilineData +=data+"\r\n";
if(data==null )
break;
}why it is not returning?
I have written debug statements.
It is printing the following lines and it still expecting something from the server even though server has finished sending all the response.
250-mail.merakdemo.com Hello <hostname>, pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH CRAM-MD5 DIGEST-MD5 LOGIN PLAIN
250-AUTH=LOGIN
250-STARTTLS
250 HELP
This is the end of response from server.
And even I tried to break the while loop by checking the "HELP" String in the response. It is breaking the loop, but it is never returning the control.
Following is the Code snippet:
private String pullMultilineData(BufferedReader reader) throws CommunicationException
String multilineData="";
String data="";
try
while(true)
data=reader.readLine();
multilineData +=data+"\r\n";
// as per SMTP Protocol last line is without "-"
if(data==null || data.equals("") || data.indexOf("-")==-1)
break;
logger.log(Level.DEBUG, "Data: "+data);
catch(IOException ioe)
logger.log(Level.ERROR, "I/O exception: "+ioe);
throw new CommunicationException("unable to pull the respose, i/o error occured");
return multilineData;
}
Similar Messages
-
SELECT statement not returning NULL records
I have the following SELECT statement:
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME <> 'N/A';
I also tried:
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME != 'N/A';
Same results - There ARE Null DUPS_SAME values
which are not being selected. I get NO results.
When I execute this, I do get NULL values.
SELECT *
FROM RPT_DS1_CNT_CAT
WHERE DUPS_SAME IS NULL;
How can I ensure that I get all non - 'N/A' records
if it won't pick up the nulls? Is there a function
I can use or a different wording? I do want to use
!= or <> because there may be other values besides
'N/A' such as 'YES' or 'NO' and they may be null or
filled with spaces.The expression
NVL(DUPS_SAME,'') is meaningless. You're saying "If DUPS_SAME is NULL, return the empty string, which is NULL, otherwise return DUPS_SAME." If you're going to use NVL, the string that gets returned if the column is NULL should be non-NULL, i.e.
NVL(DUPS_SAME,'DUPS_SAME was NULL') Your query should, as others have pointed out, either be
SELECT *
FROM rpt_ds1_cnt_cat
WHERE dups_same <> 'N/A' OR dups_same IS NULLor
SELECT *
FROM rpt_ds1_cnt_cat
WHERE NVL(dups_same, 'DUPS_SAME is NULL') <> 'N/A' Either of these return the same results as your query but they're going to be far clearer for whoever needs to maintain the code. There may be performance differences as well if DUPS_SAME is indexed depending on the data distribution...
Justin -
Subquery not returning NULL rows
Hi,
I have been working with SQL since very long, but sorry, I have not come across following problem.
In the FROM clause, I use one sub query and a table. If I run sub query alone, it lists records even if rows with RATE=NULL.
But when I join sub query with other table, it is not fetching any records for RATE=NULL.
SELECT *
FROM
(SELECT key, perceivedseverity, eventtime, nvl(rate,'NA') rate FROM tr_alarm_history a
WHERE eventtime = (SELECT MAX(eventtime) FROM tr_alarm_history WHERE key = a.key)) a,
tr_lot_list b
WHERE a.key = b.localtargetname
and b.ttid='IM_20110516_8711' ;
The sub query -
" SELECT key, perceivedseverity, eventtime, nvl(rate,'NA') rate FROM tr_alarm_history a
WHERE eventtime = (SELECT MAX(eventtime) FROM tr_alarm_history WHERE key = a.key) "
returns all records including RATE=NULLs. But when I join them, RATE columns with NULL will be filtered. Please note that joining condition (WHERE a.key = b.localtargetname) is not a problem as they will always match irrespective of RATE having NULL.
Please let me know why this behaviour and is there any other alternative where in I can get the records even if RATE column is NULL.
Thanks a lot for your help.
-AnandI am extreemly sorry. 2 or 3 examples I took were wrong one's, which were not having RATE=NULL. So I got into such confusion.
PLEASE INORE MY QUESTION.
And thanks for your valuable time.
With Best Wishes,
-Anand -
BufferedReader.readLine doesn't return null
Hi there,
I'm trying to put together a simple Chat client/server application. The issue I'm having is with the Server app. I have a class that extends Thread which contains this call:
temp = input.readLine()
in the run() method. Everytime I connect with the client side app, an instance of this class "ReceivingThread" is created and is supposed to read in any messages coming in using a BufferedReader. That's the input variable type. According to the API readLine() is supposed to return null when there's nothing more to read in. In my code I check for null but it never seems to leave the while loop.
Please advise,
Alan
package vcserver;
import java.io.*;
import java.net.*;
import java.util.StringTokenizer;
public class ReceivingThread extends Thread
private BufferedReader input;
private MessageListener messageListener;
private boolean keepListening = true;
public ReceivingThread(MessageListener listener, Socket clientSocket)
super("ReceivingThread: " + clientSocket);
messageListener = listener;
try
clientSocket.setSoTimeout(5000);
input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
catch(IOException ioe){ioe.printStackTrace();}
public void run()
StringBuffer messageBuffer = new StringBuffer();
String temp = "";
try
START:
while(keepListening)
while(true)
try
temp = input.readLine();
catch(InterruptedIOException iioe)
continue;
catch(IOException ioe){break;}
if(temp != null)
try
System.out.println("temp: " + temp);
messageBuffer.append(temp);
catch(Exception e)
e.printStackTrace();
break START;
else
break;
System.out.println("out of while loop...message:\n" + messageBuffer.toString());
String message = messageBuffer.toString();
StringTokenizer tokenizer = new StringTokenizer(message, Constants.MESSAGE_SEPERATOR);
if(tokenizer.countTokens() == 2)
System.out.println("message received");
messageListener.messageReceived(tokenizer.nextToken(), tokenizer.nextToken());
else
if(message.equalsIgnoreCase(Constants.MESSAGE_SEPERATOR + Constants.DISCONNECT_STRING))
stopListening();
input.close();
catch(IOException ioe){ioe.printStackTrace();}
public void stopListening()
keepListening = false;
}Edited by: ashiers on Nov 20, 2007 10:51 AMNot to mention garbage ...
readLine() returns null when there is nothing more to read, i.e. when the other end has closed its socket. If the other end hasn't closed its socket it won't return null, it will block. There might be more data coming later, at which time readLine() will unblock and read it and return it. -
Does readLine return null at end of file?
My program is reading lines from a file in groups of 5. I want it to stop reading when it has reached the end of the file. Does readLine return null when there are no more lines or is there another way to end a loop like this?
Thanks!
try {
String a, b, c, d, e;
a = BR.readLine();
b = BR.readLine();
c = BR.readLine();
d = BR.readLine();
e = BR.readLine();
while (a != null){
a = BR.readLine();
b = BR.readLine();
c = BR.readLine();
d = BR.readLine();
e = BR.readLine();
}readLine returns null at end of file. I actually use the following to end my loop...maybe this would help you.
FileReader file = new FileReader("bkupcandilist.bin");
BufferedReader buff = new BufferedReader(file);
boolean eof = false;
while(!eof) { //retrieve all candidate names
scandi = buff.readLine();
if(scandi == null) {
eof = true;
} else {
atally = new String[2];
atally[0] = scandi;
atally[1] = "0";
listtally.add(atally);
buff.close(); -
FindNode returning Null And XML Not Accepting Special Characters
Hi All,
i am trying the get the attribute value in the element "ns4:InfoCFDi" using FindNode method, but the method is returning NULL. I used the same code for other sample as well and was successfull. but for this specific XML file(which is below) I am getting a Null.
i can get till S:Body, but when i try to use FindNode for ":Body/s4:ResponseGeneraCFDi" I get Null value.
And I used "S:Body/*[local-name()=" | "ns4:ResponseGeneraCFDi" | "]";
as mentioned in other post but still no success.
==>I Have one more question relating to special characters. I need to use characters such as - ó in my XML to read as well as write. When I try to read i am getting XML parse error and when writing, i cannot open the file properly.
Your help is much appreciated.
My code is here:
Local XmlDoc &inXMLDoc, &reqxmldoc;
Local XmlNode &RecordNode;
&inXMLDoc = CreateXmlDoc();
&ret = &inXMLDoc.ParseXmlFromURL("D:\Agnel\Mexico Debit Memo\REALRESPONSE.xml");
If &ret Then
&RecordNode = &inXMLDoc.DocumentElement.FindNode("" );
If &RecordNode.IsNull Then
Warning MsgGet(0, 0, "Agnel FindNode not found.");
rem MessageBox(0, "", 0, 0, "FindNode not found");
Else
&qrValue = &RecordNode.GetAttributeValue("asignaFolio ");
Warning MsgGet(0, 0, "asignaFolio." | &qrValue);
End-If;
Else
Warning MsgGet(0, 0, "Error. ParseXmlString");
End-If;
XML File:
- <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
- <S:Body>
- <ns4:ResponseGeneraCFDi xmlns="http://www.xxl.com/ns/xsd/bf/rxx/52" xmlns:ns2="http://www.sat.gob.mx/cfd/3" xmlns:ns3="http://www.xx/ns/bf/conector/1&quo t; xmlns:ns4="http://www.xx/ns/xsd/bfxx/xx/32&qu ot; xmlns:ns5="http://www.xxcom/ns/xsd/bf/xxxxx&q uot; xmlns:ns6="http://wwwxx.com/ns/referenceID/v1">
- <ns3:Result version="1">
<ns3:Message message="Proceso realizado con exito." code="0" />
</ns3:Result>
- <ns4:InfoCFDi noCertificadoSAT="20001000000100003992" refId="STORFAC20121022085611" fechaTimbrado="2012-10-22T08:56:45" qr=" "
uuid="a37a7d92-a17e-49f4-8e4d-51c983587acb" version="3.2" tipo="XML" archivo="xxx" sello="B8WjuhYLouSZJ6LU2EjxZ0a4IKyIENZNBx4Lb4 jkcAk6wA+EM477yz91/iDdsON0jm8xibBfom5hvHsH7ZK1ps3NnAXWr1LW 7ctmGsvYKAMvkCx/yOVzJTKFM2hN+OqCTE0WVfgv690vVy2CDQWKlMxbK+3idwG4t OKCMelrN9c=" fecha="2012-10-22T08:56:44" folio="281" serie="IICC">
<InfoEspecial valor="Este documento es una representacin impresa de un CFDI." atributo="leyendaImpresion" />
<InfoEspecial valor="||1.0|a37a7d92-a17e-49f4-8e4d-51c983587acb|2012-10-22T08:56:45|B8WjuhYLouSZJ6LU2EjxZ0a4IKyIENZNBx4Lb4 jkcAk6wA+EM477yz91/iDdsON0jm8xibBfom5hvHsH7ZK1ps3NnAXWr1LW 7ctmGsvYKAMvkCx/yOVzJTKFM2hN+OqCTE0WVfgv690vVy2CDQWKlMxbK+3idwG4t OKCMelrN9c=|20001000000100003992||" atributo="cadenaOriginal" />
<InfoEspecial valor="Doscientos dieciocho mil cuatrocientos setenta y cinco pesos 00/100 M.N." atributo="totalConLetra" />
</ns4:InfoCFDi>
</ns4:ResponseGeneraCFDi>
</S:Body>
</S:Envelope>
TIAFirst of all you have to supply a value you want to search for and this has to be the complete path to the value. You're saying you already tried that, but can you paste the code which you used for that? I don't see the path mentioned in the code you posted.
*FindNode*
Syntax
FindNode(Path)
Description
Use the FindNode method to return a reference to an XmlNode.
The path is specified as the list of tag names, to the node that you want to find, each separated by a slash (/).
Parameters
Path
Specify the tag names up to and including the name of the node that you want returned, starting with a slash and each separated by a slash (/). This is known as the XPath query language.>
Another option would be this snippet of code:
&InfoCFDiArray = GetElementsByTagName("ns4:InfoCFDi");
&InfoCFDiNode = &InfoCFDiArray [1];
&attValue = &InfoCFDiNode.GetAttributeValue("noCertificadoSAT")
Warning(&attValue);
It creates an array of XML Nodes which match the name "ns4:InfoCFDi". Since there's only one in the XML it's safe to assume it will be the one and only node in the array. I've assigned that node to the variable &InfoCFDiNode and use that to retrieve the attribute "noCertificadoSAT" value. The warning message should display the value supplied there.
Concering the special characters; you will have to change the encoding of the XML. Peoplecode sets this to UTF-8 by default, but doesn't include this in the header. There's a little hack for that somewhere on the web, I'll see if I can find it. -
Request.getCookies() returns null, not 0 length array
(reposted from J2EE forum)
Just upgraded to 9ias with Embedded OC4J and we were getting a NullPointerException.
Our previous calls to request.getCookies() AKA http://java.sun.com/products/servlet/2.1/api/javax.servlet.http.HttpServletRequest.html#getCookies()
would return an an array of Cookie Objects or an array of zero length if there are no cookies.
When we upgraded to 9ias, we got the NPE.
Know why?
OC4J implementation of HttpServletRequest doesn't return a zero length array, it returns a null object when there are no cookies!!!
So we had to change our code to catch this.
Not a big problem, and it's fixed now, but it was a problem nonetheless.
Any reason/rationale for why this was done this way? Anyone? Bueller?Josh,
According to Servlet Spec 2.3 (page 193) SRV 15.1.3.2 Methods for (HttpServletRequest SRV.15.1.3) getCookies() returns null if no cookies present. So we are compliant to the spec.
regards
Debu Panda
Oracle That's strange that the NPE problem didn't occurr until deleting cookies on OC4J, then.
Thanks for responding! -
Graphics returning null in one place, but not another.
If you want to compile and run my program.... you can get all the files here:
http://s94182144.onlinehome.us/randomstuff/files.zip
(The main classes you'll need to look at are DrawingCanvas, Trig and GraphEngine)
Here's a visual just in case:
http://s94182144.onlinehome.us/randomstuff/graph.jpg
When I click the "Graph It" button, I'm sending all those variables in the window to another class. Except the method I need to call is passed Graphics g... and thus, I needed to create a graphics variable. But it's returning null.
Here is my code in GraphEngine, which runs when a button is clicked. You'll notice for Graph It... I created a Graphics variable... this returns null. Except you'll also notice I do the same thing for "Clear"... but this works.
NOTE: I was getting mad so I named some methods not so nicely :p .... you may notice they are different in my files.
public void actionPerformed(ActionEvent e)
userDisplay=e.getActionCommand();
if(userDisplay.equals("Draw"))
String progChoice=grapher.graphType.getSelectedItem();
System.out.println(progChoice);
if(progChoice.equals("Lines"))
grapher.allButtons[0].enable();
draw();
else if(progChoice.equals("Scatter Plot"))
lineOfBestFit();
else if(userDisplay.equals("Graph It"))
Trig.graphThisStuff();
Graphics g = canvas.getGraphics();
canvas.trig(g);
else if(userDisplay.equals("Clear"))
Graphics g = canvas.getGraphics();
System.out.println(g);
canvas.clear(g);
else if(userDisplay.equals("Reset"))
Trig.restartThis();
else if(userDisplay.equals("Credits"))
showInstructionsFrame();
else if(userDisplay.equals("Help"))
showHelpFrame();
else if(userDisplay.equals("Create Sinusodial Graph"))
showTrigFrame();1. Do you expect forum members to download and unzip your code? Good luck...
2. Inside almost every "big" problem is a small one trying to get out. Write a minimal program
demonstrating your problem (say <50 lines) and post that. The shorter code and the easier it
is to copy, paste and run, the more forum members will actually give it a go.
That being said, you problem is that you are using Component's getGraphics at all. Don't use it.
It doesn't work very well -- they rendering you do is temporary, if you iconify and restore your
window your changes will disappear (sometimes even moving another window past yours will do this!).
What should you do instead? Put all your rendering code in paintComponent (or subroutines
it calls). Changes in state of your app should trigger a call to repaint (or you will call it directly).
Repainting will eventually cause your paintComponent to be called. -
PageDef operatingBinding is not visible or returning null
Hi,
I have an ADF application with taskflow which contains a page fragement which has some methodAction bindings in its pageDef.
I dragged this taskflow as a region in a Webcenter Portal application project page which has a pageTemplate. When that page opens, it opens fine by initializing the page which involves invoking some methodAction bindings.
After the page got loaded, I click on a button, this again requires methodAction bindings but this time that operationBinding is returning null. so, I am not able to invoke the method.
I am getting the operatingBinding in my managed bean as below. operatingBinding is fine while loading the page (init method) but it is giving null when I click on any button in the page after page load.
OperationBinding operationBinding = getBindings().getOperationBinding("getPersonId")
public BindingContainer getBindings() {
if(this.bindings == null){
FacesContext fc = FacesContext.getCurrentInstance();
this.bindings = (BindingContainer)fc.getApplication().evaluateExpressionGet(fc, "#{bindings}", BindingContainer.class);
return bindings;
I dragged the same taskflow to an other ADF application and it worked fine before and after loading the page. I do not understand why it is not working in portal application. But it is nothing to do with Webcenter I believe. I just wanted to know if anyone faced this issue before. Please give some pointers if you have any.
regards
Vinay KumarPage Definition is
*<?xml version="1.0" encoding="UTF-8" ?>*
*<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"*
version="11.1.1.59.23" id="SearchFragmentPageDef"
Package="com.johnlewis.cpl.wcportal.ui">
*<parameters/>*
*<executables>*
*<variableIterator id="variables"/>*
*<iterator Binds="PartnerHrchy" RangeSize="25"*
DataControl="PartnerSearchAMDataControl"
id="PartnerHrchyIterator"/>
*<iterator Binds="PartnerSearchTempVO1" RangeSize="25"*
DataControl="PartnerSearchAMDataControl"
id="PartnerSearchTempVO1Iterator"/>
*<searchRegion Binds="PartnerSearchTempVO1Iterator" Criteria=""*
Customizer="oracle.jbo.uicli.binding.JUSearchBindingCustomizer"
id="PartnerSearchTempVO1Query"/>
*</executables>*
*<bindings>*
*<methodAction id="getPersonId"*
InstanceName="PartnerSearchAMDataControl.dataProvider"
DataControl="PartnerSearchAMDataControl"
RequiresUpdateModel="true" Action="invokeMethod"
MethodName="getPersonId" IsViewObjectMethod="false"
ReturnName="data.PartnerSearchAMDataControl.methodResults.getPersonId_PartnerSearchAMDataControl_dataProvider_getPersonId_result">
*<NamedData NDName="uname" NDType="java.lang.String"/>*
*</methodAction>*
*<methodAction id="initPartnerSearch"*
InstanceName="PartnerSearchAMDataControl.dataProvider"
DataControl="PartnerSearchAMDataControl"
RequiresUpdateModel="true" Action="invokeMethod"
MethodName="initPartnerSearch" IsViewObjectMethod="false"
ReturnName="data.PartnerSearchAMDataControl.methodResults.initPartnerSearch_PartnerSearchAMDataControl_dataProvider_initPartnerSearch_result">
*<NamedData NDName="uname" NDType="java.lang.String"/>*
*</methodAction>*
*<methodAction id="searchPartnerTempTable"*
InstanceName="PartnerSearchAMDataControl.dataProvider"
DataControl="PartnerSearchAMDataControl"
RequiresUpdateModel="true" Action="invokeMethod"
MethodName="searchPartnerTempTable"
IsViewObjectMethod="false">
*<NamedData NDName="uname" NDType="java.lang.String"/>*
*<NamedData NDName="param" NDType="java.lang.String"/>*
*<NamedData NDName="leavers" NDType="java.lang.String"/>*
*</methodAction>*
*<tree IterBinding="PartnerHrchyIterator" id="PartnerHrchy">*
*<nodeDefinition DefName="com.johnlewis.cpl.wcportal.model.view.PartnerHrchy"*
Name="PartnerHrchy0">
*<AttrNames>*
*<Item Value="FullName"/>*
*<Item Value="Position"/>*
*<Item Value="LocationCode"/>*
*</AttrNames>*
*<Accessors>*
*<Item Value="PositionIdPartnerHrchy"/>*
*</Accessors>*
*</nodeDefinition>*
*</tree>*
*<tree IterBinding="PartnerSearchTempVO1Iterator" id="PartnerSearchTempVO1">*
*<nodeDefinition DefName="com.johnlewis.cpl.wcportal.model.view.PartnerSearchTempVO"*
Name="PartnerSearchTempVO10">
*<AttrNames>*
*<Item Value="PartnerName"/>*
*<Item Value="EmployeeNumber"/>*
*<Item Value="SecurityProfileName"/>*
*<Item Value="ResponsibilityName"/>*
*<Item Value="PositionCode"/>*
*<Item Value="LocationCode"/>*
*</AttrNames>*
*</nodeDefinition>*
*</tree>*
*</bindings>*
*</pageDefinition>*
Managed Bean code to invoke methodAction is
*public void myTimeCard(ActionEvent actionEvent) {*
*// Add event code here...*
String uname = null;
uname = ADFContext.getCurrent().getSecurityContext().getUserName();
System.out.println("User name is " + uname);
OperationBinding operationBinding = getBindings().getOperationBinding("getPersonId");
System.out.println("Before setting parameters");
System.out.println("operationBinding is " + operationBinding);
*if(operationBinding != null){*
operationBinding.getParamsMap().put("uname", uname);
System.out.println("After setting parameters");
String out = (String)operationBinding.execute();
System.out.println("After invoking method");
System.out.println("Person Id from getPersonId is " + out);
if(out != null)
personId = Long.parseLong(out);
System.out.println("Person Id of search is " + personId);
System.out.println("User name is " + uname);
ADFContext.getCurrent().getPageFlowScope().put("personId", personId);
ADFContext.getCurrent().getPageFlowScope().put("respId", null);
ADFContext.getCurrent().getPageFlowScope().put("type", "ess");
ADFContext.getCurrent().getPageFlowScope().put("userName",uname); //TODO username need to be passed from security Context
*}* -
XMLDocument.validateContent(schema) returns "Element not completed: 'null'"
Hello all. What differences between 2 XMLDocument's (created manually and through DOMParser) for XMLDocument.validateContent()? xmlparserv2.jar from Oracle 10.2.0.3.
import oracle.xml.parser.schema.XMLSchema;
import oracle.xml.parser.schema.XSDBuilder;
import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import oracle.xml.parser.v2.XMLParseException;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import java.io.StringReader;
public class DomValidateTest {
public static void main(String[] args)
throws Exception {
// Schema
XSDBuilder builder = new XSDBuilder();
InputSource schemaSource = new InputSource(
new StringReader(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
" <xs:element name=\"root\" nillable=\"false\">\n" +
" <xs:complexType>\n" +
" <xs:sequence>\n" +
" <xs:element name=\"value\" type=\"xs:string\" nillable=\"false\"/>\n" +
" </xs:sequence>\n" +
" </xs:complexType>\n" +
" </xs:element>\n" +
"</xs:schema>"
XMLSchema schema = builder.build(schemaSource);
// First document
XMLDocument doc = new XMLDocument();
Element rootElement = doc.createElement("root");
doc.appendChild(rootElement);
rootElement.appendChild(doc.createElement("value"));
doc.print(System.out);
try {
doc.validateContent(schema);
System.out.println("document validation succeed.");
} catch (XMLParseException e) {
System.err.println("document validation error: " + e.getMessage());
// Second document
DOMParser parser = new DOMParser();
parser.parse(new StringReader("<root><value/></root>"));
XMLDocument doc2 = parser.getDocument();
doc2.print(System.out);
try {
doc2.validateContent(schema);
System.out.println("document2 validation succeed.");
} catch (XMLParseException e) {
System.err.println("document2 validation error: " + e.getMessage());
}Output:
<root>
<value/>
</root>
document validation error: Element not completed: 'null'
<root>
<value/>
</root>
document2 validation succeed.For validating an XML document with a schema
http://www.oracle.com/technology/pub/articles/vohra_xmlschema.html
Thanks but imho these examples shows how to validate XMLDocument during its creation. I already have XMLDocument and wish to validate it. -
URLConnection returns NULL when called from within a weblogic servlet
The following code snippet works when executed outside of weblogic, but does
not work from within a weblogic servlet instance.
URL u = new URL("http://" + ipString + newString.toString());
URLConnection uc = u.openConnection();
BufferedReader in = new BufferedReader (new InputStreamReader(uc.getInputStream()));
String response = "", response2 = "";
while(response2 != null)
response = ((response2 = in.readLine()) == null) ? response : response + response2;
The response is quite big. When this code is executed from within a weblogic servlet instance,
in.readLine always returns a null right away. Yet a TCP/IP trace shows that the packets are coming
back to my NT machine.
Other info:
Inside of weblogic:
u's handler is of type weblogic.net.http.Hanlder
uc is of type weblogic.net.http.HttpURLConnection
Outside of weblogic:
u's handler is of type sun.net.www.protocol.http.Handler
uc is of type sun.new.www.protocol.http.HttpURLConnection
Weblogic V4.51. Running on NT.
Attempted the following to no avail:
1. installing sp11
2. changing the security to permission java.security.AllPermission;
3. adding the following calls : uc.setRequestProperty("Content-Type", "text/xml");
uc.setDoInput(true);
uc.setDoOutput(true);
4. Started playing around with modifying the java.protocol.handler.pkgs system property,
but I shouldn't have to do this.
Any help would be appreciated.There are some problems with the WL implementations of certain protocols.
WL hides the Sun implementations when you are in the WebLogic server. Here
is an a solution that was posted to a similar problem:
Https is an add-in so to speak. Try this before you create your url:
System.setProperty ("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
// add the default security provider (again, in JSSE1.0.1)
int iap = java.security.Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider() );
dennisNote how the code overides the WL setting which overode the Sun setting.
Cameron Purdy
[email protected]
http://www.tangosol.com
WebLogic Consulting Available
"Brian Howell" <[email protected]> wrote in message
news:[email protected]...
>
The following code snippet works when executed outside of weblogic, butdoes
not work from within a weblogic servlet instance.
URL u = new URL("http://" + ipString + newString.toString());
URLConnection uc = u.openConnection();
BufferedReader in = new BufferedReader (newInputStreamReader(uc.getInputStream()));
>
String response = "", response2 = "";
while(response2 != null)
response = ((response2 = in.readLine()) == null) ? response : response +response2;
The response is quite big. When this code is executed from within aweblogic servlet instance,
in.readLine always returns a null right away. Yet a TCP/IP trace showsthat the packets are coming
back to my NT machine.
Other info:
Inside of weblogic:
u's handler is of type weblogic.net.http.Hanlder
uc is of type weblogic.net.http.HttpURLConnection
Outside of weblogic:
u's handler is of type sun.net.www.protocol.http.Handler
uc is of type sun.new.www.protocol.http.HttpURLConnection
Weblogic V4.51. Running on NT.
Attempted the following to no avail:
1. installing sp11
2. changing the security to permission java.security.AllPermission;
3. adding the following calls : uc.setRequestProperty("Content-Type","text/xml");
uc.setDoInput(true);
uc.setDoOutput(true);
4. Started playing around with modifying the java.protocol.handler.pkgssystem property,
but I shouldn't have to do this.
Any help would be appreciated. -
When I call BufferedInput.readLine(), and the data source is a socket, readLine()
will return the most recent text indefinitely until the client sends more text.
Isn't BufferedInput.readLine() supposed to clear the
buffer with each readLine() call?
Socket settings:
getTcpNoDelay: false
getSoLinger: 10
getSoTimeout: 75
getSendBufferSize: 8192
getReceiveBufferSize: 8192
Locations of complete source and output:
http://www.nationalinformatics.com/download/SocketServerClientTest.java
http://www.nationalinformatics.com/download/SocketServerTest_output.txt
http://www.nationalinformatics.com/download/SocketServerTest.java
http://www.nationalinformatics.com/download/SocketServerClientTest.java
http://www.nationalinformatics.com/download/SocketServerClientThread.java
</PRE>
Sample output:
SocketServerThread: readline loop.
SocketServerThread: Input line is 'hello' (length: 5)
SocketServerThread: input line was read
SocketServerThread: readline loop.
SocketServerThread: Input line is 'hello' (length: 5)
SocketServerThread: input line was read
. . . etc, until the client sends "Java Rules!" down the wire . . .
SocketServerThread: readline loop.
SocketServerThread: Input line is 'Java Rules!' (length: 11)
SocketServerThread: input line was read
SocketServerThread: readline loop.
SocketServerThread: Input line is 'Java Rules!' (length: 11)
SocketServerThread: input line was read
. . . etc . . .
Thread code that reads input from the client:
import java.net.*;
import java.io.*;
import java.util.*;
/** SocketServerThread is an independent thread that is used to test
socket connections.
<p>Copyright 2001 (c) Richard Schilling. All rights reserved.
class SocketServerThread extends Thread {
private boolean running;
private Socket socket = null;
public SocketServerThread(Socket s, boolean r) {
socket = s;
running = r;
public void run() {
try {
// Create a reader to receive messages from the client
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream())
String inputLine = null;
while ( running) {
System.out.println("SocketServerThread: readline loop.");
boolean lineread = false;
while (!lineread){
lineread = true;
try {
inputLine = in.readLine();
} catch (InterruptedIOException e){
lineread = false;
System.out.println("SocketServerThread: Interrupted exception while reading from 'in'");
} catch (SocketException e){
lineread = false;
System.out.println("SocketServerThread: could not read input stream 'in'");
if (inputLine != null){
if (inputLine.length() > 0){
String TrimmedInputLine = inputLine.trim();
System.out.println("SocketServerThread: Input line is '" + TrimmedInputLine + "' (length: " + TrimmedInputLine.length() + ")");
/* Process the string that has been received from the client.
System.out.println("SocketServerThread: input line was read");
if (TrimmedInputLine.equalsIgnoreCase("bye")){
running = false;
else{
// set the status of this thread so that it closes the connection and exits.
running = false;
inputLine = null;
yield();
in.close();
System.out.println("SocketServerThread: CONNECTION WITH CLIENT CLOSED");
} catch (IOException e) {
e.printStackTrace();Sounds like a bug to me. Do the other read() methods work as expected? I suppose you could compare the source from JDK1.3 with the source from JDK1.4 and see if something changed.
Worst case write your own method. I had to write one for J2ME since they decided that functionality wasn't important. grr.
Good luck. -
ReadLine() never returns even if SOTimeout is used
Hi,
I've run into a strange and (for me) hard to solve problem in my multi-threaded app which is IO intensive. After calling bufferedReader.readLine(), the tthread never returns from the call. I took a few thread dumps with a few seconds interval and the thread seems to be "popping around". Below are 6 dumps of the failing thread. I have socket.setSoTimeout(10000), but seems to have no effect in this situation. Any help would be much appreciated.
I'm running jdk1.4.2_05 on Windows XP
Bye,
Dag.
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at java.nio.HeapByteBuffer.compact(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at sun.nio.cs.SingleByteDecoder.decodeArrayLoop(Unknown Source)
at sun.nio.cs.SingleByteDecoder.decodeLoop(Unknown Source)
at java.nio.charset.CharsetDecoder.decode(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at java.nio.CharBuffer.<init>(Unknown Source)
at java.nio.HeapCharBuffer.<init>(Unknown Source)
at java.nio.CharBuffer.wrap(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at java.nio.CharBuffer.wrap(Unknown Source)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)
"runner4" prio=5 tid=0x02ddb500 nid=0xfc8 runnable [39df000..39dfd8c]
at sun.nio.cs.StreamDecoder.read(Unknown Source)
- waiting to lock <0x10666590> (a java.io.InputStreamReader)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
- locked <0x10666590> (a java.io.InputStreamReader)
at java.io.BufferedReader.readLine(Unknown Source)
at MyClass.someMethod(MyClass.java:100)The SoTimeout times out the connect if the connect to
the other end is lost.No it doesn't, it has no effect on the connect timeout.
This does not mean it is triggered just because you
have recieved no data.Yes it does, this is exactly what it does.
The following program works for me, i.e. it throws an InterruptedIOException:
import java.io.*;
import java.net.*;
public class SocketReadLineTest
ServerSocket ss;
public SocketReadLineTest() throws IOException
this.ss = new ServerSocket(0);
public static void main (String args[]) throws Exception
SocketReadLineTest t = new SocketReadLineTest();
Socket s = new Socket("localhost",t.ss.getLocalPort());
s.setSoTimeout(1000);
BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
String l = r.readLine();
s.close();
}It also works as expected (i.e. reads null) if the server closes the accepted socket immediately without sending anything. -
Output parameters always return null when ExecuteNonQuery - No RefCursor
I am trying to call a procedure through ODP that passes in one input parameter and returns two (non-RefCursor) VARCHAR2 output parameters. I am calling the procedure using ExecuteNonQuery(); however, my parameters always return null. When I run the procedure outside of ODP, such as with SQLPlus or SQL Navigator, the output parameters are populated correctly. For some reason, there appears to be a disconnect inside of ODP. Is there a way to resolve this?
Anyone have this problem?
Here is the basic code:
===========================================================
// External call of the class below
DBNonCursorParameterTest Tester = new DBNonCursorParameterTest();
===========================================================
// The class and constructor that calls the procedure and prints the results.
public class DBNonCursorParameterTest
public DBNonCursorParameterTest()
// The test procedure I used is a procedure that takes a recordID (Int32) and then returns a
// general Name (Varchar2) and a Legal Name (Varchar2) from one table with those three fields.
string strProcName = "MyTestProc;
OracleConnection conn = new OracleConnection(DBConnection.ConnectionString);
OracleCommand cmd = new OracleCommand(strProcName,conn);
cmd.CommandType = CommandType.StoredProcedure;
// Create the input parameter and the output cursor parameter to retrieve data; assign a value to the input parameter;
// then create the parameter collection and add the parameters.
OracleParameter pBPID = new OracleParameter("p_bpid", OracleDbType.Int32, ParameterDirection.Input);
OracleParameter pBPName = new OracleParameter("p_Name", OracleDbType.Varchar2, ParameterDirection.Output);
OracleParameter pBPLegalName = new OracleParameter("p_LegalName", OracleDbType.Varchar2, ParameterDirection.Output);
pBPID.Value = 1;
// Open connection and run stored procedure.
try
conn.Open();
cmd.Parameters.Add(pBPID);
cmd.Parameters.Add(pBPName);
cmd.Parameters.Add(pBPLegalName);
cmd.ExecuteNonQuery();
Console.Write("\n" + cmd.CommandText + "\n\n");
//for (int i = 0; i < cmd.Parameters.Count; i++)
// Console.WriteLine("Parameter: " + cmd.Parameters.ParameterName + " Direction = " + cmd.Parameters[i].Direction.ToString());
// Console.WriteLine("Parameter: " + cmd.Parameters[i].ParameterName + " Status = " + cmd.Parameters[i].Status.ToString());
// Console.WriteLine("Parameter: " + cmd.Parameters[i].ParameterName + " Value = " + cmd.Parameters[i].Value.ToString() + "\n");
foreach (OracleParameter orap in cmd.Parameters)
Console.WriteLine("Parameter: " + orap.ParameterName + " Direction = " + orap.Direction.ToString() + " Value = " + orap.Value.ToString());
Console.WriteLine("Parameter: " + orap.ParameterName + " Status = " + orap.Status.ToString());
Console.WriteLine("Parameter: " + orap.ParameterName + " Value = " + orap.Value.ToString() + "\n");
// End Test code.
catch (Exception ex)
throw new Exception("ExecuteQuery() failed: " + ex.Message);
finally
this.Close();
public void Close()
if (conn.State != ConnectionState.Closed)
conn.Close();
=========================================================
Other things to note:
I have no problems with returning RefCursors; they work fine. I just don't want to use RefCursors when they are not efficient, and I want to have the ability to return output parameters when I only want to return single values and/or a value from an insert/update/delete.
Thanks for any help you can provide.Hello,
Here's a short test using multiple out parameters and a stored procedure. Does this work as expected in your environment?
Database:
/* simple procedure to return multiple out parameters */
create or replace procedure out_test (p_text in varchar2,
p_upper out varchar2,
p_initcap out varchar2)
as
begin
select upper(p_text) into p_upper from dual;
select initcap(p_text) into p_initcap from dual;
end;
/C# source:
using System;
using System.Data;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
namespace Miscellaneous
class Program
static void Main(string[] args)
// change connection string as appropriate
const string constr = "User Id=orademo; " +
"Password=oracle; " +
"Data Source=orademo; " +
"Enlist=false; " +
"Pooling=false";
// the stored procedure to execute
const string sql = "out_test";
// simple input parameter for the stored procedure
string text = "hello!";
// create and open connection
OracleConnection con = new OracleConnection(constr);
con.Open();
// create and setup connection object
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.StoredProcedure;
// the input paramater
OracleParameter p_text = new OracleParameter("p_text",
OracleDbType.Varchar2,
text.Length,
text,
ParameterDirection.Input);
// first output parameter
OracleParameter p_upper = new OracleParameter("p_upper",
OracleDbType.Varchar2,
text.Length,
null,
ParameterDirection.Output);
// second output parameter
OracleParameter p_initcap = new OracleParameter("p_initcap",
OracleDbType.Varchar2,
text.Length,
null,
ParameterDirection.Output);
// add parameters to collection
cmd.Parameters.Add(p_text);
cmd.Parameters.Add(p_upper);
cmd.Parameters.Add(p_initcap);
// execute the stored procedure
cmd.ExecuteNonQuery();
// write results to console
Console.WriteLine(" p_text = {0}", text);
Console.WriteLine(" p_upper = {0}", p_upper.Value.ToString());
Console.WriteLine("p_initcap = {0}", p_initcap.Value.ToString());
Console.WriteLine();
// keep console from closing when run in debug mode from IDE
Console.WriteLine("ENTER to continue...");
Console.ReadLine();
}Output:
p_text = hello!
p_upper = HELLO!
p_initcap = Hello!
ENTER to continue...- Mark -
BufferedReader does not reset stream, unable to write more than one
Hi,
The following is a program that tries to read a file and write into 10 files.
I am using bufferedReader.reset() to get to the starting position of the stream, but unfotunately it says mark not supported .
Can anyone please tell me , why the stream does not reset, and do I have to close and then again reopen the input reader to write multiple times. Are there any other alternatives?
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class TestFile {
public static void main(String args[]) {
try {
FileReader fr = new FileReader("testinput.txt");
BufferedReader br = new BufferedReader(fr);
BufferedWriter out = null;
String line = null;
String name = "testoutput";
FileWriter fw = null;
for(int i=0;i<10;i++){
String fname = name + i + ".txt";
fw = new FileWriter(fname ,false);
out = new BufferedWriter(fw);
while((line = br.readLine())!= null){
out.write(line);
out.close();
if(br.markSupported()){
br.reset();
} catch (FileNotFoundException fnf) {
fnf.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}Exception
java.io.IOException: Stream not marked
at java.io.BufferedReader.reset(BufferedReader.java:485)
at TestFile.main(TestFile.java:30)but unfotunately it says mark not supported No it doesn't. It says
java.io.IOException: Stream not marked
No where in that code are you calling the method "mark" to set a mark and the API for reset says:
Reset the stream to the most recent mark.And it says it throws an IOException
If the stream has never been marked, or if the mark has been invalidated.
Maybe you are looking for
-
My i-phone 3GS with latest operating system is not recognised in i-tunes, howver windows XP does see the device. I have tried all Apple support reccomendations to no avail. There was an error message when last syncing the device with i-tunes, I have
-
Windows 7 Backup "The System cannot find the path specified" - Error Code 0x80070003
I'm having severe problems backing up my own machine to a share on our FILE-SERVER as \\FILE-SERVER\Backup\ I have already backed up another PC successfully using exactly the same settings I have used on my own PC. So I presume it is nothing to do wi
-
SAP BW data in ODS to XML and sending this XML file to 3rd Party
Hi Gurus, We are having a scenario in which we have to convert our data in ODS to XML and need to provide this XML file to our clients so that they can use this XML file in their 3rd party system. Now the issue is that i have created ABAP program for
-
I am getting this error message in the log file while installaing Oracle 9i on RHEL4 An unexpected exception has been detected in native code outside the VM. Unexpected Signal : 11 occurred at PC=0x8e44c0 Function name=(N/A) Library=/lib/ld-linux.so.
-
I just want to be able to use my phone, l thought maybe the battery was too low for it to finish loading so l plugged it in over night and it hasn't moved at all. What should l do?