aspose file tools*
The moose likes Web Services and the fly likes Web service + xml + java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web service + xml + java" Watch "Web service + xml + java" New topic
Author

Web service + xml + java

Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
hi

Please I try to retrieve data from web services (soap) and must pass an ID in cookie http header I tried with java code (eclipse) but I can not I tried also with other tools tjrs but its not happening ...
I am beginner I really need a helping hand to find the error and the tool to be used

Thank you in advance

The XML that I want to apply is the following:

==> My prob is in the URL: I can not add it and how to add the "sid"on url (sid: is the username (cookie))

///////////////////////////////////////////////////////////////

url=http://search.isiknowledge.com/esti/wokmws/ws/WokSearch&sid=2WnbbEcMI76CnAHoI2K&folder=soap&product=&saved_folder=soap&call=WokSearch/search.xml&expanded=----++&xml=1&request=<soap:Envelope

xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<woksearch:search

xmlns:woksearch="http://woksearch.cxf.wokmws.thomsonreuters.com">

<!-- this request has the minimum required elements -->

<queryParameters>

<databaseID>WOS</databaseID>

<editions>

<collection>WOS</collection>

<edition>SCI</edition>

</editions>

<userQuery>AU=Arce, G*</userQuery>

<queryLanguage>en</queryLanguage>

</queryParameters>

<retrieveParameters>

<!-- 0 < firstRecord <= recordsSearched -->

<firstRecord>1</firstRecord>

<!-- count = 0 (summary only), 1 <= count <= 100 returns records -->

<count>5</count>

</retrieveParameters>

</woksearch:search>

</soap:Body>

</soap:Envelope>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
You appear to be trying to put the SOAP request in the URL - this is incorrect.

SOAP requests must be POSTed with the request text as the body of the request.

Bill
Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
thank you for your response ...
so how can i add this url with the session id because i m trying to retirve data from a data base and it need an ID on a cookie .... can you help me :/
thank you veru much for your help
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
After you have corrected your code to POST the SOAP message, what does your URL look like and what happens when you try the corrected code?

Bill
Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
William Brogden wrote:After you have corrected your code to POST the SOAP message, what does your URL look like and what happens when you try the corrected code?

thank you for reply :i don't see exactly about which code you are talking but in my code java i put the cookie in this way :
this is my java code :

