miércoles, 21 de julio de 2010

Classloading issues when working with Procrun and Prunsrv (Apache Commons Daemon)

I was trying to configure a standalone Java program to run as a Windows service (an standalone Web service client using Axis2) using Apache Commons Daemon.

I used a great post by Christopher Pierce as guide: http://blog.platinumsolutions.com/node/234

The program ran OK when I launched it from the command line console, but when I tried to run it as a Windows service with exactly the same configuration (jvm, classpath, etc.), the program failed with errors like these:

for Java 6:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at javax.xml.ws.spi.FactoryFinder.safeLoadClass(FactoryFinder.java:148)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:30)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:128)
at javax.xml.ws.spi.Provider.provider(Provider.java:83)
at javax.xml.ws.Service.init(Service.java:56)
at javax.xml.ws.Service.create(Service.java:691)
at ...
Caused by: javax.xml.ws.WebServiceException: Error creating JAXBContext for W3CEndpointReference.
at com.sun.xml.internal.ws.spi.ProviderImpl$2.run(ProviderImpl.java:211)
at com.sun.xml.internal.ws.spi.ProviderImpl$2.run(ProviderImpl.java:206)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.spi.ProviderImpl.getEPRJaxbContext(ProviderImpl.java:206)
at com.sun.xml.internal.ws.spi.ProviderImpl.clinit(ProviderImpl.java:77)
... 13 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:187)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.sun.xml.internal.ws.spi.ProviderImpl$2.run(ProviderImpl.java:209)
... 17 more
Caused by: java.lang.ClassNotFoundException: com/sun/xml/bind/v2/ContextFactory
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:479)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:185)
... 21 more
java.lang.NoClassDefFoundError: Could not initialize class com.sun.xml.internal.ws.spi.ProviderImpl
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at javax.xml.ws.spi.FactoryFinder.safeLoadClass(FactoryFinder.java:148)
at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:30)
at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:128)
at javax.xml.ws.spi.Provider.provider(Provider.java:83)
at javax.xml.ws.Service.init(Service.java:56)
at javax.xml.ws.Service.create(Service.java:691)
at ...

for Java 5:
java.lang.NullPointerException
at org.apache.axis2.jaxws.catalog.impl.OASISCatalogManager.determineFileName(OASISCatalogManager.java:124)
at org.apache.axis2.jaxws.catalog.impl.OASISCatalogManager.init(OASISCatalogManager.java:80)
at org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.init(ServiceDescriptionImpl.java:165)
at org.apache.axis2.jaxws.description.impl.ServiceDescriptionImpl.init(ServiceDescriptionImpl.java:141)
at org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl.createServiceDescription(DescriptionFactoryImpl.java:129)
at org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl.createServiceDescription(DescriptionFactoryImpl.java:76)
at org.apache.axis2.jaxws.description.DescriptionFactory.createServiceDescription(DescriptionFactory.java:75)
at org.apache.axis2.jaxws.spi.ServiceDelegate.init(ServiceDelegate.java:208)
at org.apache.axis2.jaxws.spi.Provider.createServiceDelegate(Provider.java:59)
at javax.xml.ws.Service.init(Service.java:36)
at javax.xml.ws.Service.create(Service.java:120)
at ...

After some hours of searching, I found this bug:
Thread.currentThread().getContextClassLoader() == null when the program is runned by Prunsrv

I checked my program and this was the cause of my problem:

Running from Command line:
21/07/2010 12:44:05,281 - this.getClass().getClassLoader(): sun.misc.Launcher$AppClassLoader@e39a3e
21/07/2010 12:44:05,281 - Thread.currentThread().getContextClassLoader(): sun.misc.Launcher$AppClassLoader@e39a3e
Running as service with Procrun:
21/07/2010 12:44:29,359 - this.getClass().getClassLoader(): sun.misc.Launcher$AppClassLoader@11b86e7
21/07/2010 12:44:29,359 - Thread.currentThread().getContextClassLoader(): null

I applied the workaround described there, and my service is now working OK.
ClassLoader defaultClassLoader = APISalidaServicioWindows.class.getClassLoader();
Thread.currentThread().setContextClassLoader(defaultClassLoader)

The configuration of the current configured Procrun Windows services can be edited/visualized in this Windows registry location:
HKEY_LOCAL_MACHINE/SOFTWARE/Apache Software Foundation/Procrun 2.0/(service name)/Parameters

jueves, 8 de julio de 2010

Unicode Java codes for spanish characters

