Friday, May 19, 2017

JavaScript notes

call JavaScript after page load

This can be used to hide some elements.
2 ways:

a) using JavaScript at the bottom of the page - just before </body>
after DOM is constructed

<script>
alert("page is loaded");
</script>


b) using jQuery - mostly placed in head section:

 <script>
        $(document).ready(function() {
alert("page is loaded");
});

</script>


Set visibility of items

Hide element based on selected item in dropdown list (<select>).

<script>
var optionList = document.getElementById('customerTypeSelection');
var customerTypeId = Number(optionList.options[optionList.selectedIndex].value.split(',', 1));
var acquirersRow = document.getElementById("Acquirers");
if (customerTypeId == 7) {
acquirersRow.style.display = '';
} else {
acquirersRow.style.display = 'none';
}
</script>




Monday, May 8, 2017

Ubuntu notes

Data and Time


display current date

$ date
e.g Mon May  8 15:13:15 CEST 2017

change time zone

$ sudo dpkg-reconfigure tzdata

or

$ sudo timedatectl set-timezone Europe/Dublin


Ref

https://help.ubuntu.com/community/UbuntuTime
https://help.ubuntu.com/lts/serverguide/NTP.html

Tuesday, March 28, 2017

git notes

Git tools on windows

  • Git for Windows (git bash as CLI)
  • SourceTree (GUI for git)

Start git bash in specific directory on windows

Modify git bash shortcut - under Target:
instead
D:\Tools\Git\git-bash.exe --cd-to-home
put
D:\Tools\Git\git-bash.exe --cd=D:\git

Git usage

Clone repository

$ git clone URL

Switch to tag/branch

$ git checkout tags/<tag_name>

List all tags

$ git tag -l

Remove local repository

delete directory :)

Revert changes

# Revert changes to modified files.
$ git reset --hard

# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)
$ git clean -fd

Git stash

-- Stash the changes in a dirty working directory away
--  saves your local modifications away and reverts the working directory to match the HEAD commit.
$ git stash apply -- restore stashed files - you need to call git stash drop to remove files from stash!

$ git stash pop -- move files from stash into branch

## https://stackoverflow.com/questions/11269256/how-to-name-and-retrieve-a-stash-by-name-in-git
$ git stash save "guacamole sauce WIP"
$ git stash apply stash^{/guacamo}
or git stash apply stash@{n}


How to see remote location

$ git remote show origin

Ref

Getting Started with Git @dzone
Tutorial 1: Using branch
Git from the inside out
A successful Git branching model By Vincent Driessen

Friday, March 24, 2017

Ant notes

Multiple environments - properties overrides

By defining property files first one will override the next one that is defined:

<property file="build.${user.name}.properties" description="Local customizations, overrides"/>
<property file="build.properties" />


This means if you have property named databaseUrl defined in both files, the one with your username will have more precedence.

To ignore overrides that are based on user.name one can use antcall task instead depends and override params.
Example is bellow. In it you can override properties someParameter_1 and someParameter_2, by using antcall.

<target name="dist">

<antcall target="build">
<param name="someParameter_1" value="newValue"/>
<param name="someParameter_2" value="newValue"/>
</antcall>

<delete dir="${dist.dir}" />
<mkdir dir="${dist.dir}" />

<tar destfile="${dist.dir}/myProduct-${version}.tar.gz" compression="gzip">
<tarfileset dir="${build.dir}" />
</tar>
</target>


Ref

Managing Multiple Build Environments
Built-in Ant Properties
Apache Ant Wiki
AntCall

Thursday, March 2, 2017

Spring profiles

Requirement

Spring Profiles provide a way to segregate parts of your application configuration and make it only available in certain environments.

I'm working on 2 applications:

  1. with Spring Boot (1.3)
  2. legacy Spring XML (Spring version 3.2.)
Requirements are to have active profiles define in properties file. This is easy and by default for Spring Boot application.

Setting active profiles in Spring Boot application


Define spring.profiles.active=myProfile inside properties file


