________________________________________
From: Barioglio Riccardo
Sent: lunedì 22 marzo 2010 16.58
To: 'Paul Fremantle'; carbon-dev
Subject: RE: [Carbon-dev] Problem with Custom header in SOAP call
Hello, thanks for your interest..
There is a mistake… I tried again in axis2 and I had the same problem…
I think the issue is when I use wsse security engaged with rampart and the
custom header ignited by code.
Security alone or custom header alone don’t throws exception..
I attach my client class.
package it.telecomitalia.ictlab.api;
import it.telecomitalia.ictlab.api.util.SMSAdapterProperties;
import it.telecomitalia.ictlab.api.util.SMSReceiverException;
import
it.telecomitalia.ictlab.smsmessageadapter.eventclient.SmsAdpSSLProtocolSocketFactory;
import
it.telecomitalia.ictlab.smsmessageadapter.eventclient.SmsMessageAdapterListenerStub;
import it.telecomitalia.ictlab.smsmessageadapterschema.CallReceiveSMSEvent;
import it.telecomitalia.ictlab.smsmessageadapterschema.CallSmsReceiveResponse;
import it.telecomitalia.ictlab.smsmessageadapterschema.ReceiveSMSEventType;
import it.telecomitalia.ictlab.smsmessageadapterschema.ReceiveSMSResponse;
import it.telecomitalia.ictlab.smsmessageadapterschema.ResponseProtocolType;
import it.telecomitalia.ictlab.smsmessageadapterschema.SMSIn;
import java.io.InputStream;
import java.rmi.RemoteException;
import java.util.Observable;
import java.util.Observer;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.OMNamespaceImpl;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
import org.apache.axiom.soap.impl.llom.SOAPHeaderBlockImpl;
import org.apache.axiom.soap.impl.llom.soap11.SOAP11HeaderBlockImpl;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
/**
* Dispatching events to the subscribed WS. An instance of this class is
* associated to one instance of SMSReceiverThread (1 tel.number -> 1 thread ->
* 1 listener)
*
* @author r.cappa / r.barioglio
*
*/
public class EventListener implements Observer {
private static final Log log =
LogFactory.getLog(EventListener.class);
private String endpoint;
private String restEndpoint = null;;
private String key;
private ResponseProtocolType protocolType =
ResponseProtocolType.SOAP;
private final String userName =
SMSAdapterProperties.getProperty("smsAsynchReceiver.client.username");
private final String password =
SMSAdapterProperties.getProperty("smsAsynchReceiver.client.password");
private final long timeout =
Long.parseLong(SMSAdapterProperties.getProperty("smsAsynchReceiver.client.timeout"));
private int maxTry =
Integer.parseInt(SMSAdapterProperties.getProperty("smsAsynchReceiver.maxSendEventErrors"));
private long sendInterval =
Long.parseLong(SMSAdapterProperties.getProperty("smsAsynchReceiver.sendEventInterval.ms"));
private String headerMappingField =
SMSAdapterProperties.getProperty("smsAsynchReceiver.client.headerMappingField");
private static final String POLICY_XML = "/META-INF/policy.xml";
private SmsMessageAdapterListenerStub eventClient;
@SuppressWarnings("static-access")
public EventListener(String key, String endpoint) {
log.debug("Creating listener for key: " + key +
", endpoint: " + endpoint);
this.endpoint = endpoint;
this.key = key;
try {
eventClient = new
SmsMessageAdapterListenerStub(endpoint);
} catch (AxisFault e) {
log.error("Erroring during
creating client stub: " + e.getMessage(), e);
e.printStackTrace();
}
// Engage and configure WS-Security
Options options =
eventClient._getServiceClient().getOptions();
options.setTimeOutInMilliSeconds(this.timeout);
if (!"".equals(userName)) {
try {
log.info("Engaging module rampart");
eventClient._getServiceClient().engageModule("rampart");
log.info("Setting username Wsse for client: " + this.userName);
options.setUserName(this.userName);
log.info("Setting password Wsse for client: " + this.password);
options.setPassword(this.password);
log.info("Reading file policy for client: " + this.POLICY_XML);
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy(POLICY_XML));
} catch (AxisFault e) {
log.error("Error
during setting wsse security client stub: " + e.getMessage(), e);
e.printStackTrace();
} catch (XMLStreamException e) {
log.error("Error
during reading the policy file for wsse security client stub: " +
e.getMessage(), e);
e.printStackTrace();
}
}
}
public EventListener(String key, String endpoint,
ResponseProtocolType protocolType) {
this(key, endpoint);
this.protocolType = protocolType;
this.restEndpoint =
SMSAdapterProperties.getProperty("smsAsynchReceiver.client.RESTEndpoint");
log.info("Read REST endpoint from properties: "
+ restEndpoint);
log.debug("Creating listener for key: " + key +
", endpoint: " + endpoint + ", protocolType: " + protocolType);
}
private Policy loadPolicy(String xmlPath) throws
XMLStreamException {
InputStream stream =
this.getClass().getResourceAsStream(xmlPath);
StAXOMBuilder builder = new
StAXOMBuilder(stream);
return
PolicyEngine.getPolicy(builder.getDocumentElement());
}
@Override
public void update(Observable o, Object arg) {
boolean ok = false;
int tryCounter = 0;
// Try to send response
while (!ok && tryCounter < this.maxTry) {
tryCounter++;
if (tryCounter != 1) { // If it
isn't the first try, sleep
try {
log.info("Sending event tentative # " + tryCounter);
Thread.sleep(sendInterval);
} catch
(InterruptedException e) {
log.error(e.getMessage(), e);
}
}
if (arg instanceof
ReceiveSMSResponse) {
ReceiveSMSResponse res = ((ReceiveSMSResponse) arg);
log.info("Received message from: " + res.getSMS().getSender().getNumber());
log.info("Endpoint: " + endpoint);
log.info("Key: "
+ key);
log.info("Response Protocol: " + protocolType);
if (eventClient
!= null) {
log.debug("Creating Message to delivery to endpoint...");
CallReceiveSMSEvent callReceiveSMSEvent = new CallReceiveSMSEvent();
ReceiveSMSEventType receiveSMSEventType = new ReceiveSMSEventType();
SMSIn smsIn = res.getSMS();
receiveSMSEventType.setSMS(smsIn);
receiveSMSEventType.setSubscriptionId(key);
callReceiveSMSEvent.setReceiveSMSEvent(receiveSMSEventType);
try {
if (protocolType == ResponseProtocolType.RESTGET) {
log.info("Using REST default endpoint: " +
restEndpoint);
log.debug("Creating Message to delivery to
endpoint...");
log.info("Setting HEADER for '" +
headerMappingField + "' Element: " + endpoint);
//eventClient._getServiceClient().addStringHeader(new
QName("http://www.CustomHeaders.com", headerMappingField, "myNs"), endpoint);
//Using fake SSL factory
SmsAdpSSLProtocolSocketFactory sf = new SmsAdpSSLProtocolSocketFactory();
@SuppressWarnings("deprecation")
Protocol protocol = new Protocol("https", sf, 38181);
Protocol.registerProtocol("https", protocol);
OMNamespaceImpl customNamespaceHeader = new
OMNamespaceImpl("http://telecomitalia.customheadernamespace/rest", "chnr");
SOAPFactory factory = new SOAP11Factory();
SOAPHeaderBlockImpl block = new
SOAP11HeaderBlockImpl(headerMappingField, customNamespaceHeader, factory );
block.setText(endpoint);
eventClient._getServiceClient().addHeader(block);
eventClient._getServiceClient().setTargetEPR(new
EndpointReference(restEndpoint));
} else {
eventClient._getServiceClient().setTargetEPR(new
EndpointReference(endpoint));
}
CallSmsReceiveResponse clientResponse =
eventClient.callSmsReceive(callReceiveSMSEvent);
if (clientResponse != null && clientResponse.getAcknowledge() !=
null && clientResponse.getAcknowledge().getResultCode() == 0) {
ok = true;
} else {
ok = false;
log.error("the event listener thrown a bad
Response.");
}
}
catch (RemoteException e) {
log.error("Erroring during sending the event to listener endpoint
: " + e.getMessage(), e);
e.printStackTrace();
}
}
} else if (arg instanceof
SMSReceiverException) {
log.error("Error
during in EventListener Update Method: " + ((SMSReceiverException)
arg).getMessage(), ((SMSReceiverException) arg));
((SMSReceiverException) arg).getStackTrace();
}
// If failed for maximum times,
delete observers and stop thread
if (!ok && tryCounter >=
this.maxTry) {
// Remove
subscribers
o.deleteObservers();
// Stop and
remove thread
AsyncSMSReceiver.getInstance().unsubscribe(key);
}
}
}
}
Thanks in advance, Riccardo
From: Paul Fremantle [mailto:[email protected]]
Sent: lunedì 22 marzo 2010 12.52
To: carbon-dev
Cc: Barioglio Riccardo
Subject: Re: [Carbon-dev] Problem with Custom header in SOAP call
Can you please post a test case?
Thanks
Paul
On 22 March 2010 11:44, Cappa Roberto
<[email protected]<mailto:[email protected]>>
wrote:
Hello,
I have some problems during development of web-service that calls another
service (a kind of eventing implementation). Deployed on WSAS.
I need to add a custom header programmatically.
I tried several way for do that:
The first, I used the sample you provided in your usefully library
http://wso2.org/library/3156, but it didn’t work it.
Then I tried other ways like using SOAPHeaderBlock like above:
OMNamespaceImpl customNamespaceHeader = new
OMNamespaceImpl("http://telecomitalia.customheadernamespace.rest", "chnr");
SOAPFactory factory = new SOAP11Factory();
SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl("headerMappingField",
customNamespaceHeader, factory );
eventClient._getServiceClient().addHeader(block);
but it didn’t work again.
All Works good if I deploy the generated aar service under axis2 instance; so I
think the problems is in WSAS.
The error reported in all cases is:
[2010-03-22 12:02:46,309] ERROR - Erroring during sending the event to
listener endpoint : Error in extracting message properties
org.apache.axis2.AxisFault: Error in extracting message properties
at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:70)
at org.apache.axis2.engine.Phase.invoke(Phase.java:318)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:256)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:421)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at
it.telecomitalia.ictlab.smsmessageadapter.eventclient.SmsMessageAdapterListenerStub.callSmsReceive(SmsMessageAdapterListenerStub.java:182)
at
it.telecomitalia.ictlab.api.EventListener.update(EventListener.java:164)
at java.util.Observable.notifyObservers(Observable.java:142)
at
it.telecomitalia.ictlab.api.SMSReceiverThread.receiveSMS(SMSReceiverThread.java:224)
at
it.telecomitalia.ictlab.api.SMSReceiverThread.run(SMSReceiverThread.java:64)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.rampart.RampartException: Error in extracting message
properties
at
org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:386)
at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:64)
... 14 more
Caused by: org.apache.ws.security.WSSecurityException: Error in converting SOAP
Envelope to Document; nested exception is:
java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to
org.apache.axiom.soap.SOAPHeaderBlock
at
org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:161)
at
org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:272)
... 16 more
Caused by: java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to
org.apache.axiom.soap.SOAPHeaderBlock
at
org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:111)
... 17 more
org.apache.axis2.AxisFault: Error in extracting message properties
at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:70)
at org.apache.axis2.engine.Phase.invoke(Phase.java:318)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:256)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:421)
at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at
it.telecomitalia.ictlab.smsmessageadapter.eventclient.SmsMessageAdapterListenerStub.callSmsReceive(SmsMessageAdapterListenerStub.java:182)
at
it.telecomitalia.ictlab.api.EventListener.update(EventListener.java:164)
at java.util.Observable.notifyObservers(Observable.java:142)
at
it.telecomitalia.ictlab.api.SMSReceiverThread.receiveSMS(SMSReceiverThread.java:224)
at
it.telecomitalia.ictlab.api.SMSReceiverThread.run(SMSReceiverThread.java:64)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.rampart.RampartException: Error in extracting message
properties
at
org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:386)
at org.apache.rampart.MessageBuilder.build(MessageBuilder.java:61)
at org.apache.rampart.handler.RampartSender.invoke(RampartSender.java:64)
... 14 more
Caused by: org.apache.ws.security.WSSecurityException: Error in converting SOAP
Envelope to Document; nested exception is:
java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to
org.apache.axiom.soap.SOAPHeaderBlock
at
org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:161)
at
org.apache.rampart.RampartMessageData.<init>(RampartMessageData.java:272)
... 16 more
Caused by: java.lang.ClassCastException:
org.apache.axiom.om.impl.llom.OMElementImpl cannot be cast to
org.apache.axiom.soap.SOAPHeaderBlock
at
org.apache.rampart.util.Axis2Util.getDocumentFromSOAPEnvelope(Axis2Util.java:111)
... 17 more
Any idea? Is it a bug? Or I’m wrong?
Thanks in advance, Riccardo
_______________________________________________
Carbon-dev mailing list
[email protected]<mailto:[email protected]>
https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
--
Paul Fremantle
CTO and Co-Founder, WSO2
OASIS WS-RX TC Co-chair, VP, Apache Synapse
Office: +44 844 484 8143
Cell: +44 798 447 4618
blog: http://pzf.fremantle.org
twitter.com/pzfreo<http://twitter.com/pzfreo>
[email protected]<mailto:[email protected]>
wso2.com<http://wso2.com> Lean Enterprise Middleware
_______________________________________________
Carbon-dev mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev