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
what does your URL look like and what happens when you try the corrected code?
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
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
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|