Displaying active profile when application is starting:

@Autowired
protected Environment env;

@PostConstruct
void after() {
String[] activeProfiles = env.getActiveProfiles();
logger.info("\n** activeProfiles: " + Arrays.toString(activeProfiles));
}


Setting active profiles in legacy Spring applications (Spring 3.2)


Defining profile for legacy Spring application was done in web.xml:

<context-param>
<param-name>spring.profiles.active</param-name>

<param-value>myProfile</param-value>
</context-param>


Read active profile inside JSP page:
String activeProfile = (String) pageContext.getServletContext().getInitParameter("spring.profiles.active");

To move this definition inside properties file, you need to implement org.springframework.context.ApplicationContextInitializer interface:

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment env = applicationContext.getEnvironment();
try {
env.getPropertySources().addFirst(new ResourcePropertySource("classpath:application.properties"));

String profile = env.getProperty("spring.profiles.active");
logger.info("env.getProperty('spring.profiles.active'): " + profile);

String[] activeProfiles = env.getActiveProfiles();
logger.info("env.getActiveProfiles: " + Arrays.toString(activeProfiles));

// logger.info("changing active profile to ...");
// env.setActiveProfiles("newProfile");
} catch (IOException e) {
logger.info("file not found...");
}
}


In web.xml register it as context-param:

<context-param>
<param-name>contextInitializerClasses</param-name>
<param-value>hr.samara.demo.config.SamaraInitializer</param-value>
</context-param>


After this change reading active profile in JSP page needs to change:

<%@page import="org.springframework.web.context.support.XmlWebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>

<%
ServletContext sc = pageContext.getServletContext();
WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sc);
String[] profiles = applicationContext.getEnvironment().getActiveProfiles();
%>

Ref:

http://www.baeldung.com/spring-profiles
https://www.mkyong.com/spring/spring-profiles-example/
spring-doc-Bean definition profiles
stackoverflow - How to set active spring 3.1 environment profile via a properites file and not via an env variable or system property

Wednesday, January 11, 2017

Oracle notes

How to restart database

connect as oracle user

$ sudo su - oracle

Restart DB Instance

$ sqlplus sys/password as sysdba
$ shutdown
$ startup
$ exit

Ref: Starting Up and Shutting Down

Restart Listener

$ lsnrctl stop
$ lsnrctl start
$ lsnctl status

Listener setting

ORACLE_INSTALLATION_DIR\product\12.1.0\dbhome_1\NETWORK\ADMIN\listener.ora

Tuesday, December 20, 2016

Vagrant notes

Vagrant enables users to create and configure lightweight, reproducible, and portable development environments.

$ vagrant up

This command creates and configures guest machines according to your Vagrantfile.
Start virtual machine.

$ vagrant ssh

This will SSH into a running Vagrant machine and give you access to a shell.

$ vagrant halt

This command shuts down the running machine Vagrant is managing.

$ vagrant destroy

This command stops the running machine Vagrant is managing and destroys all resources that were created during the machine creation process.
After running this command, your computer should be left at a clean state, as if you never created the guest machine in the first place.

$ vagrant global-status

This command will tell you the state of all active Vagrant environments on the system for the currently logged in user.

Ref:

https://www.vagrantup.com/docs/cli/

Thursday, December 1, 2016

Connection to SVN on Win 10 machine with DirectAccess

 There are 2 svn connectors:
  1. SVN Kit
  2. JavaHL Native
Tortoise and Eclipse plugins for SVN by default use JavaHL and that does not work over DA by default!
Direct Access goes over IPv6.
Subclise for Eclipse can be set to use SVN Kit or JavaHL as client.
By default SVN Kit goes over IPv6 but tortoise is using JavaHL and those two are incompatible. Errors like

revert C:/projects/internal/backoffice-sso
    svn: E200030: Index not exists: I_NODES_MOVED
    Index not exists: I_NODES_MOVED
  
or
  
An internal error occurred during: "Refresh SVN status cache".
Can't overwrite cause with org.tmatesoft.svn.core.SVNException: 
svn: E155010: The node 'zzz_project' was not found.

