Issue in sending a SOAP request in ApacheHttpClient with SSL -
i want send soap request through ssl soap server (microsoft iis server). when test soap request through soapui tool ssl - keystore configurations returns response correctly. using following code returns "http/1.1 400 bad request" used httpclient-4.2.3 , httpcore-4.2.2.
import java.security.keystore; import org.apache.http.header; import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.conn.scheme.scheme; import org.apache.http.conn.scheme.schemeregistry; import org.apache.http.conn.ssl.sslsocketfactory; import org.apache.http.entity.stringentity; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.impl.conn.basicclientconnectionmanager; import org.apache.http.params.basichttpparams; import org.apache.http.params.httpparams; import org.apache.http.util.entityutils; public final static void main(string[] args) throws exception { defaulthttpclient httpclient = new defaulthttpclient(); try { keystore keystore = keystore.getinstance("jks"); fileinputstream instream1 = new fileinputstream(new file("c:\\ccdkeystore\\mykeystore.jks")); try { keystore.load(instream1, "1214524".tochararray()); } { try { instream1.close(); } catch (exception ignore) {} } sslsocketfactory socketfactory = new sslsocketfactory(keystore,"1214524"); scheme sch = new scheme("https", 443, socketfactory); schemeregistry schemeregistry = httpclient.getconnectionmanager().getschemeregistry(); schemeregistry.register(sch); final httpparams httpparams = new basichttpparams(); defaulthttpclient lhttpclient = new defaulthttpclient(new basicclientconnectionmanager(schemeregistry), httpparams); string lurl = "https://api.demo.server.com/xds/service.svc?wsdl"; stringbuffer lxmlbuffer = new stringbuffer(); lxmlbuffer.append("<s:envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">\n"); lxmlbuffer.append("<s:header>\n"); lxmlbuffer.append("<a:action s:mustunderstand=\"1\">urn:74347:4757:storedquery</a:action>\n"); lxmlbuffer.append("<a:messageid>urn:uuid:c6430690-412e-4744-afe1-233e2138f2d2</a:messageid>\n"); . . . . . . lxmlbuffer.append("</slot>\n"); lxmlbuffer.append("</adhocquery>\n"); lxmlbuffer.append("</query:adhocqueryrequest>\n"); lxmlbuffer.append("</s:body>\n"); lxmlbuffer.append("</s:envelope>\n"); string lxml = lxmlbuffer.tostring(); httppost lmethod = new httppost(lurl); httpentity lentity = new stringentity(lxml, "multipart/related", "utf-8"); lmethod.setheader("soapaction", "urn:74347:4757:storedquery"); system.out.println(entityutils.tostring(lentity)); lmethod.setentity(lentity); httpresponse lhttpresponse = lhttpclient.execute(lmethod); } { httpclient.getconnectionmanager().shutdown(); }
any on highly appreciate
thanks, mohan
finally found answer...
here following line in above code contains content type "multipart/related". web service expected content type "application/soap+xml" since soap request. please refer w3schools tutorial further information
httpentity lentity = new stringentity(lxml, "multipart/related", "utf-8");
Comments
Post a Comment