use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class LocalTransportTest method test.
@Test
public void test() throws Exception {
ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromURIs(LocalTransportTest.class.getResource("axis2.xml"), null);
AxisService service = new AxisService("Echo");
AxisOperation operation = new InOutAxisOperation(new QName("echo"));
operation.setMessageReceiver(new EchoMessageReceiver());
service.addOperation(operation);
service.addParameter(AxisService.SUPPORT_SINGLE_OP, true);
configurationContext.getAxisConfiguration().addService(service);
OMFactory factory = OMAbstractFactory.getOMFactory();
OMElement requestElement = factory.createOMElement("test", "urn:test", "t");
requestElement.setText("Hi there!");
Options options = new Options();
options.setTo(new EndpointReference("local://localhost/axis2/services/Echo"));
ServiceClient serviceClient = new ServiceClient(configurationContext, null);
serviceClient.setOptions(options);
OMElement responseElement = serviceClient.sendReceive(requestElement);
XMLAssert.assertXMLEqual(requestElement.toString(), responseElement.toString());
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class AxisInvocationController method initOperationClient.
private void initOperationClient(OperationClient opClient, MessageContext requestMsgCtx) {
org.apache.axis2.context.MessageContext axisRequest = requestMsgCtx.getAxisMessageContext();
// , axisRequest.getOptions());
setupProperties(requestMsgCtx);
if (opClient != null) {
Options options = opClient.getOptions();
// Get the target endpoint address and setup the TO endpoint
// reference. This tells us where the request is going.
EndpointReference toEPR = axisRequest.getTo();
if (toEPR == null) {
String targetUrl = (String) requestMsgCtx.getProperty(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
toEPR = new EndpointReference(targetUrl);
}
options.setTo(toEPR);
// Get the SOAP Action (if needed)
String soapAction = ClientUtils.findSOAPAction(requestMsgCtx);
options.setAction(soapAction);
// get the timeout from the request message context options as it may have been
// set by the user; if it was not set by the user we will just be setting the
// timeout on the operation client to the default so it will not have a negative
// effect; this logic is reliant on the fact the JAX-WS MessageContext is delegating
// to the Axis2 Options object and not storing its own property bag
long timeout = axisRequest.getOptions().getTimeOutInMilliSeconds();
options.setTimeOutInMilliSeconds(timeout);
// of the response in the response MessageContext.
try {
// Set the Axis2 request MessageContext
opClient.addMessageContext(axisRequest);
} catch (Exception e) {
// TODO: Do something
}
}
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class Axis2EndpointReferenceFactoryImpl method createEndpointReference.
/*
* (non-Javadoc)
* @see org.apache.axis2.jaxws.addressing.factory.Axis2EndpointReferenceFactory#createEndpointReference(java.lang.String, javax.xml.namespace.QName, javax.xml.namespace.QName, java.lang.String, java.lang.String)
*/
public EndpointReference createEndpointReference(String address, QName serviceName, QName portName, String wsdlDocumentLocation, String addressingNamespace) {
EndpointReference axis2EPR = null;
if (address != null) {
if (serviceName == null && portName != null) {
throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr", portName.toString()));
}
axis2EPR = createEndpointReference(address);
} else if (serviceName != null && portName != null) {
axis2EPR = createEndpointReference(serviceName, portName);
} else {
throw new IllegalStateException(Messages.getMessage("axisEndpointReferenceFactoryErr2"));
}
// should simply use those.
try {
// This code is locate here instead of in the createEndpointReference(QName, QName)
// method so that if the address is also specified the EPR metadata will still be
// filled in correctly.
EndpointReferenceUtils.addService(axis2EPR, serviceName, portName, addressingNamespace);
if (wsdlDocumentLocation != null) {
URL wsdlURL;
try {
wsdlURL = new URL(wsdlDocumentLocation);
} catch (MalformedURLException e) {
// just to keep it clean:
if (axis2EPR.getAddress().endsWith("/") && wsdlDocumentLocation.startsWith("/")) {
wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation.substring(1);
} else if (axis2EPR.getAddress().endsWith("/")) {
String eprAddress = axis2EPR.getAddress();
wsdlDocumentLocation = eprAddress.substring(0, eprAddress.length() - 1) + wsdlDocumentLocation;
} else {
wsdlDocumentLocation = axis2EPR.getAddress() + wsdlDocumentLocation;
}
}
wsdlURL = new URL(wsdlDocumentLocation);
// This is a temporary usage, so use a memory sensitive wrapper
WSDLWrapper wrapper = new WSDL4JWrapper(wsdlURL, true, 2);
if (serviceName != null) {
QName serviceNameNoTrailingSlash = new QName("");
// TODO: why in the world would we have to do this?
if (serviceName.getNamespaceURI().endsWith("/")) {
String ns = serviceName.getNamespaceURI();
serviceNameNoTrailingSlash = new QName(ns.substring(0, ns.length() - 1), serviceName.getLocalPart());
}
if ((wrapper.getService(serviceName) == null) && (wrapper.getService(serviceNameNoTrailingSlash) == null)) {
throw new IllegalStateException(Messages.getMessage("MissingServiceName", serviceName.toString(), wsdlDocumentLocation));
}
if (portName != null) {
String[] ports = wrapper.getPorts(serviceName);
// search the other name. TODO: again, why do we have to do this?
if (ports == null) {
ports = wrapper.getPorts(serviceNameNoTrailingSlash);
}
String portLocalName = portName.getLocalPart();
boolean found = false;
if (ports != null) {
for (String port : ports) {
// TODO: axis2 perhaps is deploying with "TypeImplPort" appended, but not reading/honoring the WSDL?
if (port.equals(portLocalName) || (port + "TypeImplPort").equals(portLocalName)) {
log.debug("found port: " + port);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalStateException(Messages.getMessage("MissingPortName", portName.toString(), wsdlDocumentLocation));
}
log.debug("Setting wsdlDocumentLocation to " + wsdlDocumentLocation + " for EndpointReference at port " + portName);
EndpointReferenceUtils.addLocation(axis2EPR, portName.getNamespaceURI(), wsdlDocumentLocation, addressingNamespace);
}
}
}
} catch (IllegalStateException ise) {
throw ise;
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointRefCreationError"), e);
}
return axis2EPR;
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class EndpointReferenceUtils method addService.
/**
* @param axis2EPR
* @param service
* @param port
* @param addressingNamespace
* @throws Exception
*/
public static void addService(EndpointReference axis2EPR, QName service, QName port, String addressingNamespace) throws Exception {
if (service != null && port != null) {
ServiceName serviceName = new ServiceName(service, port.getLocalPart());
EndpointReferenceHelper.setServiceNameMetadata(omFactory, axis2EPR, addressingNamespace, serviceName);
}
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class EndpointReferenceUtils method addLocation.
/**
* @param axis2EPR
* @param targetNamespace
* @param wsdlDocumentLocation
* @param addressingNamespace
* @throws Exception
*/
public static void addLocation(EndpointReference axis2EPR, String targetNamespace, String wsdlDocumentLocation, String addressingNamespace) throws Exception {
if (targetNamespace != null && wsdlDocumentLocation != null) {
WSDLLocation wsdlLocation = new WSDLLocation(targetNamespace, wsdlDocumentLocation);
EndpointReferenceHelper.setWSDLLocationMetadata(omFactory, axis2EPR, addressingNamespace, wsdlLocation);
}
}
Aggregations