Tortoise SVN

Get version that supports IPv6.
Latest version, 1.9.5 does not have ipv6 version and does not work!

Eclipse

Download and install SlikSVN (https://sliksvn.com/download/)
Install Subclipse in Eclipse via update site, I have used version 4.2.x where update site is https://dl.bintray.com/subclipse/releases/subclipse/4.2.x/
After, verify SVN interface that is in use (Preferences - type SVN) is SilkSvn.
Subclipse 1.10.13 does not use SlikSVN as connector! I guess versions are incompatible: Subclipse uses JavaHL 1.9.3 and installed SlikSvn uses 1.9.4

Resources

Wednesday, October 5, 2016

SSO using SAML

Single Sign On using Security Assertion Markup Language

Few options

Identity Provider (IDP) is used for authentication purposes only. It is replacing login screen :)
Service Provider (SP, application) will do authorization by reading roles from LDAP/database...
or
IDP will be used for authentication and authorization.
Problem with this approach is that SP does not know when role changes.

Session information can be stored using cookies on SP and IDP domain, so IDP can verify if user user is already logged on another SP.

Flow:

  1. User comes to SP (User is not logged. SP and IDP does not have any information about user)
  2. There is no session on SP for this user and user is redirected to IDP
  3. IDP authenticate user and send SAML response to SP
  4. SP validates SAML response and reads roles from datasource and the session is established
  5. User comes to SP2 (another application)
  6. SP2 does not have a session and asks IDP about this user.
  7. IDP knows this user has session so user is not provided with login screen. IDP reads data from datasource and returns SAML response to SP2
  8. SP2 validates SAML response and reads roles from LDAP
  9. User has seamlessly logged to SP2
Handle roles and password changes on SP.

IDP notes

IdP only reads, never having any sort of admin access. This helps security ­wise, knowing that authentication system can't write or retrieve sensitive information.

Common problems

Problem

DEBUG (SAMLProcessingFilter.java:99) - Incoming SAML message is invalid
org.opensaml.ws.security.SecurityPolicyException: Validation of protocol message signature failed

Solution

Verify that SP and IDP have proper metadata.

Problem

14:54:00.798 [http-nio-8082-exec-6] DEBUG (SAMLProcessingFilter.java:99) - Incoming SAML message is invalid
org.opensaml.ws.security.SecurityPolicyException: Validation of protocol message signature failed
at org.opensaml.common.binding.security.SAMLProtocolMessageXMLSignatureSecurityPolicyRule.doEvaluate(SAMLProtocolMessageXMLSignatureSecurityPolicyRule.java:138)
at org.opensaml.common.binding.security.SAMLProtocolMessageXMLSignatureSecurityPolicyRule.evaluate(SAMLProtocolMessageXMLSignatureSecurityPolicyRule.java:107)
at org.opensaml.ws.security.provider.BasicSecurityPolicy.evaluate(BasicSecurityPolicy.java:51)
at org.opensaml.ws.message.decoder.BaseMessageDecoder.processSecurityPolicy(BaseMessageDecoder.java:132)
at org.opensaml.ws.message.decoder.BaseMessageDecoder.decode(BaseMessageDecoder.java:83)
at org.opensaml.saml2.binding.decoding.BaseSAML2MessageDecoder.decode(BaseSAML2MessageDecoder.java:70)
at org.springframework.security.saml.processor.SAMLProcessorImpl.retrieveMessage(SAMLProcessorImpl.java:105)

Solution

Add IDP public key for signing messages to java key store. It can be found in incoming saml message from IDP.

http://stackoverflow.com/questions/23059203/http-status-401-authentication-failed-incoming-saml-message-is-invalid-with

Problem

InResponseToField of the Response doesn't correspond to sent message

