Results 1 to 9 of 9
  1. #1
    ksur12345 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default Multiple Requests on Servlet Errored

    I am sending Same data over 15 times in a gap of 3 secods.. to my servlet.

    Each instance will have to check the data with an XSD , I am using
    Validator validator = schema.newValidator() for that. Since I have a huge XML and huge XSD, each process take around 30 secs.

    Now I get an Error
    "src-resolve: Cannot resolve the name 'xml:lang' to a(n) 'attribute declaration' component."

    But this is only for few of those 15 times I am doing it. and its random, I am not sure why it would work once and not for few.. I am not accessing any file for XSD to think if its locking issue , nor any database .. the XSD is in a string the Servlet receives a doPost Request of XML ..


    Can anyone suggest ? Please

    Thanks
    Sur

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Does it do this with the same XML?
    You're not sharing a schema object in your Servlet possibly?

    Short of seeing some code it's going to be almost impossible to say.

  3. #3
    ksur12345 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    Thanks for your quick response

    Yes, with the same XML .. Same Schema.. The Schema file is tooo big, around 1000 lines..

    Can be accessed online at http://xml.cXML.org/schemas/cXML/1.1.010/cXML.dtd ofcourse this is a DTD ..I converted it to XSD

    Do you think its because of Threading issue ? if so how can I handle it, so that it accepts multiples requests at the same time.

    BufferedWriter bw =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));

    while ((line = in.readLine()) != null) {
    xml = xml + line;

    }
    String xsd ="...........................";

    InputStream temp = new ByteArrayInputStream(xsd.getBytes());
    Source asdf = new StreamSource(temp);

    try {
    Schema schema = factory.newSchema(asdf);
    Validator validator = schema.newValidator();

    InputStream is = new ByteArrayInputStream(xml.getBytes());

    Source source = new StreamSource(is);

    validator.validate(source);

    bw.write(xml);

    } catch (SAXException ex) {

    out.println("<cXML>");
    out.println("<Status code=\"500\" text=\"Error Parsing File \"/>");
    out.println("</Response>");
    out.println("</cXML>");
    out.println(ex.getMessage());
    bw.flush();
    bw.close();
    in.close();
    out.close();
    return;
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    You'll have to show your servlet code, not just a snippet, if it is threading then that's where the culprit'll be sitting.
    Also use code tags (the # button in the row above the reply box).

  5. #5
    ksur12345 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    here you go .

    Java Code:
        public void init(ServletConfig config) throws ServletException {
            super.init(config);
        }
    
        public synchronized void doPost(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException,
                                                                IOException {
    
            SchemaFactory factory =
                SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
      
    
            response.setContentType(CONTENT_TYPE);
            String xmlString;
            xmlString = "asdf";
    
            BufferedReader in = request.getReader();
            PrintWriter out = response.getWriter();
            DateFormat dateFormat =
                new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSS");
            DateFormat dateFormat1 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
            DateFormat dateFormat3 = new SimpleDateFormat("HH:mm:ssZ");
    
            Calendar cal = Calendar.getInstance();
            //System.out.println(dateFormat.format(cal.getTime()));
            File file =
                new File("../../../Integration/" +
                         dateFormat.format(cal.getTime()) + ".xml");
            String line;
            BufferedWriter bw =
                new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
            String xsd = "";
    
     xsd =" ... 1000 lines of XSD ......";
    
            String xml = "";
    
            while ((line = in.readLine()) != null) {
                xml = xml + line;
            
            }
    
            InputStream temp = new ByteArrayInputStream(xsd.getBytes());
            Source asdf = new StreamSource(temp);
           
            try {
                Schema schema = factory.newSchema(asdf);
                Validator validator = schema.newValidator();
    
    
                InputStream is = new ByteArrayInputStream(xml.getBytes());
    
                Source source = new StreamSource(is);
    
            
    
                validator.validate(source);
    
                   bw.write(xml);
    
    
            } catch (SAXException ex) {
                System.out.println(" is not valid because ");
                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
               
                out.println("<cXML><Response>");
                out.println("<Status code=\"500\" text=\"Error Parsing File \"/>");
                out.println("</Response>");
                out.println("</cXML>");
                out.println(ex.getMessage());
                bw.flush();
                bw.close();
                in.close();
                out.close();
                return;
            }
    
    
            out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            out.println("< cXML>"); 
            out.println("<Response>");
            out.println("<Status code=\"200\" text=\"OK\"/>");
            out.println("</Response>");
            out.println("</cXML>");
            bw.flush();
            bw.close();
            in.close();
            out.close();
    
        }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Why "synchronized" for the doPost?
    That's not right.

    Also you can provide the BufferedReader directly to the xml StreamSource.
    I don't think I've seen to use of a ByteArrayStream for that before.
    For the xsd you'd use a StringReader (in this case).

    Not that that is necessarily the problem, mind, I'm just mentioning things that look out of the ordinary to me.

    There's nothing there that is a threading issue, though, since there's not attributes attached to the Servlet (which is correct).

    Ah, hang on...the SchemaFactory isn't thread safe is it? Is that why you've stuck the synchronized on the doPost? If so then that's not a good place for it. You;re going to single thread your application doing that (if it works that is). I wonder if that's the root of the problem?

  7. #7
    ksur12345 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    I have added synchronized to see if it works, it doesnt, I removed it now, I replaced the BuffereReader in the validation instead of converting to bytes..etc..

    I didnt understand what you were saying about SchemaFactory .. should I make it private and declare it before the doGet method ?
    Please guide me.
    thanks

  8. #8
    ksur12345 is offline Member
    Join Date
    Jul 2011
    Posts
    7
    Rep Power
    0

    Default

    This is resolved ..

    Solution is posted in

    OTN Discussion Forums : Validator Error 'xml:lang' to a(n) ' ...

    Thanks all

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Um.
    You should have pointed out you had posted this at OTN.
    Since everything I posted above was also posted over there don't you think it might have been nice for either us here to know, or them there?
    One or the other of us have wasted our time...which is very annoying.

Similar Threads

  1. multiple Data from Jsp that having same name of multiple input tage to servlet
    By rahul9323.2007@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 07-29-2011, 02:00 PM
  2. Multiple JSPs controlled by one servlet.
    By Mean KaNean in forum JavaServer Pages (JSP) and JSTL
    Replies: 7
    Last Post: 06-07-2011, 02:52 PM
  3. Replies: 2
    Last Post: 10-28-2010, 04:55 PM
  4. Replies: 1
    Last Post: 09-27-2009, 04:36 AM
  5. Dispatching requests to other Servlet
    By gapper in forum Java Servlet
    Replies: 1
    Last Post: 02-06-2008, 07:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •