use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class MailClient method main.
public static void main(String[] args) throws AxisFault {
Options options = new Options();
options.setTo(new EndpointReference(toEpr));
options.setAction("urn:echo");
ServiceClient servicClient = new ServiceClient();
servicClient.setOptions(options);
servicClient.sendRobust(getPayload());
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class RESTSearchModel method searchYahoo.
public String searchYahoo(String query, String format) {
try {
snippet = beginHTML;
String epr = "http://search.yahooapis.com/WebSearchService/V1/webSearch";
ServiceClient client = new ServiceClient();
Options options = new Options();
client.setOptions(options);
options.setTo(new EndpointReference(epr));
options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.HTTP_METHOD, Constants.Configuration.HTTP_METHOD_GET);
options.setProperty(Constants.Configuration.MESSAGE_TYPE, org.apache.axis2.kernel.http.HTTPConstants.MEDIA_TYPE_X_WWW_FORM);
// if post is through GET of HTTP
OMElement response = client.sendReceive(getPayloadForYahooSearchCall(query, format));
generateSnippet(response);
return snippet;
} catch (Exception e) {
e.printStackTrace();
snippet = "<H2>Error occurred during the invocation to Yahoo search service</H2>" + "<p>" + e.getMessage() + "</p>" + endHTML;
}
return null;
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class ServiceDelegate method createDispatch.
@Override
public <T> Dispatch<T> createDispatch(EndpointReference jaxwsEPR, Class<T> type, Mode mode, WebServiceFeature... features) {
if (log.isDebugEnabled()) {
log.debug("Create Dispatch with epr: " + jaxwsEPR);
}
verifyServiceDescriptionActive();
if (jaxwsEPR == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNoEndpointReference"));
}
if (!isValidDispatchType(type)) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchInvalidType"));
}
if (!isValidDispatchTypeWithMode(type, mode)) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchInvalidTypeWithMode"));
}
org.apache.axis2.addressing.EndpointReference axis2EPR = EndpointReferenceUtils.createAxis2EndpointReference("");
String addressingNamespace = null;
try {
addressingNamespace = EndpointReferenceUtils.convertToAxis2(axis2EPR, jaxwsEPR);
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("invalidEndpointReference", e.toString()));
}
EndpointDescription endpointDesc = DescriptionFactory.updateEndpoint(serviceDescription, null, axis2EPR, addressingNamespace, DescriptionFactory.UpdateType.CREATE_DISPATCH, this);
if (endpointDesc == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointDescriptionConstructionFailure", jaxwsEPR.toString()));
}
XMLDispatch<T> dispatch = new XMLDispatch<T>(this, endpointDesc, axis2EPR, addressingNamespace, features);
if (mode != null) {
dispatch.setMode(mode);
} else {
dispatch.setMode(Service.Mode.PAYLOAD);
}
if (serviceClient == null)
serviceClient = getServiceClient(endpointDesc.getPortQName());
dispatch.setServiceClient(serviceClient);
dispatch.setType(type);
return dispatch;
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class Provider method getPort.
@Override
public <T> T getPort(EndpointReference jaxwsEPR, Class<T> sei, WebServiceFeature... features) {
if (jaxwsEPR == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("dispatchNoEndpointReference2"));
}
if (sei == null) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("getPortInvalidSEI", jaxwsEPR.toString(), "null"));
}
org.apache.axis2.addressing.EndpointReference axis2EPR = EndpointReferenceUtils.createAxis2EndpointReference("");
String addressingNamespace = null;
try {
addressingNamespace = EndpointReferenceUtils.convertToAxis2(axis2EPR, jaxwsEPR);
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("invalidEndpointReference", e.toString()));
}
org.apache.axis2.jaxws.spi.ServiceDelegate serviceDelegate = null;
try {
ServiceName serviceName = EndpointReferenceHelper.getServiceNameMetadata(axis2EPR, addressingNamespace);
WSDLLocation wsdlLocation = EndpointReferenceHelper.getWSDLLocationMetadata(axis2EPR, addressingNamespace);
URL wsdlLocationURL = null;
if (wsdlLocation.getLocation() != null) {
wsdlLocationURL = new URL(wsdlLocation.getLocation());
if (log.isDebugEnabled()) {
log.debug("getPort: Using EPR wsdlLocationURL = " + wsdlLocationURL);
}
} else {
wsdlLocationURL = new URL(axis2EPR.getAddress() + "?wsdl");
if (log.isDebugEnabled()) {
log.debug("getPort: Using default wsdlLocationURL = " + wsdlLocationURL);
}
}
serviceDelegate = new org.apache.axis2.jaxws.spi.ServiceDelegate(wsdlLocationURL, serviceName.getName(), Service.class);
} catch (Exception e) {
throw ExceptionFactory.makeWebServiceException(Messages.getMessage("endpointUpdateError"), e);
}
return serviceDelegate.getPort(axis2EPR, addressingNamespace, sei, features);
}
use of org.apache.axis2.addressing.EndpointReference in project axis-axis2-java-core by apache.
the class RequestURIBasedServiceDispatcherTest method testFindService.
public void testFindService() throws AxisFault {
MessageContext messageContext;
// Global services
AxisService as1 = new AxisService("Service1");
AxisService as2 = new AxisService("Service2");
as1.addEndpoint("Service1Endpoint", new AxisEndpoint());
// Hierarchical Services
AxisService as3 = new AxisService("foo/bar/Version");
AxisService as4 = new AxisService("foo/bar/1.0.1/Echo");
as3.addEndpoint("VersionEndpoint", new AxisEndpoint());
as4.addEndpoint("EchoEndpoint", new AxisEndpoint());
ConfigurationContext cc = ConfigurationContextFactory.createEmptyConfigurationContext();
AxisConfiguration ac = cc.getAxisConfiguration();
ac.addService(as1);
ac.addService(as2);
ac.addService(as3);
ac.addService(as4);
RequestURIBasedServiceDispatcher ruisd = new RequestURIBasedServiceDispatcher();
/**
* Tests for global services
*/
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2"));
ruisd.invoke(messageContext);
assertEquals(as2, messageContext.getAxisService());
// service/operation scenario
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2/getName"));
ruisd.invoke(messageContext);
assertEquals(as2, messageContext.getAxisService());
// REST scenario
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service2/student/name/peter/age/25"));
ruisd.invoke(messageContext);
assertEquals(as2, messageContext.getAxisService());
// service.endpoint scenario
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service1.Service1Endpoint"));
ruisd.invoke(messageContext);
assertEquals(as1, messageContext.getAxisService());
// service.endpoint/operation scenario
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/Service1.Service1Endpoint/getName"));
ruisd.invoke(messageContext);
assertEquals(as1, messageContext.getAxisService());
/**
* Tests for hierarchical services
*/
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version"));
ruisd.invoke(messageContext);
assertEquals(as3, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version/getVersion"));
ruisd.invoke(messageContext);
assertEquals(as3, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version/student/name/peter/age/25"));
ruisd.invoke(messageContext);
assertEquals(as3, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version.VersionEndpoint"));
ruisd.invoke(messageContext);
assertEquals(as3, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/Version.VersionEndpoint/getVersion"));
ruisd.invoke(messageContext);
assertEquals(as3, messageContext.getAxisService());
/**
* Tests for hierarchical services with '.' in the service name
*/
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo"));
ruisd.invoke(messageContext);
assertEquals(as4, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo/echo"));
ruisd.invoke(messageContext);
assertEquals(as4, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo/student/name/peter/age/25"));
ruisd.invoke(messageContext);
assertEquals(as4, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint"));
ruisd.invoke(messageContext);
assertEquals(as4, messageContext.getAxisService());
messageContext = cc.createMessageContext();
messageContext.setTo(new EndpointReference("http://127.0.0.1:8080" + "/axis2/services/foo/bar/1.0.1/Echo.EchoEndpoint/echo"));
ruisd.invoke(messageContext);
assertEquals(as4, messageContext.getAxisService());
}
Aggregations