{"id":34,"date":"2012-05-23T23:58:52","date_gmt":"2012-05-23T23:58:52","guid":{"rendered":"http:\/\/localhost\/tfcom_wp\/2012\/05\/23\/wc-context-objects\/"},"modified":"2012-05-23T23:58:52","modified_gmt":"2012-05-23T23:58:52","slug":"wc-context-objects","status":"publish","type":"post","link":"https:\/\/www.tech-freaks.com\/java\/websphere-commerce\/wc-context-objects.html","title":{"rendered":"Accessing Websphere Commerce Context Objects"},"content":{"rendered":"<p style=\"text-align: left;\">IBM Infocenter URL for CommandContext is <a href=\"https:\/\/help.hcltechsw.com\/commerce\/8.0.0\/api\/com\/ibm\/commerce\/command\/CommandContext.html\" target=\"_blank\" rel=\"noopener\">Infocenter CommandContext API<\/a><\/p>\n<p style=\"text-align: left;\">When you review the methods you will see lot of deprecated methods which mention use of other context objects to access the information.<\/p>\n<p>For this article we will review the CommandContext.getRemoteAddr() method which will give the IP address of the user accessing the site.<\/p>\n<p style=\"text-align: left;\">Infocenter mentions:<\/p>\n<p><em>getRemoteAddr()<br \/>Deprecated. The TransportData object should be retrieved from the AuditContext of the request. The remote address is retrieved by calling TransportData.getRemoteAddress()<br \/><\/em><br \/>We need to use the AuditContext, but the first question is how we get instance of AuditContext.<\/p>\n<p><em>CommandContext.getContext(strContextName)<\/em>\u00a0is the method we need to use.<\/p>\n<p>Below sample code explains how to get IP address using the AuditContext<\/p>\n<pre class=\"language-java\"><code>AuditContext auditCtx = (AuditContext) getCommandContext().getContext(AuditContext.NAME);\r\nSystem.out.println(\"IP Address \"+auditCtx.getTransportData().getRemoteAddress());<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>IBM Infocenter URL for CommandContext is Infocenter CommandContext API When you review the methods you will see lot of deprecated [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[12],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-websphere-commerce"],"_links":{"self":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-freaks.com\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}