{"id":7678,"date":"2013-04-26T15:25:15","date_gmt":"2013-04-26T20:25:15","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=7678"},"modified":"2013-07-06T11:09:17","modified_gmt":"2013-07-06T16:09:17","slug":"patch-axis-1-3-to-use-java-net-authenticator","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=7678","title":{"rendered":"Patch Axis 1.3 to Use java.net.Authenticator"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Override_org.apache.axis.transport.http.HTTPSender\">Override org.apache.axis.transport.http.HTTPSender<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Point_to_New_SimpleHTTPSender\">Point to New SimpleHTTPSender<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Test\">Test<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<p>Axis 1.3 based web services client does not support java.net.Authenticator. Follow the instruction below to enable java.net.Authenticator support.<\/p>\n<span id=\"Override_org.apache.axis.transport.http.HTTPSender\"><h3>Override org.apache.axis.transport.http.HTTPSender<\/h3><\/span>\n<pre lang=\"java\">\r\npackage com.my.patch.axis;\r\n\r\nimport java.io.BufferedInputStream;\r\nimport java.io.BufferedOutputStream;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\nimport java.net.HttpURLConnection;\r\nimport java.net.URL;\r\nimport java.net.URLConnection;\r\nimport java.util.logging.Logger;\r\nimport org.apache.axis.AxisFault;\r\nimport org.apache.axis.Message;\r\nimport org.apache.axis.MessageContext;\r\nimport org.apache.axis.transport.http.HTTPSender;\r\n\r\n\/**\r\n * Based on com.liferay.util.axis.SimpleHTTPSender.\r\n * @see http:\/\/docs.liferay.com\/portal\/5.1\/javadocs\/util-java\/com\/liferay\/util\/axis\/SimpleHTTPSender.html\r\n *\/\r\npublic class SimpleHTTPSender extends HTTPSender {\r\n\tpublic static final String CONTENT_TYPE = \"Content-Type\";\r\n\r\n\tpublic static final String CONTENT_LOCATION = \"Content-Location\";\r\n\r\n\tpublic static final String SOAP_ACTION = \"SOAPAction\";\r\n\r\n    final static Logger logger =\r\n            Logger.getLogger(SimpleHTTPSender.class.getName());\r\n    \r\n    @Override\r\n    public void invoke(MessageContext ctx) throws AxisFault {\r\n        String url = ctx.getStrProp(MessageContext.TRANS_URL);\r\n        _invoke(ctx, url);\r\n    }\r\n\r\n    private void _invoke(MessageContext ctx, String url) throws AxisFault {\r\n        try {\r\n            URL urlObj = new URL(url);\r\n\r\n            URLConnection urlc = urlObj.openConnection();\r\n\r\n            _writeToConnection(urlc, ctx);\r\n            _readFromConnection(urlc, ctx);\r\n        } catch (Exception e) {\r\n            throw AxisFault.makeFault(e);\r\n        }\r\n    }\r\n\r\n    private void _writeToConnection(URLConnection urlc, MessageContext ctx)\r\n            throws Exception {\r\n        urlc.setDoOutput(true);\r\n\r\n        Message request = ctx.getRequestMessage();\r\n\r\n        String contentType = request.getContentType(ctx.getSOAPConstants());\r\n\r\n        urlc.setRequestProperty(CONTENT_TYPE, contentType);\r\n\r\n        if (ctx.useSOAPAction()) {\r\n            urlc.setRequestProperty(SOAP_ACTION, ctx.getSOAPActionURI());\r\n        }\r\n\r\n        OutputStream out = new BufferedOutputStream(urlc.getOutputStream(),\r\n                8192);\r\n\r\n        request.writeTo(out);\r\n\r\n        out.flush();\r\n    }\r\n\r\n    private void _readFromConnection(URLConnection urlc, MessageContext ctx)\r\n            throws Exception {\r\n\r\n        String contentType = urlc.getContentType();\r\n        String contentLocation = urlc.getHeaderField(CONTENT_LOCATION);\r\n\r\n        InputStream in = ((HttpURLConnection) urlc).getErrorStream();\r\n\r\n        if (in == null) {\r\n            in = urlc.getInputStream();\r\n        }\r\n\r\n        in = new BufferedInputStream(in, 8192);\r\n\r\n        Message response = new Message(in, false, contentType, contentLocation);\r\n        response.setMessageType(Message.RESPONSE);\r\n\r\n        ctx.setResponseMessage(response);\r\n    }\r\n}\r\n<\/pre>\n<span id=\"Point_to_New_SimpleHTTPSender\"><h3>Point to New SimpleHTTPSender<\/h3><\/span>\n<p>* Create a new file named <em>client-config.wsdd<\/em> and place it in classpath Root. For example, for Maven file structure, place it in <em>src\/main\/resources<\/em> directory.<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<deployment name=\"defaultClientConfig\" xmlns=\"http:\/\/xml.apache.org\/axis\/wsdd\/\" \r\n    xmlns:java=\"http:\/\/xml.apache.org\/axis\/wsdd\/providers\/java\">\r\n<transport name=\"http\" pivot=\"java:com.my.patch.axis.SimpleHTTPSender\" \/>\r\n<transport name=\"https\" pivot=\"java:com.my.patch.axis.SimpleHTTPSender\"\/>\r\n<transport name=\"local\" pivot=\"java:com.my.patch.axis.SimpleHTTPSender\"\/>\r\n<\/deployment>\r\n<\/pre>\n<span id=\"Test\"><h3>Test<\/h3><\/span>\n<p>* Axis 1.3 now should support java.net.Authenticator<br \/>\n* See <a href=\"?p=6716\">Windows Kerberos Authentication with java.net.Authenticator<\/a> on how to setup Kerberos for testing.<\/p>\n<span id=\"References\"><h3>References<\/h3><\/span>\n<p>* <a href=\"http:\/\/grepcode.com\/file_\/repo1.maven.org\/maven2\/com.liferay.portal\/util-java\/5.2.3\/com\/liferay\/util\/axis\/SimpleHTTPSender.java\/?v=source\">com.liferay.util.axis.SimpleHTTPSender<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Axis 1.3 based web services client does not support java.net.Authenticator. Follow the instruction below to enable java.net.Authenticator support. Override org.apache.axis.transport.http.HTTPSender package com.my.patch.axis; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.util.logging.Logger; import org.apache.axis.AxisFault; &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=7678\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14,53],"tags":[372,378],"class_list":["post-7678","post","type-post","status-publish","format-standard","hentry","category-java","category-security","tag-authenticator","tag-axis1-3"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-1ZQ","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7678"}],"version-history":[{"count":7,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7678\/revisions"}],"predecessor-version":[{"id":7757,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/7678\/revisions\/7757"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}