Log
2016-10-26 12:33:20,159 DEBUG PROTOCOL_MESSAGE,http-nio-8080-exec-4:74 -
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" AssertionConsumerServiceURL="http://mercurybi-local:8080/mercurybi/saml/SSO" Destination="https://authstack/saml2.0/sso" ForceAuthn="false" ID="a293907a4b8ed0d21iggb0ci9dc0bbb" IsPassive="false" IssueInstant="2016-10-26T10:33:20.100Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0">
   <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">SAMARA_SP</saml2:Issuer>
</saml2p:AuthnRequest>

2016-10-26 12:33:22,427 DEBUG PROTOCOL_MESSAGE,http-nio-8080-exec-5:113 -
<?xml version="1.0" encoding="UTF-8"?><samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" Destination="http://mercurybi-local:8080/mercurybi/saml/SSO" ID="_4981b4a45c61a289809108b15d7c401bb2c0bcdae5" InResponseTo="a293907a4b8ed0d21iggb0ci9dc0bbb" IssueInstant="2016-10-26T10:33:20Z" Version="2.0">
   <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://authstack</saml:Issuer>
   <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
  <ds:SignedInfo>

  2016-10-26 12:33:22,698 DEBUG HttpSessionStorage,http-nio-8080-exec-5:117 - Message a293907a4b8ed0d21iggb0ci9dc0bbb not found in session A9C98F53D692EDFA486D96FB3D9F67C6
2016-10-26 12:33:22,702 DEBUG SAMLAuthenticationProvider,http-nio-8080-exec-5:98 - Error validating SAML message
org.opensaml.common.SAMLException: InResponseToField of the Response doesn't correspond to sent message a293907a4b8ed0d21iggb0ci9dc0bbb

Solution

<bean id="contextProvider" class="org.springframework.security.saml.context.SAMLContextProviderImpl">
  <property name="storageFactory">
    <bean class="org.springframework.security.saml.storage.EmptyStorageFactory"/>
  </property>
</bean>

Problem and Solution

Application is hosted on 2 different machines using different domains.
IDP manages to return proper domain name based on following rules

  1. read where to return in SP metadata
  2. if AssertionConsumerServiceURL field is present in SAML request use that one


<?xml version="1.0" encoding="UTF-8"?>

<saml2p:AuthnRequest
    AssertionConsumerServiceURL="http://app.samara.hr:8080/app/saml/SSO"
    Destination="https://myIDP/saml2.0/sso" ForceAuthn="false"
    ID="a4bi2g9cj906hj4429i0b0413h5aji4" IsPassive="false"
    IssueInstant="2016-11-03T13:57:40.212Z"
    ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
    Version="2.0" xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol">
    <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">SAMARA-SP</saml2:Issuer>
</saml2p:AuthnRequest>

Logout and SingleLogout feature

What will be URL used for redirects (if that option is used) update SP metadata:

<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://mydomain.samara.hr/myApp/saml/SingleLogout"/>

Send SAML request via POST

To be sure POST is used:

@Bean
public WebSSOProfileOptions defaultWebSSOProfileOptions() {
final WebSSOProfileOptions webSSOProfileOptions = new WebSSOProfileOptions();
webSSOProfileOptions.setIncludeScoping(false);
webSSOProfileOptions.setBinding(SAMLConstants.SAML2_POST_BINDING_URI);
return webSSOProfileOptions;
}

Ref:

SWITCH - Demo
okta - SAML
SAML Security Cheat Sheet
Spring Security SAML
Spring SAML - Troubleshooting common problems
Can one SP metadata file be used for 5 separate SPs running the same application

Wednesday, August 17, 2016

Gradle

generate dependency tree

$ ./gradlew dependencies > dep.txt


generate dependency tree and refresh dependencies

$ ./gradlew dependencies > dep.txt --refresh-dependencies
The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts.

Ref: Listing project dependencies

create java project

$ gradle init --type java-application
More info at Build Init Plugin
Clean build.gradle file

eclipse - download sources and javadoc

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        downloadJavadoc = true
        downloadSources = true
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

$ gradle cleanEclipse eclipse

If mavenLocal() is present in your repositories, don't forget to put it at the bottom of the list.


