How to split String in words and populate an array

Here a simply method to split a string in words and generate an array.
In this case I use a Length param to limit substring size.

 


...

public static String[] splitStringInWordsAndCreateArrayWithLineInSize(String input,Integer lineLength){
		String[] words = input.split(" ");
 		List<String> list = new ArrayList<String>();
 		StringBuilder line = new StringBuilder();
 		for (int x = 0; x < words.length; x++) {
 			
 			
 			Boolean c = ((line.toString()+words[x]+" ").length()<lineLength);
 			if(c){
 				line.append(words[x]).append(" ");
 			}else{
 				list.add(line.toString());
 				line = new StringBuilder(words[x]).append(" ");
 			}
 		}
 		if(line.toString().length()>0){
 			list.add(line.toString());	
 		}
 		
 		Object[] arrObj = list.toArray();
 		String[] arrString = Arrays.copyOf(arrObj, arrObj.length, String[].class);
 		
		return arrString;
	}

...

And here unit test:


...

@Test
	 	public void testSplitStringInWordsAndCreateArrayWithLineInSize(){
	 		String s = "Prodotti tricologici per la cura e la bellezza dei capelli,quali shampoo, lozioni per capelli, preparati per ondulare icapelli, preparati per effettuare la permanente dei capelli,tinture per capelli, gel per capelli, lacche e fissatori percapelli,preparati per ravvivare il colore dei capelli . ";
	 		Integer lineLength = 62;
	 		String[] out = FYStringUtils.splitStringInWordsAndCreateArrayWithLineInSize(s, lineLength);
	 		StringBuilder rebuild = new StringBuilder();
	 		for(int x=0;x<out.length;x++){
	 			//System.out.println("x-"+out[x]);
	 			assertThat(out.length<lineLength).isTrue();
	 			rebuild.append(out[x]);
	 		}
	 		
	 		
	 		assertThat(rebuild.toString()).isEqualTo(s);
	 		
	 	}

...

step by step to Integrate https with ibm connections

1)  Verify where kdb and sth files are stored :

Was console: security -> SSL certificate and key management -> Key stores and certificates -> CMSKeyStore (verify path)

2) Open plugin xml and verify where store sth and kdb files  then copy from websphere path (1) .

Server Types-> Web servers > webserver1 > Plug-in properties -> Plug-in key store directory and file name
If not present:

-) Configure Ihs using ibm docs then open  Was console: servertypes / webServers / webservername -> plugin options-> copy kdb to plugin folder
-) Set default cert in kdb using ikeyman

3) Configure virtual host to use ssl :


LoadModule ibm_ssl_module modules/mod_ibm_ssl.so

<IfModule mod_ibm_ssl.c>
Listen 0.0.0.0:443

<VirtualHost *:443>
ServerName www.mydomain.com
SSLEnable
</VirtualHost>

</IfModule>

SSLDisable
Keyfile "<path used in plugin>\plugin-key.kdb"
SSLStashFile "<path used in plugin>\plugin-key.sth"


LoadModule was_ap22_module /opt/ibm/Plugins/bin/64bits/mod_was_ap22_http.so
WebSpherePluginConfig /opt/ibm/Plugins/config/webserver1/Plugin-cfg.xml

Generate version.txt in a maven project

If you need to generate a txt with project version / timestamp in project’s root you can use an ant build like this.


<plugins>

...


<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  	<version>1.8</version>
	<executions>
  	<execution>
	<phase>prepare-package</phase>
	<configuration>
	   <tasks>
	     <tstamp>
		<format property="now" pattern="yyyy-MM-dd hh:mm:ss" locale="it" />
		  </tstamp>
		    <echo file="<path>/version.txt" append="false">
			Project Version : ${project.version} ${line.separator}Build @ ${now}
		    </echo>
            </tasks>
         </configuration>
	    <goals>
		<goal>run</goal>
	    </goals>
	</execution>
	</executions>
</plugin>

...

</plugins>

Start H2 Db as daemon

Here my script to start H2 db as daemon under linux Os.
Please note param “-baseDir $HOME” this means that default storage path is the home of the user that start db,
change variable with absolute path to prevent new Db creation with wrong users.

 
#!/bin/sh

cd `dirname ${0}`/..

case $1 in
  help)
    java -cp <h2Path>/h2-*.jar org.h2.tools.Server -?
  ;;

  start)
    java -cp <h2Path>/h2-*.jar org.h2.tools.Server -tcp -web -baseDir $HOME &
  ;;

  stop)
    java -cp <h2Path>/h2-*.jar org.h2.tools.Server -tcpShutdown "tcp://localhost"
  ;;

  *)
    echo "Usage ${0} (help|start|stop)"
  ;;
esac

Websphere 8 with war java.lang.NoSuchMethodError Exception

Using a war under websphere 8.0 can sometimes throw this exception (In my specific case with jtopen libs) solved with the screen configuration:

war-config

 

 

 

 

 

 

 

ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet main: java.lang.NoSuchMethodError: com/ibm/as400/data/ProgramCallDocument.__jr_selector__(I[Ljava/lang/Object;)Ljava/lang/Object;
at com.fakeclass.genericinvokerweb.beprogram.BEProgram.output(BEProgram.java:217)
at com.fakeclass.genericinvokerweb.PCMLutils.buildOutPut(PCMLutils.java:128)
at com.fakeclass.genericinvokerweb.MainServlet.executeCallAs400(MainServlet.java:104)
at com.fakeclass.genericinvokerweb.MainServlet.doPost(MainServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1071)
at com.ibm.ws.webcontainer.webapp.WebApp.__handleRequest(WebApp.java:3815)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1702)

[17/03/16 16.41.28:730 CET] 00000050 SystemErr R 17-mar-2016 16.41.28 com.ibm.ws.webcontainer.servlet.ServletWrapper service
SEVERE: Uncaught service() exception thrown by servlet main: java.lang.NoSuchMethodError: com/ibm/as400/data/ProgramCallDocument.__jr_selector__(I[Ljava/lang/Object;)Ljava/lang/Object;
at com.fakeclass.genericinvokerweb.beprogram.BEProgram.output(BEProgram.java:217)
at com.fakeclass.genericinvokerweb.PCMLutils.buildOutPut(PCMLutils.java:128)
at com.fakeclass.genericinvokerweb.MainServlet.executeCallAs400(MainServlet.java:104)
at com.fakeclass.genericinvokerweb.MainServlet.doPost(MainServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1071)
at com.ibm.ws.webcontainer.webapp.WebApp.__handleRequest(WebApp.java:3815)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:84)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1702)