Tomcat starts too long

Actually, by setting the following in /etc/default/tomcat7, I was fine:

JAVA_OPTS=”-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC”

Advertisements

java wsdl import for wsdl with java-reserved word

wsimport -keep -b bind.xml -J-Djavax.xml.accessExternalSchema=all https://policyrw.mtsbu.ua/v3/ChangeContracts.svc?wsdl

 

<?xml version=”1.0″ encoding=”UTF-8″?>
<jaxws:bindings wsdlLocation=”https://policyrw.mtsbu.ua/v3/ChangeContracts.svc?wsdl=wsdl0&#8243;
xmlns:jaxws=”http://java.sun.com/xml/ns/jaxws&#8221;
xmlns:wsdl=”http://schemas.xmlsoap.org/wsdl/”&gt;
<jaxws:bindings node=”wsdl:definitions/wsdl:portType[@name=’IDigitalPolicy’]/wsdl:operation[@name=’New’]”>
<jaxws:method name=”MyNewContract”/>
</jaxws:bindings>
</jaxws:bindings>

digitalocean spaces java example

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.List;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.S3ObjectSummary;

public class Test {

    private static final String SUFFIX = "/";

    public static void main(String[] args) {
        AWSCredentials credentials = new BasicAWSCredentials(
                "xxx",
                "yyy");

        AmazonS3 s3client = new AmazonS3Client(credentials);
        s3client.setEndpoint("https://ams3.digitaloceanspaces.com");
        String bucketName = "ubi-example-bucket";
        s3client.createBucket(bucketName);

        for (Bucket bucket : s3client.listBuckets()) {
            System.out.println(" - " + bucket.getName());
        }

        String folderName = "testfolder";
        createFolder(bucketName, folderName, s3client);

        String fileName = folderName + SUFFIX + "test.docx";
        s3client.putObject(new PutObjectRequest(bucketName, fileName,
                new File("/home/icdu/projects/link/amazonTest/test.docx"))
                .withCannedAcl(CannedAccessControlList.PublicRead));

//        deleteFolder(bucketName, folderName, s3client);
//        s3client.deleteBucket(bucketName);
    }

    public static void createFolder(String bucketName, String folderName, AmazonS3 client) {
        ObjectMetadata metadata = new ObjectMetadata();
        metadata.setContentLength(0);

        InputStream emptyContent = new ByteArrayInputStream(new byte[0]);

        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,
                folderName + SUFFIX, emptyContent, metadata);

        client.putObject(putObjectRequest);
    }


//    public static void deleteFolder(String bucketName, String folderName, AmazonS3 client) {
//        List fileList =
//                client.listObjects(bucketName, folderName).getObjectSummaries();
//        for (S3ObjectSummary file : fileList) {
//            client.deleteObject(bucketName, file.getKey());
//        }
//        client.deleteObject(bucketName, folderName);
//    }
}

Tomcat 7 JDBC Session Persistence

as root run:

export CATALINA_OPTS=”-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

create table in mysql:

createtabletomcat_sessions (
  session_id     varchar(100) notnullprimarykey,
  valid_session  char(1) notnull,
  max_inactive   intnotnull,
  last_access    bigintnotnull,
  app_name       varchar(255),
  session_data   mediumblob,
  KEYkapp_name(app_name)
);
cd /usr/share/java
wget http://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/5.1.44/mysql-connector-java-5.1.44.jar
cd /usr/share/tomcat7/lib and run:
/usr/share/tomcat7/lib# ln -s ../../java/mysql-connector.jar mysql-connector.jar
in META-INF create context.xml
paste Manager section:
<Context antiJARLocking="true" >
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
        virtualClasspath="/home/link/config"
        searchVirtualFirst="true" />

    <Manager className="org.apache.catalina.session.PersistentManager"
             maxIdleBackup="10">
        <Store className="org.apache.catalina.session.JDBCStore"
               connectionURL="jdbc:mysql://localhost/tomcat?user=root&amp;password=password"
               driverName="com.mysql.jdbc.Driver"
               sessionAppCol="app_name"
               sessionDataCol="session_data"
               sessionIdCol="session_id"
               sessionLastAccessedCol="last_access"
               sessionMaxInactiveCol="max_inactive"
               sessionTable="tomcat_sessions"
               sessionValidCol="valid_session" />
    </Manager>
</Context>

Run two projects on one tomcat in intellij idea

I have two web application in one project configured using pom. i want to run both the application simultaneously using same instance of Tomcat

Solution is:

Go to Run -> Edit configuration
* add a new configuration for your project (give it a jazzy name)
* Select your Application server( in your case tomcat {version} )
* on the server tab -> before launch section -> add build command for both your artifacts
* go to deployment tab -> add both your application war for deployment
* make sure you provide distinct application context (option on the right)
* Select you new configuration for your project
* click on that green play button .

Tomcat remote debuging

В начало startup.sh нужно добавить:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

в конец (добавлено jpda):
exec “$PRGDIR”/”$EXECUTABLE” jpda start “$@”

В среде разработки нужно указать хост и порт(в данном случае 8000)

sha1 java

package main;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

public class HashTextTest {

/**

* @param args

* @throws NoSuchAlgorithmException

*/

public static void main(String[] args) throws NoSuchAlgorithmException {

System.out.println(sha1(“test string to sha1”));

}

static String sha1(String input) throws NoSuchAlgorithmException {

MessageDigest mDigest = MessageDigest.getInstance(“SHA1”);

byte[] result = mDigest.digest(input.getBytes());

StringBuffer sb = new StringBuffer();

for (int i = 0; i < result.length; i++) {

sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));

}

return sb.toString();

}

}