add test sources from one project to second in multiproject environment

testCompile project(':sub-project').sourceSets.test.output

publish to local repository

$ ./gradlew publishToMavenLocal

Ref

https://stackoverflow.com/questions/28404149/how-to-download-javadocs-and-sources-for-jar-using-gradle-2-0

Tuesday, August 9, 2016

Angular.JS notes

Notes

AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag.
AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions.




A Directive is a marker on a HTML tag that tells Angular to run or reference some JavaScript code.
Controllers are where we define our app’s behavior by defining functions and values.
Modules – where our application components live
Expressions – how values get displayed within the page

AngularJS Example

index.html
<!DOCTYPE html>
<html ng-app="gemStore">
  <head>
    <script type="text/javascript" src="angular.min.js"></script>
    <script type="text/javascript" src="app.js"></script>
  </head>
  
<body ng-controller="StoreController as store">
<div ng-repeat="product in store.products">
<h1>{{product.name}}</h1>
<h2> ${{product.price}}</h2>
<p> {{product.description}}</p>
<button ng-show="product.canPurchase">Add to Cart</button>
</div>
</body>
</html>

app.js
(function() {
var app = angular.module('gemStore', []);

app.controller('StoreController', function() {
// store data in the controller
this.products = gems;
});

var gems = [
{ name: 'Azurite', price: 2.95, description: 'Dobar za prodaju....', canPurchase : true },
{ name: 'Bloodstone', price: 5.95, description: 'Ne mozes kupiti', canPurchase : false },
{ name: 'Zircon', price: 3.95, description: 'ZZZZZZ', canPurchase : true }
];

})();

Ref


Wednesday, May 25, 2016

Tomcat notes

Configure tomcat to expose files from disk

In tomcat conf/server.xml add at the bottom before </Host>:

 <Context path="/results"
                 docBase="/opt/prov/rdisk/manufacturer_results"
                 debug ="99"
                 reloadable="true">
 </Context>


In you application properties you can define:

#where to save files
path_file=/opt/prov/rdisk/manufacturer_results/{0}_name.csv
#url to fetch file
url_file=http://machine:8080/results/{0}_error.csv

Tomcat exposes files found on those places on disk.
You can reach them via http.

Thursday, April 7, 2016

Quartz with Spring - Java configuration

In my previous post Quartz with Spring and embedded database I have used xml to configure spring 3 with quartz 1.8.

Now I will configure spring 4.2 with quartz 2.2.2 using Java configuration. I am using quartz in cluster.

Java configuration class

@Configuration
@ComponentScan({ "hr.samara.job" })
public class QuartzConfig
{

@Autowired
private DataSource dataSource;
@Autowired
private JpaTransactionManager transactionManager;
@Autowired
private Environment env;

@Autowired
private SimOperation simOperation;

@Bean
public SchedulerFactoryBean scheduler()
{
SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
scheduler.setConfigLocation(new ClassPathResource("quartz.properties"));

scheduler.setDataSource(dataSource);
scheduler.setTransactionManager(transactionManager);

// inject simOperation - spring bean in job
Map<String, Object> map = new HashMap<>();
map.put("simOperation", simOperation);
scheduler.setSchedulerContextAsMap(map);


scheduler.setTriggers(blockSimTrigger().getObject());
return scheduler;
}

@Bean
public CronTriggerFactoryBean blockSimTrigger()
{
CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
cronTriggerFactoryBean.setJobDetail(blockSimJob().getObject());
cronTriggerFactoryBean.setCronExpression(env.getProperty("job.blockSim.cron"));
cronTriggerFactoryBean.setMisfireInstructionName("MISFIRE_INSTRUCTION_FIRE_ONCE_NOW");
return cronTriggerFactoryBean;
}

@Bean
public JobDetailFactoryBean blockSimJob()
{
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
jobDetailFactory.setJobClass(BlockSimJob.class);
jobDetailFactory.setDescription("call sim block");
return jobDetailFactory;
}

}


Job class