0x00E1 225 LATIN SMALL LETTER A WITH ACUTE á
0x00E9 233 LATIN SMALL LETTER E WITH ACUTE é
0x00ED 237 LATIN SMALL LETTER I WITH ACUTE í
0x00F3 243 LATIN SMALL LETTER O WITH ACUTE ó
0x00FA 250 LATIN SMALL LETTER U WITH ACUTE ú
0x00F1 241 LATIN SMALL LETTER N WITH TILDE ñ
0x00C1 193 LATIN CAPITAL LETTER A WITH ACUTE Á
0x00C9 201 LATIN CAPITAL LETTER E WITH ACUTE É
0x00CD 205 LATIN CAPITAL LETTER I WITH ACUTE Í
0x00D3 211 LATIN CAPITAL LETTER O WITH ACUTE Ó
0x00DA 218 LATIN CAPITAL LETTER U WITH ACUTE Ú
0x00D1 209 LATIN CAPITAL LETTER N WITH TILDE Ñ

Java:

á - \u00E1

é - \u00E9
í - \u00ED
ó - \u00F3
ú - \u00FA
Á - \u00C1
É - \u00C9
Í - \u00CD
Ó - \u00D3
Ú - \u00DA
ñ - \u00F1
Ñ - \u00D1

miércoles, 18 de marzo de 2009

Enable unsecured JMX monitoring in IBM JDK 5

The same for Sun JDK...

-Dcom.sun.management.jmxremote.port=
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

jueves, 18 de diciembre de 2008

How I managed to run a standalone Oracle SOA Suite Worklist basic client

Escenary:
  • Standalone command line remote client.
  • No IDE.
  • Basic client funcion: print all tasks for a hard-coded user.
  • Based on "Invoking BPEL Worklist API from Remote Server with Java [Amis blog]" and buddy's help.
  • I ran it on Java 1.4. It's not working on Java 5 for me. Java says: "java.lang.SecurityException: class "com.collaxa.cube.ExceptionIndex"'s signer information does not match signer information of other classes in the same package". But works also on Java 6. Ups.

"Project" layout:



"lib" directory:


"config" directory:


"schema" directory:


"src" directory:


"compile" file content:
set LIBDIR="lib"
set CLASSESDIR="classes"
set CP="%LIBDIR%\bpm-infra.jar;%LIBDIR%\orabpel-common.jar;%LIBDIR%\orabpel-thirdparty.jar;%LIBDIR%\orabpel.jar;%LIBDIR%\orasaaj.jar;%LIBDIR%\config;%LIBDIR%\bpm-services.jar;%LIBDIR%\schema;%LIBDIR%\wsclient_extended.jar;%CLASSESDIR%"
set JAVA_HOME="C:\java\j2sdk1.4.2_16"

%JAVA_HOME%\bin\javac.exe -classpath %CP% -d %CLASSESDIR% %1%

"run" file content:
set LIBDIR="lib"
set CLASSESDIR="classes"
set CP="%LIBDIR%\bpm-infra.jar;%LIBDIR%\orabpel-common.jar;%LIBDIR%\orabpel-thirdparty.jar;%LIBDIR%\orabpel.jar;%LIBDIR%\orasaaj.jar;%LIBDIR%\config;%LIBDIR%\bpm-services.jar;%LIBDIR%\schema;%LIBDIR%\wsclient_extended.jar;%CLASSESDIR%"
set JAVA_HOME="C:\java\j2sdk1.4.2_16"

%JAVA_HOME%\bin\java.exe -cp %CP% test.WorklistTest


"WorklistTest.java" file content:
package test;

import java.util.ArrayList;
import java.util.List;

import oracle.bpel.services.workflow.IWorkflowConstants;
import oracle.bpel.services.workflow.client.IWorkflowServiceClient;
import oracle.bpel.services.workflow.client.WorkflowServiceClientFactory;
import oracle.bpel.services.workflow.query.ITaskQueryService;
import oracle.bpel.services.workflow.repos.Predicate;
import oracle.bpel.services.workflow.repos.TableConstants;
import oracle.bpel.services.workflow.task.model.Task;
import oracle.bpel.services.workflow.verification.IWorkflowContext;

public class WorklistTest {

private static final String USER = "user";
private static final String PASSWORD = "password";
private static final String REALM = "jazn.com";

public static void main(String[] args)
{
try
{

IWorkflowServiceClient client;
IWorkflowContext workflowContext;
ITaskQueryService taskQueryService;

client = WorkflowServiceClientFactory.getWorkflowServiceClient(
WorkflowServiceClientFactory.SOAP_CLIENT);
taskQueryService = client.getTaskQueryService();
workflowContext = taskQueryService.authenticate(
USER, PASSWORD, REALM, null);

Predicate whereclause = new Predicate(
TableConstants.WFTASK_STATE_COLUMN, Predicate.OP_EQ,
IWorkflowConstants.TASK_STATE_ASSIGNED);

List displayColumns = new ArrayList();
displayColumns.add("CREATEDDATE");
displayColumns.add("TITLE");
displayColumns.add("IDENTIFICATIONKEY");
List optionalInfo = new ArrayList();

List tasks = taskQueryService.queryTasks(
workflowContext, displayColumns, optionalInfo,
"My+Group", null, whereclause, null, 0, 0);

if (tasks != null) {
String[] taskList = new String[tasks.size()];
for (int i = 0; i < tasks.size(); i++) {
Task t = (Task)tasks.get(i);
taskList[i] = t.getSystemAttributes().getTaskId();
System.out.println("Task " + i + ": " + taskList[i]);
}
} else {
System.out.println("Did not find any tasks");
}

}
catch (Throwable e) {
e.printStackTrace();
}
}

}

