"jason.greene(a)jboss.com" wrote :
| You mention that the invocation fails. Does the service class actually load
successfully? Are you caching object references?
|
Ok, let me explain a little:
Our app (called Wise, take a look to
javalinuxlabs.org if you like to understand better
ideas behind) generate client on the fly. I mean that it generate client code when you
select a wsdls. Then the client code is generated and a generic web based interface too.
After an hot deployment you have to restart the navigation flow and other client class wll
be generated. No cache and no generated class reusing.
anonymous wrote :
| Is this code running in container? Are you hot deploying the client code? If so, the
output folder will cease to exist after a hot deploy. The reason is that when you deploy
your app its extracted in a tmp directory. Any relative file writes go there. When you
redeploy a new directory is created, and thus the classes would be gone. If this is the
case then you either need to regenerate them per redeploy, or store them in some absolute
path name.
|
Yes I know. I think all things are done considering all jboss deployment standards. Just
for clarify: we don't have problem loading our generated class, but (after
redeployment) we experiences problem in loading classes of jbossws or javax.* contained in
jars deployed inside the ear apps.
Here is my complete utility class (sorry, this is becoming a long post):
| /*
| * Created on 11/02/2007
| *
| * To change the template for this generated file go to
| * Window - Preferences - Java - Code Generation - Code and Comments
| */
| package it.javalinux.wise.jaxCore;
|
| import [...]
| public class WSDynamicClient {
|
| private Class serviceClass;
| private Class endPointClass;
|
|
| private Object service;
| private Object endPoint;
| URLClassLoader classLoader;
|
| private Map<String, Method> endPoints;
|
| private Map<String, Method> webMethods;
|
| private String tmpDeployDir;
|
| public void init(String wsdlURL, String cid,String userName, String password) {
| try {
| WSContractConsumer wsImporter = WSContractConsumer.newInstance();
| wsImporter.setGenerateSource(true);
| //wsImporter.setMessageStream(System.out);
| setCurrentTmpDeployDir();
| System.out.println(tmpDeployDir);
| List<String> cp = defineAdditionalCompilerClassPath();
| wsImporter.setAdditionalCompilerClassPath(cp);
|
|
| File outputDir = new File(tmpDeployDir + "/WSDLS/" + cid);
| if (!outputDir.exists()) {
| outputDir.mkdir();
| }
| wsImporter.setOutputDirectory(outputDir);
| wsImporter.setSourceDirectory(outputDir);
| String targetPkg = "it.javalinux.ws";
| wsImporter.setTargetPackage(targetPkg);
| wsImporter.consume(getUsableWSDL(wsdlURL,userName,password));
|
| String className = getServiceClassName(outputDir);
| Properties prop = new Properties();
| // BEGIN
| SecurityAssociation.setPrincipal(new SimplePrincipal("admin"));
| SecurityAssociation.setCredential("admin".toCharArray());
| // END
| prop.put( "java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory" );
| prop.put( "java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces" );
| prop.put( "java.naming.provider.url",
"jnp://localhost:1099");
| InitialContext ctx = new InitialContext(prop);
| RMIAdaptor rmiserver = (RMIAdaptor)
ctx.lookup("jmx/invoker/RMIAdaptor");
| ObjectName onameBean = new ObjectName("seam.jboss.org:loader=Wise");
| rmiserver.invoke(onameBean, "newClassLoader" , new
Object[]{outputDir.toURL(),true}, new
String[]{"java.net.URL","boolean"});
| //classLoader = new URLClassLoader(new URL[]{outputDir.toURL()},
Thread.currentThread().getContextClassLoader());
| //URLClassLoader classLoader = new URLClassLoader(new URL[]{outputDir.toURL()},
Thread.currentThread().getContextClassLoader());
| //Thread.currentThread().setContextClassLoader(classLoader);
|
| serviceClass = JavaUtils.loadJavaType("it.javalinux.ws." + className ,
classLoader);
| service = serviceClass.newInstance();
| } catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| private String getUsableWSDL(String wsdlURL, String userName, String password) {
| if (StringUtils.trimToNull(userName) == null || StringUtils.trimToNull(password) ==
null) {
| return wsdlURL;
| }
| return null;
| }
|
| private String getServiceClassName(File outputDir) {
| String className =null;
| FilenameFilter filter = new FilenameFilter() {
| public boolean accept(File dir, String name) {
| return name.endsWith("Service.class");
| }
| };
| File scanDir = new File(outputDir.getAbsolutePath() +
"/it/javalinux/ws/");
| System.out.println(scanDir);
|
| String[] children = scanDir.list(filter);
|
| if (children != null) {
| className = children[0].substring(0, children[0].length() - 6);
|
| }
| return className;
| }
|
| private List<String> defineAdditionalCompilerClassPath() {
| List<String> cp = new LinkedList<String>();
| cp.add(tmpDeployDir + "jboss-jaxws.jar");
| cp.add(tmpDeployDir + "jaxb-api.jar");
| cp.add(tmpDeployDir + "jaxb-impl.jar");
| cp.add(tmpDeployDir + "jaxb-xjc.jar");
| return cp;
| }
|
| private void setCurrentTmpDeployDir() {
| tmpDeployDir =
Thread.currentThread().getContextClassLoader().getResource("jboss-jaxws.jar").getPath().substring(5);
| tmpDeployDir = tmpDeployDir.substring(0, tmpDeployDir.lastIndexOf("!")) +
"-contents/" ;
|
| }
|
| public List<String> getEndPointList() {
| endPoints = new HashMap<String, Method>();
| for (Method method : serviceClass.getMethods()) {
| WebEndpoint annotation = method.getAnnotation(WebEndpoint.class);
| if (annotation != null) {
| endPoints.put(annotation.name(),method);
| }
| }
| return new ArrayList<String>(endPoints.keySet());
| }
|
| public void selectEndPoint(String name) throws Exception {
|
| Method method = endPoints.get(name);
| endPoint = serviceClass.getMethod(method.getName(),
method.getParameterTypes()).invoke(service, (Object[]) null);
| endPointClass = serviceClass.getMethod(method.getName(),
method.getParameterTypes()).getReturnType();
| }
|
| public List<String> getWebMethod() {
| webMethods = new HashMap<String, Method>();
|
| for (Method method : endPointClass.getMethods()) {
| WebMethod annotation = method.getAnnotation(WebMethod.class);
| if (annotation != null) {
| webMethods.put(annotation.action(),method);
| }
| }
|
| return new ArrayList<String>(webMethods.keySet());
| }
|
| public Object invokeOperation(String methodName, Object[] args) throws Exception {
| Method methodToInvoke = webMethods.get(methodName);
| return
endPoint.getClass().getMethod(methodToInvoke.getName(),methodToInvoke.getParameterTypes()).invoke(endPoint,
args);
| }
|
| public List<WebParameter> getWebParams(String methodName) {
| LinkedList<WebParameter> parameters = new LinkedList<WebParameter>();
| Method method = webMethods.get(methodName);
| Annotation[][] annotations = method.getParameterAnnotations();
| Class[] methodparameterTypes = method.getParameterTypes();
| for (int i = 0; i < annotations.length; i++) {
| for (int j = 0; j < annotations.length; j++) {
| if (annotations[j] instanceof WebParam ) {
| parameters.add(new WebParameter(methodparameterTypes,((WebParam)
annotations[j]).name()));
| break;
| }
| }
| }
| return parameters;
|
| }
|
| }
|
|
Be careful when replacing the context loader when running in a container. If you do this
you should restore the original thread context loader.
-Jason
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4021381#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...