Hi Milinda,
Follow is the complete error stack trace.
*Exception in thread "main" org.apache.axis2.AxisFault: Read timed out
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443) at
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at
org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at
org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at
client.SecureOrderProcessServiceStub.makeOrder(SecureOrderProcessServiceStub.java:463)
at
client.SecureOrderProcessClient.makeOrder(SecureOrderProcessClient.java:134)
at
client.SecureOrderProcessClient.main(SecureOrderProcessClient.java:55)Caused
by: java.net.SocketTimeoutException: Read timed out at
java.net.SocketInputStream.socketRead0(Native Method) at
java.net.SocketInputStream.read(SocketInputStream.java:150) at
java.net.SocketInputStream.read(SocketInputStream.java:121) at
sun.security.ssl.InputRecord.readFully(InputRecord.java:312) at
sun.security.ssl.InputRecord.read(InputRecord.java:350) at
sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927) at
sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884) at
sun.security.ssl.AppInputStream.read(AppInputStream.java:102) at
java.io.BufferedInputStream.fill(BufferedInputStream.java:235) at
java.io.BufferedInputStream.read(BufferedInputStream.java:254) at
org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at
org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at
org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at
org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at
org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 10 more*
Please find the attachment for the updated code.
Thanks,
On Fri, Apr 25, 2014 at 12:46 PM, Milinda Perera <[email protected]> wrote:
> Hi Supun,
>
> can you send complete error stack trace and updated code.
>
> Thanks,
> Milinda
>
>
> On Fri, Apr 25, 2014 at 12:19 PM, Supun Sethunga <[email protected]> wrote:
>
>> Hi Malinda,
>>
>> Still gives the same exception.
>>
>> Thanks,
>>
>>
>> On Fri, Apr 25, 2014 at 11:56 AM, Milinda Perera <[email protected]>wrote:
>>
>>> Hi,
>>>
>>> I think problem is in endpoint. Try It with https endpoint.
>>>
>>> Thanks
>>>
>>>
>>> On Fri, Apr 25, 2014 at 11:49 AM, Supun Sethunga <[email protected]>wrote:
>>>
>>>> attached is the client.
>>>>
>>>> Thanks!
>>>>
>>>>
>>>> On Fri, Apr 25, 2014 at 11:39 AM, Roshan Wijesena <[email protected]>wrote:
>>>>
>>>>> can you attache your client also ..
>>>>>
>>>>>
>>>>> On Fri, Apr 25, 2014 at 11:14 AM, Supun Sethunga <[email protected]>wrote:
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> Im trying to secure a non-secured back-end service using a proxy.
>>>>>> When i create a secure proxy with policies from the ESB and execute the
>>>>>> client, i get the following exception.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> *Exception in thread "main" org.apache.axis2.AxisFault: Read timed
>>>>>> out at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at
>>>>>> org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
>>>>>> at
>>>>>> org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) at
>>>>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
>>>>>> at
>>>>>> org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
>>>>>> at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)*
>>>>>> ...
>>>>>> ...
>>>>>>
>>>>>> For the testing purpose, when I create a simple pass through proxy
>>>>>> and execute the client, the sent message actually reaches the proxy with
>>>>>> all the security headers. (checked using ESB SOAP tracer). So I guess my
>>>>>> client works fine.
>>>>>>
>>>>>> But the SOAP tracer in ESB does not track the message sent when the
>>>>>> secure proxy (with policy applied) is used.
>>>>>>
>>>>>> Any idea on what causes this exception?
>>>>>>
>>>>>> I have attached the policy file herewith.
>>>>>>
>>>>>> Thanks,
>>>>>> Supun
>>>>>>
>>>>>> --
>>>>>> *Supun Sethunga*
>>>>>> Software Engineer
>>>>>> WSO2, Inc.
>>>>>> lean | enterprise | middleware
>>>>>> Mobile : +94 716546324
>>>>>>
>>>>>> _______________________________________________
>>>>>> Dev mailing list
>>>>>> [email protected]
>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Best Regards,
>>>>> Senior Software Engineer-WSO2 Inc.
>>>>> Roshan Wijesena
>>>>> Mobile: *+94752126789*
>>>>> Email: [email protected]
>>>>> *WSO2, Inc. :** wso2.com <http://wso2.com/>*
>>>>> lean.enterprise.middleware.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> *Supun Sethunga*
>>>> Software Engineer
>>>> WSO2, Inc.
>>>> lean | enterprise | middleware
>>>> Mobile : +94 716546324
>>>>
>>>> _______________________________________________
>>>> Dev mailing list
>>>> [email protected]
>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>>>
>>>>
>>>
>>>
>>> --
>>> Milinda Perera
>>> Software Engineer;
>>> WSO2 Inc. http://wso2.com ,
>>> Mobile: (+94) 714 115 032
>>>
>>>
>>
>>
>> --
>> *Supun Sethunga*
>> Software Engineer
>> WSO2, Inc.
>> lean | enterprise | middleware
>> Mobile : +94 716546324
>>
>
>
>
> --
> Milinda Perera
> Software Engineer;
> WSO2 Inc. http://wso2.com ,
> Mobile: (+94) 714 115 032
>
>
--
*Supun Sethunga*
Software Engineer
WSO2, Inc.
lean | enterprise | middleware
Mobile : +94 716546324
package client;
import org.apache.ws.security.WSPasswordCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;
public class PWCBHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException,
UnsupportedCallbackException { WSPasswordCallback pwcb = (WSPasswordCallback) callbacks[0];
String id = pwcb.getIdentifier();
int usage = pwcb.getUsage();
if (usage == WSPasswordCallback.USERNAME_TOKEN) {
if ("admin".equals(id)) {
// if ("[email protected]".equals(id)) {
pwcb.setPassword("admin");
// pwcb.setPassword("admin123");
}
} else if (usage == WSPasswordCallback.SIGNATURE || usage == WSPasswordCallback.DECRYPT) {
// Logic to get the private key password for signture or decryption
/* if ("client".equals(id)) {
pwcb.setPassword("apache");
}
if ("service".equals(id)) {
pwcb.setPassword("apache");
} */
if ("wso2carbon".equals(id)) {
//pwcb.setPassword("wso2carbon");
pwcb.setPassword("wso2carbon");
}
if ("clientks".equals(id)) {
pwcb.setPassword("clientks");
}
if ("serviceks".equals(id)) {
pwcb.setPassword("serviceks");
}
}
}
}
package client;
import java.rmi.RemoteException;
import java.util.HashMap;
import java.util.Properties;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
import org.apache.rampart.policy.model.CryptoConfig;
import org.apache.rampart.policy.model.RampartConfig;
public class SecureOrderProcessClient {
public static void main(String args[]) throws Exception{
String clientRepo="/home/supun/workspace/SecureOrderProcessClient/clientRepo";
String clientKey ="/home/supun/workspace/SecureOrderProcessClient/wso2carbon.jks";
String securityPolicy = "/home/supun/workspace/SecureOrderProcessClient/policy.xml";
String trustStore = "/home/supun/workspace/SecureOrderProcessClient/client-truststore.jks";
String endpoint ="https://Supun:8243/services/SecureProxy2?wsdl";
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(clientRepo, null);
SecureOrderProcessServiceStub stub = new SecureOrderProcessServiceStub(ctx, endpoint);
System.setProperty("javax.net.ssl.trustStore", trustStore);
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
//ServiceClient sc = new ServiceClient(ctx, null);
ServiceClient sc = stub._getServiceClient();
sc.engageModule("rampart");
sc.engageModule("addressing");
Options opts = new Options();
opts.setTo(new EndpointReference(endpoint));
opts.setAction("urn:viewOrder");
opts.setAction("urn:makeOrder");
opts.setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy(securityPolicy,clientKey));
sc.setOptions(opts);
//viewOrder("0005", stub);
makeOrder(stub,sc);
}
public static Policy loadPolicy(String xmlPath , String clientKey) throws Exception {
StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
RampartConfig rc = new RampartConfig();
rc.setUser("admin");
rc.setUserCertAlias("wso2carbon");
// rc.setUserCertAlias("clientks");
rc.setEncryptionUser("wso2carbon");
// rc.setEncryptionUser("serviceks");
rc.setPwCbClass("client.PWCBHandler");
CryptoConfig sigCryptoConfig = new CryptoConfig();
sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
Properties prop1 = new Properties();
prop1.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
prop1.put("org.apache.ws.security.crypto.merlin.file", clientKey);
prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon");
// prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", "clientks");
sigCryptoConfig.setProp(prop1);
CryptoConfig encrCryptoConfig = new CryptoConfig();
encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
Properties prop2 = new Properties();
prop2.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
prop2.put("org.apache.ws.security.crypto.merlin.file", clientKey);
prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", "wso2carbon");
// prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", "clientks");
encrCryptoConfig.setProp(prop2);
rc.setSigCryptoConfig(sigCryptoConfig);
rc.setEncrCryptoConfig(encrCryptoConfig);
policy.addAssertion(rc);
System.out.println(policy);
return policy;
}
public static void makeOrder(SecureOrderProcessServiceStub stub,ServiceClient sc) throws RemoteException {
//create the new order
HashMap<String, Integer> order = new HashMap<>();
order.put("Large Pizza - chicken", 7);
order.put("Cocacola - 1.5l", 1);
order.put("French Fries", 3);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://service", "ns");
OMElement method = fac.createOMElement("makeOrder", omNs);
//create the element using above order, to be sent to the OrderProcessor
for (String key : order.keySet()) {
OMElement item = fac.createOMElement("item", omNs);
OMElement itemId = fac.createOMElement("itemId", omNs);
OMElement quantity = fac.createOMElement("quantity", omNs);
itemId.addChild(fac.createOMText(itemId, key));
item.addChild(itemId);
quantity.addChild(fac.createOMText(quantity, "" + order.get(key)));
item.addChild(quantity);
method.addChild(item);
}
System.out.println(method);
//sends the order to the sever and gets the response
//OMElement result = sc.sendReceive(method);
OMElement result = stub.makeOrder(method);
//extract the order code from the received response to display
OMElement orderIdElement = result.getFirstElement().getFirstElement();
String orderId = orderIdElement.getText();
System.out.println("New Order added Successfuly. Your Order Code: "+orderId);
}
public static void viewOrder(String id, SecureOrderProcessServiceStub stub) throws RemoteException{
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("orderprocessorns", "ns");
OMElement method = fac.createOMElement("viewOrder", omNs);
OMElement orderId = fac.createOMElement("orderId", omNs);
orderId.addChild(fac.createOMText(orderId, id));
method.addChild(orderId);
//send the order id element to the server, and get the order details as the response
OMElement orderInfo = stub.viewOrder(method);
//prints the received order details
printOrder(orderInfo,id);
}
public static void printOrder(OMElement element, String s) {
/* prints the details of items in an order
*
* If a invalid/non-existing order is given to print, a error message is printed
*/
element.build();
if (((OMElement) element.getFirstElement().getFirstElement()) != null) {
OMElement orderItem = element.getFirstElement().getFirstElement();
OMElement itemElement;
OMElement quantityElement;
System.out.println("\n************ Oder Details ************\n");
System.out.println("OrderCode : "+ s);
System.out.println("\nItem\t\t\t\tAmount\n");
do {
itemElement = (OMElement) orderItem.getFirstOMChild();
quantityElement = (OMElement) itemElement.getNextOMSibling();
System.out.println(itemElement.getText() + " \t\t "
+ Integer.parseInt(quantityElement.getText()));
}
while ((orderItem = (OMElement) orderItem.getNextOMSibling()) != null);
}
else {
System.out.println("No such order found! Please check the order id again.");
}
}
}
<wsp:Policy wsu:Id="SigOnly"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:InitiatorToken>
<wsp:Policy>
<sp:X509Token
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:RequireThumbprintReference/>
<sp:WssX509V3Token10/>
<!-- sp:WssX509V3Token10/ -->
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:InitiatorToken>
<sp:RecipientToken>
<wsp:Policy>
<sp:X509Token
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
<wsp:Policy>
<sp:RequireThumbprintReference/>
<sp:WssX509V3Token10/>
<!-- sp:WssX509V3Token10/ -->
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:RecipientToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:AsymmetricBinding>
<sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
<sp:MustSupportRefIssuerSerial/>
</wsp:Policy>
</sp:Wss10>
<sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<sp:Body/>
</sp:SignedParts>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev