Go Back   Java Programming Forums > Java Standard Edition Programming Help > File I/O & Other I/O Streams

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 29-06-2008, 03:39 PM
Junior Member
 

Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Buglish is on a distinguished road
Send a message via MSN to Buglish Send a message via Yahoo to Buglish Send a message via Skype™ to Buglish
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
Java Code
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
Java 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
Java Code
[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; 12-10-2008 at 09:20 AM.
Share this thread on Facebook
Sponsored Links
  #2 (permalink)  
Old 29-06-2008, 03:45 PM
Junior Member
 

Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Buglish is on a distinguished road
Send a message via MSN to Buglish Send a message via Yahoo to Buglish Send a message via Skype™ to Buglish
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
Java Code
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
to
Java Code
 messageFactory = MessageFactory.newInstance();
on the server.

Java Code
[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; 12-10-2008 at 09:09 AM.
  #3 (permalink)  
Old 12-10-2008, 09:14 AM
Junior Member
 

Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Buglish is on a distinguished road
Send a message via MSN to Buglish Send a message via Yahoo to Buglish Send a message via Skype™ to Buglish
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.

Java Code
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 (permalink)  
Old 06-11-2008, 06:42 PM
JavaPF's Avatar
mmm.. coffee
 
5 Highscores

Join Date: May 2008
Location: United Kingdom
Posts: 1,211
Thanks: 61
Thanked 66 Times in 64 Posts
JavaPF is someone you want to know!JavaPF is someone you want to know!JavaPF is someone you want to know!

I'm feeling Inspired
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.
__________________
Don't forget to add code tags around your code:

Forum Tip: Add to peoples reputation () by clicking the button on their useful posts.
Closed Thread

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Interesting error cipher Koren3 Java Networking 0 29-04-2009 02:54 PM
[SOLVED] nid some quick response here pls.!!! chronoz13 Java Theory & Questions 6 14-04-2009 01:02 PM
[SOLVED] Error Koren3 What's Wrong With My Code? 15 02-04-2009 08:20 AM
[SOLVED] no response loop problem thewonderdude Loops & Control Statements 9 15-03-2009 07:31 PM
Regarding logical error haygaurav What's Wrong With My Code? 0 04-03-2009 12:58 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java actionlistener java actionlistener jbutton addactionlistener addactionlistener java avatar hardware id convert double to integer java double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java hardware id avatar java 2 dimensional arraylist java 2d arraylist java actionlistener java addactionlistener java button actionlistener java convert double to int java double format java double to int java double to integer java for beginner eclippse java format double java forum java forums java get mouse position java jbutton java list to map java mouse position java programming forum java programming forums java sendkeys java.lang.reflect.invocationtargetexception java.util.arraylist jbutton actionlistener jbutton java jtextarea font size programming forums string to int java two dimensional arraylist java writing apps for ipod touch

All times are GMT. The time now is 05:30 PM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.