Skip to content

Commit

Permalink
Resolves #16 - fixes object to proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Flossy committed Sep 18, 2024
1 parent 7319c3f commit 5200639
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private CredentialsUtil() {
public static Credentials fromValues(final String url, final String username, final String password, final String token, final String version) {
return new CredentialsRecord(url, username, password, token, version);
}

public static Credentials fromProperties(final Properties properties) {
Objects.requireNonNull(properties, "Null properties not allowed!");

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/solenopsis/session/soap/PortEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ SoapUrlEnum getUrl() {
<P> P createPortForTargetNamespace(final String targetNamespace, final Class<? extends Service> serviceClass, final SessionContext session) throws SoapException {
try {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MethodUtil.findMethodsForAnnotationClass(serviceClass, WebEndpoint.class).get(0).getReturnType());

final P retVal = (P) factory.create();
final P retVal = (P) factory.create(MethodUtil.findMethodsForAnnotationClass(serviceClass, WebEndpoint.class).get(0).getReturnType());

final String url = getUrl().computeUrl(serviceClass, session);

final SOAPElement sessionId = SoapUtil.getSoapFactory().createElement(new QName(targetNamespace, SessionHeaderEnum.SESSION_ID.getString()));
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/org/solenopsis/session/soap/PortProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.logging.Level;
import org.flossware.commons.AbstractBase;
import org.flossware.commons.util.SoapException;
import org.solenopsis.session.Credentials;
import org.solenopsis.session.SessionContext;
import org.solenopsis.session.soap.login.LoginServiceEnum;
Expand Down Expand Up @@ -51,7 +51,7 @@ void handleException(final Method method, final Object[] args, final InvocationT
public PortProxy(final PortEnum portEnum, final Class<? extends Service> serviceClass, final Object toProxy, final SessionContext session, final LoginServiceEnum loginService) {
this.portEnum = Objects.requireNonNull(portEnum, "Must provide an instance of port enum!");
this.serviceClass = Objects.requireNonNull(serviceClass, "Must provide a service class!");
this.proxy = Objects.requireNonNull(toProxy, "Must provide an instance to proxy!");
this.proxy = Objects.requireNonNull(toProxy, "Must provide an instance to a proxy!");
this.session = Objects.requireNonNull(session, "Must provide a session!");
this.loginService = Objects.requireNonNull(loginService, "Must provide a login service!");
}
Expand All @@ -72,9 +72,8 @@ public PortProxy(final PortEnum portEnum, final Class<? extends Service> service

@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
boolean isDone = false;

while(!isDone) {
// Run forever...
while(true) {
try {
return method.invoke(getProxy(), args);
} catch(final InvocationTargetException exception) {
Expand All @@ -83,12 +82,11 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
} else if (SoapExceptionUtil.isRetry(exception)) {
continue;
}
else if (SoapExceptionUtil.isInvalidQueryLocator(exception)) {
throw exception;
}

log(Level.SEVERE, exception, "Problem Invoking " + getProxy().getClass().getName() + " -> " + method.getName());

throw exception;
}
}

throw new SoapException("Could not call [" + proxy.getClass().getName() + "." + method.getName() + "]");
}
}
20 changes: 11 additions & 9 deletions src/main/java/org/solenopsis/session/soap/ProxyPortEnum.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.solenopsis.session.soap;

import jakarta.xml.ws.Service;
import jakarta.xml.ws.WebEndpoint;
import java.lang.reflect.Proxy;
import org.flossware.commons.util.MethodUtil;
import org.solenopsis.session.Credentials;
import org.solenopsis.session.SessionContext;
import org.solenopsis.session.soap.login.LoginServiceEnum;
Expand All @@ -24,20 +26,20 @@ private ProxyPortEnum(final PortEnum portEnum) {
this.portEnum = portEnum;
}

<P> P createProxyPort(final Class<? extends Service> serviceClass, final P port, final SessionContext session, final LoginServiceEnum loginService) {
return (P) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {port.getClass()}, new PortProxy(getPortEnum(), serviceClass, port, session, loginService));
<P> P createProxyPort(final Class<? extends Service> serviceClass, final Class portClass, final Object toProxy, final SessionContext session, final LoginServiceEnum loginService) {
return (P) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {portClass}, new PortProxy(getPortEnum(), serviceClass, toProxy, session, loginService));
}

<P> P createProxyPort(final Class<? extends Service> serviceClass, final P port, final Credentials credentials, final LoginServiceEnum loginService) {
return (P) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {port.getClass()}, new PortProxy(getPortEnum(), serviceClass, port, credentials, loginService));
<P> P createProxyPort(final Class<? extends Service> serviceClass, final Class portClass, final Object toProxy, final Credentials credentials, final LoginServiceEnum loginService) {
return (P) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {portClass}, new PortProxy(getPortEnum(), serviceClass, toProxy, credentials, loginService));
}

<P> P createProxyPort(final Class<? extends Service> serviceClass, final SessionContext session, final LoginServiceEnum loginService) {
return createProxyPort(serviceClass, getPortEnum().createPortForService(serviceClass, session), session, loginService);
return createProxyPort(serviceClass, MethodUtil.findMethodsForAnnotationClass(serviceClass, WebEndpoint.class).get(0).getReturnType(), getPortEnum().createPortForService(serviceClass, session), session, loginService);
}

<P> P createProxyPort(final Class<? extends Service> serviceClass, final Credentials credentials, final LoginServiceEnum loginService) {
return createProxyPort(serviceClass, getPortEnum().createPortForService(serviceClass, credentials), credentials, loginService);
return createProxyPort(serviceClass, MethodUtil.findMethodsForAnnotationClass(serviceClass, WebEndpoint.class).get(0).getReturnType(), getPortEnum().createPortForService(serviceClass, credentials), credentials, loginService);
}

public PortEnum getPortEnum() {
Expand All @@ -49,14 +51,14 @@ public <P> P createProxyPortForService(final Class<? extends Service> serviceCla
}

public <P> P createProxyPortForService(final Class<? extends Service> serviceClass, final SessionContext session) {
return createProxyPortForService(serviceClass, session, LoginServiceEnum.DEFAULT_LOGIN_SERVICE);
return createProxyPortForService(serviceClass, session, LoginServiceEnum.DEFAULT_LOGIN_SERVICE);
}

public <P> P createProxyPortForService(final Class<? extends Service> serviceClass, final Credentials credentials, final LoginServiceEnum loginService) {
return createProxyPort(serviceClass, credentials, loginService);
return createProxyPort(serviceClass, credentials, loginService);
}

public <P> P createProxyPortForService(final Class<? extends Service> serviceClass, final Credentials credentials) {
return createProxyPortForService(serviceClass, credentials, LoginServiceEnum.DEFAULT_LOGIN_SERVICE);
return createProxyPortForService(serviceClass, credentials, LoginServiceEnum.DEFAULT_LOGIN_SERVICE);
}
}
8 changes: 4 additions & 4 deletions src/main/java/org/solenopsis/session/soap/login/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.solenopsis.session.SessionContext;
import org.solenopsis.session.credentials.CredentialsUtil;
import org.solenopsis.session.soap.PortEnum;
import org.solenopsis.session.soap.ProxyPortEnum;
import org.solenopsis.soap.enterprise.SforceService;
import org.solenopsis.soap.enterprise.Soap;
import org.solenopsis.soap.tooling.SforceServicePortType;
import org.solenopsis.soap.tooling.SforceServiceService;


/**
Expand Down Expand Up @@ -39,7 +38,8 @@ public static void main(final String[] args) throws Exception {
final SessionContext session = LoginServiceEnum.TOOLING.getLoginService().login(CredentialsUtil.fromFile("/home/sfloess/.solenopsis/credentials/qa.properties"));


SforceServicePortType port = PortEnum.TOOLING.TOOLING.createPortForService(SforceServiceService.class, session);
// SforceServicePortType port = PortEnum.TOOLING.TOOLING.createPortForService(SforceServiceService.class, session);
Soap port = ProxyPortEnum.ENTERPRISE.createProxyPortForService(SforceService.class, session);

// .createPortForService(SforceService.class, session);
port.query("select foo from bar");
Expand Down

0 comments on commit 5200639

Please sign in to comment.