package clt;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import com.thomsonreuters.wokmws.cxf.auth.*;
import com.thomsonreuters.wokmws.cxf.woksearchlite.WokSearchLite;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
public class Authentificate {
private String log_;
public static String REMOTE_WSDL_URL =
"http://search.isiknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
public static URL LOCAL_WSDL_URL =
WOKMWSAuthenticateService.WSDL_LOCATION;
private static QName SERVICE_NAME = new QName(
"http://auth.cxf.wokmws.thomsonreuters.com",
"WOKMWSAuthenticateService"
);
WOKMWSAuthenticateService service;
WOKMWSAuthenticate port;
String session_identifier;
public String getSessionIdentifier() throws Exception
{
try {
/*
* comment start:
* now we have not an authentication account,
* so comment out the following to use IP authentication
*/
BindingProvider bp=(BindingProvider) port;
Map<String, Object> context = bp.getRequestContext();
/*
* comment start:
* the next line of code has already been done for this port in createPort()
* otherwise the SESSION_MAINTAIN_PROPERTY needs to be set to Boolean.TRUE
*/
context.put(
javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY,
Boolean.valueOf(true)
);
/* comment end */
//

/*
* comment start:
* make the call to the authenticate operation
*/
session_identifier = null;
session_identifier = port.authenticate();
} catch (Exception e) {
// Unexpected error while calling the authenticate operation.
// ¡- finish your exception handling,
// we are simply printing the stack trace and rethrowing the exception
e.printStackTrace();
throw e;
}
return session_identifier;
}
/**
* Close the session: make a call to the closeSession operation.
*
*


* The session identifier is sent as an HTTP cookie with name "SID".
* The value of the cookie is the
* session identifier. This cookie is already set in the requestContext
* for this binding provider/port
* within the {@link #setSessionCookie()} method.
*
*@throws Exception
*
*@see #setSessionCookie()
*/ public void closeSession() throws Exception {
try {
/*
* comment start:
* the next three lines of code have already been done for this port
* in createPort()
* otherwise the SESSION_MAINTAIN_PROPERTY needs to be set to Boolean.TRUE
*/
BindingProvider bp = (BindingProvider)port;
Map<String, Object> context = bp.getRequestContext();
context.put(
javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY,
Boolean.valueOf(true)
);
/* comment end */
/*
* comment start:
* Create the SID cookie
*/
Cookie cookie = new Cookie("SID", session_identifier);
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setCookie(cookie.getName()+"="+cookie.getValue());
cookie.setValue(session_identifier);

/* comment end */
http.setClient(httpClientPolicy);
port.closeSession();
} catch( Exception e) {
// Unexpected error
// ¡- finish your exception handling,
// we are simply printing the stack trace and rethrowing the exception
e.printStackTrace();
throw e;
}
}
/**
* Put the session cookie into the request context for the binding provider/port
*
*


* Once this is done the session cookie will be set for all
* outgoing requests from this port.
*
*@throws Exception
*/
public void setSessionCookie() throws Exception {
try {
/*
* comment start:
* the next three lines of code have already been done for
* this port in createPort()
* otherwise the SESSION_MAINTAIN_PROPERTY needs to be set to Boolean.TRUE
*/

BindingProvider bp = (BindingProvider)port;
Map<String, Object> context = bp.getRequestContext();
context.put(
javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY,
Boolean.valueOf(true)
);

/* comment end */
/*
* comment start:
* create the cookie
*/

Cookie cookie = new Cookie("SID", session_identifier);
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setCookie(cookie.getName() + "=" + cookie.getValue());
http.setClient(httpClientPolicy);
cookie.setValue(session_identifier);

} catch (Exception e) {
// Unexpected error while calling the authenticate service.
// ¡- finish your exception handling,
// we are simply printing the stack trace and rethrowing the exception
e.printStackTrace();
throw e;
}}
/*
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

Cookie[] cookies = request.getCookies();

for(int i=0; i<cookies.length; i++) {
Cookie cookie = cookies[i];
String nomCookie = cookie.getName();
if (nomCookie.equals( "utilisateur"))
session_identifier = cookie.getValue();
}

response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println( "<BODY><P>Bonjour Mr" + session_identifier + "!</P></BODY></HTML>");

}

* comment start:
* * pattern of cookie is incorrect.*/



public void createPort( URL wsdlURL ) throws Exception {
// default to the WSDL used by WSDL2Java
if (wsdlURL == null) {
wsdlURL = WOKMWSAuthenticateService.WSDL_LOCATION;
}
try {
service = new WOKMWSAuthenticateService(
wsdlURL ,
SERVICE_NAME
);
port = service.getWOKMWSAuthenticatePort();
/*
* comment start:
* output HTTP message.
*/
Client client = ClientProxy.getClient(port);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
/* comment end */
/*
* Must set the SESSION_MAINTAIN_PROPERTY to Boolean.TRUE
*/
BindingProvider bp = (BindingProvider)port;
Map<String, Object> context = bp.getRequestContext();
context.put(
javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY,
Boolean.valueOf(true)
);
} catch (Exception e) {
// Unexpected error while calling the authenticate service.
// ¡- finish your exception handling,
// we are simply printing the stack trace and rethrowing the exception
e.printStackTrace();
throw e;
}
}
public static void main(String[] args) throws Exception
{
/*
* comment start:
* Select a WSDL: Each WSDL may define the save service(s) but
* have a different service endpoint address
*
* We will default to the local one used by WSDL2Java
*/
// use the local WSDL used by WSDL2Java to generate the client code
URL wsdlURL = LOCAL_WSDL_URL;
// use the remote WSDL
wsdlURL = new URL(REMOTE_WSDL_URL);
// or pass in your own local WSDL:
if (args.length > 0) {
File wsdlFile = new File(args[0]);
try{
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
// Unexpected error
// ¡- finish your exception handling,
// we are simply printing the stack trace and rethrowing the exception
e.printStackTrace();
throw e;
}

Authentificate auth = new Authentificate();
// create the service and port
auth.createPort( wsdlURL );
/*
* call the authenticate operation:
* get the session identifier that all other operations need
* */
String identifier = auth.getSessionIdentifier();
System.out.println("Identifier cookie : " + identifier);
/*
* create the session cookie:
* make the session identifier available to all other Web service
* operations within
* this service port
*/
auth.setSessionCookie();
/*
* call the other operation in this Web service: close the session
*/
auth.closeSession();
System.exit(0);
}
}

}