@DisallowConcurrentExecution
public class BlockSimJob extends QuartzJobBean
{

private transient SimOperation simOperation;

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException
{
simOperation.blockSim();
}

public void setSimOperation(SimOperation simOperation)
{
this.simOperation = simOperation;
}

}


Ref:
http://www.baeldung.com/spring-quartz-schedule

Tuesday, November 10, 2015

Web services FAQ

Using cxf 2.7, generated wsdl contains 2 files, because interface and implementation are not in same package.
Solution annotate implementation and override targetNamespace
@WebService(targetNamespace = "om.samara.hr")



Friday, August 28, 2015

Wednesday, July 29, 2015

Quartz troubleshooting

Problem:
Quartz in clustered mode, nodes are sync via db.
There are many lines like these in logs:
[2015-07-04 00:00:01,620]  WARN [QuartzScheduler_scheduler-prov011435933239135_ClusterManager] (JobStoreSupport.java:3298) - This scheduler instance (prov011435933239135) is still active but was recovered by another instance in the cluster.  This may cause inconsistent behavior.

"The most probable cause of such a cluster-related error is having cluster nodes with system clock not synchronized."



Ref:
http://quartz-scheduler.org/documentation/faq

Tuesday, July 28, 2015

web service client

Server is returning soap fault with http status 400

SOAP UI is displaying nicely













When using cxf Java client I get strange, misleading message:
org.apache.cxf.interceptor.Fault: Could not send Message.

On server side I see everything is as expected soap fault is returned with bad request status code 400.
After little debugging I found this in org.apache.cxf.transport.http.HTTPConduit class:
// "org.apache.cxf.transport.process_fault_on_http_400" property should be set in case a 
// soap fault because of a HTTP 400 should be returned back to the client (SOAP 1.2 spec)

So before making a call configure client:
Client client = ClientProxy.getClient(port);
client.getBus().setProperty("org.apache.cxf.transport.process_fault_on_http_400", true);

After that I get expected exception:
Caused by: org.apache.cxf.binding.soap.SoapFault: some validation message


One more example of calling web service with Apache CXF - now within the same project I'm doing integration test with Spock and SpringBootTest.
HelloWorldWs is interface annotated with @WebService

def setup() {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean()
    proxyFactory.setServiceClass(HelloWorldWs)
    this.pismaUrl = "http://localhost:" + this.port + "/services/pisma"
    proxyFactory.setAddress(pismaUrl)
    this.client = (HelloWorldWs) proxyFactory.create()

    Client client = ClientProxy.getClient(this.client);
    client.getBus().setProperty("org.apache.cxf.transport.process_fault_on_http_400", true);
}


web service client example


//web service interface to be called
@WebService(targetNamespace = "http://services.crm.ticketing.samara.com", name = "ticketingServicePortTypes")
@XmlSeeAlso({ObjectFactory.class})
public interface TicketingServicePortTypes {

// web service client that was generated with wsdltojava
// This class was generated by Apache CXF 3.0.3
TicketingService extends javax.xml.ws.Service

Java client that calls TicketingService, using basic authentication with u/p.
final TicketingService service = new TicketingService(); // should be singleton
final TicketingServicePortTypes port = service.getTicketingServicePort();
javax.xml.ws.BindingProvider bp = (BindingProvider) port;
log.trace("username: " + username + ", password: " + password);
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://10.105.100.127:8445/");


Using spring cxf xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
        http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
        ">




<!-- jaxws client to front end -->
<jaxws:client id="crmService"
serviceClass="com.samara.generated.crm.api.TicketingServicePortTypes"
address="${crm.url}" username="${crm.username}" password="${crm.password}">
<jaxws:binding>
<soap:soapBinding mtomEnabled="false" version="1.1" />
</jaxws:binding>
</jaxws:client>

</beans>



Monday, July 27, 2015

Generating random integers in a range


Random rand;
int randomNum = rand.nextInt((max - min) + 1) + min;

or

int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1);


Ref:
stackoverflow - Generating random integers in a range with Java
Random - nextInt