Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: SOAP Message Factory response error

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Location
    Pretoria, South Africa
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default SOAP Message Factory response error

    I am writing both the server and the client. The server builds the XML using JAXB marshalling and piping back to the client in the HTTP socket. From the client the request is built using the message factory and sent over the connection factory instantiation. When the response is received the SAAJ API indicates the response was bad and equals null. The client is a applet.

    Error Message
    Jun 29, 2008 5:01:49 PM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
    SEVERE: SAAJ0008: Bad Response; null
    com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: java.security.PrivilegedActionException: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (-1null


    Client Code
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    if(connection == null)
    	connection = soapConnectionFactory.createConnection();
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPHeader header = message.getSOAPHeader();
    SOAPBody body = message.getSOAPBody();
    header.detachNode();
    QName bodymain = new QName("icb_xml");
    SOAPBodyElement mainbodyElement =  body.addBodyElement(bodymain);
    ...
    ...
    ...
     URL endpoint = new URL(serverurl);
    System.out.println("b");
    SOAPMessage response = connection.call(message, endpoint);

    Comm_log
    [Client Request]>POST / HTTP/1.1
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Content-Type: text/xml; charset=utf-8
    Content-Length: 242
    Cache-Control: no-cache
    Pragma: no-cache
    User-Agent: Java(tm) 2 SDK, Standard Edition v1.6.0_05 Java/1.6.0_05
    Host: sjdpprojectserver.hopto.org
    Connection: keep-alive
     
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><icb_xml><login><username>jaco</username><password>12345</password><language>English</language></login></icb_xml></SOAP-ENV:Body></SOAP-ENV:Envelope>
     
    [Server Response]><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"><env:Header/><env:Body><icb_xml><loginResponse><err_code>0</err_code><user_id>101</user_id></loginResponse></icb_xml></env:Body></env:Envelope>

    In your opinion is this a server or client related problem or should I look for an alternative function rather than the SOAP message factory and connection factory?

    Regards,
    Buglish
    Last edited by Buglish; October 12th, 2008 at 04:20 AM.


  2. #2
    Junior Member
    Join Date
    Jun 2008
    Location
    Pretoria, South Africa
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SOAP Message Factory response error

    After I had placed the post I noticed my response SOAP message format is not the same is the client. I used in both instences the MessageFactory.

    On the server side how do I detect the SOAP version?

    I had change the instantiation from
    messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    to
     messageFactory = MessageFactory.newInstance();

    on the server.

    [Client Request]>POST / HTTP/1.1
    Accept: text/xml, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    Content-Type: text/xml; charset=utf-8
    Content-Length: 241
    Cache-Control: no-cache
    Pragma: no-cache
    User-Agent: Java(tm) 2 SDK, Standard Edition v1.6.0_05 Java/1.6.0_05
    Host: sjdpprojectserver.hopto.org
    Connection: keep-alive
     
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><icb_xml><login><username>rsdth</username><password>sth</password><language>English</language></login></icb_xml></SOAP-ENV:Body></SOAP-ENV:Envelope>
     
    [Server Response]><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><icb_xml><loginResponse><err_code>102</err_code><err_data>Login Failed. Incorrect username or password.</err_data></loginResponse></icb_xml></SOAP-ENV:Body></SOAP-ENV:Envelope>

    Unfortunatly this did not resolve the problem as I still receive the above error message
    Last edited by Buglish; October 12th, 2008 at 04:09 AM.

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Location
    Pretoria, South Africa
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: SOAP Message Factory response error

    Hi,

    To solve this problem; I used the SOAPMEssageFactory to only create the SOAP packet and HTTPConnection for the transmission protocol. It's a normal socket push which is allot simpler and old school. This did not give my any environment errors.

    public String sendSoapLoginMessage(String usernameintput, String passwordintput) throws Exception
        {       
            SOAPFactory soapFactory = SOAPFactory.newInstance(); 
            MessageFactory mf = MessageFactory.newInstance();
            SOAPMessage message = mf.createMessage();
            SOAPBody body = message.getSOAPBody();
            // You can detach the SOAP header in this example
            // msg.getSOAPHeader().detachNode();
     
     
            Name bodyName = soapFactory.createName("icb_xml" , "sjp", serverurl);
     
            SOAPElement xmlElement = body.addBodyElement(bodyName);
     
     
            Name loginName = soapFactory.createName("login");
            SOAPElement loginElement = xmlElement.addChildElement(loginName);
     
            SOAPElement child = soapFactory.createElement("username");
            child.addTextNode(usernameintput);
     
            loginElement.addChildElement(child);
     
            child = soapFactory.createElement("password");
            child.addTextNode(passwordintput);
     
     
            loginElement.addChildElement(child);
     
            child = soapFactory.createElement("language");
            child.addTextNode(icb.language);
     
            loginElement.addChildElement(child);
     
            message.saveChanges();
     
            // Send the message
            System.out.println("Send the SOAP message\n");
     
     
            String server = serverurl;
            String response = "";
     
            try 
            {
                if(out==null)
                {
                    if(uc == null)
                    {    
                        u = new URL(DEFAULT_SERVER);
                        uc = u.openConnection();
                    }
     
                    if(urlconnection == null)
                    {    
                        urlconnection = (HttpURLConnection) uc;
                        urlconnection.setDoOutput(true);
                        urlconnection.setDoInput(true);
                        urlconnection.setRequestMethod("POST");
                        urlconnection.setRequestProperty("SOAPAction", SOAP_ACTION);
                    }
                    out = urlconnection.getOutputStream();
                }
     
                if(wout == null)
                    wout = new OutputStreamWriter(out);
     
                String soapmessage = printMessage(message);
                wout.write(soapmessage); 
     
                wout.flush();
                //wout.close();
                System.out.println(2);
                if(is == null)
                    is = urlconnection.getInputStream();
                response = readServerResponseMessage(is);
                //is.close();
                int sizemore = "</loginResponse>".length();
                response = response.substring(response.indexOf("<loginResponse>"),response.indexOf("</loginResponse>")+sizemore);
                System.out.println("[SERVER RESPONSE]"+response);
            }
            catch (IOException e) 
            {
                System.err.println(e); 
            }
            catch(Exception eb)
            {
                System.err.println(eb); 
            }        
     
     
     
           return response;
        }
     
    public void closeConnections()
    {
    		try
    		{
    				wout.close();
    				is.close();
    		}
    		catch(Exception e)
    		{
    				e.printStackTrace();
    		}        
    }
     
    public String readServerResponseMessage(InputStream is)
    {
    	BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
    	char[] readChars = new char[65000];
    	String response = "";
    	try
    	{   
    			while (br.read(readChars) != -1)
    			{           
    					response = new String(readChars);
    				 break;
     
    			}
     
    	}
    	catch (IOException e)
    	{   
    					e.printStackTrace();
    	}
    	catch(Exception e)
    	{
    					e.printStackTrace();
    	}
     
    	return response;
    }

    Regards,
    Buglish

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: SOAP Message Factory response error

    Thank you for posting your solution Buglish.

    This seems to be a very popular thread so no doubt it will help others.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. How to solve NullPointerException in runtime?
    By Koren3 in forum What's Wrong With My Code?
    Replies: 16
    Last Post: September 20th, 2017, 11:25 PM
  2. [SOLVED] Interesting error cipher while sending message
    By Koren3 in forum Java Networking
    Replies: 0
    Last Post: April 29th, 2009, 09:54 AM
  3. Replies: 6
    Last Post: April 14th, 2009, 08:02 AM
  4. [SOLVED] Java for loop problem and out put is not coming
    By thewonderdude in forum Loops & Control Statements
    Replies: 9
    Last Post: March 15th, 2009, 02:31 PM
  5. Proper output for Non preemptive scheduling problem
    By haygaurav in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 4th, 2009, 07:58 AM