package clt;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import com.thomsonreuters.wokmws.cxf.woksearchlite.*;

import javax.servlet.http.Cookie;
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;


public class Interrog {
/*
* comment start:
* add constant WSDL_URL.
*/
private String log_;
public static String SERVICE_ENDPOINT_URL
= "http://search.isiknowledge.com/esti/wokmws/ws/WokSearchLite";
public static String REMOTE_WSDL_URL = SERVICE_ENDPOINT_URL + "?wsdl";
public static URL LOCAL_WSDL_URL = WokSearchLiteService.WSDL_LOCATION;
/* comment end */
private static final QName SERVICE_NAME
= new QName(
"http://woksearchlite.cxf.wokmws.thomsonreuters.com",
"WokSearchLiteService"
);
private Interrog()
{
}
/**
* Create the port for WokSearchLite Web service
* using the WokSearchLiteService class.
*
*@param wsdlURL the url of the WSDL
*
*@return the port (e.g. instance of the WokSearchLite interface) for the
* WokSearchLite Web service
*
*@throws Exception
*/
public static WokSearchLite createPort( URL wsdlURL ) throws Exception {
try {
WokSearchLiteService ss = new WokSearchLiteService(wsdlURL, SERVICE_NAME);
WokSearchLite port = ss.getWokSearchLitePort();
return port;
} catch( Exception e) {
// do error handling. Here we just print stack trace and rethrow execption
e.printStackTrace();
throw e;
}
}
/**
* Create the port for WokSearchLite Web service using a JAX-WS factory class and
* the
* service endpoint url.
*
*


* Also, set the logging interceptors
*
*@return the port (e.g. instance of the WokSearchLite interface) for the
* WokSearchLite Web service
*
*@throws Exception
*/

public static WokSearchLite createPortUsingFactory( ) throws Exception {
try {
/*
* comment start:
* CXF Factory for creating JAX-WS Proxies. This class provides access to
* internal
* properties used to setup proxies. Using it provides more control than the
* standard JAX-WS APIs.
///*/
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(WokSearchLite.class);
factory.setAddress( SERVICE_ENDPOINT_URL );
WokSearchLite port = (WokSearchLite) factory.create();
return port;
} catch( Exception e) {
// do error handling. Here we just print stack trace and rethrow execption
e.printStackTrace();
throw e;
}
}

public static void setSessionCookie( WokSearchLite port, String sid )
throws Exception {
Client client = ClientProxy.getClient(port);
/*
* comment start:
* * output HTTP message.
*
* if you are using createPort() method then uncomment the following two
* lines.
* if you are using createPortUsingFactory() method then leave these
* two lines commented out.
*/
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
/* comment end */
BindingProvider bindingProvider = (BindingProvider)port;
Map<String, Object> requestContext = bindingProvider.getRequestContext();
requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
Cookie cookie = new Cookie("SID", sid);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
http.setClient(httpClientPolicy);
}

public static void main(String args[]) throws Exception {
/*
* comment start:
* Select a WSDL: Each WSDL may define the save service(s) but
* have a different service endpoint address
*
* We will default to the local one used by WSDL2Java
*/
// use the local WSDL used by WSDL2Java to generate the client code
URL wsdlURL = LOCAL_WSDL_URL;
// use the remote WSDL
wsdlURL = new URL(REMOTE_WSDL_URL);


// or pass in your own local WSDL:
if (args.length > 0) {
File wsdlFile = new File(args[0]);
try {
if (wsdlFile.exists()) {
wsdlURL = wsdlFile.toURI().toURL();
} else {
wsdlURL = new URL(args[0]);
}
} catch (MalformedURLException e) {
// do error handling. Here we just print stack trace and rethrow
// execption
e.printStackTrace();
throw e;
}
}
/* comment end */
/*
* comment start:
* use one of the following two methods to create the Web service port
*/
//WokSearchLite port = createPort( wsdlURL );
WokSearchLite port = createPortUsingFactory();
/*
* comment start:
* Get the session identifier using the Authentication client
*/
Authentificate auth = new Authentificate();
// use remote WSDL
auth.createPort( new URL( Authentificate.REMOTE_WSDL_URL ) );
// use local WSDL
auth.createPort( Authentificate.LOCAL_WSDL_URL );
String sid = auth.getSessionIdentifier();
auth.setSessionCookie();
/* end comment */
/*
* Set up the request context properly, including setting the SID cookie
* This setup is required for all operations to work.
*/
setSessionCookie(port, sid);
System.out.println("Invoking search...");
com.thomsonreuters.wokmws.cxf.woksearchlite.QueryParameters _search_queryParameters = new QueryParameters();
com.thomsonreuters.wokmws.cxf.woksearchlite.RetrieveParameters _search_retrieveParameters = new RetrieveParameters();
/*
* comment start:
* initialize QueryParameters & RetrieveParameters
*/

_search_queryParameters.setDatabaseID("WOS");
EditionDesc desc_sci = new EditionDesc();
desc_sci.setCollection("WOS");
desc_sci.setEdition("SCI");
EditionDesc desc_ssci = new EditionDesc();
desc_ssci.setCollection("WOS");
desc_ssci.setEdition("SSCI");
EditionDesc desc_ahci = new EditionDesc();
desc_ahci.setCollection("WOS");
desc_ahci.setEdition("AHCI");
EditionDesc desc_ic = new EditionDesc();
desc_ic.setCollection("WOS");
desc_ic.setEdition("IC");
EditionDesc desc_ccr = new EditionDesc();
desc_ccr.setCollection("WOS");
desc_ccr.setEdition("CCR");
EditionDesc desc_istp = new EditionDesc();
desc_istp.setCollection("WOS");
desc_istp.setEdition("ISTP");
EditionDesc desc_isshp = new EditionDesc();
desc_isshp.setCollection("WOS");
desc_isshp.setEdition("ISSHP");
_search_queryParameters.getEditions().add(desc_sci);
_search_queryParameters.getEditions().add(desc_ssci);
_search_queryParameters.getEditions().add(desc_ahci);
_search_queryParameters.getEditions().add(desc_ic);
_search_queryParameters.getEditions().add(desc_ccr);
_search_queryParameters.getEditions().add(desc_istp);
_search_queryParameters.getEditions().add(desc_ssci);
_search_queryParameters.setQueryLanguage("en");
_search_queryParameters.setUserQuery("AD=(NATL TAIWAN UNIV SAME CHILUNG)");
TimeSpan timeSpan = new TimeSpan();
timeSpan.setBegin("1900-01-01");
timeSpan.setEnd("2009-12-31");
_search_queryParameters.setTimeSpan(timeSpan);
_search_retrieveParameters.setFirstRecord(1);
_search_retrieveParameters.setCount(100);
/* comment end */
try {
com.thomsonreuters.wokmws.cxf.woksearchlite.SearchResults
_search__return = port.search
(
_search_queryParameters,
_search_retrieveParameters
);
System.out.println(
"search.result.getRecordsFound()=" + _search__return.getRecordsFound() );
} catch (Exception e) {
e.printStackTrace();
}
auth.closeSession();
System.exit(0);
}

}


