Results 1 to 5 of 5

Thread: SSL in JAVA

  1. #1
    ssroy is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default SSL in JAVA

    Hi,

    Recently we had a requirement to invoke a WebService over HTTPS which was earlier written in HTTP. Client was written in Axis2 API.

    While googling around the solution, I found that if standard certificate like Verisign is used then no client side change is required except changing the URL from HTTP to HTTPS. But if custom certificate is used then keytool has to be used to import the certificate and code changes are involved.

    Now my question is why no code change is required incase of standard certificate like Verisign. Can anyone please help me to understand this or point to any URL.

    Thanks a lot.

    Best Regards - Roy

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Take a look at:

    The Apache Tomcat 5.5 Servlet/JSP Container - SSL Configuration HOW-TO

    specially take a look on part:
    Installing a Certificate from a Certificate Authority

    ...but i would suggest going through whole text on this link and introduce yourself to all concepts. Configuring Tomcat for SSL is piece of cake. Do try it. But before that make sure you know WHEN you want to use it.


    Typical case

    if some company with secured server allow connecting to this server, they will probably send you certificate file: 'example.crt'.

    You have to import a root or intermediate CA certificate to an existing Java keystore using keytool.

    In your https client class
    before connecting to this secured site,
    you must refer to example.crt in your keystore by using something like this:

    Java Code:
       System.setProperty("java.protocol.handler.pkgs",
            "com.sun.net.ssl.internal.www.protocol");
       Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    //...add property to point to *.crt
    After this it is same thing as doing with regular http client.

    Do explore this things and come back for more info and advices if needed. best of luck!

  3. #3
    ssroy is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Thanks a lot FON for the informations.

    I will test my client code once our vendor provides the HTTPS URL.


    Best Regards - Roy

  4. #4
    ssroy is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi FON,

    Earlier we were calling a web service over HTTP and one of the element was encrypted and was working fine.

    Now we need to invoke the web service over HTTPS and all elements are encrypted using the previous key only.

    We have imported the certificate. But while calling the service we are getting following exception. I am not getting any clue about this error. Any help will be greately appreciated.

    Java Code:
    [B]ERROR STACK TRACE[/B]
    Web Service general exception **** org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,28]
    Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#ElementPrefixUnbound?ns2&ns2:error
    org.apache.axiom.om.OMException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,28]
    Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#ElementPrefixUnbound?ns2&ns2:error
            at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:249)
            at org.apache.axiom.om.impl.llom.OMElementImpl.getNextOMSibling(OMElementImpl.java:307)
            at org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator.findNextElementWithQName(OMChildrenQNameIterator.java:96
    )
            at org.apache.axiom.om.impl.traverse.OMChildrenQNameIterator.hasNext(OMChildrenQNameIterator.java:76)
            at org.apache.axiom.om.impl.llom.OMElementImpl.getFirstChildWithName(OMElementImpl.java:251)
            at org.apache.axiom.soap.impl.llom.soap11.SOAP11FaultImpl.getCode(SOAP11FaultImpl.java:124)
            at org.apache.axis2.AxisFault.initializeValues(AxisFault.java:202)
            at org.apache.axis2.AxisFault.<init>(AxisFault.java:196)
            at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
            at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
            at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
            at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
            at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
            at SMSPinClient.smspin(SMSPinClient.java:81)
            at TestPinWS.main(TestPinWS.java:49)
    Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[7,28]
    Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#ElementPrefixUnbound?ns2&ns2:error
            at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
            at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:506)
            at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:161)
    Java Code:
    [B]CODE[/B]
    operationClient = client.createClient(ServiceClient.ANON_OUT_IN_OP);
    MessageContext outMsgCtx = new MessageContext();
    Options opts = outMsgCtx.getOptions();
    opts.setTo(new EndpointReference("https://URL") );
    opts.setAction("urn:org-com:secure_msg:msg_delivery");
    opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED,"false");
    opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT,"true");	
    client.setOptions(opts);
    SOAPEnvelope csEnv = createPayLoad(arg1, arg2, arg3, arg4 , arg5);
    outMsgCtx.setEnvelope(csEnv);
    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);
    We are getting error from the last line of the code.

    Thanks for your help.

    Best Regards - Roy

  5. #5
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Looks like you have namespace problem in your xml.
    Maybe you use that ns2 prefix and it is not defined.
    Try to debug that SOAP message that you are creating and see how envelope and body looks like and check namespaces.

    Just to give you an idea what could go wrong that a look at this validator (i'm not sure that this one is yours too!) file that works you under hub:

    Java > Open Source Codes > org > apache > xerces > impl > dtd > XMLNSDTDValidator _ Java API By Example, From Geeks To Geeks.

    find 'ElementPrefixUnbound' in this file and try to figure out what is that you are missing

    hope this can help...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •