Hi All,
I have two web service ServiceA & ServiceB and both implemented in weblogic.
The ServiceA is SSL enable and protocol is https which is not published by me.
The ServieB is my web service(wls8.1) and act as client for ServiceA.
My problem is when i hit my service, its not able set the handler when it call ServiceA but it is invoking the service and giving application exception like authentication error.
My service file:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.HandlerRegistry;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import weblogic.webservice.client.SSLAdapterFactory;
import weblogic.webservice.client.WLSSLAdapter;
public class HelloService {
String wsdl = "https://188.122.123.23/RemoetService?WSDL";
static {
SSLAdapterFactory factory = SSLAdapterFactory.getDefaultFactory();
WLSSLAdapter adapter = (WLSSLAdapter) factory.getSSLAdapter();
adapter.setTrustedCertificatesFile("D:\\lib\\certs
cacerts");
factory.setDefaultAdapter(adapter);
System.setProperty("weblogic.xml.encryption.verbose","true");
System.setProperty("weblogic.xml.signature.verbose","true");
System.setProperty("weblogic.webservice.verbose","true");
}
public String sayHello(String user) {
RemoteService_Impl service = new RemoteService_Impl(wsdl);
RemotePortType port = service.getRemoteServicePort1();
String namespace = service.getServiceName()
.getNamespaceURI();
QName portName = new QName(namespace,
"RemoteServicePortType");
HandlerRegistry reg = service.getHandlerRegistry();
List handlerList = new ArrayList();
Map map = new HashMap();
map.put("Username", "user1");
map.put("Password", "pwd1");
HandlerInfo info = new HandlerInfo();
info.setHandlerClass(WSClientHandler .class);
info.setHandlerConfig(map);
handlerList.add(info);
reg.setHandlerChain(portName,(List)handlerList);
RemoteServiceResponse = port.callMe(name);
}
}
My Handler Class:
package com.test;
import java.util.Map;
import javax.xml.namespace.QName;
import javax.xml.rpc.handler.Handler;
import javax.xml.rpc.handler.HandlerInfo;
import javax.xml.rpc.handler.MessageContext;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
public class WSClientHandler implements Handler {
private HandlerInfo handlerInfo;
public WSClientAuthenticateHandler(){}
public void init(HandlerInfo hi) {
System.out.println("Handler init");
handlerInfo = hi;
}
public void destroy() {
System.out.println("Handler destroy method called");
handlerInfo = null;
}
public QName[] getHeaders() {
System.out.println("Handler Header method called");
try {
Map map = handlerInfo.getHandlerConfig();
QName[] headers = handlerInfo.getHeaders();
System.out.println(" Config :"+map);
for(int i=0;i<headers.length;i++) {
System.out.println(headers.getLocalPart()+" "+
headers.toString()+" "+headers.getNamespaceURI());
}
}catch(Exception e) {
e.printStackTrace();
}
return handlerInfo.getHeaders();
}
public boolean handleRequest(MessageContext mc) {
SOAPMessageContext smc = (SOAPMessageContext) mc;
System.out.println("Calling handler class.....................");
try {
SOAPEnvelope se = smc.getMessage().getSOAPPart().getEnvelope();
System.out.println("Calling handler class.....................");
SOAPHeader soapHeader = se.getHeader();
Name headerName = se.createName("Security","wsse","http://schemas.xmlsoap.org/ws/2002/07/secext");
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(headerName);
SOAPElement element = headerElement.addChildElement(se.createName("UsernameToken", "wsse", "http://schemas.xmlsoap.org/ws/2002/07/secext"));
element.addChildElement(se.createName("Username", "wsse","http://schemas.xmlsoap.org/ws/2002/07/secext")).addTextNode("testuser");
element.addChildElement(se.createName("Password", "wsse","http://schemas.xmlsoap.org/ws/2002/07/secext")).addTextNode("testpwd");
System.out.println("Calling handler class.....................");
System.out.println("** Request: \n "se.toString()"\n");
}catch(SOAPException e) {
e.printStackTrace();
}
return true;
}
/** * Specifies that the SOAP response message be logged to a
* log file before the
* * message is sent back to the client application
* that invoked the Web service.
* */
public boolean handleResponse(MessageContext mc) {
System.out.println("Handler Response method called");
SOAPMessageContext messageContext = (SOAPMessageContext) mc;
System.out.println("** Response: \n"messageContext.getMessage().toString()"\n");
return true;
}
/** * Specifies that a message be logged to the log file if a SOAP fault is
* * thrown by the Handler instance.
* */
public boolean handleFault(MessageContext mc) {
SOAPMessageContext messageContext = (SOAPMessageContext) mc;
System.out.println("** Fault: \n"messageContext.getMessage().toString()"\n");
return true;
}
}
Please need help here.
Thanks in Advance,
pps>