Skip to content

Commit

Permalink
Fixed SoapAndInternalProxyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
t-burch authored and rrayst committed Feb 14, 2024
1 parent ea0c2ef commit b02cb73
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.collect.Lists;
import com.predic8.membrane.core.HttpRouter;
import com.predic8.membrane.core.Router;
import com.predic8.membrane.core.config.Path;
import com.predic8.membrane.core.config.security.Certificate;
import com.predic8.membrane.core.config.security.Key;
Expand All @@ -27,6 +28,7 @@
import com.predic8.membrane.core.interceptor.Outcome;
import com.predic8.membrane.core.interceptor.WSDLInterceptor;
import com.predic8.membrane.core.interceptor.server.WSDLPublisherInterceptor;
import com.predic8.membrane.core.interceptor.soap.SampleSoapServiceInterceptor;
import com.predic8.membrane.core.rules.*;
import com.predic8.membrane.core.transport.http.HttpClient;
import org.bouncycastle.asn1.x500.X500Name;
Expand All @@ -45,17 +47,18 @@

import javax.security.auth.x500.X500Principal;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -109,16 +112,17 @@ private void runCheck(boolean checkTrigger) throws Exception {
HttpClient hc = new HttpClient();
Response r1 = hc.call(new Request.Builder().get("http://localhost:3047/b?wsdl").buildExchange()).getResponse();
//r1.write(System.out, true);
assertTrue(r1.getBodyAsStringDecoded().contains("<soap12:address location=\"https://a.b.local/b\">"));
assertTrue(r1.getBodyAsStringDecoded().contains("\"https://a.b.local/b\""));

if (checkTrigger)
assertTrue(trigger.getAndSet(false));

String body = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:wsaw=\"http://www.w3.org/2006/05/addressing/wsdl\" xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" xmlns:tns=\"http://thomas-bayer.com/blz/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ><SOAP-ENV:Body><tns:getBank xmlns:tns=\"http://thomas-bayer.com/blz/\"><tns:blz>38060186</tns:blz></tns:getBank></SOAP-ENV:Body></SOAP-ENV:Envelope> ";

String body = new String(requireNonNull(this.getClass().getResourceAsStream("/get-city.xml")).readAllBytes(), StandardCharsets.UTF_8);

Response r2 = hc.call(new Request.Builder().post("http://localhost:3047/b").body(body).buildExchange()).getResponse();
//r2.write(System.out,true);
assertTrue(r2.getBodyAsStringDecoded().contains("GENODED1BRS"));
assertTrue(r2.getBodyAsStringDecoded().contains("population"));

if (checkTrigger)
assertTrue(trigger.getAndSet(false));
Expand Down Expand Up @@ -166,7 +170,7 @@ private void generateKeyAndCert() throws NoSuchAlgorithmException, OperatorCreat
key = sw.toString();
}

private ServiceProxy createTLSProxy() {
private ServiceProxy createTLSProxy() throws Exception {
ServiceProxy sp = new ServiceProxy();
sp.setPort(3048);
SSLParser ssl = new SSLParser();
Expand All @@ -192,14 +196,20 @@ public Outcome handleRequest(Exchange exc) throws Exception {
wsdlInterceptor.setProtocol("https");
sp.setInterceptors(Lists.newArrayList(triggerInterceptor, wsdlInterceptor));

ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(9500), null, 0);
rule.getInterceptors().add(new SampleSoapServiceInterceptor());
Router router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();

AbstractServiceProxy.Target target = new AbstractServiceProxy.Target();
target.setHost("www.thomas-bayer.com");
target.setPort(80);
target.setHost("localhost");
target.setPort(9500);
sp.setTarget(target);
return sp;
}

private Rule createInternalProxy(boolean useTLS) {
private Rule createInternalProxy(boolean useTLS) throws Exception {
InternalProxy internalProxy = new InternalProxy();
internalProxy.setName("int");
AbstractServiceProxy.Target target = new AbstractServiceProxy.Target();
Expand All @@ -214,8 +224,13 @@ private Rule createInternalProxy(boolean useTLS) {
ssl.setTrust(trust);
target.setSslParser(ssl);
} else {
target.setHost("www.thomas-bayer.com");
target.setPort(80);
ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(9501), null, 0);
rule.getInterceptors().add(new SampleSoapServiceInterceptor());
Router router = new HttpRouter();
router.getRuleManager().addProxyAndOpenPortIfNew(rule);
router.init();
target.setHost("localhost");
target.setPort(9501);
}
internalProxy.setTarget(target);
return internalProxy;
Expand All @@ -224,7 +239,7 @@ private Rule createInternalProxy(boolean useTLS) {
private Rule createSoapProxy() {
SOAPProxy soapProxy = new SOAPProxy();
soapProxy.setPort(3047);
soapProxy.setWsdl("service:int/axis2/services/BLZService?wsdl");
soapProxy.setWsdl("service:int/?wsdl");
Path path = new Path();
path.setValue("/b");
soapProxy.setPath(path);
Expand Down

0 comments on commit b02cb73

Please sign in to comment.