"wf_client_config.xml" file content:
<servicesClientConfigurations xmlns="http://xmlns.oracle.com/bpel/services/client">

<ejb>
<!-- <serverURL>opmn:ormi://[server]:[opmn_port]:[oc4j_soa_instance]/hw_services</serverURL> --> <!-- for stand alone -->
<serverURL>opmn:ormi://[server]/hw_services</serverURL> <!-- for opmn managed instance -->
<user>oc4jadmin</user>
<password>password</password>
<initialContextFactory>oracle.j2ee.rmi.RMIInitialContextFactory</initialContextFactory>
</ejb>

<identityService>
<soapEndPoint>http://[server]:7777/integration/services/IdentityService/identity</soapEndPoint>
</identityService>

<identityConfigService>
<soapEndPoint>http://[server]:7777/integration/services/IdentityService/configuration</soapEndPoint>
</identityConfigService>

<taskService>
<soapEndPoint>http://[server]:7777/integration/services/TaskService/TaskServicePort</soapEndPoint>
</taskService>

<taskMetadataService>
<soapEndPoint>http://[server]:7777/integration/services/TaskMetadataService/TaskMetadataServicePort</soapEndPoint>
</taskMetadataService>

<taskQueryService>
<soapEndPoint>http://[server]:7777/integration/services/TaskQueryService/TaskQueryService</soapEndPoint>
</taskQueryService>

<userMetadataService>
<soapEndPoint>http://[server]:7777/integration/services/UserMetadataService/UserMetadataService</soapEndPoint>
</userMetadataService>

<runtimeConfigService>
<soapEndPoint>http://[server]:7777/integration/services/RuntimeConfigService/RuntimeConfigService</soapEndPoint>
</runtimeConfigService>

<!-- specifies the mapping for portal realm to is_config realm -->
<portal>
<realmMapping>jazn.com</realmMapping>
</portal>

</servicesClientConfigurations>

"wf_config.xml" file content:
<workflowConfigurations
xmlns="http://xmlns.oracle.com/pcbpel/humanworkflow/configurations"
xmlns:user="http://xmlns.oracle.com/bpel/workflow/userMetadata">

<taskAutoReleaseConfigurations>
<taskAutoRelease priority="1" default="P1D" percentageOfExpiration="30"/>
<taskAutoRelease priority="2" default="P2D" percentageOfExpiration="40"/>
<taskAutoRelease priority="3" default="P3D" percentageOfExpiration="50"/>
<taskAutoRelease priority="4" default="P4D" percentageOfExpiration="60"/>
<taskAutoRelease priority="5" default="P5D" percentageOfExpiration="70"/>
</taskAutoReleaseConfigurations>

<worklistApplicationURL>http://[server]:7777/integration/worklistapp/TaskDetails?taskId=PC_HW_TASK_ID_TAG</worklistApplicationURL>

<actionableEmailAccountName/>

<pushbackAssignee>INITIAL_ASSIGNEES</pushbackAssignee>

<assigneeDelimiter><![CDATA[,]]></assigneeDelimiter>

<shortHistoryActions>
<action>ACQUIRE</action>
<action>INFO_REQUEST</action>
<action>INFO_SUBMIT</action>
<action>RELEASE</action>
</shortHistoryActions>

<workflowServiceSessionTimeoutInMinutes>60</workflowServiceSessionTimeoutInMinutes>

<user:ruleRepositoryInfo>
<user:ruleEngine>ORACLE</user:ruleEngine>
<user:repositoryLocation>WFRepository</user:repositoryLocation>
<user:dictionaryName>WFDictionary</user:dictionaryName>
<user:reposProperty name="reposType">jar</user:reposProperty>
</user:ruleRepositoryInfo>

<property name="worklist.redirectpage" value="TaskDetails" />
<property name="worklist.loginpage" value="Login.jsp" />
<property name="worklist.errorpage" value="Error.jsp" />

</workflowConfigurations>

lunes, 27 de agosto de 2007

Macros Vim

Para grabar la macro:
  • q[letra (= nombre macro)] - Inicia el proceso de grabación
  • ('recording' aparece en la parte inferior de la pantalla)
  • Realizar los pasos que conforman la macro
  • q - Finaliza el proceso de grabación
Para ejecutar la macro:
  • @[letra nombre macro]

sábado, 4 de agosto de 2007

Archivos Hosts

  • Unix: /etc/hosts
  • Win 95/98/Me: c:\Windows\Hosts
  • Windows NT/2000: c:\WINNT\System32\drivers\etc
  • Windows XP: c:\WINDOWS\system32\drivers\etc