==> the first code is for authentification and close session (which need also an ID) and the second for interrogation

really i m loosing my mind thank you for help

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
I didn't ask for an unreadable code dump, I asked:
what does your URL look like and what happens when you try the corrected code?


Bill
Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
William Brogden wrote:I didn't ask for an unreadable code dump, I asked:
what does your URL look like and what happens when you try the corrected code?


Bill


the Url which i work with is : http://search.isiknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate and when i execute it give me this :
<soap:Envelope> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>Session ID cookie value cannot be null or empty string - It is required that the high level Web service client program participate in the session initialized by the server.</faultstring> <detail> <ns2:SessionException/> </detail> </soap:Fault> </soap:Body> </soap:Envelope>


and the correct URL must be launched is : url=http://search.isiknowledge.com/esti/wokmws/ws/WokSearch&sid=2WnbbEcMI76CnAHoI2K&folder=soap&product=&saved_folder=soap&call=WokSearch/search.xml&expanded=----++&xml=1&request=<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">


===>>> et là j'ai réussi à mettre la cookie en entête et je poste ça comme requete
Address: http://search.isiknowledge.com/esti/wokmws/ws/WokSearchLite
Encoding: UTF-8
Content-Type: text/xml
Headers: {Accept=[*/*], Cookie=[SID=W6HEj3NB27j4kiFMo3C], SOAPAction=[""]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:search xmlns:ns2="http://woksearchlite.cxf.wokmws.thomsonreuters.com"><queryParameters><databaseID>WOS</databaseID><editions><collection>WOS</collection><edition>SCI</edition></editions><editions><collection>WOS</collection><edition>SSCI</edition></editions><editions><collection>WOS</collection><edition>AHCI</edition></editions><editions><collection>WOS</collection><edition>IC</edition></editions><editions><collection>WOS</collection><edition>CCR</edition></editions><editions><collection>WOS</collection><edition>ISTP</edition></editions><editions><collection>WOS</collection><edition>SSCI</edition></editions><queryLanguage>en</queryLanguage><timeSpan><begin>1900-01-01</begin><end>2009-12-31</end></timeSpan><userQuery>AD=(NATL TAIWAN UNIV SAME CHILUNG)</userQuery></queryParameters><retrieveParameters><count>100</count><firstRecord>1</firstRecord></retrieveParameters></ns2:search></soap:Body></soap:Envelope>

===>>> Et je reçoit sa comme réponse :
ID: 2
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml;charset=UTF-8
Headers: {Content-Length=[352], content-type=[text/xml;charset=UTF-8], Date=[Thu, 21 Jun 2012 12:00:48 GMT], Server=[Apache-Coyote/1.1], X-Cnection=[close]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Not authorized to edition SSCI in collection WOS</faultstring><detail><ns2:InvalidInputException xmlns:ns2="http://woksearchlite.cxf.wokmws.thomsonreuters.com" /></detail></soap:Fault></soap:Body></soap:Envelope>


it must contain "sid" (cookie)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
So you are not getting authenticated for some reason.

Have you looked at the example code provided by the service? This page appears to link to examples.

Bill
Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
William Brogden wrote:So you are not getting authenticated for some reason.

Have you looked at the example code provided by the service? This page appears to link to examples.

Bill


Yes and I m using the same example !!!
Amal Mathlouthi
Greenhorn

Joined: May 15, 2012
Posts: 13
now i progress it work in console but not on Web i don'n know why
Thank you veryyyy much i m veru gratful for your help
hyphen tech
Greenhorn

Joined: Jun 27, 2012
Posts: 3
Hello Dear,

SOAP requests must be POST with the request text as the body of the request with header Messages.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web service + xml + java