Merged in brasseld/openesb-components (pull request #8)
Access to imported WSDL from concrete WSDL through Load Balancermaster
commit
6306792bd3
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
package com.sun.jbi.httpsoapbc;
|
package com.sun.jbi.httpsoapbc;
|
||||||
|
|
||||||
|
import com.ibm.wsdl.Constants;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -57,21 +58,16 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
private String lbHost;
|
private String lbHost;
|
||||||
private String lbPort;
|
private String lbPort;
|
||||||
private Definition definition;
|
// private Definition definition;
|
||||||
private boolean isWsdl;
|
private boolean isWsdl;
|
||||||
private String localhostFQDN;
|
private String localhostFQDN;
|
||||||
|
|
||||||
private Document doc;
|
private Document doc;
|
||||||
|
|
||||||
private ByteBuffer byteBuffer;
|
private ByteBuffer byteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is the port on which http-bc is running
|
* this is the port on which http-bc is running
|
||||||
*/
|
*/
|
||||||
String httpbcPort;
|
String httpbcPort;
|
||||||
|
|
||||||
private CoyoteRequest request;
|
private CoyoteRequest request;
|
||||||
|
|
||||||
private static Messages mMessages = Messages.getMessages(WsdlQueryHelper.class);
|
private static Messages mMessages = Messages.getMessages(WsdlQueryHelper.class);
|
||||||
private static Logger mLog = Messages.getLogger(WsdlQueryHelper.class);
|
private static Logger mLog = Messages.getLogger(WsdlQueryHelper.class);
|
||||||
|
|
||||||
|
@ -95,6 +91,7 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||||
|
|
||||||
|
/*
|
||||||
if (isWsdl) {
|
if (isWsdl) {
|
||||||
WSDLFactoryImpl wsdlFactory = new WSDLFactoryImpl();
|
WSDLFactoryImpl wsdlFactory = new WSDLFactoryImpl();
|
||||||
WSDLReader reader = (WSDLReader) wsdlFactory.newWSDLReader();
|
WSDLReader reader = (WSDLReader) wsdlFactory.newWSDLReader();
|
||||||
|
@ -104,6 +101,7 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
this.definition = reader.readWSDL("", source);
|
this.definition = reader.readWSDL("", source);
|
||||||
} else {
|
} else {
|
||||||
|
* */
|
||||||
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
builderF.setNamespaceAware(true);
|
builderF.setNamespaceAware(true);
|
||||||
|
@ -111,7 +109,7 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
doc = builder.parse(new ByteArrayInputStream(def.array()));
|
doc = builder.parse(new ByteArrayInputStream(def.array()));
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (mLog.isLoggable(Level.FINE)) {
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
|
@ -121,14 +119,13 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WsdlQueryHelper(CoyoteRequest request, int rPort, ByteArrayOutputStream baos, boolean wsdl) {
|
||||||
public WsdlQueryHelper(CoyoteRequest request, int rPort, Definition def, boolean wsdl) {
|
|
||||||
|
|
||||||
this.isWsdl = wsdl;
|
this.isWsdl = wsdl;
|
||||||
|
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
|
||||||
this.definition = def;
|
// this.definition = def;
|
||||||
|
|
||||||
lbHost = request.getServerName();
|
lbHost = request.getServerName();
|
||||||
lbPort = Integer.toString(request.getServerPort());
|
lbPort = Integer.toString(request.getServerPort());
|
||||||
|
@ -137,7 +134,14 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
localhostFQDN = InetAddress.getLocalHost().getCanonicalHostName().toString();
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
|
DocumentBuilderFactory builderF = DocumentBuilderFactory.newInstance();
|
||||||
|
|
||||||
|
builderF.setNamespaceAware(true);
|
||||||
|
DocumentBuilder builder = builderF.newDocumentBuilder();
|
||||||
|
|
||||||
|
doc = builder.parse(new ByteArrayInputStream(baos.toByteArray()));
|
||||||
|
} catch (Exception e) {
|
||||||
if (mLog.isLoggable(Level.FINE)) {
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
mLog.log(Level.FINE, "the proxy host may be unknown.", e);
|
mLog.log(Level.FINE, "the proxy host may be unknown.", e);
|
||||||
}
|
}
|
||||||
|
@ -145,6 +149,7 @@ public class WsdlQueryHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public Definition getServiceDescriptor() {
|
public Definition getServiceDescriptor() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -158,7 +163,7 @@ public class WsdlQueryHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return definition;
|
return definition;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public ByteBuffer getServiceDescriptorAsByteBuffer() {
|
public ByteBuffer getServiceDescriptorAsByteBuffer() {
|
||||||
|
|
||||||
|
@ -166,11 +171,56 @@ public class WsdlQueryHelper {
|
||||||
* check if the request is a direct request, return the byte-buffer if
|
* check if the request is a direct request, return the byte-buffer if
|
||||||
* true
|
* true
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (isDirectRequest()) {
|
if (isDirectRequest()) {
|
||||||
return byteBuffer;
|
return byteBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isWsdl) {
|
||||||
|
try {
|
||||||
|
updateImportDom(doc.getDocumentElement());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.out.println("Exception : " + ex);
|
||||||
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
|
mLog.log(Level.FINE, "unable to modify the wsdl.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {// this is xsd
|
||||||
|
try {
|
||||||
|
updateSchemaDom(doc.getDocumentElement());
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
|
mLog.log(Level.FINE, "unable to modify the xsd.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
String encoding = doc.getXmlEncoding();
|
||||||
|
|
||||||
|
Transformer trans = TransformerFactory.newInstance().newTransformer();
|
||||||
|
//trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||||
|
if (encoding == null) {
|
||||||
|
trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
|
||||||
|
} else {
|
||||||
|
trans.setOutputProperty(OutputKeys.ENCODING, encoding);
|
||||||
|
}
|
||||||
|
//changes ends here
|
||||||
|
trans.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||||
|
trans.setOutputProperty(OutputKeys.METHOD, "xml");
|
||||||
|
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, false ? "yes" : "no");
|
||||||
|
trans.transform(new DOMSource(doc), new StreamResult(baos));
|
||||||
|
|
||||||
|
return ByteBuffer.wrap(baos.toByteArray());
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
|
mLog.log(Level.FINE, "not able to transform.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (isWsdl) {
|
if (isWsdl) {
|
||||||
try {
|
try {
|
||||||
WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
|
WSDLFactory wsdlFactory = (WSDLFactory) WSDLFactory.newInstance();
|
||||||
|
@ -212,6 +262,7 @@ public class WsdlQueryHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +297,7 @@ public class WsdlQueryHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void modifyWSDL(Definition def) throws Exception {
|
private void modifyWSDL(Definition def) throws Exception {
|
||||||
|
|
||||||
// Search all wsdl imports for the resourceName
|
// Search all wsdl imports for the resourceName
|
||||||
Iterator importLists = def.getImports().values().iterator();
|
Iterator importLists = def.getImports().values().iterator();
|
||||||
|
@ -431,6 +482,18 @@ public class WsdlQueryHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateImportDom(Element el) throws Exception {
|
||||||
|
Element tempEl = DOMUtils.getFirstChildElement(el);
|
||||||
|
|
||||||
|
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||||
|
QName tempElType = QNameUtils.newQName(tempEl);
|
||||||
|
|
||||||
|
if (Constants.Q_ELEM_IMPORT.equals(tempElType)) {
|
||||||
|
updateImportDomReference(tempEl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSchemaDom(Element el) throws Exception {
|
private void updateSchemaDom(Element el) throws Exception {
|
||||||
Element tempEl = DOMUtils.getFirstChildElement(el);
|
Element tempEl = DOMUtils.getFirstChildElement(el);
|
||||||
|
|
||||||
|
@ -444,6 +507,19 @@ public class WsdlQueryHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateImportDomReference(Element tempEl) throws Exception {
|
||||||
|
String locationURI = DOMUtils.getAttribute(tempEl, Constants.ATTR_LOCATION);
|
||||||
|
if (locationURI != null) {
|
||||||
|
if (mLog.isLoggable(Level.FINE)) {
|
||||||
|
mLog.log(Level.FINE, "nlocationURI = " + locationURI);
|
||||||
|
}
|
||||||
|
String result = getResultUrl(locationURI);
|
||||||
|
|
||||||
|
setAttribute(tempEl, Constants.ATTR_LOCATION, result);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSchemaDomReference(Element tempEl) throws Exception {
|
private void updateSchemaDomReference(Element tempEl) throws Exception {
|
||||||
String locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
|
String locationURI = DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION);
|
||||||
if (locationURI != null) {
|
if (locationURI != null) {
|
||||||
|
@ -468,13 +544,4 @@ public class WsdlQueryHelper {
|
||||||
private String getlocalhostFQDN() {
|
private String getlocalhostFQDN() {
|
||||||
return localhostFQDN;
|
return localhostFQDN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param args
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import com.ibm.wsdl.extensions.schema.SchemaImpl;
|
||||||
*/
|
*/
|
||||||
public class WsdlQueryHelperTest extends TestCase {
|
public class WsdlQueryHelperTest extends TestCase {
|
||||||
|
|
||||||
private CoyoteRequest req = new DummyCoyoteRequest();
|
private CoyoteRequest req = new WsdlQueryHelperTest.DummyCoyoteRequest();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +50,7 @@ public class WsdlQueryHelperTest extends TestCase {
|
||||||
|
|
||||||
System.out.println(new String(baos.toByteArray()));
|
System.out.println(new String(baos.toByteArray()));
|
||||||
|
|
||||||
WsdlQueryHelper helper = new WsdlQueryHelper(req, 9080, def, true);
|
WsdlQueryHelper helper = new WsdlQueryHelper(req, 9080, baos, true);
|
||||||
ByteBuffer buffer = helper.getServiceDescriptorAsByteBuffer();
|
ByteBuffer buffer = helper.getServiceDescriptorAsByteBuffer();
|
||||||
|
|
||||||
System.out.println(new String(buffer.array()));
|
System.out.println(new String(buffer.array()));
|
||||||
|
|
Loading…
Reference in New Issue